管理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()
有用的链接
- https://cloud.google.com/compute/docs/tutorials/python-guide
- https://github.com/google/google-api-python-client
- https://developers.google.com/resources/api-libraries/documentation/cloudresourcemanager/v1/python/latest/cloudresourcemanager_v1.projects.html#list
- https://developers.google.com/resources/api-libraries/documentation/compute/v1/python/latest/compute_v1.disks.html#list
- https://developers.google.com/resources/api-libraries/documentation/compute/v1/python/latest/compute_v1.zones.html#list
- https://developers.google.com/resources/api-libraries/documentation/compute/v1/python/latest/compute_v1.routes.html
项目详情
关闭
gcpinventory-0.0.15.tar.gz 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | f3672bd4b8c6249f80b295af39ee7b24b7c0aacecce73b7b50ac3c44a1ec6209 |
|
MD5 | 8dcaae108b8b813e2f95519d41c3c132 |
|
BLAKE2b-256 | 9e0c5d5b88335f511c09cd4644a9a7e030f29793a0c169e81cca95a610d4531b |
关闭
gcpinventory-0.0.15-py2-none-any.whl 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | a4fcebcc5885b806b455b8ac6cede5621271bafd1b40a7ac77ed10e3c7e4d43f |
|
MD5 | 67444c39f1f57d552ee35ee55bc1b46d |
|
BLAKE2b-256 | 79cb88d566896b14309b4d7f842fcfe07c4efa584a7fa29c19ca90bfef5cbc11 |