Skip to content
This repository has been archived by the owner on Mar 6, 2024. It is now read-only.

Commit

Permalink
Copy/Move VM from source vApp to target vApp
Browse files Browse the repository at this point in the history
This commit address issue to copy/move vms from
source vApp to target vApp

Work towards: #200
  • Loading branch information
mukultaneja committed Feb 10, 2022
1 parent 6403bf6 commit 620997c
Showing 1 changed file with 44 additions and 1 deletion.
45 changes: 44 additions & 1 deletion modules/vcd_vapp_vm.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,8 @@
VAPP_VM_SET_METADATA_VALUE_TYPE = ['String', 'Number', 'Boolean', 'DateTime']
VAPP_VM_OPERATIONS = ['poweron', 'poweroff', 'reloadvm',
'deploy', 'undeploy', 'list_disks', 'list_nics',
'set_meta', 'get_meta', 'remove_meta']
'set_meta', 'get_meta', 'remove_meta', 'copy',
'move']


def vapp_vm_argument_spec():
Expand Down Expand Up @@ -310,6 +311,12 @@ def manage_operations(self):
if operation == "remove_meta":
return self.remove_meta()

if operation == "move":
return self.move_vm()

if operation == "copy":
return self.copy_vm()

def get_org(self):
org_name = self.params.get('org_name')
org_resource = self.client.get_org()
Expand Down Expand Up @@ -635,6 +642,42 @@ def remove_meta(self):

return response

def copy_vm(self):
response = dict()
response['changed'] = False
target_vm_name = self.params.get('target_vm_name')
source_vapp_name = self.params.get('source_vapp')
target_vapp_name = self.params.get('target_vapp')
vm = self.get_vm()

try:
vm.copy_to(source_vapp_name, target_vapp_name, target_vm_name)
msg = "VM has been copied to {0} with name {1}"
response["msg"] = msg.format(target_vapp_name, target_vm_name)
response['changed'] = True
except Exception as ex:
response['msg'] = ex

return response

def move_vm(self):
response = dict()
response['changed'] = False
target_vm_name = self.params.get('target_vm_name')
source_vapp_name = self.params.get('source_vapp')
target_vapp_name = self.params.get('target_vapp')
vm = self.get_vm()

try:
vm.move_to(source_vapp_name, target_vapp_name, target_vm_name)
msg = "VM has been moved to {0} with name {1}"
response["msg"] = msg.format(target_vapp_name, target_vm_name)
response['changed'] = True
except Exception as ex:
response['msg'] = ex

return response


def main():
argument_spec = vapp_vm_argument_spec()
Expand Down

0 comments on commit 620997c

Please sign in to comment.