lib/sles4sap/azure_cli.pm

SYNOPSIS

Library to compose and run Azure cli commands

az_version

az_version();

Print the version of the az cli available on system

az_group_create

az_group_create(
    name => 'openqa-rg',
    region => 'westeurope');

Create an Azure resource group in a specific region

name - full name of the resource group
region - Azure region where to create the resource group

az_group_name_get

my $ret = az_group_name_get();

Get the name of all existing Resource Group in the current subscription

az_group_delete

az_group_delete( name => 'openqa-rg' );

Delete a resource group with a specific name

name - full name of the resource group
timeout - timeout, default 60

az_network_vnet_create

az_network_vnet_create(
    resource_group => 'openqa-rg',
    region => 'westeurope',
    vnet => 'openqa-vnet',
    snet => 'openqa-subnet',
    address_prefixes => '10.0.1.0/16',
    subnet_prefixes => '10.0.1.0/24')

Create a virtual network

resource_group - existing resource group where to create the network
region - Azure region where to create the VNET
vnet - name of the virtual network
snet - name of the subnet
address_prefixes - virtual network ip address space. Default 192.168.0.0/16
subnet_prefixes - subnet ip address space. Default 192.168.0.0/24

az_network_vnet_subnet_update

az_network_vnet_subnet_update(
    resource_group => 'openqa-rg',
    vnet => 'openqa-vnet',
    snet => 'openqa-subnet',
    nat_gateway => 'openqa-nat')

Update a Subnet

resource_group - existing resource group where to create the network
vnet - name of the virtual network
snet - name of the subnet
nat_gateway - optional argument, if provided the update is about associating a Subnet th a NAT gateway

az_network_vnet_get

my $res = az_network_vnet_get(resource_group => 'openqa-rg')

Return the output of az network vnet list

resource_group - resource group name to query
query - valid jmespath https://jmespath.org/

az_network_nsg_create

az_network_nsg_create(
    resource_group => 'openqa-rg',
    name => 'openqa-nsg')

Create a network security group

resource_group - existing resource group where to create the NSG
name - security group name

az_network_nsg_rule_create

az_network_nsg_rule_create(
    resource_group => 'openqa-rg',
    nsg => 'openqa-nsg',
    name => 'openqa-nsg-rule-ssh',
    port => 22)

Create a very specific type of inbound rule for an existing network security group Just few parameters are configurable here, like the port number

resource_group - existing resource group where to create the NSG rule
nsg - existing security group name
name - security rule name
port - allowed port

az_network_publicip_create

az_network_publicip_create(
    resource_group => 'openqa-rg',
    name => 'openqa-pip',
    zone => '1 2 3')

Create an IPv4 public IP resource

resource_group - existing resource group where to create the PubIP
name - public IP resource name
sku - default Standard
allocation_method - optionally add --allocation-method
zone - optionally add --zone

az_network_publicip_get

az_network_publicip_get(
    resource_group => 'openqa-rg',
    name => 'openqa-pip')

Return an IPv4 public IP address from its name

resource_group - existing resource group including the PubIP
name - existing public IP resource name

az_network_nat_gateway_create

az_network_nat_gateway_create(
    resource_group => 'openqa-rg',
    region => 'westeurope',
    name => 'openqa-nat-gateway',
    public_ip => 'openqa-pubip')

Create a NAT Gateway

resource_group - existing resource group where to create the NAT Gateway
region - Azure region where to create the NAT Gateway
name - NAT Gateway resource name
public_ip - add to the NAT Gateway a public IP

az_network_lb_create

az_network_lb_create(
    resource_group => 'openqa-rg',
    name => 'openqa-lb',
    vnet => 'openqa-vnet',
    snet => 'openqa-subnet',
    backend => 'openqa-be',
    frontend_ip_name => 'openqa-feip',
    sku => 'Standard')

Create a load balancer entity. LB is mostly "just" a "group" definition to link back-end and front-end resources (usually an IP)

SKU Standard (and not Basic) is needed to get some Metrics

resource_group - existing resource group where to create lb
name - load balancer name
vnet - existing Virtual network name where to create LB in
snet - existing Subnet network name where to create LB in
backend - name to assign to created backend pool
frontend_ip_name - name to assign to created frontend ip, will be reused in "az network lb rule create"
sku - default Basic
fip - optionally add --private-ip-address

az_network_lb_probe_create

