Module: Fog::Compute::Ecloud::Shared

Included in:
Real
Defined in:
lib/fog/ecloud/compute.rb,
lib/fog/ecloud/requests/compute/compute_pool_edit.rb,
lib/fog/ecloud/requests/compute/node_service_edit.rb,
lib/fog/ecloud/requests/compute/node_service_create.rb,
lib/fog/ecloud/requests/compute/virtual_machine_copy.rb,
lib/fog/ecloud/requests/compute/virtual_machine_edit.rb,
lib/fog/ecloud/requests/compute/internet_service_edit.rb,
lib/fog/ecloud/requests/compute/virtual_machine_import.rb,
lib/fog/ecloud/requests/compute/internet_service_create.rb,
lib/fog/ecloud/requests/compute/virtual_machine_copy_identical.rb,
lib/fog/ecloud/requests/compute/virtual_machine_create_from_template.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#versions_uriObject (readonly)

Returns the value of attribute versions_uri.



262
263
264
# File 'lib/fog/ecloud/compute.rb', line 262

def versions_uri
  @versions_uri
end

Instance Method Details

#build_compute_pool_body_edit(options) ⇒ Object



13
14
15
16
17
# File 'lib/fog/ecloud/requests/compute/compute_pool_edit.rb', line 13

def build_compute_pool_body_edit(options)
  xml = Builder::XmlMarkup.new
  xml.ComputePool(:name => options[:name]) do
  end    
end

#build_node_service_body_edit(options) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/fog/ecloud/requests/compute/node_service_edit.rb', line 13

def build_node_service_body_edit(options)
  xml = Builder::XmlMarkup.new
  xml.NodeService(:name => options[:name]) do
    xml.Enabled options[:enabled]
    if options[:description]
      xml.Description options[:description]
    end
  end    
end

#build_request_body(options) ⇒ Object



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
96
97
98
99
100
101
102
103
104
105
# File 'lib/fog/ecloud/requests/compute/virtual_machine_create_from_template.rb', line 35

def build_request_body(options)
  xml = Builder::XmlMarkup.new
  xml.CreateVirtualMachine(:name => options[:name]) do
    xml.ProcessorCount options[:cpus]
    xml.Memory do
      xml.Unit "MB"
      xml.Value options[:memory]
    end
    xml.Layout do
      xml.NewRow options[:row]
      xml.NewGroup options[:group]
    end
    xml.Description options[:description]
    xml.Tags do
      options[:tags].each do |tag|
        xml.Tag tag
      end
    end
    if options[:customization] == :windows
      xml.WindowsCustomization do
        xml.NetworkSettings do
          xml.NetworkAdapterSettings do
            options[:network_uri].each do |uri|
              xml.NetworkAdapter do
                xml.Network(:href => uri[:href], :name => uri[:name], :type => "application/vnd.tmrk.cloud.network")
                xml.IpAddress uri[:ip]
              end
            end
          end
          if options[:dns_settings]
            xml.DnsSettings do
              xml.PrimaryDns options[:dns_settings][:primary_dns]
              if options[:dns_settings][:secondary_dns]
                xml.SecondaryDns options[:dns_settings][:secondary_dns]
              end
            end
          end
        end
        xml.Password options[:windows_password]
        if options[:windows_license_key]
          xml.LicenseKey options[:windows_license_key]
        end
      end
    else
      xml.LinuxCustomization do
        xml.NetworkSettings do
          xml.NetworkAdapterSettings do
            options[:network_uri] = options[:network_uri].is_a?(String) ? [options[:network_uri]] : options[:network_uri]
            options[:network_uri].each do |uri|
              xml.NetworkAdapter do
                xml.Network(:href => uri[:href], :name => uri[:name], :type => "application/vnd.tmrk.cloud.network") 
                xml.IpAddress uri[:ip]
              end
            end
          end
          if options[:dns_settings]
            xml.DnsSettings do
              xml.PrimaryDns options[:dns_settings][:primary_dns]
              if options[:dns_settings][:secondary_dns]
                xml.SecondaryDns options[:dns_settings][:secondary_dns]
              end
            end
          end
        end                
      end
      xml.SshKey(:href => options[:ssh_key_uri])
    end
    xml.PoweredOn options[:powered_on]
    xml.Template(:href => options[:template_uri], :type => options[:template_type]) 
  end
end

#build_request_body_copy(options) ⇒ Object



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
96
97
98
# File 'lib/fog/ecloud/requests/compute/virtual_machine_copy.rb', line 28

