def test_9998_teardown(self): """Delete the vApp created during setup. This test passes if the task for deleting the vApp succeed. """ vapps_to_delete = [] if TestVM._test_vapp_href is not None: vapps_to_delete.append(TestVM._test_vapp_name) vapp = VApp(TestVM._client, href=TestVM._test_vapp_href) if vapp.is_powered_on(): task = vapp.power_off() TestVM._client.get_task_monitor().wait_for_success(task) task = vapp.undeploy() TestVM._client.get_task_monitor().wait_for_success(task) if TestVM._empty_vapp_href is not None: vapps_to_delete.append(TestVM._empty_vapp_name) if TestVM._test_vapp_vmtools_href is not None: vapps_to_delete.append(TestVM._test_vapp_vmtools_name) vapp = VApp(TestVM._client, href=TestVM._test_vapp_vmtools_href) if vapp.is_powered_on(): task = vapp.power_off() TestVM._client.get_task_monitor().wait_for_success(task) task = vapp.undeploy() TestVM._client.get_task_monitor().wait_for_success(task) vdc = Environment.get_test_vdc(TestVM._sys_admin_client) vdc.delete_disk(name=self._idisk_name) vdc = Environment.get_test_vdc(TestVM._client) for vapp_name in vapps_to_delete: task = vdc.delete_vapp(name=vapp_name, force=True) result = TestVM._client.get_task_monitor().wait_for_success(task) self.assertEqual(result.get('status'), TaskStatus.SUCCESS.value)
def power_off(self): vapp_name = self.params.get('vapp_name') response = dict() response['changed'] = False vapp = self.get_vapp() if vapp.is_powered_off(): msg = 'Vapp {} is already powered off' response['warnings'] = msg.format(vapp_name) return response try: vapp_resource = self.vdc.get_vapp(vapp_name) vapp = VApp(self.client, name=vapp_name, resource=vapp_resource) power_off_vapp_task = vapp.power_off() self.execute_task(power_off_vapp_task) msg = 'Vapp {} has been powered off' response['msg'] = msg.format(vapp_name) response['changed'] = True except OperationNotSupportedException: msg = 'Operation is not supported. You may have no VM(s) in {}' response['warnings'] = msg.format(vapp_name) return response
def test_0060_detach_disk_from_vm_in_vapp(self): """Test the method vapp.detach_disk_to_vm(). Invoke the method for the second independent disk, detach it from the first vm of the vApp created during setup. We need to power down the vm before running this test, and power it back on once the test is over. This test passes if the disk detachment task succeeds. """ vdc = Environment.get_test_vdc(TestDisk._client) vapp = VApp(TestDisk._client, href=TestDisk._test_vapp_href) vm_name = TestDisk._test_vapp_first_vm_name disk = vdc.get_disk(disk_id=TestDisk._idisk2_id) # vm needs to be powered off for detach to succeed. is_vapp_powered_on_before_test = vapp.is_powered_on() if is_vapp_powered_on_before_test: task = vapp.power_off() TestDisk._client.get_task_monitor().wait_for_success(task=task) vapp.reload() task = vapp.detach_disk_from_vm( disk_href=disk.get('href'), vm_name=vm_name) TestDisk._client.get_task_monitor().wait_for_success(task=task) vapp.reload() # restore vApp to powered on state (if required) if is_vapp_powered_on_before_test: task = vapp.power_on() TestDisk._client.get_task_monitor().wait_for_success(task=task)
def power_off(ctx, name, force): try: client = ctx.obj['client'] vdc_href = ctx.obj['profiles'].get('vdc_href') vdc = VDC(client, href=vdc_href) vapp_resource = vdc.get_vapp(name) vapp = VApp(client, resource=vapp_resource) task = vapp.power_off() stdout(task, ctx) except Exception as e: stderr(e, ctx)
def power_off(self): vapp_name = self.params.get('vapp_name') response = dict() response['changed'] = False try: vapp_resource = self.vdc.get_vapp(vapp_name) vapp = VApp(self.client, name=vapp_name, resource=vapp_resource) power_off_vapp_task = vapp.power_off() self.execute_task(power_off_vapp_task) response['msg'] = 'Vapp {} has been powered off.'.format(vapp_name) response['changed'] = True except OperationNotSupportedException: response['warnings'] = 'Vapp {} is already powered off.'.format(vapp_name) return response
def power_off(self): params = self.module.params client = self.module.client vdc_name = params.get('vdc') vapp_name = params.get('name') response = dict() vdc = self.get_vdc_object(vdc_name) vapp_resource = vdc.get_vapp(vapp_name) vapp = VApp(client, name=vapp_name, resource=vapp_resource) power_off_vapp_task = vapp.power_off() self.execute_task(power_off_vapp_task) response['msg'] = 'Vapp {} has been powered off.'.format(vapp_name) response['changed'] = True return response
def power_off(self): vapp_name = self.params.get('vapp_name') response = dict() response['changed'] = False try: vapp_resource = self.vdc.get_vapp(vapp_name) vapp = VApp(self.client, name=vapp_name, resource=vapp_resource) power_off_vapp_task = vapp.power_off() self.execute_task(power_off_vapp_task) response['msg'] = 'Vapp {} has been powered off.'.format(vapp_name) response['changed'] = True except OperationNotSupportedException: response['warnings'] = 'Vapp {} is already powered off.'.format( vapp_name) return response
def power_off(ctx, name, vm_names): try: client = ctx.obj['client'] vdc_href = ctx.obj['profiles'].get('vdc_href') vdc = VDC(client, href=vdc_href) vapp_resource = vdc.get_vapp(name) vapp = VApp(client, resource=vapp_resource) if len(vm_names) == 0: task = vapp.power_off() stdout(task, ctx) else: for vm_name in vm_names: vm = VM(client, resource=vapp.get_vm(vm_name)) task = vm.power_off() stdout(task, ctx) except Exception as e: stderr(e, ctx)
def power_off(ctx, name, vm_names): try: restore_session(ctx, vdc_required=True) client = ctx.obj['client'] vdc_href = ctx.obj['profiles'].get('vdc_href') vdc = VDC(client, href=vdc_href) vapp_resource = vdc.get_vapp(name) vapp = VApp(client, resource=vapp_resource) if len(vm_names) == 0: task = vapp.power_off() stdout(task, ctx) else: for vm_name in vm_names: vm = VM(client, resource=vapp.get_vm(vm_name)) task = vm.power_off() stdout(task, ctx) except Exception as e: stderr(e, ctx)
or ('ip_address' not in vm_obj.list_nics()[0].keys())): print(" VM '{0}' ... {1} - IP = {2}\r".format( vm.get('name'), "UP", "... (waiting)".ljust(20)), end='') vm_obj.reload() time.sleep(5) print(" VM '{0}' ... {1} - IP = {2}".format( vm.get('name'), "UP", vm_obj.list_nics()[0]['ip_address'].ljust(20))) if (vapp.is_powered_on()): print(" vApp '{0}' ... powering off {1}\r".format(cfg.vapp['name'], "".ljust(20)), end='') # result = vapp.shutdown() result = vapp.power_off() handle_task(client, result) print(" vApp '{0}' ... DOWN {1}\r".format(cfg.vapp['name'], "".ljust(20)), end='') result = vapp.undeploy() handle_task(client, result) print(" vApp '{0}' ... UNDEPLOYED {1}\r".format(cfg.vapp['name'], "".ljust(20))) else: print(" vApp '{0}' ... UNDEPLOYED (already)".format( cfg.vapp['name']).ljust(20)) result = vdc.delete_vapp(cfg.vapp['name'], force=True) handle_task(client, result) print(" vApp '{0}' ... DELETED".format(cfg.vapp['name']).ljust(20))