az_network_lb_probe_create(
    resource_group => 'openqa-rg',
    lb_name => 'openqa-lb',
    name => 'openqa-lb-hp',
    port => '4242',
    protocol => 'Udp',
    )

Create a load balancer health probe.

resource_group - existing resource group where to create lb probe
lb_name - existing load balancer name
name - name for the new health probe
port - port number monitored by the health probe
protocol - protocol for the health probe. Default Tcp

az_network_lb_rule_create

az_network_lb_rule_create(
    resource_group => 'openqa-rg',
    lb_name => 'openqa-lb',
    hp_name => 'openqa-hb',
    frontend_ip => 'openqa-fe',
    backend => 'openqa-be',
    name => 'openqa-lb-rule',
    port => '80'
    )

Configure the load balancer behavior.

resource_group - existing resource group where to create lb rule
lb_name - existing load balancer name
hp_name - existing load balancer health probe name
frontend_ip - existing load balancer front end IP name
backend - existing load balancer back end pool name
name - name for the new load balancer rule
port - port mapped between the frontend and the backend. This poor Perl wrapper map them 1:1
protocol - protocol for the load balancer rule. Default Tcp

az_vm_as_create

az_vm_as_create(
    resource_group => 'openqa-rg',
    region => 'westeurope',
    name => 'openqa-as',
    fault_count => 2)

Create an availability set. Later on VM can be assigned to it.

resource_group - existing resource group where to create the Availability set
region - region where to create the Availability set
name - availability set name
fault_count - value for --platform-fault-domain-count

az_vm_create

az_vm_create(
    resource_group => 'openqa-rg',
    region => 'westeurope',
    name => 'openqa-vm',
    image => 'SUSE:sles-sap-15-sp5:gen2:latest')

Create a virtual machine

resource_group - existing resource group where to create the VM
region - optional region where to create the VM
name - virtual machine name
image - OS image name
vnet - optional name of the Virtual Network where to place the VM
snet - optional name of the SubNet where to connect the VM
size - VM size, default Standard_B1s
availability_set - optional inclusion in an availability set
username - optional admin username
nsg - optional inclusion in an network security group
nic - optional add to the VM a NIC created separately with 'az network nic create'
public_ip - optional add to the VM a public IP. Value like "" is a valid one and is not the same as not including the argument at all.
custom_data - optional provide a cloud-init script file
ssh_pubkey - optional inclusion in an availability set, if missing the command is configured to generate one
security_type - is used force a specific value for '--security-type'

az_vm_list

my $ret = az_vm_list(resource_group => 'openqa-rg', query => '[].name');

Get the info from all existing VMs within a Resource Group Return a decoded json hash according to the provided jmespath query

resource_group - existing resource group where to search for VMs
query - valid jmespath https://jmespath.org/

az_vm_instance_view_get

my $res = az_vm_instance_view_get(
    resource_group => 'openqa-rg',
    name => 'openqa-vm')

Get some details of a specific VM

Json output looks like:

[ "PowerState/running", "VM running" ]

resource_group - existing resource group where to look for a specific VM
name - name of an existing virtual machine

az_vm_wait_running

my $res = az_vm_wait_running(
    resource_group => 'openqa-rg',
    name => 'openqa-vm',
    timeout => 300)

Get the VM state until status looks like:

[ "PowerState/running", "VM running" ]

or reach timeout. Polling frequency is dynamically calculated based on the timeout

resource_group - existing resource group where to look for a specific VM
name - name of an existing virtual machine
timeout - optional, default 300

az_vm_openport

az_vm_openport(
    resource_group => 'openqa-rg',
    name => 'openqa-vm',
    port => 80)

Open a port on an existing VM

resource_group - existing resource group where to search for a specific VM
name - name of an existing VM
port - port to open

az_vm_wait_cloudinit

az_vm_wait_cloudinit(
    resource_group => 'openqa-rg',
    name => 'openqa-vm')

Wait cloud-init completion on a running VM

resource_group - existing resource group where to search for a specific VM
name - name of an existing VM
username - username default cloudadmin
timeout - max wait time in seconds. Default 3600.

az_nic_id_get

my $nic_id = az_nic_id_get(
    resource_group => 'openqa-rg',
    name => 'openqa-vm')

Get the NIC ID of the first NIC of a given VM

resource_group - existing resource group where to search for a specific NIC
name - name of an existing VM

az_nic_get

Get the NIC data from NIC ID

nic_id - existing NIC ID (eg. from az_nic_id_get)
filter - query filter

