class GoogleCloudReplicaPool

Public Class Methods

new(project_name, app_name, credentials_path) click to toggle source
# File lib/infrastructure/google_cloud_platform/google_cloud_replica_pool.rb, line 3
def initialize(project_name, app_name, credentials_path)
    @project_name = project_name
    @app_name = app_name

    @client = Google::APIClient.new(
        :application_name => 'docker-publish',
        :application_version => '0.0.2'
    )

    json_key = JSON.parse(File.read(credentials_path))
    gauth = {
        token_credential_uri: 'https://accounts.google.com/o/oauth2/token',
        audience: 'https://accounts.google.com/o/oauth2/token',
        scope: 'https://www.googleapis.com/auth/compute',
        issuer: json_key['client_email'],
        signing_key: OpenSSL::PKey::RSA.new(json_key['private_key'])
    }
    @client.authorization = Signet::OAuth2::Client.new(gauth)
    @client.authorization.fetch_access_token!

    @replica_pool = @client.discovered_api('replicapool', 'v1beta2')
end

Public Instance Methods

create_instance_group(template_uri, zone, size) click to toggle source
# File lib/infrastructure/google_cloud_platform/google_cloud_replica_pool.rb, line 26
def create_instance_group(template_uri, zone, size)
    result = @client.execute(
        :api_method => @replica_pool.instance_group_managers.insert,
        :parameters => {
            :project => @project_name,
            :zone => zone,
            :size => size
        },
        :body_object => {
            name: @app_name,
            instanceTemplate: template_uri,
            baseInstanceName: @app_name
        }
    )

    puts result.response.body

    result
end