Class: Fog::Vcloud::Terremark::Ecloud::Real

Inherits:
Real
  • Object
show all
Includes:
Shared
Defined in:
lib/fog/vcloud/terremark/ecloud.rb,
lib/fog/vcloud/terremark/ecloud/requests/get_vdc.rb,
lib/fog/vcloud/terremark/ecloud/requests/add_node.rb,
lib/fog/vcloud/terremark/ecloud/requests/get_node.rb,
lib/fog/vcloud/terremark/ecloud/requests/get_task.rb,
lib/fog/vcloud/terremark/ecloud/requests/get_vapp.rb,
lib/fog/vcloud/terremark/ecloud/requests/power_on.rb,
lib/fog/vcloud/terremark/ecloud/requests/get_nodes.rb,
lib/fog/vcloud/terremark/ecloud/requests/power_off.rb,
lib/fog/vcloud/terremark/ecloud/requests/clone_vapp.rb,
lib/fog/vcloud/terremark/ecloud/requests/delete_node.rb,
lib/fog/vcloud/terremark/ecloud/requests/delete_vapp.rb,
lib/fog/vcloud/terremark/ecloud/requests/get_catalog.rb,
lib/fog/vcloud/terremark/ecloud/requests/get_network.rb,
lib/fog/vcloud/terremark/ecloud/requests/power_reset.rb,
lib/fog/vcloud/terremark/ecloud/requests/get_public_ip.rb,
lib/fog/vcloud/terremark/ecloud/requests/get_task_list.rb,
lib/fog/vcloud/terremark/ecloud/requests/configure_node.rb,
lib/fog/vcloud/terremark/ecloud/requests/configure_vapp.rb,
lib/fog/vcloud/terremark/ecloud/requests/get_network_ip.rb,
lib/fog/vcloud/terremark/ecloud/requests/get_public_ips.rb,
lib/fog/vcloud/terremark/ecloud/requests/power_shutdown.rb,
lib/fog/vcloud/terremark/ecloud/requests/get_network_ips.rb,
lib/fog/vcloud/terremark/ecloud/requests/get_catalog_item.rb,
lib/fog/vcloud/terremark/ecloud/requests/get_firewall_acl.rb,
lib/fog/vcloud/terremark/ecloud/requests/configure_network.rb,
lib/fog/vcloud/terremark/ecloud/requests/get_firewall_acls.rb,
lib/fog/vcloud/terremark/ecloud/requests/get_vapp_template.rb,
lib/fog/vcloud/terremark/ecloud/requests/add_internet_service.rb,
lib/fog/vcloud/terremark/ecloud/requests/configure_network_ip.rb,
lib/fog/vcloud/terremark/ecloud/requests/get_internet_services.rb,
lib/fog/vcloud/terremark/ecloud/requests/get_network_extensions.rb,
lib/fog/vcloud/terremark/ecloud/requests/delete_internet_service.rb,
lib/fog/vcloud/terremark/ecloud/requests/get_customization_options.rb,
lib/fog/vcloud/terremark/ecloud/requests/instantiate_vapp_template.rb,
lib/fog/vcloud/terremark/ecloud/requests/configure_internet_service.rb,
lib/fog/vcloud/terremark/ecloud/requests/add_backup_internet_service.rb

Instance Attribute Summary

Attributes included from Shared

#versions_uri

Instance Method Summary collapse

Methods included from Shared

#ecloud_xmlns, #validate_backup_internet_service_data, #validate_internet_service_data, #validate_internet_service_monitor

Methods inherited from Real

#default_organization_uri, #initialize, #login, #reload, #request

Methods included from Generators

#basic_request, #unauthenticated_basic_request

Methods included from Shared

#default_organization_uri, #do_login, #ensure_unparsed, #supported_versions, #xmlns

Constructor Details

This class inherits a constructor from Fog::Vcloud::Real

Instance Method Details

#add_backup_internet_service(internet_services_uri, service_data) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/fog/vcloud/terremark/ecloud/requests/add_backup_internet_service.rb', line 20

def add_backup_internet_service(internet_services_uri, service_data)
  validate_backup_internet_service_data(service_data)
  if monitor = service_data[:monitor]
    validate_internet_service_monitor(monitor)
    ensure_monitor_defaults!(monitor)
  end

  request(
    :body     => generate_backup_internet_service_request(service_data),
    :expects  => 200,
    :headers  => {'Content-Type' => 'application/xml'},
    :method   => 'POST',
    :uri      => internet_services_uri,
    :parse    => true
  )