az_nic_name_get

my $nic_name = az_nic_name_get(
    resource_group => 'openqa-rg',
    name => 'openqa-vm')

Get the NIC name from NIC ID

nic_id - existing NIC ID (eg. from az_nic_id_get)

az_ipconfig_name_get

my $ipconfig_name = az_ipconfig_name_get(
    resource_group => 'openqa-rg',
    name => 'openqa-vm')

Get the name of the first IpConfig of a NIC from a NIC ID

nic_id - existing NIC ID (eg. from az_nic_id_get)

az_ipconfig_update

az_ipconfig_update(
    resource_group => 'openqa-rg',
    ipconfig_name => 'openqa-ipconfig',
    nic_name => 'openqa-nic',
    ip => '192.168.0.42')

Change the IpConfig to use a static IP

resource_group - existing resource group
ipconfig_name - existing IP configuration NAME (eg. from az_ipconfig_name_get)
nic_name - existing NIC NAME (eg. from az_nic_name_get)
ip - IPv4 address to assign as static IP

az_ipconfig_delete

az_ipconfig_delete(
    resource_group => 'openqa-rg',
    ipconfig_name => 'openqa-ipconfig',
    nic_name => 'openqa-nic')

Delete a specific IpConfig to use a static IP

resource_group - existing resource group
ipconfig_name - existing IP configuration NAME (eg. from az_ipconfig_name_get)
nic_name - existing NIC NAME (eg. from az_nic_name_get)

az_ipconfig_pool_add

az_ipconfig_pool_add(
    resource_group => 'openqa-rg',
    lb_name => 'openqa-lb',
    address_pool => 'openqa-addr-pool',
    ipconfig_name => 'openqa-ipconfig',
    nic_name => 'openqa-nic')

Add the IpConfig to a LB address pool

resource_group - existing resource group
lb_name - existing Load balancer NAME
address_pool - existing Load balancer address pool name
timeout - timeout, default 60

az_vm_diagnostic_log_enable

az_vm_diagnostic_log_enable(resource_group => 'openqa-rg',
                            storage_account => 'openqasa',
                            vm_name => 'openqa-vm')

Enable diagnostic log for a specific VM

resource_group - existing resource group where to search for a specific VM
storage_account - existing storage account
vm_name - existing VM name

az_vm_diagnostic_log_get

my $list_of_logs = az_vm_diagnostic_log_get(resource_group => 'openqa-rg')

Call `az vm boot-diagnostics json` for each running VM in the resource group associated to this openQA job

Return a list of diagnostic file paths on the JumpHost

resource_group - existing resource group where to search for a specific VM

az_storage_account_create

az_storage_account_create(
    resource_group => 'openqa-rg',
    region => 'westeurope'
    name => 'openqasa')

Create a storage account

resource_group - existing resource group where to create the storage account
region - Azure region where to create the storage
name - name for the storage account to be created. Storage account name must be between 3 and 24 characters in length and use numbers and lower-case letters only.

az_network_peering_create

az_network_peering_create(
    name => 'openqa-fromVNET-toVNET',
    source_rg => 'openqa-rg',
    source_vnet => 'openqa-this-vnet',
    target_rg => 'openqa-rg',
    target_vnet => 'openqa-this-vnet')

Create network peering

name - NAME for the network peering to create
source_rg - existing resource group that contain vnet source of the peering
source_vnet - existing vnet in source_rg, used as source of the peering
target_rg - existing resource group that contain vnet target of the peering
target_vnet - existing vnet in target_rg, used as target of the peering

az_network_peering_list

my $res = az_network_peering_list(
    resource_group => 'openqa-rg',
    vnet => 'openqa-this-vnet' [, query=>'[].name'])

Return HASH representing existing net peering

resource_group - existing resource group that contain vnet source of the peering
vnet - existing vnet in resource_group, used as source of the peering
query - valid jmespath https://jmespath.org/

az_network_peering_delete

az_network_peering_delete(
    name => 'openqa-fromVNET-toVNET',
    resource_group => 'openqa-rg',
    vnet => 'openqa-this-vnet')

Delete a specific network peering

name - name of the existing the network peering to delete
resource_group - existing resource group that contain vnet source of the peering
vnet - existing vnet in resource_group, used as source of the peering

az_disk_create

az_disk_create(resource_group=>$resource_group, name=>$name
    [, size_gb=>60, source=$source, tags="tag1=value1 tag2=value2"]);

