Method: Fog::Compute::Ecloud::Shared#validate_create_server_options

Defined in:
lib/rackspace-fog/ecloud/requests/compute/virtual_machine_create_from_template.rb

#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/rackspace-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