Class: Fog::Vcloud::Compute::Real

Inherits:
Object
  • Object
show all
Includes:
Shared
Defined in:
lib/rackspace-fog/vcloud/compute.rb,
lib/rackspace-fog/vcloud/requests/compute/login.rb,
lib/rackspace-fog/vcloud/requests/compute/get_vdc.rb,
lib/rackspace-fog/vcloud/requests/compute/get_task.rb,
lib/rackspace-fog/vcloud/requests/compute/get_vapp.rb,
lib/rackspace-fog/vcloud/requests/compute/power_on.rb,
lib/rackspace-fog/vcloud/requests/compute/undeploy.rb,
lib/rackspace-fog/vcloud/requests/compute/power_off.rb,
lib/rackspace-fog/vcloud/requests/compute/clone_vapp.rb,
lib/rackspace-fog/vcloud/requests/compute/get_server.rb,
lib/rackspace-fog/vcloud/requests/compute/delete_node.rb,
lib/rackspace-fog/vcloud/requests/compute/delete_vapp.rb,
lib/rackspace-fog/vcloud/requests/compute/get_catalog.rb,
lib/rackspace-fog/vcloud/requests/compute/get_network.rb,
lib/rackspace-fog/vcloud/requests/compute/power_reset.rb,
lib/rackspace-fog/vcloud/requests/compute/configure_vm.rb,
lib/rackspace-fog/vcloud/requests/compute/get_vm_disks.rb,
lib/rackspace-fog/vcloud/requests/compute/get_task_list.rb,
lib/rackspace-fog/vcloud/requests/compute/get_vm_memory.rb,
lib/rackspace-fog/vcloud/requests/compute/configure_node.rb,
lib/rackspace-fog/vcloud/requests/compute/configure_vapp.rb,
lib/rackspace-fog/vcloud/requests/compute/get_network_ip.rb,
lib/rackspace-fog/vcloud/requests/compute/power_shutdown.rb,
lib/rackspace-fog/vcloud/requests/compute/get_network_ips.rb,
lib/rackspace-fog/vcloud/requests/compute/get_catalog_item.rb,
lib/rackspace-fog/vcloud/requests/compute/get_organization.rb,
lib/rackspace-fog/vcloud/requests/compute/configure_network.rb,
lib/rackspace-fog/vcloud/requests/compute/get_vapp_template.rb,
lib/rackspace-fog/vcloud/requests/compute/configure_vm_disks.rb,
lib/rackspace-fog/vcloud/requests/compute/configure_vm_memory.rb,
lib/rackspace-fog/vcloud/requests/compute/configure_network_ip.rb,
lib/rackspace-fog/vcloud/requests/compute/get_network_extensions.rb,
lib/rackspace-fog/vcloud/requests/compute/get_customization_options.rb,
lib/rackspace-fog/vcloud/requests/compute/instantiate_vapp_template.rb,
lib/rackspace-fog/vcloud/requests/compute/configure_vm_name_description.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Real

Returns a new instance of Real.



180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
# File 'lib/rackspace-fog/vcloud/compute.rb', line 180

def initialize(options = {})
  require 'builder'
  require 'rackspace-fog/core/parser'

  @connections = {}
  @connection_options = options[:connection_options] || {}
  @persistent = options[:persistent]

  @username  = options[:vcloud_username]
  @password  = options[:vcloud_password]
  @host      = options[:vcloud_host]
  @vdc_href  = options[:vcloud_default_vdc]
  @base_path = options[:vcloud_base_path]   || Fog::Vcloud::Compute::BASE_PATH
  @version   = options[:vcloud_version]     || Fog::Vcloud::Compute::DEFAULT_VERSION
  @path      = options[:vcloud_path]        || "#{@base_path}/v#{@version}"
  @port      = options[:vcloud_port]        || Fog::Vcloud::Compute::PORT
  @scheme    = options[:vcloud_scheme]      || Fog::Vcloud::Compute::SCHEME
end

Instance Attribute Details

#versionObject (readonly)

Returns the value of attribute version.



178
179
180
# File 'lib/rackspace-fog/vcloud/compute.rb', line 178

def version
  @version
end

Class Method Details

.basic_request(*args) ⇒ Object



147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/rackspace-fog/vcloud/compute.rb', line 147