def build_request_body_copy(options)
  xml = Builder::XmlMarkup.new
  xml.CopyVirtualMachine(:name => options[:name]) do
    xml.Source(:href => options[:source], :type => "application/vnd.tmrk.cloud.virtualMachine")
    xml.ProcessorCount options[:cpus]
    xml.Memory do
      xml.Unit "MB"
      xml.Value options[:memory]
    end
    xml.Layout do
      xml.NewRow options[:row]
      xml.NewGroup options[:group]
    end
    if options[:customization] == :windows
      xml.WindowsCustomization do
        xml.NetworkSettings do
          xml.NetworkAdapterSettings do
            options[:network_uri].each do |uri|
              xml.NetworkAdapter do
                xml.Network(:href => uri[:href], :name => uri[:name], :type => "application/vnd.tmrk.cloud.network")
                xml.IpAddress uri[:ip]
              end
            end
          end
          if options[:dns_settings]
            xml.DnsSettings do
              xml.PrimaryDns options[:dns_settings][:primary_dns]
              if options[:dns_settings][:secondary_dns]
                xml.SecondaryDns options[:dns_settings][:secondary_dns]
              end
            end
          end
        end
        xml.Password options[:windows_password]
        if options[:windows_license_key]
          xml.LicenseKey options[:windows_license_key]
        end
      end
    else
      xml.LinuxCustomization do
        xml.NetworkSettings do
          xml.NetworkAdapterSettings do
            options[:network_uri] = options[:network_uri].is_a?(String) ? [options[:network_uri]] : options[:network_uri]
            options[:network_uri].each do |uri|
              xml.NetworkAdapter do
                xml.Network(:href => uri[:href], :name => uri[:name], :type => "application/vnd.tmrk.cloud.network") 
                xml.IpAddress uri[:ip]
              end
            end
          end
          if options[:dns_settings]
            xml.DnsSettings do
              xml.PrimaryDns options[:dns_settings][:primary_dns]
              if options[:dns_settings][:secondary_dns]
                xml.SecondaryDns options[:dns_settings][:secondary_dns]
              end
            end
          end
        end                
      end
      xml.SshKey(:href => options[:ssh_key_uri])
    end
    xml.Description options[:description]
    xml.Tags do
      options[:tags].each do |tag|
        xml.Tag tag
      end
    end
    xml.PoweredOn options[:powered_on]
  end
end

#build_request_body_edit(options) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/fog/ecloud/requests/compute/virtual_machine_edit.rb', line 13

def build_request_body_edit(options)
  xml = Builder::XmlMarkup.new
  xml.VirtualMachine(:name => options[:name]) do
    if options[:description]
      xml.Description options[:description]
    end
    if options[:tags]
      xml.Tags do
        options[:tags].each do |tag|
          xml.Tag tag
        end
      end
    end
  end    
end

#build_request_body_identical(options) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/fog/ecloud/requests/compute/virtual_machine_copy_identical.rb', line 15

def build_request_body_identical(options)
  xml = Builder::XmlMarkup.new
  xml.CopyIdenticalVirtualMachine(:name => options[:name]) do
    xml.Source(:href => options[:source], :type => "application/vnd.tmrk.cloud.virtualMachine")
    xml.Layout do
      xml.NewRow options[:row]
      xml.NewGroup options[:group]
    end
    xml.Description options[:description]
  end
end

#build_request_body_import(options) ⇒ Object



17
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
# File 'lib/fog/ecloud/requests/compute/virtual_machine_import.rb', line 17

def build_request_body_import(options)
  xml = Builder::XmlMarkup.new
  xml.ImportVirtualMachine(:name => options[:name]) do
    xml.ProcessorCount options[:cpus]
    xml.Memory do
      xml.Unit "MB"
      xml.Value options[:memory]
    end
    xml.Layout do
      xml.NewRow options[:row]
      xml.NewGroup options[:group]
    end
    xml.Description options[:description]
    if options[:tags]
      xml.Tags do
        options[:tags].each do |tag|
          xml.Tag tag
        end
      end
    end
    xml.CatalogEntry(:href => options[:template_uri])
    xml.NetworkMappings do
      xml.NetworkMapping(:name => options[:catalog_network_name]) do
        xml.Network(:href => options[:network_uri][0])
      end
    end
    if options[:operating_system]
      xml.OperatingSystem(:href => options[:operating_system][:href], :name => options[:operating_system][:name], :type => "application/vnd.tmrk.cloud.operatingSystem")
    end
  end
end

#default_organization_uriObject



264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
# File 'lib/fog/ecloud/compute.rb', line 264

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

#do_loginObject

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



282
283
284
# File 'lib/fog/ecloud/compute.rb', line 282

def 
  @login_results = get_organizations
end

#ecloud_xmlnsObject



286
287
288
289
290
291
# File 'lib/fog/ecloud/compute.rb', line 286

def ecloud_xmlns
  {
    "xmlns"     => "urn:tmrk:eCloudExtensions-2.8",
    "xmlns:i"   => "http://www.w3.org/2001/XMLSchema-instance"
  }
end

#ensure_unparsed(uri) ⇒ Object



293
294
295
296
297
298
299
# File 'lib/fog/ecloud/compute.rb', line 293

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

#supported_versionsObject



301
302
303
# File 'lib/fog/ecloud/compute.rb', line 301

def supported_versions
  @supported_versions ||= get_versions(@versions_uri).body[:VersionInfo]
end

#validate_create_server_options(template_uri, options) ⇒ 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
30
31
32
33
# File 'lib/fog/ecloud/requests/compute/virtual_machine_create_from_template.rb', line 6

