Class: Chef::Provisioning::FogDriver::Providers::DigitalOcean
- Inherits:
-
Driver
- Object
- Provisioning::Driver
- Driver
- Chef::Provisioning::FogDriver::Providers::DigitalOcean
show all
- Defined in:
- lib/chef/provisioning/fog_driver/providers/digitalocean.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
Class Method Details
.compute_options_for(provider, id, config) ⇒ Object
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
# File 'lib/chef/provisioning/fog_driver/providers/digitalocean.rb', line 99
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: { version: :v2 } },
machine_options: { bootstrap_options: {}, ssh_options: {} }
}
result = Cheffish::MergedConfig.new(new_config, config, new_defaults)
new_compute_options[:digitalocean_token] = id if id && id != ""
[result, new_compute_options[:digitalocean_token]]
end
|
Instance Method Details
#bootstrap_options_for(action_handler, machine_spec, machine_options) ⇒ Object
23
24
25
26
27
28
29
30
31
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
# File 'lib/chef/provisioning/fog_driver/providers/digitalocean.rb', line 23
def bootstrap_options_for(action_handler, machine_spec, machine_options)
bootstrap_options = symbolize_keys(machine_options[:bootstrap_options] || {})
if bootstrap_options[:key_path] || bootstrap_options[:key_name]
bootstrap_options[:key_name] ||= File.basename(bootstrap_options[:key_path])
driver = self
Provisioning.inline_resource(action_handler) do
fog_key_pair bootstrap_options[:key_name] do
private_key_path bootstrap_options[:key_path]
driver driver
end
end
else
bootstrap_options[:key_name] ||= overwrite_default_key_willy_nilly(action_handler, machine_spec)
end
bootstrap_options[:tags] = default_tags(machine_spec, bootstrap_options[:tags] || {})
if !bootstrap_options[:image_id] && !bootstrap_options[:image]
if !bootstrap_options[:image_distribution] && !bootstrap_options[:image_name]
bootstrap_options[:image_distribution] = "CentOS"
bootstrap_options[:image_name] = "6.5 x64"
end
distributions = compute.images.select { |image| image.distribution == bootstrap_options[:image_distribution] }
if distributions.empty?
raise "No images on DigitalOcean with distribution #{bootstrap_options[:image_distribution].inspect}"
end
images = distributions.select { |image| image.name == bootstrap_options[:image_name] } if bootstrap_options[:image_name]
if images.empty?
raise "No images on DigitalOcean with distribution #{bootstrap_options[:image_distribution].inspect} and name #{bootstrap_options[:image_name].inspect}"
end
bootstrap_options[:image] = images.first.id
end
if !bootstrap_options[:flavor_id] && !bootstrap_options[:size]
bootstrap_options[:flavor_name] ||= "512MB"
flavors = compute.flavors.select do |f|
f.slug.casecmp(bootstrap_options[:flavor_name]).zero?
end
if flavors.empty?
raise "Could not find flavor named '#{bootstrap_options[:flavor_name]}' on #{driver_url}"
end
bootstrap_options[:size] = flavors.first.slug
end
unless bootstrap_options[:region]
bootstrap_options[:region_name] ||= "San Francisco 1"
regions = compute.regions.select { |region| region.name == bootstrap_options[:region_name] }
if regions.empty?
raise "Could not find region named '#{bootstrap_options[:region_name]}' on #{driver_url}"
end
bootstrap_options[:region] = regions.first.slug
end
keys = compute.ssh_keys.select { |k| k.name == bootstrap_options[:key_name] }
if keys.empty?
raise "Could not find key named '#{bootstrap_options[:key_name]}' on #{driver_url}"
end
found_key = keys.first
bootstrap_options[:ssh_keys] ||= [found_key.id]
bootstrap_options[:name] = machine_spec.name
bootstrap_options[:version] ||= :v2
bootstrap_options
end
|
#converge_floating_ips(action_handler, machine_spec, machine_options, server) ⇒ Object
19
20
21
|
# File 'lib/chef/provisioning/fog_driver/providers/digitalocean.rb', line 19
def converge_floating_ips(action_handler, machine_spec, machine_options, server)
end
|
#convergence_strategy_for(machine_spec, machine_options) ⇒ Object
13
14
15
16
17
|
# File 'lib/chef/provisioning/fog_driver/providers/digitalocean.rb', line 13
def convergence_strategy_for(machine_spec, machine_options)
machine_options = Cheffish::MergedConfig.new(machine_options,
convergence_options: { ohai_hints: { "digital_ocean" => {} } })
super(machine_spec, machine_options)
end
|
#creator ⇒ Object
9
10
11
|
# File 'lib/chef/provisioning/fog_driver/providers/digitalocean.rb', line 9
def creator
""
end
|
#destroy_machine(action_handler, machine_spec, machine_options) ⇒ Object
87
88
89
90
91
92
93
94
95
96
97
|
# File 'lib/chef/provisioning/fog_driver/providers/digitalocean.rb', line 87
def destroy_machine(action_handler, machine_spec, machine_options)
server = server_for(machine_spec)
if server && server.status != "archive"
action_handler.perform_action "destroy machine #{machine_spec.name} (#{machine_spec.location['server_id']} at #{driver_url})" do
server.delete
end
end
machine_spec.location = nil
strategy = convergence_strategy_for(machine_spec, machine_options)
strategy.cleanup_convergence(action_handler, machine_spec)
end
|