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:
parent
1ec99a295c
commit
44ddaae200
4 changed files with 17 additions and 7 deletions
|
@ -123,7 +123,7 @@ module Fog
|
||||||
# This inline rescue catches any standard error. While a VM is
|
# This inline rescue catches any standard error. While a VM is
|
||||||
# cloning, a call to the macs method will throw and NoMethodError
|
# cloning, a call to the macs method will throw and NoMethodError
|
||||||
attrs['mac_addresses'] = vm_mob_ref.macs rescue nil
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -93,16 +93,23 @@ module Fog
|
||||||
connection.vm_migrate('instance_uuid' => instance_uuid, 'priority' => options[:priority])
|
connection.vm_migrate('instance_uuid' => instance_uuid, 'priority' => options[:priority])
|
||||||
end
|
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 = {})
|
def clone(options = {})
|
||||||
requires :name, :datacenter
|
requires :name, :datacenter
|
||||||
# Convert symbols to strings
|
# Convert symbols to strings
|
||||||
req_options = options.inject({}) { |hsh, (k,v)| hsh[k.to_s] = v; hsh }
|
req_options = options.inject({}) { |hsh, (k,v)| hsh[k.to_s] = v; hsh }
|
||||||
# Give our path to the request
|
# Give our path to the request
|
||||||
req_options['path'] ="#{path}/#{name}"
|
req_options['template_path'] ="#{path}/#{name}"
|
||||||
# Perform the actual clone
|
# Perform the actual clone
|
||||||
clone_results = connection.vm_clone(req_options)
|
clone_results = connection.vm_clone(req_options)
|
||||||
# Create the new VM model.
|
# 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
|
# We need to assign the collection and the connection otherwise we
|
||||||
# cannot reload the model.
|
# cannot reload the model.
|
||||||
new_vm.collection = self.collection
|
new_vm.collection = self.collection
|
||||||
|
|
|
@ -16,7 +16,7 @@ module Fog
|
||||||
else
|
else
|
||||||
# try to find based on VM name
|
# try to find based on VM name
|
||||||
if dc
|
if dc
|
||||||
get_datacenter(dc).find_vm(id)
|
get_raw_datacenter(dc).find_vm(id)
|
||||||
else
|
else
|
||||||
raw_datacenters.map { |d| d.find_vm(id) }.compact.first
|
raw_datacenters.map { |d| d.find_vm(id) }.compact.first
|
||||||
end
|
end
|
||||||
|
|
|
@ -10,7 +10,10 @@ module Fog
|
||||||
'linked_clone' => false,
|
'linked_clone' => false,
|
||||||
}
|
}
|
||||||
options = default_options.merge(options)
|
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|
|
required_options.each do |param|
|
||||||
raise ArgumentError, "#{required_options.join(', ')} are required" unless options.has_key? param
|
raise ArgumentError, "#{required_options.join(', ')} are required" unless options.has_key? param
|
||||||
end
|
end
|
||||||
|
@ -176,11 +179,11 @@ module Fog
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Return hash
|
# Return hash
|
||||||
{
|
{
|
||||||
'vm_ref' => new_vm ? new_vm._ref : nil,
|
'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
|
'task_ref' => task._ref
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue