Git Product home page Git Product logo

gcp-api-pyhton's Introduction

README

Overview Solution - @ caetano-the-sdk-challenge-and-more.pdf

# gcp-python-instances-list This python script run similar the gcloud compute instances list

gcp_list_vms.py

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 People

Contributors

lucianod2 avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.