Creates new disk device either by specifying size_gb or by cloning another disk device using argument source. Arguments size_gb and source are mutually exclusive.

name New disk name
resource_group Existing resource group name.
source Create disk by cloning snapshot
size_gb New disk size
tags Additional tags to add to the disk resource. key=value pairs must be separated by empty space. Example: az_disk_create(tags=>"some_tag=some_value another_tag=another_value")

az_resource_delete

az_resource_delete(resource_group=>$resource_group, name=>$name);

Deletes resource from specified resource group. Single resource can be deleted by specifying name or list of resource IDs delimited by empty space using argument ids. Arguments name and ids are mutually exclusive. Function returns `az` command exit code.

resource_group Existing resource group name.
name Name of the resource to delete
ids list of resource IDs to delete
verbose Turn on az command verbosity. Default: off
timeout Timeout for az command. Default: 60

az_resource_list

az_resource_list([resource_group=>$resource_group, query=>$query, output=>$output]);

Lists existing az resources based on arguments provided. Calling function without any argument returns full information from all existing resource groups. Returns decoded json structure if json format is requested, otherwise whole output is a string.

resource_group Existing resource group name.
query Jmespath query

az_validate_uuid_pattern

az_validate_uuid_pattern( uuid => $uuid_string )

Function checks input string against uuid pattern
which is commonly used as an identifier for Azure resources.
returns uuid (true) on match, 0 (false) on mismatch.
uuid UUID string to test.

az_storage_blob_upload

az_storage_blob_upload(
    container_name=>'somecontainer',
    storage_account_name=>'storageaccount',
    file=>'somefilename' [, timeout=>42]);

Uploads file to a storage container.

container_name Existing storage container name.
storage_account_name Storage account name.
file File to upload.
timeout Timeout for az command. Default: 90s

az_storage_blob_lease_acquire

az_storage_blob_lease_acquire(
    container_name=>'somecontainer',
    storage_account_name=>'storageaccount',
    blob_name => 'somefilename' [, lease_duration=>'42']
);

Acquire a lease for a storage blob. Function returns UUID which is then required to modify the file and gives the UUID owner exclusive rights. Optionally lease_duration can be defined to limit this file lock up to 60s instead of infinity. In case of function returns nothing, the reasons may vary and it is up to caller to decide how to deal with the result. In that case Possible reasons are that there is already a lease present (az cli returns a message which is not a valid UUID)

container_name Existing storage container name.
storage_account_name Storage account name.
blob_name Blob name to acquire lease for.
lease_duration Lease duration between 15-60s. Default: infinite

az_storage_blob_list

az_storage_blob_list(
    container_name=>'somecontainer',
    storage_account_name=>'storageaccount' [, query=>'[].name']
);

List information about storage blob(s) specified by storage_account_name, container_name and query.

container_name Existing storage container name.
storage_account_name Storage account name.
query Query in jmespath format

az_storage_blob_update

az_storage_blob_update(container_name=>'container', account_name=>'stuff', name='blobby' [, lease_id=42]);

Update properties of storage blob. Returns az cli command exit code.

container_name Existing resource group name.
account_name Name of the resource to delete
name Blob name
lease_id Lease id in case there is a lease put on a file

az_keyvault_list

az_keyvault_list(resource_group=>'resource group' [, query=>'[].id']);

Lists all keyvault resource names located in specified resource group. Output can be modified using query argument.

resource_group Existing resource group name.
query Modify output filter using jmespath query

az_keyvault_secret_list

az_keyvault_secret_list(vault_name=>'Gringotts' [, query=>'[].id']);

Lists all keyvault secret names located in specified keyvault. Output can be modified using query argument.

vault_name Existing keyvault name.
query Modify output filter using jmespath query

az_keyvault_secret_show

az_keyvault_secret_show(id=>'someid'
    [, name=>'Vault 713', vault_name=>'Gringotts', query=>'[].id', output=>'json', save_to_file=>'/alohomora']);

Lists all keyvault secret names located in specified keyvault. Output can be modified using query argument.

id Existing secret resource ID. name and vault_name not needed if this is specified.
name Existing secret name. Required if id not used.
vault_name Existing keyvault name. Required if id not used.
query Modify output filter using jmespath query. Default: value
output Output format. Allowed values: json, tsv. Default: tsv.
save_to_file Save output to a file specified. This can be used to prevent the secret being shown in OpenQA outputs. Default: undefined/false