Class: Fog::Ecloud::Compute::Real

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

Instance Attribute Summary

Attributes included from Shared

#versions_uri

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Shared

#ecloud_xmlns, #ensure_monitor_defaults!, #ensure_unparsed, #supported_versions, #validate_backup_internet_service_data, #validate_internet_service_data, #validate_internet_service_monitor, #xmlns

Constructor Details

#initialize(options = {}) ⇒ Real

Returns a new instance of Real.



1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
# File 'lib/fog/compute/ecloud.rb', line 1138

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

  @connections = {}
  @versions_uri = URI.parse(options[:ecloud_versions_uri])
  @version = options[:ecloud_version]
  @username = options[:ecloud_username]
  @password = options[:ecloud_password]
  @persistent = options[:persistent]
end

Class Method Details

.basic_request(*args) ⇒ Object



1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
# File 'lib/fog/compute/ecloud.rb', line 1109

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



1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
# File 'lib/fog/compute/ecloud.rb', line 1123

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

#add_backup_internet_service(internet_services_uri, service_data) ⇒ Object



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

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



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/fog/compute/requests/ecloud/add_internet_service.rb', line 70

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



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

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



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/fog/compute/requests/ecloud/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_internet_service(internet_service_uri, service_data, ip_address_data) ⇒ Object



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

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



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/fog/compute/requests/ecloud/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.tmrk.ecloud.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/fog/compute/requests/ecloud/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.tmrk.ecloud.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/fog/compute/requests/ecloud/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.tmrk.ecloud.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/fog/compute/requests/ecloud/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

#default_organization_uriObject



1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
# File 'lib/fog/compute/ecloud.rb', line 1150

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

#generate_clone_vapp_request(uri, options) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/fog/compute/requests/ecloud/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/fog/compute/requests/ecloud/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

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



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

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

#loginObject



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/fog/compute/requests/ecloud/login.rb', line 8

def 
  unauthenticated_request({
    :expects  => 200,
    :headers  => {
      'Authorization' => authorization_header
    },
    :method   => 'POST',
    :parse    => true,
    :uri      => 
  })
end

#reloadObject



1166
1167
1168
# File 'lib/fog/compute/ecloud.rb', line 1166

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



1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
# File 'lib/fog/compute/ecloud.rb', line 1173

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

#supporting_versionsObject



1185
1186
1187
# File 'lib/fog/compute/ecloud.rb', line 1185

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

#validate_clone_vapp_options(options) ⇒ Object



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

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



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

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