这个包提供了代理类,用于直接从python调用gcloud命令。
GCloudPyProx的Python项目详细描述
gcloud pyproxy
这个python包提供了一个代理类,用于直接从python调用gcloud命令。
要求
- gcloud
- python 3.x
安装
通过PIP
pip3 install gcloudpyproxy
或
python3 -m pip install gcloudpyproxy
从源构建
wget https://github.com/tomasvotava/gcloud-pyproxy/archive/master.zipunzip master.zipcd gcloud-pyproxy-masterpython setup.py buildpython setup.py install
用法
fromgcloud_pyproxyimportGCloudgcloud=GCloud()# comamnd: gcloud compute instances listgcloud.compute_instances_list()# command: gcloud compute instances start virtualgcloud.compute_instances_start("virtual")# additional flags and parameters# next method call expands like this:# gcloud compute instances list --project="gcp-project-id"gcloud.compute_instances_list(project="gcp-project-id")# positional arguments are simply concatenated after the command callgcloud.compute_instances_start("virtual",project="gcp-project-id")# expands as:# gcloud compute instances start virtual --project="gcp-project-id"# by default, underscores in flag names are replaced with dashesgcloud.kms_encrypt(plaintext_file="file.txt")# gcloud kms encrypt --plaintext-file="file.txt"# however, this can be overriden by specifying replace_underscore=Falsegcloud.kms_encrypt(plaintext_file="file.txt",replace_underscore=False)# gcloud kms encrypt --plaintext_file="file.txt"