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_detach_disk.rb,
lib/fog/ecloud/requests/compute/virtual_machine_upload_file.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

#base_pathObject

Returns the value of attribute base_path.



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

def base_path
  @base_path
end

#versions_uriObject (readonly)

Returns the value of attribute versions_uri.



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

def versions_uri
  @versions_uri
end

Instance Method Details

#build_compute_pool_body_edit(options) ⇒ Object



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

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



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

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



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_create_from_template.rb', line 28

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

#build_request_body_attach_disk(options) ⇒ Object



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

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

#build_request_body_copy(options) ⇒ Object



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

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_detach_disk(options) ⇒ Object



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

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

#build_request_body_edit(options) ⇒ Object



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

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_edit_assigned_ips(networks) ⇒ Object



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

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

#build_request_body_identical(options) ⇒ Object



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

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



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

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



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

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

#id_from_uri(uri) ⇒ Object



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

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

#validate_create_server_options(template_uri, options) ⇒ Object



5
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_create_from_template.rb', line 5

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.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

#validate_create_server_options_copy(template_uri, options) ⇒ Object



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

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.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



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

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

  options
end

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



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

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

#validate_edit_compute_pool_options(options) ⇒ Object



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

def validate_edit_compute_pool_options(options)
  required_opts = [:name]
  unless required_opts.all? { |opt| options.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)


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

def validate_edit_internet_service_options(options)
  required_opts = [:name, :enabled, :persistence]
  unless required_opts.all? { |opt| options.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



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

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

#validate_edit_server_options(options) ⇒ Object



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

def validate_edit_server_options(options)
  required_opts = [:name]
  unless required_opts.all? { |opt| options.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



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

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.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

#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.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.key?(opt) }
    raise ArgumentError.new("Required Internet Service data missing: #{(required_opts - service_data.keys).map(&:inspect).join(", ")}")
  end
end

#validate_upload_file_options(options) ⇒ Object



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

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