Class: Deltacloud::Drivers::Opennebula::OpennebulaDriver
- Inherits:
-
BaseDriver
- Object
- BaseDriver
- Deltacloud::Drivers::Opennebula::OpennebulaDriver
show all
- Defined in:
- lib/deltacloud/drivers/opennebula/opennebula_driver.rb
Constant Summary
collapse
- OCCI_VM =
TBD Add Context to the VMs
%q{
<COMPUTE>
<% if opts[:name] %>
<NAME><%=opts[:name]%></NAME>
<% end %>
<INSTANCE_TYPE><%= opts[:hwp_id] || 'small' %></INSTANCE_TYPE>
<DISK>
<STORAGE href="<%= storage_href %>" />
</DISK>
</COMPUTE>
}
- OCCI_ACTION =
%q{
<COMPUTE>
<ID><%= id %></ID>
<STATE><%= strstate %></STATE>
</COMPUTE>
}
- VM_STATES =
{
"INIT" => "START",
"PENDING" => "PENDING",
"HOLD" => "STOPPED",
"ACTIVE" => "RUNNING",
"STOPPED" => "STOPPED",
"SUSPENDED" => "STOPPED",
"DONE" => "FINISHED",
"FAILED" => "FINISHED"
}
Constants inherited
from BaseDriver
BaseDriver::MEMBER_SHOW_METHODS, BaseDriver::STATE_MACHINE_OPTS
Instance Method Summary
collapse
-
#create_instance(credentials, image_id, opts = nil) ⇒ Object
-
#destroy_image(credentials, id) ⇒ Object
-
#destroy_instance(credentials, id) ⇒ Object
-
#hardware_profiles(credentials, opts = nil) ⇒ Object
-
#image(credentials, opts = nil) ⇒ Object
-
#images(credentials, opts = nil) ⇒ Object
-
#instance(credentials, opts = nil) ⇒ Object
-
#instances(credentials, opts = nil) ⇒ Object
-
#realms(credentials, opts = nil) ⇒ Object
-
#reboot_instance(credentials, id) ⇒ Object
-
#start_instance(credentials, id) ⇒ Object
-
#stop_instance(credentials, id) ⇒ Object
Methods inherited from BaseDriver
#address, #api_provider, #blob, #bucket, #catched_exceptions_list, #configured_providers, constraints, define_hardware_profile, define_instance_states, driver_name, feature, features, #filter_hardware_profiles, #filter_on, #find_hardware_profile, #firewall, #hardware_profile, hardware_profiles, #has_capability?, #has_feature?, has_feature?, #instance_actions_for, instance_state_machine, #instance_state_machine, #key, #name, #realm, #storage_snapshot, #storage_volume, #supported_collections
Methods included from Exceptions
exception_from_status, exceptions, included, logger, #safely
Instance Method Details
#create_instance(credentials, image_id, opts = nil) ⇒ Object
172
173
174
175
176
177
178
179
180
181
182
183
184
185
|
# File 'lib/deltacloud/drivers/opennebula/opennebula_driver.rb', line 172
def create_instance(credentials, image_id, opts=nil)
occi_client = new_client(credentials)
storage_href = "#{occi_client.endpoint}/storage/#{image_id}"
instancexml = ERB.new(OCCI_VM).result(binding)
instancefile = "|echo '#{instancexml}'"
xmlvm = treat_response(occi_client.post_vms(instancefile))
convert_instance(xmlvm, credentials)
end
|
#destroy_image(credentials, id) ⇒ Object
101
102
103
104
|
# File 'lib/deltacloud/drivers/opennebula/opennebula_driver.rb', line 101
def destroy_image(credentials, id)
occi_client = new_client(credentials)
treat_response(occi_client.delete_image(opts[:id]))
end
|
#destroy_instance(credentials, id) ⇒ Object
197
198
199
|
# File 'lib/deltacloud/drivers/opennebula/opennebula_driver.rb', line 197
def destroy_instance(credentials, id)
occi_action(credentials, id, 'DONE')
end
|
#hardware_profiles(credentials, opts = nil) ⇒ Object
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/deltacloud/drivers/opennebula/opennebula_driver.rb', line 35
def hardware_profiles(credentials, opts=nil)
occi_client = new_client(credentials)
xml = occi_client.get_instance_types
if CloudClient.is_error?(xml)
@hardware_profiles = ['small','medium','large'].map {|name|
::Deltacloud::HardwareProfile.new(name)
}
else
@hardware_profiles = REXML::Document.new(xml).root.elements.map {|d|
elem = d.elements
::Deltacloud::HardwareProfile.new(elem['NAME'].text) {
cpu elem['CPU'].text if elem['CPU']
memory elem['MEMORY'].text if elem['MEMORY']
storage elem['STORAGE'].text if elem['STORAGE']
architecture elem['ARCHITECTURE'].text if elem['ARCHITECTURE']
}
}
end
filter_hardware_profiles(@hardware_profiles, opts)
end
|
#image(credentials, opts = nil) ⇒ Object
95
96
97
98
99
|
# File 'lib/deltacloud/drivers/opennebula/opennebula_driver.rb', line 95
def image(credentials, opts=nil)
occi_client = new_client(credentials)
xml = treat_response(occi_client.get_image(opts[:id]))
convert_image(xml, credentials)
end
|
#images(credentials, opts = nil) ⇒ Object
84
85
86
87
88
89
90
91
92
93
|
# File 'lib/deltacloud/drivers/opennebula/opennebula_driver.rb', line 84
def images(credentials, opts=nil)
occi_client = new_client(credentials)
xml = treat_response(occi_client.get_images(true))
images = REXML::Document.new(xml).root.elements.map do |d|
convert_image(d, credentials)
end
end
|
#instance(credentials, opts = nil) ⇒ Object
166
167
168
169
170
|
# File 'lib/deltacloud/drivers/opennebula/opennebula_driver.rb', line 166
def instance(credentials, opts=nil)
occi_client = new_client(credentials)
xml = treat_response(occi_client.get_vm(opts[:id]))
convert_instance(xml, credentials)
end
|
#instances(credentials, opts = nil) ⇒ Object
154
155
156
157
158
159
160
161
162
163
164
|
# File 'lib/deltacloud/drivers/opennebula/opennebula_driver.rb', line 154
def instances(credentials, opts=nil)
occi_client = new_client(credentials)
xml = treat_response(occi_client.get_vms(true))
instances = REXML::Document.new(xml).root.elements.map do |d|
convert_instance(d, credentials)
end
instances = filter_on( instances, :state, opts )
end
|
#realms(credentials, opts = nil) ⇒ Object
73
74
75
76
77
78
|
# File 'lib/deltacloud/drivers/opennebula/opennebula_driver.rb', line 73
def realms(credentials, opts=nil)
return REALMS if ( opts.nil? )
results = REALMS
results = filter_on( results, :id, opts )
results
end
|
#reboot_instance(credentials, id) ⇒ Object
201
202
203
204
205
206
207
208
209
|
# File 'lib/deltacloud/drivers/opennebula/opennebula_driver.rb', line 201
def reboot_instance(credentials, id)
begin
occi_action(credentials, id, 'REBOOT')
rescue Exception => e
raise "Reboot action not supported"
end
end
|
#start_instance(credentials, id) ⇒ Object
187
188
189
|
# File 'lib/deltacloud/drivers/opennebula/opennebula_driver.rb', line 187
def start_instance(credentials, id)
occi_action(credentials, id, 'RESUME')
end
|
#stop_instance(credentials, id) ⇒ Object
192
193
194
|
# File 'lib/deltacloud/drivers/opennebula/opennebula_driver.rb', line 192
def stop_instance(credentials, id)
occi_action(credentials, id, 'STOPPED')
end
|