Class: Cyclid::API::Plugins::Google

Inherits:
Builder show all
Defined in:
app/cyclid/plugins/builder/google.rb

Overview

Google builder. Creates Google Compute instances.

Instance Method Summary collapse

Methods inherited from Builder

human_name

Methods inherited from Base

config?, config_schema, default_config, get_config, human_name, register_plugin, set_config, update_config

Constructor Details

#initializeGoogle

Returns a new instance of Google.



35
36
37
38
39
40
41
42
# File 'app/cyclid/plugins/builder/google.rb', line 35

def initialize
  @config = load_google_config(Cyclid.config.plugins)
  Cyclid.logger.debug "config=#{@config.inspect}"
  @api = Fog::Compute.new(provider: 'Google',
                          google_project: @config[:project],
                          google_client_email: @config[:client_email],
                          google_json_key_location: @config[:json_key_location])
end

Instance Method Details

#get(args = {}) ⇒ Object

Create & return a build host



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'app/cyclid/plugins/builder/google.rb', line 45

def get(args = {})
  args.symbolize_keys!

  Cyclid.logger.debug "google: args=#{args}"

  # If there is one, split the 'os' into a 'distro' and 'release'
  if args.key? :os
    match = args[:os].match(/\A(\w*)_(.*)\Z/)
    distro = match[1] if match
    release = match[2] if match
  else
    # No OS was specified; use the default
    # XXX Defaults should be configurable
    distro = 'ubuntu'
    release = 'trusty'
  end

  name = create_name

  source_image, size = find_source_image(distro, release)
  disk = create_disk(name, size, source_image)
  instance = create_instance(name, disk)

  Cyclid.logger.debug "instance=#{instance.inspect}"

  GoogleHost.new(name: name,
                 host: instance.public_ip_address,
                 username: @config[:username],
                 workspace: "/home/#{@config[:username]}",
                 password: nil,
                 key: @config[:ssh_private_key],
                 distro: distro,
                 release: release)
end

#release(_transport, buildhost) ⇒ Object

Destroy the build host



81
82
83
84
85
86
87
88
89
# File 'app/cyclid/plugins/builder/google.rb', line 81

def release(_transport, buildhost)
  name = buildhost['name']

  instance = @api.servers.get(name)
  raise "instance #{name} does not exist" unless instance

  Cyclid.logger.info "destroying #{name}"
  raise 'failed to destroy instance' unless instance.destroy
end