def basic_request(*args)
  self.class_eval <<-EOS, __FILE__,__LINE__
    def #{args[0]}(uri)
      request(
        {
          :expects => #{args[1] || 200},
          :method  => '#{args[2] || 'GET'}',
          :headers => #{args[3] ? args[3].inspect : '{}'},
          :body => '#{args[4] ? args[4] : ''}',
          :parse => true,
          :uri     => uri
        }
      )
    end
  EOS
end

.unauthenticated_basic_request(*args) ⇒ Object



164
165
166
167
168
169
170
171
172
173
174
175
# File 'lib/rackspace-fog/vcloud/compute.rb', line 164

def unauthenticated_basic_request(*args)
  self.class_eval <<-EOS, __FILE__,__LINE__
    def #{args[0]}(uri)
      unauthenticated_request({
        :expects => #{args[1] || 200},
        :method  => '#{args[2] || 'GET'}',
        :headers => #{args[3] ? args[3].inspect : '{}'},
        :parse => true,
        :uri     => uri })
    end
  EOS
end

Instance Method Details

#base_path_urlObject



279
280
281
# File 'lib/rackspace-fog/vcloud/compute.rb', line 279

def base_path_url
  "#{@scheme}://#{@host}:#{@port}#{@base_path}"
end

#basic_request_params(uri, *args) ⇒ Object



268
269
270
271
272
273
274
275
276
277
# File 'lib/rackspace-fog/vcloud/compute.rb', line 268

def basic_request_params(uri,*args)
  {
    :expects => args[0] || 200,
    :method  => args[1] || 'GET',
    :headers => args[2] ? args[2].inspect : {},
    :body => args[3] ? args[3] : '',
    :parse => true,
    :uri     => uri
  }
end

#clone_vapp(vdc_uri, vapp_uri, options = {}) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/rackspace-fog/vcloud/requests/compute/clone_vapp.rb', line 21

def clone_vapp(vdc_uri, vapp_uri, options = {})
  unless options.has_key?(:poweron)
    options[:poweron] = "false"
  end

  validate_clone_vapp_options(options)

  request(
    :body     => generate_clone_vapp_request(vapp_uri, options),
    :expects  => 202,
    :headers  => {'Content-Type' => 'application/vnd.vmware.vcloud.cloneVAppParams+xml'},
    :method   => 'POST',
    :uri      => vdc_uri + '/action/clonevapp',
    :parse    => true
  )
end

#configure_network(network_uri, network_data) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/rackspace-fog/vcloud/requests/compute/configure_network.rb', line 13

def configure_network(network_uri, network_data)
  validate_network_data(network_data)

  request(
    :body     => generate_configure_network_request(network_data),
    :expects  => 200,
    :headers  => {'Content-Type' => 'application/vnd.vmware.vcloud.networkService+xml'},
    :method   => 'PUT',
    :uri      => network_uri,
    :parse    => true
  )
end

#configure_network_ip(network_ip_uri, network_ip_data) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/rackspace-fog/vcloud/requests/compute/configure_network_ip.rb', line 18

def configure_network_ip(network_ip_uri, network_ip_data)
  validate_network_ip_data(network_ip_data)

  request(
    :body     => generate_configure_network_ip_request(network_ip_data),
    :expects  => 200,
    :headers  => {'Content-Type' => 'application/vnd.vmware.vcloud.ip+xml' },
    :method   => 'PUT',
    :uri      => network_ip_uri,
    :parse    => true
  )
end

#configure_node(node_uri, node_data) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/rackspace-fog/vcloud/requests/compute/configure_node.rb', line 22

def configure_node(node_uri, node_data)
  validate_node_data(node_data, true)

  request(
    :body     => generate_configure_node_request(node_data),
    :expects  => 200,
    :headers  => {'Content-Type' => 'application/vnd.vmware.vcloud.nodeService+xml'},
    :method   => 'PUT',
    :uri      => node_uri,
    :parse    => true
  )
end

#configure_vapp(vapp_uri, vapp_data) ⇒ Object



96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/rackspace-fog/vcloud/requests/compute/configure_vapp.rb', line 96

def configure_vapp(vapp_uri, vapp_data)
  validate_vapp_data(vapp_data)

  request(
    :body     => generate_configure_vapp_request(vapp_uri, vapp_data),
    :expects  => 202,
    :headers  => {'Content-Type' => 'application/vnd.vmware.vcloud.vApp+xml' },
    :method   => 'PUT',
    :uri      => vapp_uri,
    :parse    => true
  )
