def main(): api = el.get_client() # List existing VMs pprint(api.list_namespaced_virtual_machine(NAMESPACE)) # Create new one vm = el.read_yaml_file("vm-ephemeral.yaml") pprint(api.create_namespaced_virtual_machine(vm, NAMESPACE)) # Wait until VM is running try: w = el.Watch(api.list_namespaced_virtual_machine, NAMESPACE) vm = w.wait_for_item(el.get_name(vm), timeout=60, success_condition=lambda e: el.get_status(e[ 'object']) == "Running") except el.WaitForTimeout: vm = el.read_namespaced_virtual_machine(el.get_name(vm), NAMESPACE) raise Exception("VM is not in expected state: %s != %s" % (el.get_status(vm), "Running")) # Update memory of VM vm['spec']['domain']['resources']['requests']['memory'] = '512M' vm = api.replace_namespaced_virtual_machine(vm, NAMESPACE, el.get_name(vm)) pprint(vm) # Delete VM pprint( api.delete_namespaced_virtual_machine(V1DeleteOptions(), NAMESPACE, el.get_name(vm)))
def test_virtual_machine_instance_absent( self, mock_exit_json, mock_kubevirt_read, mock_kubevirt_delete, ): args = dict(state='absent', kind='VirtualMachineInstance', name='testvmi', namespace='vms', api_version='v1', resource_definition=V1VirtualMachineInstance().to_dict()) set_module_args(args) mock_kubevirt_read.return_value = V1VirtualMachineInstance() k = raw.KubeVirtRawModule() k.execute_module() mock_kubevirt_delete.assert_called_once_with(V1DeleteOptions(), 'vms', 'testvmi') mock_exit_json.assert_called_once_with(changed=True, result={})
def delete(self, name, namespace): """ Delete VirtualMachineInstancePreset resource """ return self.__client.delete_namespaced_virtual_machine_instance_preset( V1DeleteOptions(), namespace, name)
def delete(self, name, namespace): """ Delete VirtualMachine resource """ return self.__client.delete_namespaced_virtual_machine( V1DeleteOptions(), namespace, name)