def test_get_vm_power_status(self): """Retrieve virtual machine power status; return power status object.""" vm_name = 'test' vm = SpokeVMPowerXen(self.hv_uri, vm_name) result = vm.get()['data'][0]['state'] expected_result = 'On' self.assertEquals(result, expected_result)
def power_search(vm_name): from spoke.lib.vm_power import SpokeVMPowerXen vmp = SpokeVMPowerXen(hv_uri, vm_name) try: result = vmp.get() except error.SpokeError as e: result = common.handle_error(e) return result
def power_search(vm_name): try: conf = _spoke_config(_salt_config('config')) hv_uri = conf.get('VM', 'hv_uri') vmp = SpokeVMPowerXen(hv_uri, vm_name) result = vmp.get() except error.SpokeError as e: result = common.handle_error(e) return result
config = config.setup(config_file) if __name__ == '__main__': log = logger.setup('main', verbose=False, quiet=True) mc = mc.MCollectiveAction() request = mc.request() try: hv_uri = config.get('VM', 'hv_uri') vm_name = request['data']['hostname'] vmp = SpokeVMPowerXen(hv_uri, vm_name) except error.SpokeError, e: mc.fail(e.msg, e.exit_code) if request['action'] == 'search': try: mc.data = vmp.get() except error.SpokeError, e: mc.fail(e.msg, e.exit_code) elif request['action'] == 'on': try: mc.data = vmp.create() except error.SpokeError, e: mc.fail(e.msg, e.exit_code) elif request['action'] == 'off': try: mc.data = vmp.delete() except error.SpokeError, e: mc.fail(e.msg, e.exit_code) elif request['action'] == 'forceoff': try: mc.data = vmp.delete(force=True)