跳转到主要内容

管理GCP库存资源的服务

项目描述

资源清单

这不是一个官方的Google产品。

这是一个可以提供GCP中资源清单的软件包,除了访问项目、区域和磁盘。

可以通过`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使用

示例

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()

有用的链接

项目详情


下载文件

下载适合您平台的应用程序。如果您不确定选择哪个,请了解更多关于安装软件包的信息。

源分布

gcpinventory-0.0.15.tar.gz (6.3 kB 查看哈希值)

上传时间

构建发行版

gcpinventory-0.0.15-py2-none-any.whl (7.1 kB 查看哈希值)

上传时间 Python 2

支持