Python helpers to interact with GCP
Project description
Wrap essential Google Cloud Platform functions to a python API
Set project credentials and list VM's by prefix
import os
os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = "/Users/vadimskritskii/PycharmProjects/report/gcp/rock-embassy-279812-b252be8804df.json"
os.environ['FROM_LOCAL'] = 'false'
os.environ['GCP_BUCKET'] = 'bucket_name'
from python_wrap_gcp import manage_instance
manage_instance.list_gcp_instances('INTERNAL_IP', prefix='cc-wiki')
Returns project VM's filtered by prefix as pandas.DataFrame
NAME ZONE MACHINE_TYPE PREEMPTIBLE INTERNAL_IP EXTERNAL_IP STATUS
0 cc-wiki-1 us-central1-f e2-medium true 10.128.0.10 35.232.196.210 RUNNING
1 cc-wiki-2 us-central1-f e2-medium true 10.128.0.12 35.193.87.226 RUNNING
2 cc-wiki-3 us-central1-f e2-medium true 10.128.0.14 34.123.56.251 RUNNING
3 cc-wiki-4 us-central1-f e2-medium true 10.128.0.11 35.223.179.167 RUNNING
4 cc-wiki-5 us-central1-f e2-medium true 10.128.0.15 35.225.92.133 RUNNING
5 cc-wiki-6 us-central1-f e2-medium true 10.128.0.13 35.238.125.9 RUNNING```
Start all VM's by a prefix
manage_instance.manage_gcp_instance(action='start', prefix='cc-wiki')
[12:35:43.3]-[wrap_gcloud.py]-[wrap_gcloud_action]-[start: us-central1-f: cc-wiki-1,cc-wiki-2,cc-wiki-3,cc-wiki-4,cc-wiki-5,cc-wiki-6]-[I]-[9520cb]
Abstraction interface to read/write data either locally or on GCP
Load data from the bucket
import json
from python_wrap_gcp import io
data = json.loads(io.emulate_open("gs://meely-inventory/data/context.json"))
# alternatively
from python_wrap_gcp.reload_data import load_gcs_file
data, time_data_updated = load_gcs_file("gs://meely-inventory/data/context.json")
Save data locally
import json, os
from python_wrap_gcp import io
os.environ['TO_LOCAL'] = 'true'
context = {"hello": "witam",
"world": "świat"}
io.emulate_open("~/Desktop/context.json", method='wb', data=context)
Create VM's by creating a template & setting VM replicas
from meely_crawl.docs import config
from python_wrap_gcp.configure_gcp import configure
configure_gcp = configure.Configure(config.Path, config.GCPConfig)
configure_gcp.set_up()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
python-wrap-gcp-0.0.12.tar.gz
(11.2 kB
view hashes)
Built Distribution
Close
Hashes for python_wrap_gcp-0.0.12-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 37ca80c064c5e5d534739cd26244b52665861e8cff049b738ed26422a166ceae |
|
MD5 | c37072cb350a10b7af47d3b5b9cd7cb4 |
|
BLAKE2b-256 | c9d71a63374f36d2c0157f06c44e88395eebe6c5750f8887ff62b553cb744c96 |