Class: OCCIClient::Client
- Inherits:
-
Object
- Object
- OCCIClient::Client
- Defined in:
- lib/deltacloud/drivers/opennebula/occi_client.rb
Overview
Client Library to interface with the OpenNebula OCCI Service
Instance Attribute Summary collapse
-
#endpoint ⇒ Object
Returns the value of attribute endpoint.
Instance Method Summary collapse
-
#delete_image(id) ⇒ Object
:id VM identifier.
-
#delete_network(id) ⇒ Object
:id VM identifier.
-
#delete_vm(id) ⇒ Object
:id Compute identifier.
-
#get_image(id) ⇒ Object
Retieves an Image :image_uuid Image identifier.
-
#get_images(verbose = false) ⇒ Object
Retieves the pool of Images owned by the user.
-
#get_instance_types ⇒ Object
Retieves the available Instance types.
-
#get_network(id) ⇒ Object
Retrieves a Virtual Network :id Virtual Network identifier.
-
#get_networks ⇒ Object
Retieves the pool of Virtual Networks.
-
#get_root ⇒ Object
Pool Resource Request Methods #.
-
#get_vm(id) ⇒ Object
:id VM identifier.
-
#get_vms(verbose = false) ⇒ Object
Retieves the pool of Virtual Machines.
-
#initialize(endpoint_str = nil, user = nil, pass = nil, timeout = nil, debug_flag = true) ⇒ Client
constructor
Initialize client library.
-
#post_image(xmlfile, curb = true) ⇒ Object
Post a new Image to the Image Pool :xmlfile.
-
#post_network(xmlfile) ⇒ Object
Post a new Network to the VN Pool :xmlfile xml description of the Virtual Network.
-
#post_vms(xmlfile) ⇒ Object
Post a new VM to the VM Pool :xmlfile.
-
#put_image(xmlfile) ⇒ Object
Puts a new Storage representation in order to change its state :xmlfile Storage OCCI xml representation.
-
#put_network(xmlfile) ⇒ Object
Puts a new Network representation in order to change its state :xmlfile Network OCCI xml representation.
-
#put_vm(xmlfile) ⇒ Object
Puts a new Compute representation in order to change its state :xmlfile Compute OCCI xml representation.
Constructor Details
#initialize(endpoint_str = nil, user = nil, pass = nil, timeout = nil, debug_flag = true) ⇒ Client
Initialize client library
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# 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 |
Instance Attribute Details
#endpoint ⇒ Object
Returns the value of attribute endpoint.
32 33 34 |
# File 'lib/deltacloud/drivers/opennebula/occi_client.rb', line 32 def endpoint @endpoint end |
Instance Method Details
#delete_image(id) ⇒ Object
:id VM identifier
272 273 274 |
# File 'lib/deltacloud/drivers/opennebula/occi_client.rb', line 272 def delete_image(id) delete('/storage/'+id.to_s) end |
#delete_network(id) ⇒ Object
:id VM identifier
249 250 251 |
# File 'lib/deltacloud/drivers/opennebula/occi_client.rb', line 249 def delete_network(id) delete('/network/'+id.to_s) end |
#delete_vm(id) ⇒ Object
:id Compute identifier
226 227 228 |
# File 'lib/deltacloud/drivers/opennebula/occi_client.rb', line 226 def delete_vm(id) delete('/compute/'+id.to_s) end |
#get_image(id) ⇒ Object
Retieves an Image :image_uuid Image identifier
257 258 259 |
# File 'lib/deltacloud/drivers/opennebula/occi_client.rb', line 257 def get_image(id) get('/storage/'+id.to_s) end |
#get_images(verbose = false) ⇒ Object
Retieves the pool of Images owned by the user
199 200 201 |
# File 'lib/deltacloud/drivers/opennebula/occi_client.rb', line 199 def get_images(verbose=false) get('/storage', verbose) end |
#get_instance_types ⇒ Object
Retieves the available Instance types
71 72 73 |
# File 'lib/deltacloud/drivers/opennebula/occi_client.rb', line 71 def get_instance_types get('/instance_type?verbose=yes') end |
#get_network(id) ⇒ Object
Retrieves a Virtual Network :id Virtual Network identifier
234 235 236 |
# File 'lib/deltacloud/drivers/opennebula/occi_client.rb', line 234 def get_network(id) get('/network/'+id.to_s) end |
#get_networks ⇒ Object
Retieves the pool of Virtual Networks
101 102 103 |
# File 'lib/deltacloud/drivers/opennebula/occi_client.rb', line 101 def get_networks get('/network') end |
#get_root ⇒ Object
Pool Resource Request Methods #
64 65 66 |
# File 'lib/deltacloud/drivers/opennebula/occi_client.rb', line 64 def get_root get('/') end |
#get_vm(id) ⇒ Object
:id VM identifier
211 212 213 |
# File 'lib/deltacloud/drivers/opennebula/occi_client.rb', line 211 def get_vm(id) get('/compute/'+id.to_s) end |
#get_vms(verbose = false) ⇒ Object
Retieves the pool of Virtual Machines
86 87 88 |
# File 'lib/deltacloud/drivers/opennebula/occi_client.rb', line 86 def get_vms(verbose=false) get('/compute', verbose) end |
#post_image(xmlfile, curb = true) ⇒ Object
Post a new Image to the Image Pool :xmlfile
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
# 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.) 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.) 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_network(xmlfile) ⇒ Object
Post a new Network to the VN Pool :xmlfile xml description of the Virtual Network
94 95 96 |
# File 'lib/deltacloud/drivers/opennebula/occi_client.rb', line 94 def post_network(xmlfile) post('/network', xmlfile) end |
#post_vms(xmlfile) ⇒ Object
Post a new VM to the VM Pool :xmlfile
79 80 81 |
# File 'lib/deltacloud/drivers/opennebula/occi_client.rb', line 79 def post_vms(xmlfile) post('/compute', xmlfile) end |
#put_image(xmlfile) ⇒ Object
Puts a new Storage representation in order to change its state :xmlfile Storage OCCI xml representation
265 266 267 |
# File 'lib/deltacloud/drivers/opennebula/occi_client.rb', line 265 def put_image(xmlfile) put('/storage/', xmlfile) end |
#put_network(xmlfile) ⇒ Object
Puts a new Network representation in order to change its state :xmlfile Network OCCI xml representation
242 243 244 |
# File 'lib/deltacloud/drivers/opennebula/occi_client.rb', line 242 def put_network(xmlfile) put('/network/', xmlfile) end |
#put_vm(xmlfile) ⇒ Object
Puts a new Compute representation in order to change its state :xmlfile Compute OCCI xml representation
219 220 221 |
# File 'lib/deltacloud/drivers/opennebula/occi_client.rb', line 219 def put_vm(xmlfile) put('/compute/', xmlfile) end |