Skip to content

Commit 006bd6a

Browse files
authored
Merge pull request #433 from stuggi/apiversion
fence_kubevirt: make apiversion a parameter
2 parents 286957e + 7b494c3 commit 006bd6a

File tree

2 files changed

+40
-25
lines changed

2 files changed

+40
-25
lines changed

Diff for: agents/kubevirt/fence_kubevirt.py

+35-25
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,14 @@
1111
except ImportError:
1212
logging.error("Couldn\'t import kubernetes.client.exceptions.ApiException - not found or not accessible")
1313

14-
API_VERSION='kubevirt.io/v1'
15-
1614
def get_nodes_list(conn, options):
1715
logging.debug("Starting list/monitor operation")
1816
result = {}
1917
try:
18+
apiversion = options.get("--apiversion")
2019
namespace = options.get("--namespace")
2120
include_uninitialized = True
22-
vm_api = conn.resources.get(api_version=API_VERSION, kind='VirtualMachine')
21+
vm_api = conn.resources.get(api_version=apiversion, kind='VirtualMachine')
2322
vm_list = vm_api.get(namespace=namespace)
2423
for vm in vm_list.items:
2524
result[vm.metadata.name] = ("", None)
@@ -30,9 +29,10 @@ def get_nodes_list(conn, options):
3029
def get_power_status(conn, options):
3130
logging.debug("Starting get status operation")
3231
try:
32+
apiversion = options.get("--apiversion")
3333
namespace = options.get("--namespace")
3434
name = options.get("--plug")
35-
vmi_api = conn.resources.get(api_version=API_VERSION,
35+
vmi_api = conn.resources.get(api_version=apiversion,
3636
kind='VirtualMachineInstance')
3737
vmi = vmi_api.get(name=name, namespace=namespace)
3838
if vmi is not None:
@@ -52,35 +52,45 @@ def get_power_status(conn, options):
5252
def set_power_status(conn, options):
5353
logging.debug("Starting set status operation")
5454
try:
55+
apiversion= options.get("--apiversion")
5556
namespace = options.get("--namespace")
5657
name = options.get("--plug")
5758
action = 'start' if options["--action"] == "on" else 'stop'
58-
virtctl_vm_action(conn, action, namespace, name)
59+
virtctl_vm_action(conn, action, namespace, name, apiversion)
5960
except Exception as e:
6061
logging.error("Failed to set power status, with Exception: %s", e)
6162
fail(EC_STATUS)
6263

6364
def define_new_opts():
64-
all_opt["namespace"] = {
65-
"getopt" : ":",
66-
"longopt" : "namespace",
67-
"help" : "--namespace=[namespace] Namespace of the KubeVirt machine",
68-
"shortdesc" : "Namespace of the KubeVirt machine.",
69-
"required" : "1",
70-
"order" : 2
71-
}
72-
all_opt["kubeconfig"] = {
73-
"getopt" : ":",
74-
"longopt" : "kubeconfig",
75-
"help" : "--kubeconfig=[kubeconfig] Kubeconfig file path",
76-
"shortdesc": "Kubeconfig file path",
77-
"required": "0",
78-
"order": 4
79-
}
80-
81-
def virtctl_vm_action(conn, action, namespace, name):
65+
all_opt["namespace"] = {
66+
"getopt" : ":",
67+
"longopt" : "namespace",
68+
"help" : "--namespace=[namespace] Namespace of the KubeVirt machine",
69+
"shortdesc" : "Namespace of the KubeVirt machine.",
70+
"required" : "1",
71+
"order" : 2
72+
}
73+
all_opt["kubeconfig"] = {
74+
"getopt" : ":",
75+
"longopt" : "kubeconfig",
76+
"help" : "--kubeconfig=[kubeconfig] Kubeconfig file path",
77+
"shortdesc": "Kubeconfig file path",
78+
"required": "0",
79+
"order": 4
80+
}
81+
all_opt["apiversion"] = {
82+
"getopt" : ":",
83+
"longopt" : "apiversion",
84+
"help" : "--apiversion=[apiversion] Version of the KubeVirt API",
85+
"shortdesc" : "Version of the KubeVirt API.",
86+
"required" : "0",
87+
"default" : "kubevirt.io/v1",
88+
"order" : 5
89+
}
90+
91+
def virtctl_vm_action(conn, action, namespace, name, apiversion):
8292
path = '/apis/subresources.{api_version}/namespaces/{namespace}/virtualmachines/{name}/{action}'
83-
path = path.format(api_version=API_VERSION, namespace=namespace, name=name, action=action)
93+
path = path.format(api_version=apiversion, namespace=namespace, name=name, action=action)
8494
return conn.request('put', path, header_params={'accept': '*/*'})
8595

8696
def validate_options(required_options_list, options):
@@ -92,7 +102,7 @@ def validate_options(required_options_list, options):
92102
def main():
93103
conn = None
94104

95-
device_opt = ["port", "namespace", "kubeconfig", "ssl_insecure", "no_password"]
105+
device_opt = ["port", "namespace", "kubeconfig", "ssl_insecure", "no_password", "apiversion"]
96106
define_new_opts()
97107
options = check_input(device_opt, process_input(device_opt))
98108

Diff for: tests/data/metadata/fence_kubevirt.xml

+5
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@
3333
<content type="string" />
3434
<shortdesc lang="en">Kubeconfig file path</shortdesc>
3535
</parameter>
36+
<parameter name="apiversion" unique="0" required="0">
37+
<getopt mixed="--apiversion=[apiversion]" />
38+
<content type="string" default="kubevirt.io/v1" />
39+
<shortdesc lang="en">Version of the KubeVirt API.</shortdesc>
40+
</parameter>
3641
<parameter name="quiet" unique="0" required="0">
3742
<getopt mixed="-q, --quiet" />
3843
<content type="boolean" />

0 commit comments

Comments
 (0)