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

Included in:
Mock, 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_attach_disk.rb,
lib/fog/ecloud/requests/compute/virtual_machine_upload_file.rb,
lib/fog/ecloud/requests/compute/virtual_machine_detach_disk.rb,
lib/fog/ecloud/requests/compute/virtual_machine_copy_identical.rb,
lib/fog/ecloud/requests/compute/virtual_machine_edit_assigned_ips.rb,
lib/fog/ecloud/requests/compute/virtual_machine_create_from_template.rb

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Instance Attribute Details

- (Object) base_path

Returns the value of attribute base_path



251
252
253
# File 'lib/fog/ecloud/compute.rb', line 251

def base_path
  @base_path
end

- (Object) versions_uri (readonly)

Returns the value of attribute versions_uri



252
253
254
# File 'lib/fog/ecloud/compute.rb', line 252

def versions_uri
  @versions_uri
end

Instance Method Details

- (Object) build_compute_pool_body_edit(options)



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

- (Object) build_node_service_body_edit(options)



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

- (Object) build_request_body(options)



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

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
        xml.SshKey(:href => options[:ssh_key_uri])
      end
    end
    xml.PoweredOn options[:powered_on]
    xml.Template(:href => options[:template_uri], :type => options[:template_type])
  end
end

- (Object) build_request_body_attach_disk(options)



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

def build_request_body_attach_disk(options)
  xml = Builder::XmlMarkup.new
  xml.AttachDisks(:name => options[:name]) do
    xml.DetachedDisks do
      xml.DetachedDisk(:href => options[:href], :name => options[:name], :type => "application/vnd.tmrk.cloud.detachedDisk")
    end
  end
end

- (Object) build_request_body_copy(options)



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

- (Object) build_request_body_detach_disk(options)



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

def build_request_body_detach_disk(options)
  xml = Builder::XmlMarkup.new
  xml.DetachDisk(:name => options[:name]) do
    xml.Description options[:description]
    xml.Disk do
      xml.Index options[:disk][:Index]
    end
  end
end

- (Object) build_request_body_edit(options)



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

- (Object) build_request_body_edit_assigned_ips(networks)



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

def build_request_body_edit_assigned_ips(networks)
  xml = Builder::XmlMarkup.new
  xml.AssignedIpAddresses do
    xml.Networks do
      networks.each do |network|
        xml.Network(:href => network[:href], :type => network[:type]) do
          xml.IpAddresses do
            network[:ips].each do |ip|
              xml.IpAddress ip
            end
          end
        end
      end
    end
  end
end

- (Object) build_request_body_identical(options)



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

- (Object) build_request_body_import(options)



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

- (Object) default_organization_uri



264
265
266
# File 'lib/fog/ecloud/compute.rb', line 264

def default_organization_uri
  "#{@base_path}/organizations"
end

- (Object) id_from_uri(uri)



260
261
262
# File 'lib/fog/ecloud/compute.rb', line 260

def id_from_uri(uri)
  uri.match(/(\d+)$/)[1].to_i
end

- (Object) validate_create_server_options(template_uri, options)



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# 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

  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

- (Object) validate_create_server_options_copy(template_uri, options)



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

- (Object) validate_create_server_options_identical(template_uri, options)



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

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



254
255
256
257
258
# File 'lib/fog/ecloud/compute.rb', line 254

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

- (Object) validate_edit_compute_pool_options(options)



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

- (Object) validate_edit_internet_service_options(options)

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

- (Object) validate_edit_node_service_options(options)



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

- (Object) validate_edit_server_options(options)



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

- (Object) validate_import_server_options(template_uri, options)



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]]
  options[:template_uri] = template_uri
  options
end

- (Object) validate_internet_service_data(service_data)



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

- (Object) validate_node_service_data(service_data)



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

- (Object) validate_upload_file_options(options)



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

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