end

#configure_vm(vm_uri, vm_data) ⇒ Object



93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/rackspace-fog/vcloud/requests/compute/configure_vm.rb', line 93

def configure_vm(vm_uri, vm_data)
  validate_vm_data(vm_data)

  request(
    :body     => generate_configure_vm_request(vm_uri, vm_data),
    :expects  => 202,
    :headers  => {'Content-Type' => 'application/vnd.vmware.vcloud.vm+xml' },
    :method   => 'PUT',
    :uri      => vm_uri,
    :parse    => true
  )
end

#configure_vm_disks(vm_href, disk_data) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/rackspace-fog/vcloud/requests/compute/configure_vm_disks.rb', line 81

def configure_vm_disks(vm_href, disk_data)
  disk_href = vm_href + '/virtualHardwareSection/disks'

  body = generate_configure_vm_disks_request(disk_href, disk_data)

  request(
    :body     => body,
    :expects  => 202,
    :headers  => {'Content-Type' => 'application/vnd.vmware.vcloud.rasdItem+xml' },
    :method   => 'PUT',
    :uri      => disk_href,
    :parse    => true
  )
end

#configure_vm_memory(vm_data) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/rackspace-fog/vcloud/requests/compute/configure_vm_memory.rb', line 7

def configure_vm_memory(vm_data)
  edit_uri = vm_data.select {|k,v| k == :Link && v[:rel] == 'edit'}
  edit_uri = edit_uri.kind_of?(Array) ? edit_uri.flatten[1][:href] : edit_uri[:Link][:href]

  body = <<EOF
<?xml version="1.0" encoding="UTF-8"?>
<Item xmlns="http://www.vmware.com/vcloud/v1" xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData" xmlns:vcloud="http://www.vmware.com/vcloud/v1" vcloud:href="https://vcd01.esx.dev.int.realestate.com.au/api/v1.0/vApp/vm-329805878/virtualHardwareSection/memory" vcloud:type="application/vnd.vmware.vcloud.rasdItem+xml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="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 http://www.vmware.com/vcloud/v1 http://vcd01.esx.dev.int.realestate.com.au/api/v1.0/schema/master.xsd">
    <rasd:AllocationUnits>byte * 2^20</rasd:AllocationUnits>
    <rasd:Description>Memory Size</rasd:Description>
    <rasd:ElementName>#{vm_data[:'rasd:VirtualQuantity']} MB of memory</rasd:ElementName>
    <rasd:InstanceID>5</rasd:InstanceID>
    <rasd:Reservation>0</rasd:Reservation>
    <rasd:ResourceType>4</rasd:ResourceType>
    <rasd:VirtualQuantity>#{vm_data[:'rasd:VirtualQuantity']}</rasd:VirtualQuantity>
    <rasd:Weight>5120</rasd:Weight>
    <Link rel="edit" type="application/vnd.vmware.vcloud.rasdItem+xml" href="https://vcd01.esx.dev.int.realestate.com.au/api/v1.0/vApp/vm-329805878/virtualHardwareSection/memory"/>
</Item>
EOF

  request(
    :body     => body,
    :expects  => 202,
    :headers  => {'Content-Type' => vm_data[:"vcloud_type"] },
    :method   => 'PUT',
    :uri      => edit_uri,
    :parse    => true
  )
end

#configure_vm_name_description(edit_href, name, description) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/rackspace-fog/vcloud/requests/compute/configure_vm_name_description.rb', line 7

def configure_vm_name_description(edit_href, name, description)

  body = <<EOF
<?xml version="1.0" encoding="UTF-8"?>
<VApp xmlns="http://www.vmware.com/vcloud/v1" name="#{name}" type="application/vnd.vmware.vcloud.vApp+xml">
    <Description>#{description}</Description>
</VApp>
EOF

  request(
    :body     => body,
    :expects  => 202,
    :headers  => {'Content-Type' => "application/vnd.vmware.vcloud.vApp+xml"},
    :method   => 'PUT',
    :uri      => edit_href,
    :parse    => true
  )
end

#default_organization_uriObject



203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
# File 'lib/rackspace-fog/vcloud/compute.rb', line 203

