Class: GoogleCloud

Inherits:
Provider show all
Defined in:
lib/open-dock/providers/google_cloud.rb

Instance Method Summary collapse

Methods inherited from Provider

#initialize

Constructor Details

This class inherits a constructor from Provider

Instance Method Details

#create(config) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/open-dock/providers/google_cloud.rb', line 8

def create(config)
  say "Creating Disk and Server instance, please wait ..."
  disk = @connection.disks.create name: config["name"].parameterize,
                                  size_gb: config["disk_size_gb"],
                                  zone_name: config["zone_name"],
                                  source_image: config["source_image"]
  disk.wait_for{ disk.ready? }
  server = @connection.servers.bootstrap name: config["name"].parameterize,
                                         machine_type: config["machine_type"],
                                         zone_name: config["zone_name"],
                                         disks: [disk.get_as_boot_disk(true)],
                                         user: config["user"],
                                         public_key_path: File.expand_path(config["public_key_path"])
  server.wait_for{ server.ready? }
  server.set_disk_auto_delete true, server.disks[0]["deviceName"]

  ip = server.network_interfaces[0]["accessConfigs"][0]["natIP"]
  say "Instance #{config["name"]} (IP: #{ip}) successfully created!"
end

#delete(host) ⇒ Object



28
29
30
31
32
33
34
35
36
# File 'lib/open-dock/providers/google_cloud.rb', line 28

def delete(host)
  server = @connection.servers.get(host.parameterize)
  if server
    server.destroy
    say "Instance #{host} successfully deleted!"
  else
    raise "Instance #{host} does not exist in your Google account"
  end
end

#list_paramsObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/open-dock/providers/google_cloud.rb', line 38

def list_params
  say "\nZones"
  @connection.zones.each do |i|
    say "   - #{i.name}"
  end

  say "\nMachine types:"
  @connection.flavors.group_by(&:zone).each do |zone, flavors|
    say "    Zone #{zone}:"
    flavors.each do |i|
      say "       - #{i.name.ljust(16)} =>   #{i.description}"
    end
  end

  say "\nImages:"
  @connection.images.select{|z| z.deprecated.nil?}.each do |i|
    say "   - #{i.name.ljust(40)} =>   #{i.description}\n"
  end

end