in google_cloud_automlops/utils/utils.py [0:0]
def check_installation_versions(provisioning_framework: str):
"""Checks the version of the provisioning tool (e.g. terraform, gcloud) and generates warning if
either the tool is not installed, or if it below the recommended version.
Args:
provisioning_framework (str): The IaC tool to use (e.g. Terraform, Pulumi, etc.).
"""
if provisioning_framework == Provisioner.GCLOUD.value:
try:
gcloud_sdk_version = subprocess.check_output(
['gcloud info --format="value(basic.version)" 2> /dev/null'], shell=True, stderr=subprocess.STDOUT).decode('utf-8').strip('\n')
if version.parse(MIN_GCLOUD_SDK_VERSION) > version.parse(gcloud_sdk_version):
logging.warning(f'WARNING: You are currently using version {gcloud_sdk_version} of the gcloud sdk. We recommend using at least version {MIN_GCLOUD_SDK_VERSION}.\n '
f'Please update your sdk version by running: gcloud components update.\n')
except subprocess.CalledProcessError:
logging.warning('WARNING: You do not have gcloud installed. Please install the gcloud sdk.\n')
try:
gcloud_beta_version = subprocess.check_output(
['gcloud info --format="value(installation.components.beta)" 2> /dev/null'], shell=True, stderr=subprocess.STDOUT).decode('utf-8').strip('\n')
if version.parse(MIN_GCLOUD_BETA_VERSION) > version.parse(gcloud_beta_version):
logging.warning(f'WARNING: You are currently using version {gcloud_beta_version} of the gcloud beta. We recommend using at least version {MIN_GCLOUD_BETA_VERSION}.\n '
f'Please update your beta version by running: gcloud components install beta.\n')
except subprocess.CalledProcessError:
logging.warning('WARNING: You do not have gcloud beta installed. Please install the gcloud beta by running: gcloud components install beta\n')
if provisioning_framework == Provisioner.TERRAFORM.value:
try:
terraform_version_json_string = subprocess.check_output(
['terraform version -json 2> /dev/null'], shell=True, stderr=subprocess.STDOUT).decode('utf-8').strip('\n')
terraform_version = json.loads(terraform_version_json_string)['terraform_version']
if version.parse(MIN_RECOMMENDED_TERRAFORM_VERSION) > version.parse(terraform_version):
logging.warning(f'WARNING: You are currently using version {terraform_version} of terraform. AutoMLOps has been tested with version {MIN_RECOMMENDED_TERRAFORM_VERSION}.\n '
f'We recommend updating your terraform version.\n')
except subprocess.CalledProcessError:
logging.warning('WARNING: You do not have terraform installed. Please install terraform.\n')