def default_organization_uri
  @default_organization_uri ||= begin
    unless @login_results
      
    end
    case @login_results.body[:Org]
    when Array
      @login_results.body[:Org].first[:href]
    when Hash
      @login_results.body[:Org][:href]
    else
      nil
    end
  end
end

#default_vdc_hrefObject



219
220
221
# File 'lib/rackspace-fog/vcloud/compute.rb', line 219

def default_vdc_href
  @vdc_href
end

#do_loginObject

login handles the auth, but we just need the Set-Cookie header from that call.



225
226
227
228
# File 'lib/rackspace-fog/vcloud/compute.rb', line 225

def 
  @login_results = 
  @cookie = @login_results.headers['Set-Cookie']
end

#ensure_unparsed(uri) ⇒ Object



230
231
232
233
234
235
236
# File 'lib/rackspace-fog/vcloud/compute.rb', line 230

def ensure_unparsed(uri)
  if uri.is_a?(String)
    uri
  else
    uri.to_s
  end
end

#generate_clone_vapp_request(uri, options) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/rackspace-fog/vcloud/requests/compute/clone_vapp.rb', line 13

def generate_clone_vapp_request(uri, options)
  xml = Builder::XmlMarkup.new
  xml.CloneVAppParams(xmlns.merge!(:name => options[:name], :deploy => "true", :powerOn => options[:poweron])) {
    xml.VApp( :href => uri, :type => "application/vnd.vmware.vcloud.vApp+xml",
              :xmlns => "http://www.vmware.com/vcloud/v0.8")
  }
end

#generate_configure_vapp_request(vapp_uri, vapp_data) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/rackspace-fog/vcloud/requests/compute/configure_vapp.rb', line 18

def generate_configure_vapp_request(vapp_uri, vapp_data)
  rasd_xmlns = { "xmlns" => "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData" }

  xml = Nokogiri::XML(request( :uri => vapp_uri).body)
  xml.root['name'] = vapp_data[:name]

  #cpu
  xml.at("//xmlns:ResourceType[.='3']/..", rasd_xmlns).at('.//xmlns:VirtualQuantity', rasd_xmlns).content = vapp_data[:cpus]

  #memory
  xml.at("//xmlns:ResourceType[.='4']/..", rasd_xmlns).at('.//xmlns:VirtualQuantity', rasd_xmlns).content = vapp_data[:memory]

  #disks
  real_disks = xml.xpath("//xmlns:ResourceType[ .='17']/..", rasd_xmlns)
  real_disk_numbers = real_disks.map { |disk| disk.at('.//xmlns:AddressOnParent', rasd_xmlns).content }
  disk_numbers = vapp_data[:disks].map { |vdisk| vdisk[:number].to_s }

  if vapp_data[:disks].length < real_disks.length
    #Assume we're removing a disk
    remove_disk_numbers = real_disk_numbers - disk_numbers
    remove_disk_numbers.each do |number|
      if result = xml.at("//xmlns:ResourceType[ .='17']/../xmlns:AddressOnParent[.='#{number}']/..", rasd_xmlns)
        result.remove
      end
    end
  elsif vapp_data[:disks].length > real_disks.length
    add_disk_numbers = disk_numbers - real_disk_numbers

    add_disk_numbers.each do |number|
      new_disk = real_disks.first.dup
      new_disk.at('.//xmlns:AddressOnParent', rasd_xmlns).content = -1
      new_disk.at('.//xmlns:VirtualQuantity', rasd_xmlns).content = vapp_data[:disks].detect { |disk| disk[:number].to_s == number.to_s }[:size]
      real_disks.first.parent << new_disk
    end
  end

  #puts xml.root.to_s
  xml.root.to_s

  #builder = Builder::XmlMarkup.new
  #builder.Vapp(:href => vapp_uri.to_s,
  #             :type => 'application/vnd.vmware.vcloud.vApp+xml',
  #             :name => vapp_data[:name],
  #             :status => 2,
  #             :size => 0,
  #             :xmlns => 'http://www.vmware.com/vcloud/v0.8',
  #             :"xmlns:xsi" => 'http://www.w3.org/2001/XMLSchema-instance',
  #             :"xmlns:xsd" => 'http://www.w3.org/2001/XMLSchema') {
  #  #builder.VirtualHardwareSection(:xmlns => 'http://schemas.dmtf.org/ovf/envelope/1') {
  #  builder.Section(:"xsi:type" => "q2:VirtualHardwareSection_Type", :xmlns => "http://schemas.dmtf.org/ovf/envelope/1", :"xmlns:q2" => "http://www.vmware.com/vcloud/v0.8") {
  #    builder.Info('Virtual Hardware')
  #    builder.Item(:xmlns => 'http://schemas.dmtf.org/ovf/envelope/1') {
  #    #builder.Item {
  #      builder.InstanceID(1, :xmlns => 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData')
  #      builder.ResourceType(3, :xmlns => 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData')
  #      builder.VirtualQuantity(vapp_data[:cpus], :xmlns => 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData')
  #    }
  #    builder.Item(:xmlns => 'http://schemas.dmtf.org/ovf/envelope/1') {
  #    #builder.Item {
  #      builder.InstanceID(2, :xmlns => 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData')
  #      builder.ResourceType(4, :xmlns => 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData')
  #      builder.VirtualQuantity(vapp_data[:memory], :xmlns => 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData')
  #    }
  #    vapp_data[:disks].each do |disk_data|
  #      #builder.Item(:xmlns => 'http://schemas.dmtf.org/ovf/envelope/1') {
  #      builder.Item {
  #        builder.AddressOnParent(disk_data[:number], :xmlns => 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData')
  #        builder.HostResource(disk_data[:resource], :xmlns => 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData')
  #        builder.InstanceID(9, :xmlns => 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData')
  #        builder.ResourceType(17, :xmlns => 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData')
  #        builder.VirtualQuantity(disk_data[:size], :xmlns => 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData')
  #      }
  #    end
  #
  #  }
  #}
