Client Library to interface with the OpenNebula OCCI Service
Initialize client library
# File lib/deltacloud/drivers/opennebula/occi_client.rb, line 37 def initialize(endpoint_str=nil, user=nil, pass=nil, timeout=nil, debug_flag=true) @debug = debug_flag @timeout = timeout # Server location @endpoint = ENV["OCCI_URL"] || endpoint_str || Proc.new(raise "No OpenNebula Provider location configured! Client needs to set \'X-Deltacloud-Provider\' HTTP request header, OR, Deltacloud server administrator must set either the OCCI_URL or API_PROVIDER environment variables") #"http://localhost:4567" # Autentication if user && pass @occiauth = [user, pass] else @occiauth = CloudClient::get_one_auth end if !@occiauth raise "No authorization data present" end @occiauth[1] = Digest::SHA1.hexdigest(@occiauth[1]) end
:id VM identifier
# File lib/deltacloud/drivers/opennebula/occi_client.rb, line 272 def delete_image(id) delete('/storage/'+id.to_s) end
:id VM identifier
# File lib/deltacloud/drivers/opennebula/occi_client.rb, line 249 def delete_network(id) delete('/network/'+id.to_s) end
:id Compute identifier
# File lib/deltacloud/drivers/opennebula/occi_client.rb, line 226 def delete_vm(id) delete('/compute/'+id.to_s) end
Retieves an Image :image_uuid Image identifier
# File lib/deltacloud/drivers/opennebula/occi_client.rb, line 257 def get_image(id) get('/storage/'+id.to_s) end
Retieves the pool of Images owned by the user
# File lib/deltacloud/drivers/opennebula/occi_client.rb, line 199 def get_images(verbose=false) get('/storage', verbose) end
Retieves the available Instance types
# File lib/deltacloud/drivers/opennebula/occi_client.rb, line 71 def get_instance_types get('/instance_type?verbose=yes') end
Retrieves a Virtual Network :id Virtual Network identifier
# File lib/deltacloud/drivers/opennebula/occi_client.rb, line 234 def get_network(id) get('/network/'+id.to_s) end
Retieves the pool of Virtual Networks
# File lib/deltacloud/drivers/opennebula/occi_client.rb, line 101 def get_networks get('/network') end
Pool Resource Request Methods #
# File lib/deltacloud/drivers/opennebula/occi_client.rb, line 64 def get_root get('/') end
:id VM identifier
# File lib/deltacloud/drivers/opennebula/occi_client.rb, line 211 def get_vm(id) get('/compute/'+id.to_s) end
Retieves the pool of Virtual Machines
# File lib/deltacloud/drivers/opennebula/occi_client.rb, line 86 def get_vms(verbose=false) get('/compute', verbose) end
Post a new Image to the Image Pool :xmlfile
# File lib/deltacloud/drivers/opennebula/occi_client.rb, line 109 def post_image(xmlfile, curb=true) xml = File.read(xmlfile) begin image_info = REXML::Document.new(xml).root rescue Exception => e error = CloudClient::Error.new(e.message) return error end if image_info.elements['URL'] file_path = image_info.elements['URL'].text m = file_path.match(/^\w+:\/\/(.*)$/) if m file_path="/"+m[1] end elsif !image_info.elements['TYPE'] == "DATABLOCK" return CloudClient::Error.new("Can not find URL") end if curb if !CURL_LOADED error_msg = "curb gem not loaded" error = CloudClient::Error.new(error_msg) return error end curl=Curl::Easy.new(@endpoint+"/storage") curl.http_auth_types = Curl::CURLAUTH_BASIC curl.userpwd = "#{@occiauth[0]}:#{@occiauth[1]}" curl.verbose = true if @debug curl.multipart_form_post = true begin postfields = Array.new postfields << Curl::PostField.content('occixml', xml) if file_path postfields << Curl::PostField.file('file', file_path) end curl.http_post(*postfields) rescue Exception => e return CloudClient::Error.new(e.message) end return curl.body_str else if !MULTIPART_LOADED error_msg = "multipart-post gem not loaded" error = CloudClient::Error.new(error_msg) return error end params=Hash.new if file_path file=File.open(file_path) params["file"]=UploadIO.new(file, 'application/octet-stream', file_path) end params['occixml'] = xml url = URI.parse(@endpoint+"/storage") req = Net::HTTP::Post::Multipart.new(url.path, params) req.basic_auth @occiauth[0], @occiauth[1] res = CloudClient::http_start(url, @timeout) do |http| http.request(req) end file.close if file_path if CloudClient::is_error?(res) return res else return res.body end end end
Post a new Network to the VN Pool :xmlfile xml description of the Virtual Network
# File lib/deltacloud/drivers/opennebula/occi_client.rb, line 94 def post_network(xmlfile) post('/network', xmlfile) end
Post a new VM to the VM Pool :xmlfile
# File lib/deltacloud/drivers/opennebula/occi_client.rb, line 79 def post_vms(xmlfile) post('/compute', xmlfile) end
Puts a new Storage representation in order to change its state :xmlfile Storage OCCI xml representation
# File lib/deltacloud/drivers/opennebula/occi_client.rb, line 265 def put_image(xmlfile) put('/storage/', xmlfile) end
Puts a new Network representation in order to change its state :xmlfile Network OCCI xml representation
# File lib/deltacloud/drivers/opennebula/occi_client.rb, line 242 def put_network(xmlfile) put('/network/', xmlfile) end
Puts a new Compute representation in order to change its state :xmlfile Compute OCCI xml representation
# File lib/deltacloud/drivers/opennebula/occi_client.rb, line 219 def put_vm(xmlfile) put('/compute/', xmlfile) end