Class: GoogleCloudCompute::ComputeAttributes

Inherits:
Object
  • Object
show all
Defined in:
app/lib/google_cloud_compute/compute_attributes.rb

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ ComputeAttributes

Returns a new instance of ComputeAttributes.



3
4
5
# File 'app/lib/google_cloud_compute/compute_attributes.rb', line 3

def initialize(client)
  @client = client
end

Instance Method Details

#for_create(instance) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'app/lib/google_cloud_compute/compute_attributes.rb', line 21

def for_create(instance)
  {
    name: instance.name,
    machine_type: "zones/#{instance.zone}/machineTypes/#{instance.machine_type}",
    disks: instance.volumes.map.with_index { |vol, i| { source: "zones/#{instance.zone}/disks/#{vol.device_name}", boot: i.zero? } },
    network_interfaces: instance.network_interfaces,
    metadata: instance.,
  }
end

#for_instance(instance) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
# File 'app/lib/google_cloud_compute/compute_attributes.rb', line 31

def for_instance(instance)
  {
    name: instance.name, hostname: instance.name,
    creation_timestamp: instance.creation_timestamp.to_datetime,
    zone_name: instance.zone.split('/').last,
    machine_type: instance.machine_type,
    network: instance.network_interfaces[0].network.split('/').last,
    network_interfaces: instance.network_interfaces,
    volumes: instance.disks, metadata: instance.
  }
end

#for_new(args) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'app/lib/google_cloud_compute/compute_attributes.rb', line 7

def for_new(args)
  name = parameterize_name(args[:name])
  network = args[:network] || 'default'
  associate_external_ip = ActiveModel::Type::Boolean.new.cast(args[:associate_external_ip])

  { name: name, hostname: name,
    machine_type: args[:machine_type],
    network: network, associate_external_ip: associate_external_ip,
    network_interfaces: construct_network(network, associate_external_ip, args[:network_interfaces] || []),
    image_id: args[:image_id],
    volumes: construct_volumes(name, args[:image_id], args[:volumes]),
    metadata: (args) }
end