end

#generate_configure_vm_disks_request(href, disk_data) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/rackspace-fog/vcloud/requests/compute/configure_vm_disks.rb', line 40

def generate_configure_vm_disks_request(href, disk_data)
  xmlns = {
    "xmlns:rasd" => "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData",
    "xmlns" => "http://www.vmware.com/vcloud/v1"
  }
  # Get the XML from the API, parse it.
  xml = Nokogiri::XML(request( :uri => href).body)

  #xml.root['name'] = vapp_data[:name]

  #disks
  real_disks = xml.xpath("//rasd:ResourceType[ .='17']/..", xmlns)
  real_disk_numbers = real_disks.map { |disk| disk.at('.//rasd:AddressOnParent', xmlns).content }
  disk_numbers = disk_data.map { |vdisk| vdisk[:"rasd:AddressOnParent"].to_s }

  if disk_data.length < real_disks.length
    #Assume we're removing a disk
    remove_disk_numbers = real_disk_numbers - disk_numbers
    remove_disk_numbers.each do |number|
      if result = xml.at("//rasd:ResourceType[ .='17']/../rasd:AddressOnParent[.='#{number}']/..", xmlns)
        result.remove
      end
    end
  elsif disk_data.length > real_disks.length
    add_disk_numbers = disk_numbers - real_disk_numbers

    add_disk_numbers.each do |number|
      new_disk = real_disks.first.dup
      new_disk.at('.//rasd:AddressOnParent', xmlns).content = number.to_i #-1
      new_disk.at('.//rasd:HostResource', xmlns)["vcloud:capacity"] = disk_data.detect { |disk| disk[:'rasd:AddressOnParent'].to_s == number.to_s }[:'rasd:HostResource'][:vcloud_capacity].to_s
      # nokogiri bug? shouldn't need to add this explicitly.
      new_disk.at('.//rasd:HostResource', xmlns)["xmlns:vcloud"] = xmlns['xmlns']
      new_disk.at('.//rasd:InstanceID', xmlns).content = (2000 + number.to_i).to_s
      new_disk.at('.//rasd:ElementName', xmlns).content = "Hard disk #{number.to_i + 1}"
      real_disks.first.parent << new_disk
    end

  end
  xml.to_s
end

#generate_configure_vm_request(vm_data) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/rackspace-fog/vcloud/requests/compute/configure_vm.rb', line 18

