Class: Fog::Compute::VcloudDirector::Real
- Inherits:
-
Object
- Object
- Fog::Compute::VcloudDirector::Real
show all
- Includes:
- Helper
- Defined in:
- lib/fog/vcloud_director/compute.rb,
lib/fog/vcloud_director/requests/compute/get_vm.rb,
lib/fog/vcloud_director/requests/compute/get_vdc.rb,
lib/fog/vcloud_director/requests/compute/get_vms.rb,
lib/fog/vcloud_director/requests/compute/get_href.rb,
lib/fog/vcloud_director/requests/compute/get_task.rb,
lib/fog/vcloud_director/requests/compute/get_vapp.rb,
lib/fog/vcloud_director/requests/compute/get_vm_cpu.rb,
lib/fog/vcloud_director/requests/compute/put_vm_cpu.rb,
lib/fog/vcloud_director/requests/compute/delete_vapp.rb,
lib/fog/vcloud_director/requests/compute/get_catalog.rb,
lib/fog/vcloud_director/requests/compute/get_network.rb,
lib/fog/vcloud_director/requests/compute/get_request.rb,
lib/fog/vcloud_director/requests/compute/get_metadata.rb,
lib/fog/vcloud_director/requests/compute/get_vm_disks.rb,
lib/fog/vcloud_director/requests/compute/put_vm_disks.rb,
lib/fog/vcloud_director/requests/compute/get_vm_memory.rb,
lib/fog/vcloud_director/requests/compute/put_vm_memory.rb,
lib/fog/vcloud_director/requests/compute/get_tasks_list.rb,
lib/fog/vcloud_director/requests/compute/get_vm_network.rb,
lib/fog/vcloud_director/requests/compute/put_vm_network.rb,
lib/fog/vcloud_director/requests/compute/delete_metadata.rb,
lib/fog/vcloud_director/requests/compute/post_vm_poweron.rb,
lib/fog/vcloud_director/requests/compute/get_catalog_item.rb,
lib/fog/vcloud_director/requests/compute/get_organization.rb,
lib/fog/vcloud_director/requests/compute/post_task_cancel.rb,
lib/fog/vcloud_director/requests/compute/post_vm_metadata.rb,
lib/fog/vcloud_director/requests/compute/post_vm_poweroff.rb,
lib/fog/vcloud_director/requests/compute/get_organizations.rb,
lib/fog/vcloud_director/requests/compute/get_vapp_template.rb,
lib/fog/vcloud_director/requests/compute/post_vapp_undeploy.rb,
lib/fog/vcloud_director/requests/compute/put_metadata_value.rb,
lib/fog/vcloud_director/requests/compute/get_current_session.rb,
lib/fog/vcloud_director/requests/compute/get_vms_by_metadata.rb,
lib/fog/vcloud_director/requests/compute/get_vm_customization.rb,
lib/fog/vcloud_director/requests/compute/put_vm_customization.rb,
lib/fog/vcloud_director/requests/compute/get_supported_versions.rb,
lib/fog/vcloud_director/requests/compute/instantiate_vapp_template.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
-
#add_id_from_href!(data = {}) ⇒ Object
-
#auth_token ⇒ Object
-
#delete_metadata(vm_id, metadata_key) ⇒ Object
-
#delete_vapp(vapp_id) ⇒ Object
-
#do_request(params) ⇒ Object
-
#generate_instantiate_vapp_template_request(options = {}) ⇒ Object
-
#get_catalog(catalog_uuid) ⇒ Object
-
#get_catalog_item(catalog_item_id) ⇒ Object
-
#get_current_session ⇒ Object
Retrieve a representation of the current session.
-
#get_href(href) ⇒ Object
-
#get_metadata(vm_id) ⇒ Object
-
#get_network(network_id) ⇒ Object
-
#get_organization(organization_id) ⇒ Object
-
#get_organizations ⇒ Object
-
#get_request(uri) ⇒ Object
-
#get_supported_versions ⇒ Object
Retrieve the supported versions.
-
#get_task(task_id) ⇒ Object
-
#get_tasks_list(tasks_list_id) ⇒ Object
-
#get_vapp(vapp_id) ⇒ Object
-
#get_vapp_template(vapp_template_id) ⇒ Object
-
#get_vdc(vdc_id) ⇒ Object
-
#get_vm(vm_id) ⇒ Object
-
#get_vm_cpu(vm_id) ⇒ Object
-
#get_vm_customization(vm_id) ⇒ Object
-
#get_vm_disks(vm_id) ⇒ Object
-
#get_vm_memory(vm_id) ⇒ Object
-
#get_vm_network(vm_id) ⇒ Object
-
#get_vms(vapp_id) ⇒ Object
-
#get_vms_by_metadata(key, value) ⇒ Object
-
#initialize(options = {}) ⇒ Real
constructor
-
#instantiate_vapp_template(vapp_name, template_id, options = {}) ⇒ Object
TODO move all the logic to a generator.
-
#make_task_object(task_response) ⇒ Object
-
#org_name ⇒ Object
-
#populate_uris(options = {}) ⇒ Object
-
#post_task_cancel(task_id) ⇒ Object
-
#post_vm_metadata(vm_id, metadata = {}) ⇒ Object
-
#post_vm_poweroff(vm_id) ⇒ Object
-
#post_vm_poweron(vm_id) ⇒ Object
-
#process_task(response_body) ⇒ Object
-
#put_metadata_value(vm_id, metadata_key, metadata_value) ⇒ Object
-
#put_vm_cpu(vm_id, num_cpus) ⇒ Object
-
#put_vm_customization(vm_id, customization = {}) ⇒ Object
-
#put_vm_disks(vm_id, disks = []) ⇒ Object
disks is the body of get_vm_disks.
-
#put_vm_memory(vm_id, memory) ⇒ Object
-
#put_vm_network(vm_id, network = {}) ⇒ Object
-
#reload ⇒ Object
-
#request(params) ⇒ Object
-
#undeploy(vapp_id) ⇒ Object
-
#validate_uris(options = {}) ⇒ Object
-
#wait_and_raise_unless_success(task) ⇒ Object
-
#xmlns ⇒ Object
Methods included from Helper
#catalog_item_end_point, #default_network_id, #default_network_name, #default_organization_body, #default_organization_id, #default_vdc_body, #default_vdc_id, #endpoint, #network_end_point, #vapp_template_end_point, #vdc_end_point
Constructor Details
#initialize(options = {}) ⇒ Real
Returns a new instance of Real.
189
190
191
192
193
194
195
196
197
198
199
200
201
|
# File 'lib/fog/vcloud_director/compute.rb', line 189
def initialize(options={})
@vcloud_director_password = options[:vcloud_director_password]
@vcloud_director_username = options[:vcloud_director_username]
@connection_options = options[:connection_options] || {}
@host = options[:vcloud_director_host]
@path = options[:path] || Fog::Compute::VcloudDirector::Defaults::PATH
@persistent = options[:persistent] || false
@port = options[:port] || Fog::Compute::VcloudDirector::Defaults::PORT
@scheme = options[:scheme] || Fog::Compute::VcloudDirector::Defaults::SCHEME
@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options)
@end_point = "#{@scheme}://#{@host}#{@path}/"
@api_version = options[:vcloud_director_api_version] || Fog::Compute::VcloudDirector::Defaults::API_VERSION
end
|
Instance Attribute Details
#api_version ⇒ Object
Returns the value of attribute api_version.
187
188
189
|
# File 'lib/fog/vcloud_director/compute.rb', line 187
def api_version
@api_version
end
|
#end_point ⇒ Object
Returns the value of attribute end_point.
187
188
189
|
# File 'lib/fog/vcloud_director/compute.rb', line 187
def end_point
@end_point
end
|
Instance Method Details
#add_id_from_href!(data = {}) ⇒ Object
279
280
281
|
# File 'lib/fog/vcloud_director/compute.rb', line 279
def add_id_from_href!(data={})
data[:id] = data[:href].split('/').last
end
|
#auth_token ⇒ Object
203
204
205
206
|
# File 'lib/fog/vcloud_director/compute.rb', line 203
def auth_token
login if @auth_token.nil?
@auth_token
end
|
6
7
8
9
10
11
12
13
14
15
|
# File 'lib/fog/vcloud_director/requests/compute/delete_metadata.rb', line 6
def delete_metadata(vm_id, metadata_key)
require 'fog/vcloud_director/parsers/compute/metadata'
request(
:expects => 202,
:method => 'DELETE',
:parser => Fog::ToHashDocument.new,
:path => "vApp/#{vm_id}/metadata/#{URI.escape(metadata_key)}"
)
end
|
#delete_vapp(vapp_id) ⇒ Object
6
7
8
9
10
11
12
13
14
|
# File 'lib/fog/vcloud_director/requests/compute/delete_vapp.rb', line 6
def delete_vapp(vapp_id)
request(
:expects => 202,
:method => 'DELETE',
:parser => Fog::ToHashDocument.new,
:path => "vApp/#{vapp_id}"
)
end
|
#do_request(params) ⇒ Object
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
|
# File 'lib/fog/vcloud_director/compute.rb', line 231
def do_request(params)
= { 'Accept' => 'application/*+xml;version=' + @api_version }
if @cookie
.merge!('Cookie' => @cookie)
end
if params[:path]
if params[:override_path] == true
path = params[:path]
else
path = "#{@path}/#{params[:path]}"
end
else
path = "#{@path}"
end
@connection.request({
:body => params[:body],
:expects => params[:expects],
:headers => .merge!(params[:headers] || {}),
:host => @host,
:method => params[:method],
:parser => params[:parser],
:path => path
})
rescue => @e
raise @e unless @e.class.to_s =~ /^Excon::Errors/
if @e.respond_to?(:response)
puts @e.response.status
puts CGI::unescapeHTML(@e.response.body)
end
raise @e
end
|
#generate_instantiate_vapp_template_request(options = {}) ⇒ Object
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
# File 'lib/fog/vcloud_director/requests/compute/instantiate_vapp_template.rb', line 51
def generate_instantiate_vapp_template_request(options ={})
xml = Builder::XmlMarkup.new
xml.InstantiateVAppTemplateParams(xmlns.merge!(:name => options[:vapp_name], :"xml:lang" => "en")) {
xml.Description(options[:description])
xml.InstantiationParams {
if options[:network_uri]
xml.NetworkConfigSection {
xml.tag!("ovf:Info"){ "Configuration parameters for logical networks" }
xml.NetworkConfig("networkName" => options[:network_name]) {
xml.Configuration {
xml.ParentNetwork(:href => options[:network_uri])
xml.FenceMode("bridged")
}
}
}
end
}
xml.Source(:href => options[:template_uri])
xml.AllEULAsAccepted("true")
}
end
|
#get_catalog(catalog_uuid) ⇒ Object
6
7
8
9
10
11
12
13
|
# File 'lib/fog/vcloud_director/requests/compute/get_catalog.rb', line 6
def get_catalog(catalog_uuid)
request(
:expects => 200,
:method => 'GET',
:parser => Fog::ToHashDocument.new,
:path => "catalog/#{catalog_uuid}"
)
end
|
#get_catalog_item(catalog_item_id) ⇒ Object
6
7
8
9
10
11
12
13
|
# File 'lib/fog/vcloud_director/requests/compute/get_catalog_item.rb', line 6
def get_catalog_item(catalog_item_id)
request(
:expects => 200,
:method => 'GET',
:parser => Fog::ToHashDocument.new,
:path => "catalogItem/#{catalog_item_id}"
)
end
|
#get_current_session ⇒ Object
Retrieve a representation of the current session.
A Session object contains one or more URLs from which you can begin browsing, as well as links to the query service and entity resolver. The list of URLs in the Session object is based on the role and privileges of the authenticated user.
A Session object expires after a configurable interval of client inactivity.
Returns
vCloud API Documentation
20
21
22
23
24
25
26
27
28
|
# File 'lib/fog/vcloud_director/requests/compute/get_current_session.rb', line 20
def get_current_session
request(
:expects => 200,
:idempotent => true,
:method => 'GET',
:parser => Fog::ToHashDocument.new,
:path => 'session'
)
end
|
#get_href(href) ⇒ Object
6
7
8
9
10
11
12
13
14
|
# File 'lib/fog/vcloud_director/requests/compute/get_href.rb', line 6
def get_href(href)
request(
:expects => 200,
:method => 'GET',
:parser => Fog::ToHashDocument.new,
:override_path => true,
:path => URI.parse(href).path
)
end
|
6
7
8
9
10
11
12
13
14
15
|
# File 'lib/fog/vcloud_director/requests/compute/get_metadata.rb', line 6
def get_metadata(vm_id)
require 'fog/vcloud_director/parsers/compute/metadata'
request(
:expects => 200,
:method => 'GET',
:parser => Fog::Parsers::Compute::VcloudDirector::Metadata.new,
:path => "vApp/#{vm_id}/metadata/"
)
end
|
#get_network(network_id) ⇒ Object
8
9
10
11
12
13
14
15
|
# File 'lib/fog/vcloud_director/requests/compute/get_network.rb', line 8
def get_network(network_id)
request(
:expects => 200,
:method => 'GET',
:parser => Fog::Parsers::Compute::VcloudDirector::Network.new,
:path => "network/#{network_id}"
)
end
|
#get_organization(organization_id) ⇒ Object
5
6
7
8
9
10
11
12
|
# File 'lib/fog/vcloud_director/requests/compute/get_organization.rb', line 5
def get_organization(organization_id)
request({
:expects => 200,
:method => 'GET',
:parser => Fog::ToHashDocument.new,
:path => "org/#{organization_id}"
})
end
|
#get_organizations ⇒ Object
5
6
7
8
9
10
11
12
|
# File 'lib/fog/vcloud_director/requests/compute/get_organizations.rb', line 5
def get_organizations
request({
:expects => 200,
:method => 'GET',
:parser => Fog::ToHashDocument.new,
:path => 'org'
})
end
|
#get_request(uri) ⇒ Object
6
7
8
9
10
11
12
|
# File 'lib/fog/vcloud_director/requests/compute/get_request.rb', line 6
def get_request(uri)
request(
:expects => 200,
:method => 'GET',
:path => uri
)
end
|
#get_supported_versions ⇒ Object
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/fog/vcloud_director/requests/compute/get_supported_versions.rb', line 12
def get_supported_versions
@connection.request(
:expects => 200,
:host => @host,
:idempotent => true,
:method => 'GET',
:parser => Fog::ToHashDocument.new,
:path => "#{@path}/versions"
)
end
|
#get_task(task_id) ⇒ Object
6
7
8
9
10
11
12
13
|
# File 'lib/fog/vcloud_director/requests/compute/get_task.rb', line 6
def get_task(task_id)
request(
:expects => 200,
:method => 'GET',
:parser => Fog::ToHashDocument.new,
:path => "task/#{task_id}"
)
end
|
#get_tasks_list(tasks_list_id) ⇒ Object
6
7
8
9
10
11
12
13
|
# File 'lib/fog/vcloud_director/requests/compute/get_tasks_list.rb', line 6
def get_tasks_list(tasks_list_id)
request(
:expects => 200,
:method => 'GET',
:parser => Fog::ToHashDocument.new,
:path => "tasksList/#{tasks_list_id}"
)
end
|
#get_vapp(vapp_id) ⇒ Object
6
7
8
9
10
11
12
13
|
# File 'lib/fog/vcloud_director/requests/compute/get_vapp.rb', line 6
def get_vapp(vapp_id)
request(
:expects => 200,
:method => 'GET',
:parser => Fog::ToHashDocument.new,
:path => "vApp/#{vapp_id}"
)
end
|
#get_vapp_template(vapp_template_id) ⇒ Object
6
7
8
9
10
11
12
13
|
# File 'lib/fog/vcloud_director/requests/compute/get_vapp_template.rb', line 6
def get_vapp_template(vapp_template_id)
request(
:expects => 200,
:method => 'GET',
:parser => Fog::ToHashDocument.new,
:path => "vAppTemplate/#{vapp_template_id}"
)
end
|
#get_vdc(vdc_id) ⇒ Object
5
6
7
8
9
10
11
12
|
# File 'lib/fog/vcloud_director/requests/compute/get_vdc.rb', line 5
def get_vdc(vdc_id)
request(
:expects => 200,
:method => 'GET',
:parser => Fog::ToHashDocument.new,
:path => "vdc/#{vdc_id}"
)
end
|
#get_vm(vm_id) ⇒ Object
8
9
10
11
12
13
14
15
|
# File 'lib/fog/vcloud_director/requests/compute/get_vm.rb', line 8
def get_vm(vm_id)
request(
:expects => 200,
:method => 'GET',
:parser => Fog::Parsers::Compute::VcloudDirector::Vm.new,
:path => "vApp/#{vm_id}"
)
end
|
#get_vm_cpu(vm_id) ⇒ Object
6
7
8
9
10
11
12
13
|
# File 'lib/fog/vcloud_director/requests/compute/get_vm_cpu.rb', line 6
def get_vm_cpu(vm_id)
request(
:expects => 200,
:method => 'GET',
:parser => Fog::ToHashDocument.new,
:path => "vApp/#{vm_id}/virtualHardwareSection/cpu"
)
end
|
#get_vm_customization(vm_id) ⇒ Object
8
9
10
11
12
13
14
15
|
# File 'lib/fog/vcloud_director/requests/compute/get_vm_customization.rb', line 8
def get_vm_customization(vm_id)
request(
:expects => 200,
:method => 'GET',
:parser => Fog::Parsers::Compute::VcloudDirector::VmCustomization.new,
:path => "vApp/#{vm_id}/guestCustomizationSection"
)
end
|
#get_vm_disks(vm_id) ⇒ Object
8
9
10
11
12
13
14
15
|
# File 'lib/fog/vcloud_director/requests/compute/get_vm_disks.rb', line 8
def get_vm_disks(vm_id)
request(
:expects => 200,
:method => 'GET',
:parser => Fog::Parsers::Compute::VcloudDirector::Disks.new,
:path => "vApp/#{vm_id}/virtualHardwareSection/disks"
)
end
|
#get_vm_memory(vm_id) ⇒ Object
6
7
8
9
10
11
12
13
|
# File 'lib/fog/vcloud_director/requests/compute/get_vm_memory.rb', line 6
def get_vm_memory(vm_id)
request(
:expects => 200,
:method => 'GET',
:parser => Fog::ToHashDocument.new,
:path => "vApp/#{vm_id}/virtualHardwareSection/memory"
)
end
|
#get_vm_network(vm_id) ⇒ Object
8
9
10
11
12
13
14
15
|
# File 'lib/fog/vcloud_director/requests/compute/get_vm_network.rb', line 8
def get_vm_network(vm_id)
request(
:expects => 200,
:method => 'GET',
:parser => Fog::Parsers::Compute::VcloudDirector::VmNetwork.new,
:path => "vApp/#{vm_id}/networkConnectionSection/"
)
end
|
#get_vms(vapp_id) ⇒ Object
8
9
10
11
12
13
14
15
|
# File 'lib/fog/vcloud_director/requests/compute/get_vms.rb', line 8
def get_vms(vapp_id)
request(
:expects => 200,
:method => 'GET',
:parser => Fog::Parsers::Compute::VcloudDirector::Vms.new,
:path => "vApp/#{vapp_id}"
)
end
|
8
9
10
11
12
13
14
15
|
# File 'lib/fog/vcloud_director/requests/compute/get_vms_by_metadata.rb', line 8
def get_vms_by_metadata(key,value)
request(
:expects => 200,
:method => 'GET',
:parser => Fog::Parsers::Compute::VcloudDirector::VmsByMetadata.new,
:path => "vms/query?format=records&filter=metadata:#{key}==STRING:#{value}"
)
end
|
#instantiate_vapp_template(vapp_name, template_id, options = {}) ⇒ Object
TODO move all the logic to a generator
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/fog/vcloud_director/requests/compute/instantiate_vapp_template.rb', line 8
def instantiate_vapp_template(vapp_name, template_id, options = {})
params = populate_uris(options.merge(:vapp_name => vapp_name, :template_id => template_id))
validate_uris(params)
data = generate_instantiate_vapp_template_request(params)
request(
:body => data,
:expects => 201,
:headers => { 'Content-Type' => 'application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml' },
:method => 'POST',
:parser => Fog::ToHashDocument.new,
:path => "vdc/#{params[:vdc_id]}/action/instantiateVAppTemplate"
)
end
|
#make_task_object(task_response) ⇒ Object
269
270
271
272
|
# File 'lib/fog/vcloud_director/compute.rb', line 269
def make_task_object(task_response)
task_response[:id] = task_response[:href].split('/').last
tasks.new(task_response)
end
|
#org_name ⇒ Object
208
209
210
211
|
# File 'lib/fog/vcloud_director/compute.rb', line 208
def org_name
login if @org_name.nil?
@org_name
end
|
#populate_uris(options = {}) ⇒ Object
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/fog/vcloud_director/requests/compute/instantiate_vapp_template.rb', line 31
def populate_uris(options = {})
options[:vdc_id] ||= default_vdc_id
options[:vdc_uri] = vdc_end_point(options[:vdc_id])
options[:network_id] ||= default_network_id
options[:network_uri] = network_end_point(options[:network_id])
options[:template_uri] = vapp_template_end_point(options[:template_id]) || raise(":template_id option is required")
options
end
|
#post_task_cancel(task_id) ⇒ Object
Cancel a task.
Parameters
Returns
14
15
16
17
18
19
20
|
# File 'lib/fog/vcloud_director/requests/compute/post_task_cancel.rb', line 14
def post_task_cancel(task_id)
request(
:expects => 204,
:method => 'POST',
:path => "task/#{task_id}/action/cancel"
)
end
|
#post_vm_metadata(vm_id, metadata = {}) ⇒ Object
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/fog/vcloud_director/requests/compute/post_vm_metadata.rb', line 8
def post_vm_metadata(vm_id, metadata={})
metadata_klass = case api_version
when '5.1' ; Fog::Generators::Compute::VcloudDirector::MetadataV51
when '1.5' ; Fog::Generators::Compute::VcloudDirector::MetadataV15
else raise "API version: #{api_version} not supported"
end
data = metadata_klass.new(metadata)
request(
:body => data.generate_xml,
:expects => 202,
:headers => { 'Content-Type' => "application/vnd.vmware.vcloud.metadata+xml" },
:method => 'POST',
:parser => Fog::ToHashDocument.new,
:path => "vApp/#{vm_id}/metadata/"
)
end
|
#post_vm_poweroff(vm_id) ⇒ Object
6
7
8
9
10
11
12
13
14
|
# File 'lib/fog/vcloud_director/requests/compute/post_vm_poweroff.rb', line 6
def post_vm_poweroff(vm_id)
request(
:expects => 202,
:method => 'POST',
:parser => Fog::ToHashDocument.new,
:path => "vApp/#{vm_id}/power/action/powerOff"
)
end
|
#post_vm_poweron(vm_id) ⇒ Object
6
7
8
9
10
11
12
13
|
# File 'lib/fog/vcloud_director/requests/compute/post_vm_poweron.rb', line 6
def post_vm_poweron(vm_id)
request(
:expects => 202,
:method => 'POST',
:parser => Fog::ToHashDocument.new,
:path => "vApp/#{vm_id}/power/action/powerOn"
)
end
|
#process_task(response_body) ⇒ Object
263
264
265
266
267
|
# File 'lib/fog/vcloud_director/compute.rb', line 263
def process_task(response_body)
task = make_task_object(response_body)
wait_and_raise_unless_success(task)
true
end
|
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
# File 'lib/fog/vcloud_director/requests/compute/put_metadata_value.rb', line 6
def put_metadata_value(vm_id, metadata_key, metadata_value)
body="
<MetadataValue xmlns=\"http://www.vmware.com/vcloud/v1.5\">
<Value>#{metadata_value}</Value>
</MetadataValue>"
request(
:body => body,
:expects => 202,
:headers => { 'Content-Type' => "application/vnd.vmware.vcloud.metadata.value+xml" },
:method => 'PUT',
:parser => Fog::ToHashDocument.new,
:path => "vApp/#{vm_id}/metadata/#{URI.escape(metadata_key)}"
)
end
|
#put_vm_cpu(vm_id, num_cpus) ⇒ Object
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/fog/vcloud_director/requests/compute/put_vm_cpu.rb', line 6
def put_vm_cpu(vm_id, num_cpus)
data = <<EOF
<Item xmlns="http://www.vmware.com/vcloud/v1.5" xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns12="http://www.vmware.com/vcloud/v1.5" ns12:href="#{endpoint}vApp/#{vm_id}/virtualHardwareSection/cpu" ns12:type="application/vnd.vmware.vcloud.rasdItem+xml" xsi:schemaLocation="http://www.vmware.com/vcloud/v1.5 http://10.194.1.65/api/v1.5/schema/master.xsd http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2.22.0/CIM_ResourceAllocationSettingData.xsd">
<rasd:AllocationUnits>hertz * 10^6</rasd:AllocationUnits>
<rasd:Description>Number of Virtual CPUs</rasd:Description>
<rasd:ElementName>#{num_cpus} virtual CPU(s)</rasd:ElementName>
<rasd:InstanceID>4</rasd:InstanceID>
<rasd:Reservation>0</rasd:Reservation>
<rasd:ResourceType>3</rasd:ResourceType>
<rasd:VirtualQuantity>#{num_cpus}</rasd:VirtualQuantity>
<rasd:Weight>0</rasd:Weight>
<Link rel="edit" type="application/vnd.vmware.vcloud.rasdItem+xml" href="#{endpoint}vApp/#{vm_id}/virtualHardwareSection/cpu"/>
</Item>
EOF
request(
:body => data,
:expects => 202,
:headers => { 'Content-Type' => 'application/vnd.vmware.vcloud.rasdItem+xml' },
:method => 'PUT',
:parser => Fog::ToHashDocument.new,
:path => "vApp/#{vm_id}/virtualHardwareSection/cpu"
)
end
|
#put_vm_customization(vm_id, customization = {}) ⇒ Object
8
9
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/fog/vcloud_director/requests/compute/put_vm_customization.rb', line 8
def put_vm_customization(vm_id, customization={})
data = Fog::Generators::Compute::VcloudDirector::Customization.new(customization)
request(
:body => data.generate_xml,
:expects => 202,
:headers => { 'Content-Type' => 'application/vnd.vmware.vcloud.guestCustomizationSection+xml' },
:method => 'PUT',
:parser => Fog::ToHashDocument.new,
:path => "vApp/#{vm_id}/guestCustomizationSection"
)
end
|
#put_vm_disks(vm_id, disks = []) ⇒ Object
disks is the body of get_vm_disks
9
10
11
12
13
14
15
16
17
18
19
20
|
# File 'lib/fog/vcloud_director/requests/compute/put_vm_disks.rb', line 9
def put_vm_disks(vm_id, disks=[])
data = Fog::Generators::Compute::VcloudDirector::Disks.new(disks)
request(
:body => data.generate_xml,
:expects => 202,
:headers => { 'Content-Type' => 'application/vnd.vmware.vcloud.rasdItemsList+xml' },
:method => 'PUT',
:parser => Fog::ToHashDocument.new,
:path => "vApp/#{vm_id}/virtualHardwareSection/disks"
)
end
|
#put_vm_memory(vm_id, memory) ⇒ Object
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/fog/vcloud_director/requests/compute/put_vm_memory.rb', line 6
def put_vm_memory(vm_id, memory)
data = <<EOF
<Item xmlns="http://www.vmware.com/vcloud/v1.5" xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns12="http://www.vmware.com/vcloud/v1.5" ns12:href="#{endpoint}vApp/#{vm_id}/virtualHardwareSection/memory" ns12:type="application/vnd.vmware.vcloud.rasdItem+xml" xsi:schemaLocation="http://www.vmware.com/vcloud/v1.5 http://10.194.1.65/api/v1.5/schema/master.xsd http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2.22.0/CIM_ResourceAllocationSettingData.xsd">
<rasd:AllocationUnits>byte * 2^20</rasd:AllocationUnits>
<rasd:Description>Memory Size</rasd:Description>
<rasd:ElementName>#{memory} MB of memory</rasd:ElementName>
<rasd:InstanceID>5</rasd:InstanceID>
<rasd:Reservation>0</rasd:Reservation>
<rasd:ResourceType>4</rasd:ResourceType>
<rasd:VirtualQuantity>#{memory}</rasd:VirtualQuantity>
<rasd:Weight>0</rasd:Weight>
<Link rel="edit" type="application/vnd.vmware.vcloud.rasdItem+xml" href="#{endpoint}vApp/#{vm_id}/virtualHardwareSection/memory"/>
</Item>
EOF
request(
:body => data,
:expects => 202,
:headers => { 'Content-Type' => 'application/vnd.vmware.vcloud.rasdItem+xml' },
:method => 'PUT',
:parser => Fog::ToHashDocument.new,
:path => "vApp/#{vm_id}/virtualHardwareSection/memory"
)
end
|
#put_vm_network(vm_id, network = {}) ⇒ Object
8
9
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/fog/vcloud_director/requests/compute/put_vm_network.rb', line 8
def put_vm_network(vm_id, network={})
data = Fog::Generators::Compute::VcloudDirector::VmNetwork.new(network)
request(
:body => data.generate_xml,
:expects => 202,
:headers => { 'Content-Type' => 'application/vnd.vmware.vcloud.networkConnectionSection+xml' },
:method => 'PUT',
:parser => Fog::ToHashDocument.new,
:path => "vApp/#{vm_id}/networkConnectionSection/"
)
end
|
#reload ⇒ Object
213
214
215
216
|
# File 'lib/fog/vcloud_director/compute.rb', line 213
def reload
@cookie = nil @connection.reset
end
|
#request(params) ⇒ Object
218
219
220
221
222
223
224
225
226
227
228
229
|
# File 'lib/fog/vcloud_director/compute.rb', line 218
def request(params)
unless @cookie
@cookie = auth_token
end
begin
do_request(params)
end
end
|
#undeploy(vapp_id) ⇒ Object
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/fog/vcloud_director/requests/compute/post_vapp_undeploy.rb', line 6
def undeploy(vapp_id)
body = <<EOF
<UndeployVAppParams xmlns="http://www.vmware.com/vcloud/v1.5">
<UndeployPowerAction>shutdown</UndeployPowerAction>
</UndeployVAppParams>
EOF
request(
:body => body,
:expects => 202,
:method => 'POST',
:parser => Fog::ToHashDocument.new,
:headers => {'Content-Type' => 'application/vnd.vmware.vcloud.undeployVAppParams+xml' },
:path => "vApp/#{vapp_id}/action/undeploy"
)
end
|
#validate_uris(options = {}) ⇒ Object
24
25
26
27
28
29
|
# File 'lib/fog/vcloud_director/requests/compute/instantiate_vapp_template.rb', line 24
def validate_uris(options ={})
[:vdc_uri, :network_uri].each do |opt_uri|
result = default_organization_body[:Link].detect {|org| org[:href] == options[opt_uri]}
raise("#{opt_uri}: #{options[opt_uri]} not found") unless result
end
end
|
#wait_and_raise_unless_success(task) ⇒ Object
274
275
276
277
|
# File 'lib/fog/vcloud_director/compute.rb', line 274
def wait_and_raise_unless_success(task)
task.wait_for { non_running? }
raise Errors::Task.new "status: #{task.status}, error: #{task.error}" unless task.success?
end
|
#xmlns ⇒ Object
75
76
77
78
79
80
81
82
|
# File 'lib/fog/vcloud_director/requests/compute/instantiate_vapp_template.rb', line 75
def xmlns
{
'xmlns' => "http://www.vmware.com/vcloud/v1.5",
"xmlns:ovf" => "http://schemas.dmtf.org/ovf/envelope/1",
"xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance",
"xmlns:xsd" => "http://www.w3.org/2001/XMLSchema"
}
end
|