lib/sles4sap/gcp_cli.pm

SYNOPSIS

Library to compose and run GCP gcloud cli commands.

gcp_network_create

gcp_network_create(
    project => 'my-project',
    name => 'my-network');

Create a new GCP VPC network

project - GCP project ID
name - name for the VPC network

gcp_network_delete

my $ret = gcp_network_delete(name => 'my-network');

Delete a VPC network. Does not assert but returns the exit code.

name - name of the VPC network to delete
timeout - Optional. By default is 600

gcp_subnet_create

gcp_subnet_create(
    project => 'my-project',
    region => 'us-central1',
    name => 'my-subnet',
    network => 'my-network',
    cidr => '10.0.0.0/24');

Create a subnet within a VPC network

project - GCP project ID
region - GCP region (e.g., 'us-central1')
name - name for the subnet
network - name of the VPC network
cidr - CIDR range for the subnet (e.g., '10.0.0.0/24')

gcp_subnet_delete

my $ret = gcp_subnet_delete(
    region => 'us-central1',
    name => 'my-subnet');

Delete a subnet. Does not assert but returns the exit code.

region - GCP region
name - name of the subnet to delete
timeout - Optional. By default is 600

gcp_firewall_rule_create

gcp_firewall_rule_create(
    project => 'my-project',
    name => 'allow-ssh',
    network => 'my-network',
    port => 22);

Create a firewall rule to allow inbound traffic on a specific port

project - GCP project ID
name - name for the firewall rule
network - name of the VPC network
port - port number to allow (e.g., 22 for SSH)
protocol - Optional. By default is tcp

gcp_firewall_rule_delete

my $ret = gcp_firewall_rule_delete(name => 'allow-ssh');

Delete a firewall rule. Does not assert but returns the exit code.

name - name of the firewall rule to delete
timeout - Optional. By default is 600

gcp_external_ip_create

gcp_external_ip_create(
    project => 'my-project',
    region => 'us-central1',
    name => 'my-ip');

Reserve an external static IP address

project - GCP project ID
region - GCP region
name - name for the external IP address

gcp_external_ip_delete

my $ret = gcp_external_ip_delete(
    region => 'us-central1',
    name => 'my-ip');

Release an external IP address. Does not assert but returns the exit code.

region - GCP region
name - name of the external IP address to delete
timeout - Optional. By default is 600

gcp_vm_create

gcp_vm_create(
    project => 'my-project',
    zone => 'us-central1-a',
    name => 'my-vm',
    image => 'sles-sap-$version',
    image_prject => 'cloud',
    machine_type => 'n1-standard-2',
    network => 'my-network',
    subnet => 'my-subnet',
    address => 'my-ip',
    ssh_key => 'ssh public key file);

Create a VM instance

project - GCP project ID
zone - GCP zone (e.g., 'us-central1-a')
name - name for the VM instance
image - specifies the boot image for the instances
image_project - the Google Cloud project against which all image and image family references will be resolved. If not specified and either image or image-family is provided, the current default project is used.
machine_type - machine type (e.g., 'n1-standard-2')
network - name of the VPC network
subnet - name of the subnet
address - name of the external IP address to assign
ssh_key - SSH public key file to add to the VM
timeout - optional, timeout for the command (default 900)

gcp_vm_wait_running

gcp_vm_wait_running(
    zone => 'us-central1-a',
    name => 'my-vm',
    timeout => 300);

Wait for a VM instance to reach RUNNING state

zone - GCP zone
name - name of the VM instance
timeout - optional, timeout in seconds (default 300)

gcp_vm_terminate

my $ret = gcp_vm_terminate(
    zone => 'us-central1-a',
    name => 'my-vm');

Delete a VM instance. Does not assert but returns the exit code.

zone - GCP zone, it is made of <region>-<availability_zone>
name - name of the VM instance to delete
timeout - Optional. By default is 600

gcp_public_ip_get

my $ip = gcp_public_ip_get(
    project => 'my-project',
    zone => 'us-central1-a',
    name => 'my-vm');

Get the external (public) IP address of a VM instance

project - GCP project ID
zone - GCP zone, it is made of <region>-<availability_zone>
name - name of the VM instance

gcp_ncc_spoke_create

gcp_ncc_spoke_create(
    project => 'my-project',
    name    => 'my-spoke',
    hub     => 'projects/ibsm-project/locations/global/hubs/ibsm-hub',
    network => 'my-network');

Create a VPC spoke and attach it to an NCC hub. The hub may be in a different project.

project - GCP project ID where the spoke will be created
name - name for the spoke
hub - full resource URI of the NCC hub
network - name of the VPC network to attach
group - optional, NCC hub group to join (e.g., 'default')

gcp_ncc_spoke_delete

my $ret = gcp_ncc_spoke_delete(name => 'my-spoke' [, timeout => 600]);

Delete a VPC spoke. Does not assert but returns the exit code.

name - name of the spoke to delete
timeout - optional, timeout for the delete operation (default 600)

gcp_ncc_spoke_wait_active

gcp_ncc_spoke_wait_active(name => 'my-spoke' [, timeout => 300]);

Wait for an NCC spoke to reach ACTIVE state. Die if it does not reach ACTIVE state within timeout.

name - name of the spoke
timeout - optional, timeout in seconds (default 300)