Client Library to interface with the OpenNebula OCCI Service
Initialize client library
# File lib/deltacloud/drivers/opennebula/occi_client.rb, line 35 def initialize(endpoint_str=nil, user=nil, pass=nil, debug_flag=true) @debug = debug_flag # Server location if endpoint_str @endpoint = endpoint_str elsif ENV["OCCI_URL"] @endpoint = ENV["OCCI_URL"] else @endpoint = "http://localhost:4567" end # 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
Retieves an Image :image_uuid Image identifier
# File lib/deltacloud/drivers/opennebula/occi_client.rb, line 185 def get_image(image_uuid) url = URI.parse(@endpoint+"/storage/"+image_uuid) req = Net::HTTP::Get.new(url.path) req.basic_auth @occiauth[0], @occiauth[1] res = CloudClient::http_start(url) {|http| http.request(req) } if CloudClient::is_error?(res) return res else return res.body end end
Retieves the pool of Images owned by the user
# File lib/deltacloud/drivers/opennebula/occi_client.rb, line 114 def get_images url = URI.parse(@endpoint+"/storage") req = Net::HTTP::Get.new(url.path) req.basic_auth @occiauth[0], @occiauth[1] res = CloudClient::http_start(url) {|http| http.request(req) } if CloudClient::is_error?(res) return res else return res.body end end
:id VM identifier
# File lib/deltacloud/drivers/opennebula/occi_client.rb, line 138 def get_vm(id) url = URI.parse(@endpoint+"/compute/" + id.to_s) req = Net::HTTP::Get.new(url.path) req.basic_auth @occiauth[0], @occiauth[1] res = CloudClient::http_start(url) {|http| http.request(req) } if CloudClient::is_error?(res) return res else return res.body end end
Retieves the pool of Virtual Machines
# File lib/deltacloud/drivers/opennebula/occi_client.rb, line 94 def get_vms url = URI.parse(@endpoint+"/compute") req = Net::HTTP::Get.new(url.path) req.basic_auth @occiauth[0], @occiauth[1] res = CloudClient::http_start(url) {|http| http.request(req) } if CloudClient::is_error?(res) return res else return res.body end end
Post a new VM to the VM Pool :instance_type :xmlfile
# File lib/deltacloud/drivers/opennebula/occi_client.rb, line 70 def post_vms(xmlfile) xml=File.read(xmlfile) url = URI.parse(@endpoint+"/compute") req = Net::HTTP::Post.new(url.path) req.body=xml req.basic_auth @occiauth[0], @occiauth[1] res = CloudClient::http_start(url) do |http| http.request(req) end if CloudClient::is_error?(res) return res else return res.body end 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 159 def put_vm(xmlfile) xml=File.read(xmlfile) vm_info=REXML::Document.new(xml).root.elements url = URI.parse(@endpoint+'/compute/' + vm_info['ID'].text) req = Net::HTTP::Put.new(url.path) req.body = xml req.basic_auth @occiauth[0], @occiauth[1] res = CloudClient::http_start(url) do |http| http.request(req) end if CloudClient::is_error?(res) return res else return res.body end end
Generated with the Darkfish Rdoc Generator 2.