Skip to main content

Service to manage GCP inventory resource

Project description

Resources Inventory

This is not an official Google product.

This is a package that can provide inventory of resources in GCP In addition to accessing projects,zones and disks.

The package can be installed by `pip install gcpinventory'

def list_zones(self, project):
    List the zones for the given project

    Args:
        project: The project id

    Yields:
         The zones for this project

    Raises:
        InventoryServiceException: An exception occurred

    # https://developers.google.com/resources/api-libraries/documentation/compute/v1/python/latest/compute_v1.zones.html#list



def list_projects(self):
   List the projects that the user has access to.

         Yields:
              The zones for this project

         Raises:
             InventoryServiceException: An  exception occurred

    # https://developers.google.com/resources/api-libraries/documentation/cloudresourcemanager/v1/python/latest/cloudresourcemanager_v1.projects.html#list


def list_disks(self, project, zone):
    List the disks for the given project and zone.

        Args:
            project: The project id
            zone: The zone id

        Yields:
             The disks for this project

        Raises:
            InventoryServiceException: An exception occurred

    # https://developers.google.com/resources/api-libraries/documentation/compute/v1/python/latest/compute_v1.disks.html#list

 def list_routes(self, project):
    List the routes for the given project and zone.

        Args:
            project: The project id

        Yields:
             The routes for this project

        Raises:
            InventoryServiceException: An exception occurred

    #https://developers.google.com/resources/api-libraries/documentation/compute/v1/python/latest/compute_v1.routes.html

 def create_route(self, project, name, priority, network, destination_range, next_hop_gateway):
    Create the routes.

        Args:
            project: The project id
            name: The name of the route
            priority: The priority for the route (integer)
            network: The network for this route (FQDN)
            destination_range: The cidr that the route is applicable to
            next_hop_gateway: The next hop gateway(FQDN)

        Yields:
             The response of the created route object

        Raises:
            InventoryServiceException: An exception occurred

    # https://developers.google.com/resources/api-libraries/documentation/compute/v1/python/latest/compute_v1.routes.html


def delete_route(self, project, route):
    Delete the routes.

        Args:
            project: The project id
            route: The route name to delete
        Raises:
            InventoryServiceException: An exception occurred

    # https://developers.google.com/resources/api-libraries/documentation/compute/v1/python/latest/compute_v1.routes.html       

def swap_disks(self, project, primary_instance, primary_zone, standby_instance, standby_zone, user, key_filename,
               ip_selector=""".[]| select(.name=="nic0")|.accessConfigs[].natIP""",
               max_attach_retries=10
               ):
    """Attach(force attach) the disk to the instance

         Args:
             project: The project id
             primary_instance: The primary_instance
             primary_zone: the primary_zone
             standby_instance : standby_instance
             standby_zone : standby_zone
             user: user to ssh in as
             key_filename: the key file for the user

         Returns:

         Raises:
                InventoryServiceException: An exception occurred

        Flow:
        1. Identify the Primary region
        2. Get all regional disks for primary region and keep in "regional_disk" set
           This is needed as there is no tag in the instance that identifies a disk as regional
        3. Get the attatched disk for the primary instance. Skip all the boot and  zonal disks
        4. Force attach to standby instance
        5. ssh into standby instance
        6. mount the drive

        Note that the disk attach expects the device names to be provided as per
        https://medium.com/@DazWilkin/compute-engine-identifying-your-devices-aeae6c01a4d7

        The disks will be mounted at /mnt/disks/<device-name>
    """

API Usage

Example:

from gcpinventory import gcpinventory as inventory_service    
import logging
logger = logging.getLogger()
logging.basicConfig()
logger.setLevel(logging.INFO)

inventory_service = inventory_service.InventoryService()

 inventory_service.list_projects()

Helpful links

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gcpinventory-0.0.15.tar.gz (6.3 kB view details)

Uploaded Source

Built Distribution

gcpinventory-0.0.15-py2-none-any.whl (7.1 kB view details)

Uploaded Python 2

File details

Details for the file gcpinventory-0.0.15.tar.gz.

File metadata

  • Download URL: gcpinventory-0.0.15.tar.gz
  • Upload date:
  • Size: 6.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/2.7.18rc1

File hashes

Hashes for gcpinventory-0.0.15.tar.gz
Algorithm Hash digest
SHA256 f3672bd4b8c6249f80b295af39ee7b24b7c0aacecce73b7b50ac3c44a1ec6209
MD5 8dcaae108b8b813e2f95519d41c3c132
BLAKE2b-256 9e0c5d5b88335f511c09cd4644a9a7e030f29793a0c169e81cca95a610d4531b

See more details on using hashes here.

File details

Details for the file gcpinventory-0.0.15-py2-none-any.whl.

File metadata

  • Download URL: gcpinventory-0.0.15-py2-none-any.whl
  • Upload date:
  • Size: 7.1 kB
  • Tags: Python 2
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/2.7.18rc1

File hashes

Hashes for gcpinventory-0.0.15-py2-none-any.whl
Algorithm Hash digest
SHA256 a4fcebcc5885b806b455b8ac6cede5621271bafd1b40a7ac77ed10e3c7e4d43f
MD5 67444c39f1f57d552ee35ee55bc1b46d
BLAKE2b-256 79cb88d566896b14309b4d7f842fcfe07c4efa584a7fa29c19ca90bfef5cbc11

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page