from pprint import pprint
from googleapiclient import discovery
from oauth2client.client import GoogleCredentials
from six.moves import input
import googleapiclient.discovery
import argparse
import os
#os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "/full-path/service-account-key-automation.json"
# Project ID for this request.
project = "project-name"
zone = "us-east1-b"
compute = googleapiclient.discovery.build('compute', 'v1')
space = ' '
def list_instances(compute, project, zone):
result = compute.instances().list(project=project, zone=zone).execute()
print ("{:<7} {:<11} {:<13} {:<12} {:<12} {:<15} {:<0}".format('NAME','ZONE','MACHINE_TYPE','PREEMPTIBLE','INTERNAL_IP','EXTERNAL_IP','STATUS'))
for item in result['items']:
if item['status'] == "RUNNING":
var_name = item['name']
var_zone = item['zone']
var_machine_type = item['machineType']
var_preemptible = item['scheduling']['preemptible']
var_internal_ip = item['networkInterfaces'][0]['networkIP']
var_external_ip = '{:<14}'.format(item['networkInterfaces'][0]['accessConfigs'][0]['natIP'])
var_status = item['status'].rjust(0)
print ("{:<7} {:<11} {:<13} {:<12} {:<12} {:<15} {:<0}".format(var_name, var_zone.rsplit('/', 1)[-1], var_machine_type.rsplit('/', 1)[-1], str(var_preemptible),var_internal_ip, var_external_ip,var_status))
return result['items'] if 'items' in result else None
list_instances(compute, project, zone)
print ("\nWinners never quit, and quitters never win.")
print ("\nVencedores nunca desistem e desistentes nunca ganham.")
print('\n#pracima')
```'
*Live :v:
*Love :heart:
*Learn :see_no_evil: :hear_no_evil: :speak_no_evil:
:rocket::rocket::rocket:
*google cloud platfomr GCP
*python
*Winners never quit, and quitters never win.
*pracima
*thecloudbootcamp
gcp-api-pyhton's Introduction
gcp-api-pyhton's People
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.