Compute Engine

ComputeEngineUtility

class gwrappy.compute.ComputeEngineUtility(project_id, **kwargs)[source]

Initializes object for interacting with Compute Engine API.

By default, Application Default Credentials are used.
If gcloud SDK isn’t installed, credential files have to be specified using the kwargs json_credentials_path and client_id.
Parameters:
  • project_id – Project ID linked to Compute Engine.
  • max_retries (integer) – Argument specified with each API call to natively handle retryable errors.
  • client_secret_path – File path for client secret JSON file. Only required if credentials are invalid or unavailable.
  • json_credentials_path – File path for automatically generated credentials.
  • client_id – Credentials are stored as a key-value pair per client_id to facilitate multiple clients using the same credentials file. For simplicity, using one’s email address is sufficient.
get_project()[source]

Abstraction of projects().get() method. [https://cloud.google.com/compute/docs/reference/latest/projects/get]

Returns:Project Resource
list_regions(max_results=None, filter_str=None)[source]

Abstraction of regions().list() method with inbuilt iteration functionality. [https://cloud.google.com/compute/docs/reference/latest/regions/list]

Parameters:
  • max_results (integer) – If None, all results are iterated over and returned.
  • filter_str – Check documentation link for more details.
Returns:

Generator for dictionary objects representing resources.

list_zones(max_results=None, filter_str=None)[source]

Abstraction of zones().list() method with inbuilt iteration functionality. [https://cloud.google.com/compute/docs/reference/latest/zones/list]

Parameters:
  • max_results (integer) – If None, all results are iterated over and returned.
  • filter_str – Check documentation link for more details.
Returns:

Generator for dictionary objects representing resources.

list_instances(zone_id=None, max_results=None, filter_str=None)[source]

Abstraction of instances().list() method with inbuilt iteration functionality. [https://cloud.google.com/compute/docs/reference/latest/instances/list]

Parameters:
  • zone_id – Zone name. If None, all Zones are iterated over and returned.
  • max_results (integer) – If None, all results are iterated over and returned.
  • filter_str – Check documentation link for more details.
Returns:

Generator for dictionary objects representing resources.

list_addresses(region_id=None, max_results=None, filter_str=None)[source]

Abstraction of addresses().list() method with inbuilt iteration functionality. [https://cloud.google.com/compute/docs/reference/latest/addresses/list]

Parameters:
  • region_id – Region name. If None, all Regions are iterated over and returned.
  • max_results (integer) – If None, all results are iterated over and returned.
  • filter_str – Check documentation link for more details.
Returns:

Generator for dictionary objects representing resources.

list_operations(operation_type, location_id=None, max_results=None, filter_str=None)[source]

Choose between region or zone operations with operation_type.

Abstraction of zoneOperations()/regionOperations().list() method with inbuilt iteration functionality.

https://cloud.google.com/compute/docs/reference/latest/zoneOperations/list

https://cloud.google.com/compute/docs/reference/latest/regionOperations/list

Parameters:
  • operation_type – ‘zone’ or ‘region’ type operations.
  • location_id – Zone/Region name. If None, all Zones/Regions are iterated over and returned.
  • max_results (integer) – If None, all results are iterated over and returned.
  • filter_str – Check documentation link for more details.
Returns:

Generator for dictionary objects representing resources.

get_operation(operation_type, location_id, operation_name)[source]

Choose between region or zone operations with operation_type.

Abstraction of zoneOperations()/regionOperations().get() method.

https://cloud.google.com/compute/docs/reference/latest/zoneOperations/get

https://cloud.google.com/compute/docs/reference/latest/regionOperations/get

Parameters:
  • operation_type – ‘zone’ or ‘region’ type operations.
  • location_id – Zone/Region name.
  • operation_name – Operation name.
Returns:

ZoneOperations/RegionOperations Resource.

poll_operation_status(operation_type, location_id, operation_name, end_state, sleep_time=0.5)[source]

Poll operation to until desired end_state is achieved. eg. ‘DONE’ when adding addresses.

Parameters:
  • operation_type – ‘zone’ or ‘region’ type operations.
  • location_id – Zone/Region name.
  • operation_name – Operation name.
  • end_state – Final status that signifies operation is finished.
  • sleep_time – Intervals between polls.
Returns:

ZoneOperations/RegionOperations Resource.

get_address(region_id, address_name)[source]

Abstraction of addresses().get() method. [https://cloud.google.com/compute/docs/reference/latest/addresses/get]

Parameters:
  • region_id – Region name.
  • address_name – Address name.
Returns:

Addresses Resource.

add_address(region_id, address_name)[source]

Abstraction of address.insert() method with operation polling functionality. [https://cloud.google.com/compute/docs/reference/latest/addresses/insert]

Parameters:
  • region_id – Region name.
  • address_name – Address name.
Returns:

RegionOperations Resource.

delete_address(region_id, address_name)[source]

Abstraction of address.delete() method with operation polling functionality. [https://cloud.google.com/compute/docs/reference/latest/addresses/delete]

Parameters:
  • region_id – Region name.
  • address_name – Address name.
Returns:

RegionOperations Resource.

get_instance(zone_id, instance_name)[source]

Abstraction of instances().get() method. [https://cloud.google.com/compute/docs/reference/latest/instances/get]

Parameters:
  • zone_id – Zone name.
  • instance_name – Instance name.
Returns:

Instances Resource.

start_instance(zone_id, instance_name)[source]

Abstraction of instances().start() method with operation polling functionality. [https://cloud.google.com/compute/docs/reference/latest/instances/start]

Parameters:
  • zone_id – Zone name.
  • instance_name – Instance name.
Returns:

ZoneOperations Resource.

stop_instance(zone_id, instance_name)[source]

Abstraction of instances().stop() method with operation polling functionality. [https://cloud.google.com/compute/docs/reference/latest/instances/stop]

Parameters:
  • zone_id – Zone name.
  • instance_name – Instance name.
Returns:

ZoneOperations Resource.

delete_instance(zone_id, instance_name)[source]

Abstraction of instances().delete() method with operation polling functionality. [https://cloud.google.com/compute/docs/reference/latest/instances/delete]

Parameters:
  • zone_id – Zone name.
  • instance_name – Instance name.
Returns:

ZoneOperations Resource.