Method: Fog::Compute::Ecloud::Server#copy

Defined in:
lib/rackspace-fog/ecloud/models/compute/server.rb

#copy(options = {}) ⇒ Object



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/rackspace-fog/ecloud/models/compute/server.rb', line 102

def copy(options = {})
  options = {:type => :copy}.merge(options)
  options[:source] ||= href
  if options[:type] == :copy
    options[:cpus] ||= 1
    options[:memory] ||= 512
    options[:customization] ||= :linux
    options[:tags] ||= []
    options[:powered_on] ||= false
    if options[:ips]
      options[:ips] = options[:ips].is_a?(String) ? [options[:ips]] : options[:ips]
    else
      options[:network_uri] = options[:network_uri].is_a?(String) ? [options[:network_uri]] : options[:network_uri]
      options[:network_uri].each do |uri|
        index = options[:network_uri].index(uri)
        ip = Fog::Compute::Ecloud::IpAddresses.new(:connection => connection, :href => uri).detect { |i| i.host == nil }.name
        options[:ips] ||= []
        options[:ips][index] = ip
      end
    end
    data = connection.virtual_machine_copy("/cloudapi/ecloud/virtualMachines/computePools/#{compute_pool_id}/action/copyVirtualMachine", options).body
  elsif options[:type] == :identical
    data = connection.virtual_machine_copy_identical("/cloudapi/ecloud/virtualMachines/computePools/#{compute_pool_id}/action/copyIdenticalVirtualMachine", options).body
  end
  vm = collection.from_data(data)
  vm
end