Class: Deltacloud::Drivers::Opennebula::OpennebulaDriver

Inherits:
BaseDriver
  • Object
show all
Defined in:
lib/deltacloud/drivers/opennebula/opennebula_driver.rb

Constant Summary

Constants inherited from BaseDriver

BaseDriver::MEMBER_SHOW_METHODS

Instance Method Summary collapse

Methods inherited from BaseDriver

#blob, #bucket, #catched_exceptions_list, declare_feature, define_hardware_profile, define_instance_states, feature, feature_decl_for, feature_decls, #features, features, #features_for_operation, #filter_hardware_profiles, #filter_on, #find_hardware_profile, #hardware_profile, #hardware_profiles, hardware_profiles, #has_capability?, #has_collection?, #image, #instance, #instance_actions_for, #instance_state_machine, instance_state_machine, #key, #realm, #safely, #storage_snapshot, #storage_volume, #supported_collections

Instance Method Details

#create_instance(credentials, image_id, opts = nil) ⇒ Object



126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/deltacloud/drivers/opennebula/opennebula_driver.rb', line 126

def create_instance(credentials, image_id, opts=nil)
	occi_client = new_client(credentials)

	hwp_id = opts[:hwp_id] || 'small'

	instancexml = ERB.new(OCCI_VM).result(binding)
	instancefile = "|echo '#{instancexml}'"

	xmlvm = occi_client.post_vms(instancefile)

	convert_instance(xmlvm.to_s(), credentials)
end

#destroy_instance(credentials, id) ⇒ Object



150
151
152
# File 'lib/deltacloud/drivers/opennebula/opennebula_driver.rb', line 150

def destroy_instance(credentials, id)
	occi_action(credentials, id, 'DONE')
end

#images(credentials, opts = nil) ⇒ Object

Images



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/deltacloud/drivers/opennebula/opennebula_driver.rb', line 72

def images(credentials, opts=nil)
	occi_client = new_client(credentials)

	images = []
	imagesxml = occi_client.get_images

	storage = REXML::Document.new(imagesxml)
	storage.root.elements.each do |d|
id = d.attributes['href'].split("/").last

diskxml = occi_client.get_image(id)

images << convert_image(diskxml.to_s(), credentials)
	end
	images
end

#instances(credentials, opts = nil) ⇒ Object



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/deltacloud/drivers/opennebula/opennebula_driver.rb', line 106

def instances(credentials, opts=nil)
	occi_client = new_client(credentials)

	instances = []
	instancesxml = occi_client.get_vms

	computes = REXML::Document.new(instancesxml)
	computes.root.elements.each do |d|
vm_id = d.attributes['href'].split("/").last

computexml = occi_client.get_vm(vm_id)

instances << convert_instance(computexml.to_s(), credentials)
	end
      instances = filter_on( instances, :id, opts )
      instances = filter_on( instances, :state, opts )
	instances
end

#realms(credentials, opts = nil) ⇒ Object



60
61
62
63
64
65
# File 'lib/deltacloud/drivers/opennebula/opennebula_driver.rb', line 60

def realms(credentials, opts=nil)
	return REALMS if ( opts.nil? )
	results = REALMS
	results = filter_on( results, :id, opts )
	results
end

#start_instance(credentials, id) ⇒ Object



140
141
142
# File 'lib/deltacloud/drivers/opennebula/opennebula_driver.rb', line 140

def start_instance(credentials, id)
	occi_action(credentials, id, 'RESUME')
end

#stop_instance(credentials, id) ⇒ Object



145
146
147
# File 'lib/deltacloud/drivers/opennebula/opennebula_driver.rb', line 145

def stop_instance(credentials, id)
	occi_action(credentials, id, 'STOPPED')
end