def validate_create_server_options(template_uri, options)
  required_opts = [:name, :cpus, :memory, :row, :group, :customization, :network_uri]
  if options[:customization] == :windows
    required_opts.push(:windows_password)
  else
    required_opts.push(:ssh_key_uri)
  end
  unless required_opts.all? { |opt| options.has_key?(opt) }
    raise ArgumentError.new("Required data missing: #{(required_opts - options.keys).map(&:inspect).join(", ")}")
  end

  if template_uri.scan(/\/catalog\/\d+/)[0]
    options[:template_type] = get_catalog_item(template_uri).body[:type]
  elsif template_uri.scan(/\/templates\/\d+/)[0]
    options[:template_type] = get_template(template_uri).body[:type]
  end

  options[:network_uri] = options[:network_uri].is_a?(String) ? [options[:network_uri]] : options[:network_uri]
  options[:network_uri].map! do |uri|
    network = get_network(uri).body
    if options[:ips]
      ip = options[:ips][options[:network_uri].index(uri)]
    end
    {:href => uri, :name => network[:name], :ip => ip}
  end 
  options[:template_uri] = template_uri
  options
end

#validate_create_server_options_copy(template_uri, options) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/fog/ecloud/requests/compute/virtual_machine_copy.rb', line 6

def validate_create_server_options_copy(template_uri, options)
  required_opts = [:name, :cpus, :memory, :row, :group, :customization, :network_uri, :source]
  if options[:customization] == :windows
    required_opts.push(:windows_password)
  else
    required_opts.push(:ssh_key_uri)
  end
  unless required_opts.all? { |opt| options.has_key?(opt) }
    raise ArgumentError.new("Required data missing: #{(required_opts - options.keys).map(&:inspect).join(", ")}")
  end

  options[:network_uri] = options[:network_uri].is_a?(String) ? [options[:network_uri]] : options[:network_uri]
  options[:network_uri].map! do |uri|
    network = get_network(uri).body
    if options[:ips]
      ip = options[:ips][options[:network_uri].index(uri)]
    end
    {:href => uri, :name => network[:name], :ip => ip}
  end 
  options
end

#validate_create_server_options_identical(template_uri, options) ⇒ Object



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

def validate_create_server_options_identical(template_uri, options)
  required_opts = [:name, :row, :group, :source]
  unless required_opts.all? { |opt| options.has_key?(opt) }
    raise ArgumentError.new("Required data missing: #{(required_opts - options.keys).map(&:inspect).join(", ")}")
  end

  options
end

#validate_data(required_opts = [], options = {}) ⇒ Object



311
312
313
314
315
# File 'lib/fog/ecloud/compute.rb', line 311

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

#validate_edit_compute_pool_options(options) ⇒ Object



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

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

#validate_edit_internet_service_options(options) ⇒ Object

Raises:

  • (ArgumentError)


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

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

#validate_edit_node_service_options(options) ⇒ Object



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

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

#validate_edit_server_options(options) ⇒ Object



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

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

#validate_import_server_options(template_uri, options) ⇒ Object



6
7
8
9
10
11
12
13
14
15
# File 'lib/fog/ecloud/requests/compute/virtual_machine_import.rb', line 6

def validate_import_server_options(template_uri, options)
  required_opts = [:name, :cpus, :memory, :row, :group, :network_uri, :catalog_network_name]
  unless required_opts.all? { |opt| options.has_key?(opt) }
    raise ArgumentError.new("Required data missing: #{(required_opts - options.keys).map(&:inspect).join(", ")}")
  end

  options[:network_uri] = options[:network_uri].is_a?(String) ? [options[:network_uri]] : options[:network_uri]
  options[:template_uri] = template_uri
  options
end

#validate_internet_service_data(service_data) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/fog/ecloud/requests/compute/internet_service_create.rb', line 5

def validate_internet_service_data(service_data)
  required_opts = [:name, :protocol, :port, :description, :enabled, :persistence]
  unless required_opts.all? { |opt| service_data.has_key?(opt) }
    raise ArgumentError.new("Required Internet Service data missing: #{(required_opts - service_data.keys).map(&:inspect).join(", ")}")
  end
  if service_data[:trusted_network_group]
    raise ArgumentError.new("Required Trusted Network Group data missing: #{([:name, :href] - service_data[:trusted_network_group].keys).map(&:inspect).join(", ")}")
  end
  if service_data[:backup_internet_service]
    raise ArgumentError.new("Required Backup Internet Service data missing: #{([:name, :href] - service_data[:backup_internet_service].keys).map(&:inspect).join(", ")}")
  end
end

#validate_node_service_data(service_data) ⇒ Object



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

def validate_node_service_data(service_data)
  required_opts = [:name, :port, :enabled, :ip_address]
  unless required_opts.all? { |opt| service_data.has_key?(opt) }
    raise ArgumentError.new("Required Internet Service data missing: #{(required_opts - service_data.keys).map(&:inspect).join(", ")}")
  end
end

#xmlnsObject



305
306
307
308
309
# File 'lib/fog/ecloud/compute.rb', line 305

def xmlns
  { "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" }
end