def destroy(name, call=None): """ This function irreversibly destroys a virtual machine on the cloud provider. Before doing so, it should fire an event on the Salt event bus. The tag for this event is `salt/cloud/<vm name>/destroying`. Once the virtual machine has been destroyed, another event is fired. The tag for that event is `salt/cloud/<vm name>/destroyed`. Dependencies: list_nodes @param name: @type name: str @param call: @type call: @return: True if all went well, otherwise an error message @rtype: bool|str """ log.info("Attempting to delete instance %s", name) if not vb_machine_exists(name): return "{0} doesn't exist and can't be deleted".format(name) cloud.fire_event('event', 'destroying instance', 'salt/cloud/{0}/destroying'.format(name), {'name': name}, transport=__opts__['transport']) vb_destroy_machine(name) cloud.fire_event('event', 'destroyed instance', 'salt/cloud/{0}/destroyed'.format(name), {'name': name}, transport=__opts__['transport'])
def test_vm_creation_and_destruction(self): vm_name = BASE_BOX_NAME vb_create_machine(vm_name) self.assertMachineExists(vm_name) vb_destroy_machine(vm_name) self.assertMachineDoesNotExist(vm_name)
def test_create_machine(self): vb_name = "NewTestMachine" machine = vb_clone_vm(name=vb_name, clone_from=self.name) self.assertEqual(machine.get("name"), vb_name) self.assertMachineExists(vb_name) vb_destroy_machine(vb_name) self.assertMachineDoesNotExist(vb_name)
def test_create_machine(self): vb_name = "NewTestMachine" machine = vb_clone_vm( name=vb_name, clone_from=self.name ) self.assertEqual(machine.get("name"), vb_name) self.assertMachineExists(vb_name) vb_destroy_machine(vb_name) self.assertMachineDoesNotExist(vb_name)
def tearDown(self): try: vb_stop_vm(BOOTABLE_BASE_BOX_NAME) except Exception: pass if vb_machine_exists(INSTANCE_NAME): try: vb_stop_vm(INSTANCE_NAME) vb_destroy_machine(INSTANCE_NAME) except Exception as e: log.warning("Possibly dirty state after exception", exc_info=True)
def destroy(name, call=None): """ This function irreversibly destroys a virtual machine on the cloud provider. Before doing so, it should fire an event on the Salt event bus. The tag for this event is `salt/cloud/<vm name>/destroying`. Once the virtual machine has been destroyed, another event is fired. The tag for that event is `salt/cloud/<vm name>/destroyed`. Dependencies: list_nodes @param name: @type name: str @param call: @type call: @return: True if all went well, otherwise an error message @rtype: bool|str """ log.info("Attempting to delete instance %s", name) if not vb_machine_exists(name): return "{0} doesn't exist and can't be deleted".format(name) cloud.fire_event( 'event', 'destroying instance', 'salt/cloud/{0}/destroying'.format(name), args={'name': name}, sock_dir=__opts__['sock_dir'], transport=__opts__['transport'] ) vb_destroy_machine(name) cloud.fire_event( 'event', 'destroyed instance', 'salt/cloud/{0}/destroyed'.format(name), args={'name': name}, sock_dir=__opts__['sock_dir'], transport=__opts__['transport'] )
def tearDown(self): vb_destroy_machine(self.name) self.assertMachineDoesNotExist(self.name)
def tearDown(self): """ Clean up after tests """ if vb_machine_exists(INSTANCE_NAME): vb_destroy_machine(INSTANCE_NAME)
def tearDownClass(cls): vb_destroy_machine(BASE_BOX_NAME)