end

#add_internet_service(internet_services_uri, service_data) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/fog/vcloud/terremark/ecloud/requests/add_internet_service.rb', line 41

def add_internet_service(internet_services_uri, service_data)
  validate_internet_service_data(service_data)
  if monitor = service_data[:monitor]
    validate_internet_service_monitor(monitor)
    ensure_monitor_defaults!(monitor)
  end

  request(
    :body     => generate_internet_service_request(service_data),
    :expects  => 200,
    :headers  => {'Content-Type' => 'application/vnd.tmrk.ecloud.internetService+xml'},
    :method   => 'POST',
    :uri      => internet_services_uri,
    :parse    => true
  )
end

#add_node(nodes_uri, node_data) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/fog/vcloud/terremark/ecloud/requests/add_node.rb', line 33

def add_node(nodes_uri, node_data)
  validate_node_data(node_data)

  request(
    :body     => generate_node_request(node_data),
    :expects  => 200,
    :headers  => {'Content-Type' => 'application/vnd.tmrk.ecloud.nodeService+xml'},
    :method   => 'POST',
    :uri      => nodes_uri,
    :parse    => true
  )
end

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



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/fog/vcloud/terremark/ecloud/requests/clone_vapp.rb', line 23

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_internet_service(internet_service_uri, service_data, ip_address_data) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/fog/vcloud/terremark/ecloud/requests/configure_internet_service.rb', line 19

def configure_internet_service(internet_service_uri, service_data, ip_address_data)
  validate_internet_service_data(service_data, true)

  validate_public_ip_address_data(ip_address_data)

  if monitor = service_data[:monitor]
    validate_internet_service_monitor(monitor)
    ensure_monitor_defaults!(monitor)
  end

  request(
    :body     => generate_configure_internet_service_request(service_data, ip_address_data),
    :expects  => 200,
    :headers  => {'Content-Type' => 'application/vnd.tmrk.ecloud.internetService+xml'},
    :method   => 'PUT',
    :uri      => internet_service_uri,
    :parse    => true
  )
end

#configure_network(network_uri, network_data) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/fog/vcloud/terremark/ecloud/requests/configure_network.rb', line 14

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.tmrk.ecloud.networkService+xml'},
    :method   => 'PUT',
    :uri      => network_uri,
    :parse    => true
  )
end

#configure_network_ip(network_ip_uri, network_ip_data) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/fog/vcloud/terremark/ecloud/requests/configure_network_ip.rb', line 19

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.tmrk.ecloud.ip+xml' },
    :method   => 'PUT',
    :uri      => network_ip_uri,
    :parse    => true
  )
end

#configure_node(node_uri, node_data) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/fog/vcloud/terremark/ecloud/requests/configure_node.rb', line 23

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.tmrk.ecloud.nodeService+xml'},
    :method   => 'PUT',
    :uri      => node_uri,
    :parse    => true
  )
end

#configure_vapp(vapp_uri, vapp_data) ⇒ Object



97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/fog/vcloud/terremark/ecloud/requests/configure_vapp.rb', line 97

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

#generate_clone_vapp_request(uri, options) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/fog/vcloud/terremark/ecloud/requests/clone_vapp.rb', line 15

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



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
95
# File 'lib/fog/vcloud/terremark/ecloud/requests/configure_vapp.rb', line 19

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

#instantiate_vapp_template(catalog_item_uri, options = {}) ⇒ Object



82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/fog/vcloud/terremark/ecloud/requests/instantiate_vapp_template.rb', line 82

def instantiate_vapp_template(catalog_item_uri, options = {})
  validate_instantiate_vapp_template_options(catalog_item_uri, options)

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

#supporting_versionsObject



178
179
180
# File 'lib/fog/vcloud/terremark/ecloud.rb', line 178

def supporting_versions
  ["v0.8b-ext2.6", "0.8b-ext2.6"]
end

#validate_clone_vapp_options(options) ⇒ Object



8
9
10
11
12
13
# File 'lib/fog/vcloud/terremark/ecloud/requests/clone_vapp.rb', line 8

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

#validate_network_data(network_data, configure = false) ⇒ Object



7
8
9
10
11
12
# File 'lib/fog/vcloud/terremark/ecloud/requests/configure_network.rb', line 7

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