Class: Fission::Action::VM::Cloner
- Defined in:
- lib/fission/action/vm/cloner.rb
Instance Method Summary collapse
-
#clone ⇒ Object
Public: Creates a new VM which is a clone of an existing VM.
-
#initialize(source_vm, target_vm) ⇒ Cloner
constructor
Internal: Creates a new VMCloner object.
Constructor Details
#initialize(source_vm, target_vm) ⇒ Cloner
18 19 20 21 |
# File 'lib/fission/action/vm/cloner.rb', line 18 def initialize(source_vm, target_vm) @source_vm = source_vm @target_vm = target_vm end |
Instance Method Details
#clone ⇒ Object
Public: Creates a new VM which is a clone of an existing VM. As Fusion doesn’t provide a native cloning mechanism, this is a best effort. This essentially is a directory copy with updates to relevant files. It’s recommended to clone VMs which are not running.
Examples
@cloner.clone
Returns a Response with the result. If successful, the Response’s data attribute will be nil. If there is an error, an unsuccessful Response will be returned.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/fission/action/vm/cloner.rb', line 35 def clone unless @source_vm.exists? return Response.new :code => 1, :message => 'VM does not exist' end if @target_vm.exists? return Response.new :code => 1, :message => 'VM already exists' end FileUtils.cp_r @source_vm.path, @target_vm.path rename_vm_files @source_vm.name, @target_vm.name update_config @source_vm.name, @target_vm.name Response.new :code => 0 end |