def generate_configure_vm_request(vm_data)
  xmlns = 'http://schemas.dmtf.org/ovf/envelope/1'
  xmlns_vcloud = 'http://www.vmware.com/vcloud/v1'
  xmlns_rasd = 'http://schemas.dmtf.org/wbem/wscim/1/cim‐schema/2/CIM_ResourceAllocationSettingData'
  xmlns_vssd = 'http://schemas.dmtf.org/wbem/wscim/1/cim‐schema/2/CIM_VirtualSystemSettingData'

  builder = Builder::XmlMarkup.new(:target=>STDOUT, :indent=>2) # TODO - remove params
  builder.VirtualHardwareSection(
                                 :"vcloud:href" => vm_data[:"vcloud_href"],
                                 :"vcloud:type" => vm_data[:"vcloud_type"],
                                 :name => vm_data[:name],
                                 :status => 2,
                                 :size => 0,
                                 :xmlns => xmlns,
                                 :"xmlns:vcloud" => xmlns_vcloud,
                                 :"xmlns:rasd" => xmlns_rasd,
                                 :"xmlns:vssd" => xmlns_vssd) {
    #builder.VirtualHardwareSection(:xmlns => 'http://schemas.dmtf.org/ovf/envelope/1') {

    builder.Info(vm_data[:"ovf:Info"])
    if system = vm_data[:"ovf:System"]
      builder.System {
        builder.ElementName(system[:"vssd:ElementName"], :xmlns => xmlns_vssd) if system[:"vssd:ElementName"]
        builder.InstanceID(system[:"vssd:InstanceID"], :xmlns => xmlns_vssd) if system[:"vssd:InstanceID"]
        builder.VirtualSystemIdentifier(system[:"vssd:VirtualSystemIdentifier"], :xmlns => xmlns_vssd) if system[:"vssd:VirtualSystemIdentifier"]
        builder.VirtualSystemType(system[:"vssd:VirtualSystemType"], :xmlns => xmlns_vssd) if system[:"vssd:VirtualSystemType"]
      }
    end

    vm_data[:'ovf:Item'].each do |oi|
      builder.Item {
        builder.Address(oi[:'rasd:Address'], :xmlns => xmlns_rasd) if oi[:'rasd:Address']
        builder.AddressOnParent(oi[:'rasd:AddressOnParent'], :xmlns => xmlns_rasd) if oi[:'rasd:AddressOnParent']
        builder.AutomaticAllocation(oi[:'rasd:AutomaticAllocation'], :xmlns => xmlns_rasd) if oi[:'rasd:AutomaticAllocation']
        builder.Connection(oi[:'rasd:Connection'], :xmlns => xmlns_rasd) if oi[:'rasd:Connection']
        builder.Description(oi[:'rasd:Description'], :xmlns => xmlns_rasd) if oi[:'rasd:Description']
        builder.ElementName(oi[:'rasd:ElementName'], :xmlns => xmlns_rasd) if oi[:'rasd:ElementName']
        builder.InstanceID(oi[:'rasd:InstanceID'], :xmlns => xmlns_rasd) if oi[:'rasd:InstanceID']
        builder.ResourceSubType(oi[:'rasd:ResourceSubType'], :xmlns => xmlns_rasd) if oi[:'rasd:ResourceSubType']
        builder.ResourceType(oi[:'rasd:ResourceType'], :xmlns => xmlns_rasd) if oi[:'rasd:ResourceType']
        if hr = oi[:'rasd:HostResource']
          attrs = {}
          attrs[]
        end
      }
    end



     # builder.Item(:xmlns => 'http://schemas.dmtf.org/ovf/envelope/1') {
     # #builder.Item {
     #   builder.InstanceID(1, :xmlns => 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData')
     #   builder.ResourceType(3, :xmlns => 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData')
     #   builder.VirtualQuantity(vm_data[:cpus], :xmlns => 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData')
     # }
     # builder.Item(:xmlns => 'http://schemas.dmtf.org/ovf/envelope/1') {
     # #builder.Item {
     #   builder.InstanceID(2, :xmlns => 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData')
     #   builder.ResourceType(4, :xmlns => 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData')
     #   builder.VirtualQuantity(vm_data[:memory], :xmlns => 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData')
     # }
     # vm_data[:disks].each do |disk_data|
     #   #builder.Item(:xmlns => 'http://schemas.dmtf.org/ovf/envelope/1') {
     #   builder.Item {
     #     builder.AddressOnParent(disk_data[:number], :xmlns => 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData')
     #     builder.HostResource(disk_data[:resource], :xmlns => 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData')
     #     builder.InstanceID(9, :xmlns => 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData')
     #     builder.ResourceType(17, :xmlns => 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData')
     #     builder.VirtualQuantity(disk_data[:size], :xmlns => 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData')
     #   }
     # end

   }
