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

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

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

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

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 - image name
image_project - image project name
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
name - name of the VM instance to delete

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
name - name of the VM instance