fix(kubevirt_vm): Allow switching between running and run_strategy

Allow switching between running and run_strategy by always clearing the
other value. E.g. if run_strategy was provided then running set to None
to clear it or vice versa.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
This commit is contained in:
Felix Matouschek
2025-04-28 17:19:19 +02:00
parent 0b542ddced
commit aeb98d241c
2 changed files with 16 additions and 0 deletions

View File

@@ -333,7 +333,9 @@ def create_vm(params: Dict) -> Dict:
if (run_strategy := params.get("run_strategy")) is not None:
vm["spec"]["runStrategy"] = run_strategy
vm["spec"]["running"] = None
else:
vm["spec"]["runStrategy"] = None
vm["spec"]["running"] = (
running if (running := params.get("running")) is not None else True
)

View File

@@ -44,6 +44,7 @@ VM_DEFINITION_CREATE = {
},
"spec": {
"running": True,
"runStrategy": None,
"instancetype": {"name": "u1.medium"},
"preference": {"name": "fedora"},
"dataVolumeTemplates": [
@@ -83,6 +84,7 @@ VM_DEFINITION_RUNNING = {
},
"spec": {
"running": True,
"runStrategy": None,
"template": {
"spec": {
"domain": {"devices": {}},
@@ -100,6 +102,7 @@ VM_DEFINITION_STOPPED = {
},
"spec": {
"running": False,
"runStrategy": None,
"template": {
"spec": {
"domain": {"devices": {}},
@@ -116,6 +119,7 @@ VM_DEFINITION_HALTED = {
"namespace": "default",
},
"spec": {
"running": None,
"runStrategy": "Halted",
"template": {
"spec": {
@@ -383,6 +387,7 @@ CREATED_VM = {
},
"spec": {
"running": True,
"runStrategy": None,
"template": {
"spec": {
"domain": {
@@ -400,6 +405,7 @@ CREATED_VM_RUN_STRATEGY = {
"namespace": "default",
},
"spec": {
"running": None,
"runStrategy": "Manual",
"template": {
"spec": {
@@ -422,6 +428,7 @@ CREATED_VM_LABELS = {
},
"spec": {
"running": True,
"runStrategy": None,
"template": {
"metadata": {
"labels": {"test": "test"},
@@ -446,6 +453,7 @@ CREATED_VM_ANNOTATIONS = {
},
"spec": {
"running": True,
"runStrategy": None,
"template": {
"metadata": {
"annotations": {"test": "test"},
@@ -467,6 +475,7 @@ CREATED_VM_INSTANCETYPE = {
},
"spec": {
"running": True,
"runStrategy": None,
"instancetype": {"name": "u1.medium"},
"template": {
"spec": {
@@ -486,6 +495,7 @@ CREATED_VM_PREFERENCE = {
},
"spec": {
"running": True,
"runStrategy": None,
"preference": {"name": "fedora"},
"template": {
"spec": {
@@ -505,6 +515,7 @@ CREATED_VM_DATAVOLUMETEMPLATE = {
},
"spec": {
"running": True,
"runStrategy": None,
"dataVolumeTemplates": [
{
"metadata": {"name": "testdv"},
@@ -540,6 +551,7 @@ CREATED_VM_NAME = {
},
"spec": {
"running": True,
"runStrategy": None,
"template": {
"spec": {
"domain": {
@@ -559,6 +571,7 @@ CREATED_VM_GENERATE_NAME = {
},
"spec": {
"running": True,
"runStrategy": None,
"template": {
"spec": {
"domain": {
@@ -577,6 +590,7 @@ CREATED_VM_SPECS = {
},
"spec": {
"running": True,
"runStrategy": None,
"template": {
"spec": {
"domain": {