Manage subnets

This document describes how to manage subnets in VMware Engine. Management subnets are read-only subnets that you can view using the Google Cloud CLI or API. You can also update subnets of type userDefined.

Google Cloud CLI and API requirements

To use the gcloud command line tool or the API to manage your VMware Engine resources, we recommend configuring the tools as described below.

gcloud

  1. Set your default project ID:

    gcloud config set project PROJECT_ID
    
  2. Set a default region and/or zone:

    gcloud config set compute/region REGION
    gcloud config set compute/zone ZONE

For more information on the gcloud vmware tool, reviewing the Cloud SDK reference docs.

API

API examples in this documentation set use the cURL command-line tool to query the API. A valid access token is required as part of the cURL request. There are many ways to get a valid access token; the following steps use the gcloud tool to generate a access token:

  1. Login to Google Cloud

    gcloud auth login
    
  2. Generate access token and export to TOKEN

    export TOKEN=`gcloud auth print-access-token`
    
  3. Verify that TOKEN is set properly

    echo $TOKEN
    
    Output:
    TOKEN
    

Now, use the authorization token in your requests to the API. For example:

curl -X GET -H "Authorization: Bearer \"$TOKEN\""  -H "Content-Type: application/json; charset=utf-8" https://vmwareengine.googleapis.com/v1/projects/PROJECT_ID/locations

Python

Python code samples in this documentation use the VMware Engine library to communicate with the API. To be able to use this approach, the library needs to be installed and the Application Default Credentials should be configured.

  1. Download and install the Python library

     pip install google-cloud-vmwareengine
    
  2. Configure the ADC information by executing those command in your shell

      gcloud auth application-default login
    

    or use a Service Account key file

      export GOOGLE_APPLICATION_CREDENTIALS="FILE_PATH"
    

For more information about the library, visit the reference page or view code samples on GitHub.

Edit a userDefined subnet

You can edit a userDefined subnet using the Google Cloud CLI or VMware Engine API. Both methods require the name of the subnet and private cloud.

gcloud

Edit a subnet using the Google Cloud CLI by entering the gcloud vmware private-clouds subnets update command:

     gcloud vmware private-clouds subnets update SUBNET_NAME 
--private-cloud=PC_NAME --location=ZONE
--ip-cidr-range=10.0.0.0/24

Replace the following:

  • SUBNET_NAME: the name for the subnet to update in this private cloud
  • PC_NAME: the name for the private cloud
  • ZONE: the zone for the private cloud

API

To edit a subnet using the VMware Engine API, make a PATCH request:

 curl -sSL -XPATCH -H "Authorization: Bearer $(gcloud auth print-access-token)" -H "Content-Type: application/json; charset=utf-8"
 "https://vmwareengine.googleapis.com/v1/projects/PROJECT_ID/locations/ZONE/privateClouds/PC_NAME/subnets/SUBNET_NAME?update_mask=ip_cidr_range" -d '{
    "ip_cidr_range": "10.0.0.0/24"
 }'

Replace the following:

  • PROJECT_ID: the project name for this request.
  • ZONE: the zone for the private cloud
  • PC_NAME: the name for the private cloud
  • SUBNET_NAME: the name for the subnet to update in this private cloud

List management subnets

You can list VMware Engine private cloud management subnets by entering the following command using the Google Cloud CLI or VMware Engine API. This command requires the name of the subnet and private cloud.

gcloud

List a subnet using the Google Cloud CLI by entering the gcloud vmware private-clouds subnets list command:

     gcloud vmware private-clouds subnets list --private-cloud=PC_NAME 
--location=ZONE

Replace the following:

  • PC_NAME: the name for the private cloud
  • ZONE: the zone for the private cloud

API

To list a subnet using the VMware Engine API, make a GET request:

 curl -sSL -XGET -H "Authorization: Bearer $(gcloud auth print-access-token)" -H "Content-Type: application/json; charset=utf-8"
 "https://vmwareengine.googleapis.com/v1/projects/PROJECT_ID/locations/ZONE/privateClouds/PC_NAME/subnets"

Replace the following:

  • PROJECT_ID: the project name for this request.
  • ZONE: the zone for the private cloud
  • PC_NAME: the name for the private cloud

Describe of a management subnet

You can get a description of any management subnet by entering the following command:

gcloud

Get the description of a subnet using the Google Cloud CLI by entering the gcloud vmware private-clouds subnets update command:

     gcloud vmware private-clouds subnets describe SUBNET_NAME-pcon 
--private-cloud=PC_NAME
--location=ZONE

Replace the following:

  • SUBNET_NAME: the name for the subnet to update in this private cloud
  • PC_NAME: the name for the private cloud
  • ZONE: the zone for the private cloud

API

To get the description of a subnet using the VMware Engine API, make a GET request:

  curl -sSL -XGET -H "Authorization: Bearer $(gcloud auth print-access-token)" -H "Content-Type: application/json; charset=utf-8"
  "https://vmwareengine.googleapis.com/v1/projects/PROJECT_ID/locations/REGION/privateClouds/PC_NAME/subnets/SUBNET_NAME"

Replace the following:

  • PROJECT_ID: the project name for this request.
  • REGION: the region of the network.
  • PC_NAME: the name for the private cloud
  • SUBNET_NAME: the name for the subnet to update in this private cloud

What's next