Class: Chef::Provisioning::FogDriver::Providers::Google

Inherits:
Driver
  • Object
show all
Defined in:
lib/chef/provisioning/fog_driver/providers/google.rb

Constant Summary

Constants inherited from Driver

Driver::DEFAULT_OPTIONS, Driver::RETRYABLE_ERRORS, Driver::RETRYABLE_OPTIONS

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Driver

__new__, #allocate_machine, #allocate_machines, canonicalize_url, #compute, #compute_options, #connect_to_machine, #create_volume, #destroy_volume, from_provider, from_url, #image_for, inherited, #initialize, new, #provider, provider_class_for, #ready_machine, register_provider_class, #stop_machine, #transport_for

Constructor Details

This class inherits a constructor from Chef::Provisioning::FogDriver::Driver

Class Method Details

.compute_options_for(provider, _id, config) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/chef/provisioning/fog_driver/providers/google.rb', line 77

def self.compute_options_for(provider, _id, config)
  new_compute_options = {}
  new_compute_options[:provider] = provider
  new_config = { driver_options: { compute_options: new_compute_options } }
  new_defaults = {
    driver_options: { compute_options: {} },
    machine_options: { bootstrap_options: {}, ssh_options: {} }
  }
  result = Cheffish::MergedConfig.new(new_config, config, new_defaults)

  [result, ""]
end

Instance Method Details

#bootstrap_options_for(_action_handler, machine_spec, machine_options) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/chef/provisioning/fog_driver/providers/google.rb', line 32

def bootstrap_options_for(_action_handler, machine_spec, machine_options)
  bootstrap_options = symbolize_keys(machine_options[:bootstrap_options] || {})
  bootstrap_options[:image_name] ||= "debian-7-wheezy-v20150325"
  bootstrap_options[:machine_type] ||= "n1-standard-1"
  bootstrap_options[:zone_name] ||= "europe-west1-b"
  bootstrap_options[:name] ||= machine_spec.name
  bootstrap_options[:disk_size] ||= 10
  disk_type_prefix = "https://www.googleapis.com/compute/v1/projects/#{compute_options[:google_project]}/zones/#{bootstrap_options[:zone_name]}/diskTypes/"
  standard_disk_type = disk_type_prefix + "pd-standard"
  bootstrap_options[:disk_type] = if bootstrap_options[:disk_type].nil?
                                    standard_disk_type
                                  else
                                    disk_type_prefix + bootstrap_options[:disk_type]
                                  end

  if bootstrap_options[:disks].nil?
    # create the persistent boot disk
    disk_defaults = {
      name: machine_spec.name,
      size_gb: bootstrap_options[:disk_size],
      zone_name: bootstrap_options[:zone_name],
      source_image: bootstrap_options[:image_name],
      type: bootstrap_options[:disk_type]
    }

    disk = compute.disks.create(disk_defaults)
    disk.wait_for { disk.ready? }
    bootstrap_options[:disks] = [disk]
  end

  bootstrap_options
end

#converge_floating_ips(action_handler, machine_spec, machine_options, server) ⇒ Object



18
# File 'lib/chef/provisioning/fog_driver/providers/google.rb', line 18

def converge_floating_ips(action_handler, machine_spec, machine_options, server); end

#convergence_strategy_for(machine_spec, machine_options) ⇒ Object



12
13
14
15
16
# File 'lib/chef/provisioning/fog_driver/providers/google.rb', line 12

def convergence_strategy_for(machine_spec, machine_options)
  machine_options = Cheffish::MergedConfig.new(machine_options,
                                               convergence_options: { ohai_hints: { "gce" => {} } })
  super(machine_spec, machine_options)
end

#creatorObject



8
9
10
# File 'lib/chef/provisioning/fog_driver/providers/google.rb', line 8

def creator
  ""
end

#destroy_machine(action_handler, machine_spec, machine_options) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
# File 'lib/chef/provisioning/fog_driver/providers/google.rb', line 65

def destroy_machine(action_handler, machine_spec, machine_options)
  server = server_for(machine_spec)
  if server && server.state != "archive"
    action_handler.perform_action "destroy machine #{machine_spec.name} (#{machine_spec.location['server_id']} at #{driver_url})" do
      server.destroy
    end
  end
  machine_spec.location = nil
  strategy = convergence_strategy_for(machine_spec, machine_options)
  strategy.cleanup_convergence(action_handler, machine_spec)
end

#server_for(machine_spec) ⇒ Object



20
21
22
# File 'lib/chef/provisioning/fog_driver/providers/google.rb', line 20

def server_for(machine_spec)
  compute.servers.get(machine_spec.name) if machine_spec.name
end

#servers_for(machine_specs) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/chef/provisioning/fog_driver/providers/google.rb', line 24

def servers_for(machine_specs)
  result = {}
  machine_specs.each do |machine_spec|
    result[machine_spec] = server_for(machine_spec)
  end
  result
end