lib/publiccloud/utils.pm

ssh_add_suseconnect_product

ssh_add_suseconnect_product($remote, $name, [program => $program, [version => $version, [arch => $arch, [params => $params, [timeout => $timeout, [retries => $retries, [delay => $delay]]]]]]]);

Register addon in the SUT

ssh_remove_suseconnect_product

ssh_remove_suseconnect_product($name, [$version, [$arch, [$params]]]);

Deregister addon in SUT

get_credentials get_credentials(url_suffix => 'some_csp.json'[, namespace => 'some_name', output_json => './local_credentials.json'])

Get credentials from the Public Cloud micro service, which requires user and password. The resulting json will be optionally stored in a file. This function also get input from these variables: - PUBLIC_CLOUD_CREDENTIALS_URL - _SECRET_PUBLIC_CLOUD_CREDENTIALS_USER - _SECRET_PUBLIC_CLOUD_CREDENTIALS_PWD

url_suffix - last part of the micro service url
output_json - (optional) save the credential to json file with provided filename.
namespace - (optional) credential namespace on the micro service. If not provided read from PUBLIC_CLOUD_NAMESPACE

gcloud_install gcloud_install($url, $dir, $timeout)

This function is used to install the gcloud CLI for the GKE Google Cloud.

From $url we get the full package and install it in $dir local folder as a subdir of /root. Defaults are available for a simple call without parameters: gcloud_install()

ssh_update_transactional_system

ssh_update_transactional_system($host);

Connect to the remote host $instance using ssh and update the system by running zypper update twice, in transactional mode. The first run will update the package manager, the second run will update the system. Transactional systems like SLE micro used transactional_update up and reboot.

get_python_exec

get_python_exec()

Returns the Python executable name for public cloud purposes. As of now, it returns "python3.11" by default.

create_script_file

create_script_file($filename, $fullpath, $content)

Creates a script file with the given content, downloads it from the autoinst URL, and makes it executable. This is useful for creating scripts that can be run on the public cloud instance.

install_in_venv

install_in_venv($binary, %args)

Installs a Python package in a virtual environment. The package can be specified either by a requirements.txt file or by a list of pip packages. The function creates a virtual environment, installs the specified package(s), and creates a wrapper script to run the binary within the virtual environment.

venv_create

venv_create($binary)

Creates a Python virtual environment in the home directory of the root user. The virtual environment is named after the binary, prefixed with ".venv_".

venv_activate

venv_activate($venv)

Activates the Python virtual environment specified by $venv.

venv_prepare_install_source

venv_prepare_install_source($binary, $args_ref)

Prepares the source for installation in the virtual environment. If the requirements argument is defined, it fetches a requirements.txt file from the autoinst URL and returns the path to that file. If not, it returns the list of pip packages to install.

venv_install_packages

venv_install_packages($install_target)

Installs the specified package(s) in the virtual environment using pip. This function takes a string that can be either a path to a requirements.txt file or a list of pip packages.

venv_record_installed_packages

venv_record_installed_packages($venv) Records the installed packages in the virtual environment by running `pip freeze`.

venv_deactivate

venv_deactivate()

Deactivates the currently active Python virtual environment.

venv_generate_runner_script

venv_generate_runner_script($binary, $venv)

Generates a shell script that activates the virtual environment and runs the specified binary. This script checks if the binary exists in the virtual environment and exits with an error if it does not.

get_installed_packages_remote

get_installed_packages_remote($instance, $packages_ref)

This function checks which packages from the provided list are installed on the remote instance. It returns an array reference containing the names of the installed packages.

get_available_packages_remote

get_available_packages_remote($instance, $packages_ref)

This function checks which packages from the provided list are available for installation on the remote instance. It returns an array reference containing the names of the available packages. It uses `zypper -x info` to query the availability of packages.

zypper_add_repo_remote

zypper_add_repo_remote($instance, $repo_name, $repo_url)

This function adds a repository to the remote instance using zypper. It uses the `-fG` options to add the repository as a GPG-verified repository.

zypper_remove_repo_remote

zypper_remove_repo_remote($instance, $repo_name)

This function removes a repository from the remote instance using zypper. It uses the `-n` option to run the command non-interactively.

zypper_install_remote

zypper_install_remote($instance, $packages)

This function installs the specified packages on the remote instance using zypper. It handles both transactional updates and regular zypper installations based on the system type.

zypper_install_available_remote

zypper_install_available_remote($instance, $packages_ref)

This function checks which packages from the provided list are available for installation on the remote instance. If any packages are available, it installs them using zypper_install_remote.