From 3d99eb0923fa87169246d17b2b4223fbc057fc5e Mon Sep 17 00:00:00 2001 From: Joseph Callen Date: Fri, 5 Jul 2024 13:29:33 -0400 Subject: [PATCH 1/2] vcm vip step, replace bash with python --- .../vcm/ipi-conf-vsphere-vips-vcm-commands.py | 36 +++++++++++++++++++ .../vcm/ipi-conf-vsphere-vips-vcm-ref.yaml | 3 +- 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100755 ci-operator/step-registry/ipi/conf/vsphere/vips/vcm/ipi-conf-vsphere-vips-vcm-commands.py diff --git a/ci-operator/step-registry/ipi/conf/vsphere/vips/vcm/ipi-conf-vsphere-vips-vcm-commands.py b/ci-operator/step-registry/ipi/conf/vsphere/vips/vcm/ipi-conf-vsphere-vips-vcm-commands.py new file mode 100755 index 000000000000..b315203c9e72 --- /dev/null +++ b/ci-operator/step-registry/ipi/conf/vsphere/vips/vcm/ipi-conf-vsphere-vips-vcm-commands.py @@ -0,0 +1,36 @@ +#!/usr/bin/env python + +import os +import sys +import json + +cluster_profile_name = os.environ["CLUSTER_PROFILE_NAME"] +leased_resource = os.environ["LEASED_RESOURCE"] +shared_dir = os.environ["SHARED_DIR"] + +if cluster_profile_name != "vsphere-elastic": + print("using legacy sibling of this step") + sys.exit(0) + +if leased_resource == "": + print("failed to acquire lease") + sys.exit(1) + +subnets_config = shared_dir + "/NETWORK_single.json" +machine_cidr_filename = shared_dir + "/machinecidr.txt" +vips_file_name = shared_dir + "/vips.txt" + +with open(subnets_config) as f: + subnet_obj = json.load(f) + + machine_cidr = subnet_obj["spec"]["machineNetworkCidr"] + api_vip = subnet_obj["spec"]["ipAddresses"][2] + ingress_vip = subnet_obj["spec"]["ipAddresses"][3] + + with open(vips_file_name, "w") as vip_file: + print("vip addresses {} {}".format(api_vip, ingress_vip)) + vip_file.write("{}\n{}".format(api_vip, ingress_vip)) + + with open(machine_cidr_filename, "w") as machine_cidr_file: + print("machine cidr {}".format(machine_cidr)) + machine_cidr_file.write(machine_cidr) diff --git a/ci-operator/step-registry/ipi/conf/vsphere/vips/vcm/ipi-conf-vsphere-vips-vcm-ref.yaml b/ci-operator/step-registry/ipi/conf/vsphere/vips/vcm/ipi-conf-vsphere-vips-vcm-ref.yaml index 140f794c7d3a..9b9435e4c9fb 100644 --- a/ci-operator/step-registry/ipi/conf/vsphere/vips/vcm/ipi-conf-vsphere-vips-vcm-ref.yaml +++ b/ci-operator/step-registry/ipi/conf/vsphere/vips/vcm/ipi-conf-vsphere-vips-vcm-ref.yaml @@ -1,7 +1,8 @@ ref: as: ipi-conf-vsphere-vips-vcm from: tools - commands: ipi-conf-vsphere-vips-vcm-commands.sh + commands: ipi-conf-vsphere-vips-vcm-commands.py + run_as_script: true resources: requests: cpu: 10m From 6772ace079ecf2d142ded830e6289be410768b8e Mon Sep 17 00:00:00 2001 From: Joseph Callen Date: Sun, 7 Jul 2024 10:16:49 -0400 Subject: [PATCH 2/2] fix map;add lint --- .../vcm/ipi-conf-vsphere-vips-vcm-commands.py | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/ci-operator/step-registry/ipi/conf/vsphere/vips/vcm/ipi-conf-vsphere-vips-vcm-commands.py b/ci-operator/step-registry/ipi/conf/vsphere/vips/vcm/ipi-conf-vsphere-vips-vcm-commands.py index b315203c9e72..eaaf51566505 100755 --- a/ci-operator/step-registry/ipi/conf/vsphere/vips/vcm/ipi-conf-vsphere-vips-vcm-commands.py +++ b/ci-operator/step-registry/ipi/conf/vsphere/vips/vcm/ipi-conf-vsphere-vips-vcm-commands.py @@ -4,15 +4,27 @@ import sys import json -cluster_profile_name = os.environ["CLUSTER_PROFILE_NAME"] -leased_resource = os.environ["LEASED_RESOURCE"] -shared_dir = os.environ["SHARED_DIR"] +try: + from pylint.lint import Run + file_path = os.path.realpath(__file__) + Run([file_path], exit=False) +except ImportError: + print("linter not available, run outside of CI") + + +cluster_profile_name = os.environ.get("CLUSTER_PROFILE_NAME") +leased_resource = os.environ.get("LEASED_RESOURCE") +shared_dir = os.environ.get("SHARED_DIR") + +if cluster_profile_name is None: + print("CLUSTER_PROFILE_NAME is undefined") + sys.exit(1) if cluster_profile_name != "vsphere-elastic": print("using legacy sibling of this step") sys.exit(0) -if leased_resource == "": +if leased_resource is None: print("failed to acquire lease") sys.exit(1)