def cleanup():
    vm = get_vm(stub_config, vm_name)
    if vm:
        power_svc = Power(stub_config)
        vm_svc = VM(stub_config)
        state = power_svc.get(vm)
        if state == Power.Info(state=Power.State.POWERED_ON):
            power_svc.stop(vm)
        elif state == Power.Info(state=Power.State.SUSPENDED):
            power_svc.start(vm)
            power_svc.stop(vm)
        print("Deleting VM '{}' ({})".format(vm_name, vm))
        vm_svc.delete(vm)
Ejemplo n.º 2
0
 def run(self):
     """
     Delete User specified VM from Server
     """
     vm_svc = VM(self.service_manager.stub_config)
     power_svc = Power(self.service_manager.stub_config)
     vm = get_vm(self.service_manager.stub_config, self.vm_name)
     if not vm:
         raise Exception('Sample requires an existing vm with name ({}).'
                         'Please create the vm first.'.format(vm_name))
     print("Deleting VM -- '{}-({})')".format(self.vm_name, vm))
     state = power_svc.get(vm)
     if state == Power.Info(state=Power.State.POWERED_ON):
         power_svc.stop(vm)
     elif state == Power.Info(state=Power.State.SUSPENDED):
         power_svc.start(vm)
         power_svc.stop(vm)
     vm_svc.delete(vm)
     print("Deleted VM -- '{}-({})".format(self.vm_name, vm))