From 2209418218e5dddc7a8853c6607caf0130bc9f15 Mon Sep 17 00:00:00 2001 From: Piotr Kliczewski Date: Mon, 20 Aug 2018 15:59:09 +0200 Subject: [PATCH] examples: Make sure the examples run There was rename of entities in KubeVirt which were not reflected here. This PR fixes an issue with calling a method on the wrong object. Signed-off-by: Piotr Kliczewski --- examples/example_vms.py | 40 ++++++++++--------- .../{vm-ephemeral.yaml => vmi-ephemeral.yaml} | 4 +- 2 files changed, 24 insertions(+), 20 deletions(-) rename examples/{vm-ephemeral.yaml => vmi-ephemeral.yaml} (87%) diff --git a/examples/example_vms.py b/examples/example_vms.py index 1621d7db..7892a501 100644 --- a/examples/example_vms.py +++ b/examples/example_vms.py @@ -1,10 +1,11 @@ #!/usr/bin/env python """ -This script demostrates lifecycle of VM -* list existing VMs -* create VM -* wait until VM is running -* delete VM +This script demostrates lifecycle of VMI +* list existing VMIs and VMs +* create VMI +* wait until VMI is running +* update VMI +* delete VMI """ from pprint import pprint @@ -22,35 +23,38 @@ def main(): # List existing VMs pprint(api.list_namespaced_virtual_machine(NAMESPACE)) + # List existing VMIs + pprint(api.list_namespaced_virtual_machine_instance(NAMESPACE)) + # Create new one - vm = el.read_yaml_file("vm-ephemeral.yaml") - pprint(api.create_namespaced_virtual_machine(vm, NAMESPACE)) + vmi = el.read_yaml_file("vmi-ephemeral.yaml") + pprint(api.create_namespaced_virtual_machine_instance(vmi, 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, + w = el.Watch(api.list_namespaced_virtual_machine_instance, NAMESPACE) + vmi = w.wait_for_item( + el.get_name(vmi), 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) + vmi = api.read_namespaced_virtual_machine_instance(el.get_name(vmi), NAMESPACE) raise Exception( - "VM is not in expected state: %s != %s" % ( - el.get_status(vm), "Running" + "VMI is not in expected state: %s != %s" % ( + el.get_status(vmi), "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) + vmi['spec']['domain']['resources']['requests']['memory'] = '512M' + vmi = api.replace_namespaced_virtual_machine_instance(vmi, NAMESPACE, el.get_name(vmi)) + pprint(vmi) # Delete VM pprint( - api.delete_namespaced_virtual_machine( - V1DeleteOptions(), NAMESPACE, el.get_name(vm) + api.delete_namespaced_virtual_machine_instance( + V1DeleteOptions(), NAMESPACE, el.get_name(vmi) ) ) diff --git a/examples/vm-ephemeral.yaml b/examples/vmi-ephemeral.yaml similarity index 87% rename from examples/vm-ephemeral.yaml rename to examples/vmi-ephemeral.yaml index 71d3c194..c72ae3e2 100644 --- a/examples/vm-ephemeral.yaml +++ b/examples/vmi-ephemeral.yaml @@ -1,6 +1,6 @@ --- -apiVersion: kubevirt.io/v1alpha1 -kind: VirtualMachine +apiVersion: kubevirt.io/v1alpha2 +kind: VirtualMachineInstance metadata: creationTimestamp: null name: vm-ephemeral