1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

Added new output to vm_clone.rb

Fixed 'path' attribute on server model
fixed server.clone function and added some documentation.
This commit is contained in:
Nick Huanca 2012-12-01 06:42:13 -07:00
parent 1ec99a295c
commit 44ddaae200
4 changed files with 17 additions and 7 deletions

View file

@ -123,7 +123,7 @@ module Fog
# This inline rescue catches any standard error. While a VM is
# cloning, a call to the macs method will throw and NoMethodError
attrs['mac_addresses'] = vm_mob_ref.macs rescue nil
attrs['path'] = get_folder_path(vm_mob_ref.parent)
attrs['path'] = "/"+vm_mob_ref.parent.path.map(&:last).join('/')
end
end

View file

@ -93,16 +93,23 @@ module Fog
connection.vm_migrate('instance_uuid' => instance_uuid, 'priority' => options[:priority])
end
# Clone from a server object
#
# ==== Parameters
# *<~Hash>:
# * 'name'<~String> - *REQUIRED* Name of the _new_ VirtualMachine
# * See more options in vm_clone request/compute/vm_clone.rb
#
def clone(options = {})
requires :name, :datacenter
# Convert symbols to strings
req_options = options.inject({}) { |hsh, (k,v)| hsh[k.to_s] = v; hsh }
# Give our path to the request
req_options['path'] ="#{path}/#{name}"
req_options['template_path'] ="#{path}/#{name}"
# Perform the actual clone
clone_results = connection.vm_clone(req_options)
# Create the new VM model.
new_vm = self.class.new(clone_results['vm_attributes'])
new_vm = self.class.new(clone_results['new_vm'])
# We need to assign the collection and the connection otherwise we
# cannot reload the model.
new_vm.collection = self.collection

View file

@ -16,7 +16,7 @@ module Fog
else
# try to find based on VM name
if dc
get_datacenter(dc).find_vm(id)
get_raw_datacenter(dc).find_vm(id)
else
raw_datacenters.map { |d| d.find_vm(id) }.compact.first
end

View file

@ -10,7 +10,10 @@ module Fog
'linked_clone' => false,
}
options = default_options.merge(options)
required_options = %w{ path name }
# Backwards compat for "path" option
options["template_path"] ||= options["path"]
options["path"] ||= options["template_path"]
required_options = %w{ template_path name }
required_options.each do |param|
raise ArgumentError, "#{required_options.join(', ')} are required" unless options.has_key? param
end
@ -176,11 +179,11 @@ module Fog
nil
end
end
# Return hash
{
'vm_ref' => new_vm ? new_vm._ref : nil,
'vm_attributes' => new_vm ? convert_vm_mob_ref_to_attr_hash(new_vm) : {},
'new_vm' => new_vm ? get_virtual_machine("#{path_elements.join('/')}/#{options['name']}", template_dc) : nil,
'task_ref' => task._ref
}
end