end

#get_vm_disks(href) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/rackspace-fog/vcloud/requests/compute/get_vm_disks.rb', line 6

def get_vm_disks(href)
  request(
          :expects  => 200,
          :uri      => href,
          :parse    => true#false#true
          )
end

#get_vm_memory(href, parse = true) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/rackspace-fog/vcloud/requests/compute/get_vm_memory.rb', line 6

def get_vm_memory(href, parse = true)
  request(
          :expects  => 200,
          :uri      => href,
          :parse    => parse
          )
end

#instantiate_vapp_template(options = {}) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/rackspace-fog/vcloud/requests/compute/instantiate_vapp_template.rb', line 68

def instantiate_vapp_template options = {}
  validate_instantiate_vapp_template_options options

  request(
    :body     => generate_instantiate_vapp_template_request(options),
    :expects  => 201,
    :headers  => {'Content-Type' => 'application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml'},
    :method   => 'POST',
    :uri      => options[:vdc_uri] + '/action/instantiateVAppTemplate',
    :parse    => true
  )
end

#loginObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/rackspace-fog/vcloud/requests/compute/login.rb', line 8

def 
  headers = { 'Authorization' => authorization_header }
  uri = if version == '1.0'
    "#{base_url}/login"
  else
    "#{base_path_url}/sessions"
  end
  unauthenticated_request({
    :expects  => 200,
    :headers  => headers,
    :method   => 'POST',
    :parse    => true,
    :uri      => uri
  })
end

#reloadObject



199
200
201
# File 'lib/rackspace-fog/vcloud/compute.rb', line 199

def reload
  @connections.each_value { |k,v| v.reset if v }
end

#request(params) ⇒ Object

If the cookie isn’t set, do a get_organizations call to set it and try the request. If we get an Unauthorized error, we assume the token expired, re-auth and try again



255
256
257
258
259
260
261
262
263
264
265
# File 'lib/rackspace-fog/vcloud/compute.rb', line 255

def request(params)
  unless @cookie
    
  end
  begin
    do_request(params)
  rescue Excon::Errors::Unauthorized
    
    do_request(params)
  end
end

#undeploy(vapp_uri, save_state = false) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/rackspace-fog/vcloud/requests/compute/undeploy.rb', line 5

def undeploy(vapp_uri, save_state = false)
  # builder = Builder::XmlMarkup.new
  # builder.UndeployVAppParams(:xmlns => 'http://www.vmware.com/vcloud/v1',
  #                            :saveState => save_state) {}
  builder = "<UndeployVAppParams saveState=\"#{save_state.to_s}\" xmlns=\"http://www.vmware.com/vcloud/v1\"/>"

  request(
          :body     => builder,
          :expects  => 202,
          :headers  => {'Content-Type' => 'application/vnd.vmware.vcloud.undeployVAppParams+xml' },
          :method   => 'POST',
          :uri      => vapp_uri + '/action/undeploy',
          :parse    => true
          )
end

#validate_clone_vapp_options(options) ⇒ Object



6
7
8
9
10
11
# File 'lib/rackspace-fog/vcloud/requests/compute/clone_vapp.rb', line 6

def validate_clone_vapp_options(options)
  valid_opts = [:name, :poweron]
  unless valid_opts.all? { |opt| options.has_key?(opt) }
    raise ArgumentError.new("Required data missing: #{(valid_opts - options.keys).map(&:inspect).join(", ")}")
  end
end

#validate_network_data(network_data, configure = false) ⇒ Object



6
7
8
9
10
11
# File 'lib/rackspace-fog/vcloud/requests/compute/configure_network.rb', line 6

def validate_network_data(network_data, configure=false)
  valid_opts = [:id, :href, :name, :address, :broadcast, :gateway]
  unless valid_opts.all? { |opt| network_data.has_key?(opt) }
    raise ArgumentError.new("Required data missing: #{(valid_opts - network_data.keys).map(&:inspect).join(", ")}")
  end
end

#xmlnsObject



238
239
240
241
242
243
244
245
246
247
248
249
250
# File 'lib/rackspace-fog/vcloud/compute.rb', line 238

def xmlns
  if version == '1.0'
    { "xmlns" => "http://www.vmware.com/vcloud/v1",
      "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" }
  else
    { '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
end