In [1]:
#imports
import ipywidgets as widgets

In [3]:
# %load getCredentialsFromFile.py


def getCredentials():
    from  oauth2client import file
    import httplib2
    import ipywidgets as widgets
    print("Getting the credentials from file...")
    storage = file.Storage("oauth2.dat")
    credentials=storage.get()
    if credentials is None or credentials.invalid:
        print( '❗')
        display(widgets.Valid(
            value=False,
            description='Credentials are ',
            disabled=False))
        display(widgets.HTML('go create a credential valid file here: <a target="_blank" href="cloud.google.auth.ipynb.ipynb">gcloud authorization notebook</a> and try again'))
    else:
        http_auth = credentials.authorize(httplib2.Http())
        print('✅ Ok')
        return credentials

In [4]:
credentials=getCredentials()


Getting the credentials from file...
✅ Ok

In [5]:
#create the service
from apiclient.discovery import build
compute_service = build('compute', 'v1',credentials=credentials)

In [13]:
#set the projectId
projectCodeWidget=widgets.Text(description="Your project code:")
valid=widgets.Valid(value=False,description='',disabled=False)
display(widgets.Box([projectCodeWidget,valid]))
def valueChange(sender):
    if projectCodeWidget.value!="":
        valid.value=True
        valid.description='OK'
    else:
        valid.value=False
        valid.description=''

projectCodeWidget.observe(valueChange, 'value')



In [9]:
zones=compute_service.zones().list(project=projectCodeWidget.value).execute()
from pandas import DataFrame
DataFrame.from_dict(zones['items'])


Out[9]:
creationTimestamp description id kind name region selfLink status
0 2016-06-14T17:29:18.761-07:00 asia-east1-a 2220 compute#zone asia-east1-a https://www.googleapis.com/compute/v1/projects... https://www.googleapis.com/compute/v1/projects... UP
1 2016-06-14T17:29:18.761-07:00 asia-east1-b 2221 compute#zone asia-east1-b https://www.googleapis.com/compute/v1/projects... https://www.googleapis.com/compute/v1/projects... UP
2 2014-07-15T10:44:08.663-07:00 asia-east1-c 2222 compute#zone asia-east1-c https://www.googleapis.com/compute/v1/projects... https://www.googleapis.com/compute/v1/projects... UP
3 2016-08-15T17:05:00.316-07:00 asia-northeast1-c 2252 compute#zone asia-northeast1-c https://www.googleapis.com/compute/v1/projects... https://www.googleapis.com/compute/v1/projects... UP
4 2016-08-15T17:05:00.313-07:00 asia-northeast1-a 2250 compute#zone asia-northeast1-a https://www.googleapis.com/compute/v1/projects... https://www.googleapis.com/compute/v1/projects... UP
5 2016-08-15T17:05:00.315-07:00 asia-northeast1-b 2251 compute#zone asia-northeast1-b https://www.googleapis.com/compute/v1/projects... https://www.googleapis.com/compute/v1/projects... UP
6 2017-02-07T04:53:31.630-08:00 asia-southeast1-b 2261 compute#zone asia-southeast1-b https://www.googleapis.com/compute/v1/projects... https://www.googleapis.com/compute/v1/projects... UP
7 2017-02-07T04:53:31.627-08:00 asia-southeast1-a 2260 compute#zone asia-southeast1-a https://www.googleapis.com/compute/v1/projects... https://www.googleapis.com/compute/v1/projects... UP
8 2017-04-18T06:18:01.025-07:00 australia-southeast1-b 2282 compute#zone australia-southeast1-b https://www.googleapis.com/compute/v1/projects... https://www.googleapis.com/compute/v1/projects... UP
9 2017-04-04T07:53:44.445-07:00 australia-southeast1-a 2281 compute#zone australia-southeast1-a https://www.googleapis.com/compute/v1/projects... https://www.googleapis.com/compute/v1/projects... UP
10 2017-04-04T07:53:44.445-07:00 australia-southeast1-c 2280 compute#zone australia-southeast1-c https://www.googleapis.com/compute/v1/projects... https://www.googleapis.com/compute/v1/projects... UP
11 2014-09-02T15:52:35.238-07:00 europe-west1-c 2103 compute#zone europe-west1-c https://www.googleapis.com/compute/v1/projects... https://www.googleapis.com/compute/v1/projects... UP
12 2014-12-15T13:42:35.748-08:00 europe-west1-d 2104 compute#zone europe-west1-d https://www.googleapis.com/compute/v1/projects... https://www.googleapis.com/compute/v1/projects... UP
13 2016-06-14T17:29:18.761-07:00 europe-west1-b 2101 compute#zone europe-west1-b https://www.googleapis.com/compute/v1/projects... https://www.googleapis.com/compute/v1/projects... UP
14 2017-03-14T04:48:48.304-07:00 europe-west2-b 2291 compute#zone europe-west2-b https://www.googleapis.com/compute/v1/projects... https://www.googleapis.com/compute/v1/projects... UP
15 2017-03-14T04:48:48.304-07:00 europe-west2-c 2292 compute#zone europe-west2-c https://www.googleapis.com/compute/v1/projects... https://www.googleapis.com/compute/v1/projects... UP
16 2017-03-14T04:48:48.302-07:00 europe-west2-a 2290 compute#zone europe-west2-a https://www.googleapis.com/compute/v1/projects... https://www.googleapis.com/compute/v1/projects... UP
17 2014-10-29T11:20:06.229-07:00 us-central1-c 2002 compute#zone us-central1-c https://www.googleapis.com/compute/v1/projects... https://www.googleapis.com/compute/v1/projects... UP
18 2016-06-14T17:29:18.761-07:00 us-central1-a 2000 compute#zone us-central1-a https://www.googleapis.com/compute/v1/projects... https://www.googleapis.com/compute/v1/projects... UP
19 2016-06-14T17:29:18.761-07:00 us-central1-b 2001 compute#zone us-central1-b https://www.googleapis.com/compute/v1/projects... https://www.googleapis.com/compute/v1/projects... UP
20 2016-06-14T17:29:18.761-07:00 us-central1-f 2004 compute#zone us-central1-f https://www.googleapis.com/compute/v1/projects... https://www.googleapis.com/compute/v1/projects... UP
21 2015-09-03T15:15:02.330-07:00 us-east1-d 2234 compute#zone us-east1-d https://www.googleapis.com/compute/v1/projects... https://www.googleapis.com/compute/v1/projects... UP
22 2015-09-08T10:59:59.040-07:00 us-east1-c 2233 compute#zone us-east1-c https://www.googleapis.com/compute/v1/projects... https://www.googleapis.com/compute/v1/projects... UP
23 2015-09-08T16:57:06.746-07:00 us-east1-b 2231 compute#zone us-east1-b https://www.googleapis.com/compute/v1/projects... https://www.googleapis.com/compute/v1/projects... UP
24 2017-02-14T06:05:24.188-08:00 us-east4-b 2271 compute#zone us-east4-b https://www.googleapis.com/compute/v1/projects... https://www.googleapis.com/compute/v1/projects... UP
25 2017-02-14T06:05:24.188-08:00 us-east4-c 2272 compute#zone us-east4-c https://www.googleapis.com/compute/v1/projects... https://www.googleapis.com/compute/v1/projects... UP
26 2017-02-14T06:05:24.188-08:00 us-east4-a 2270 compute#zone us-east4-a https://www.googleapis.com/compute/v1/projects... https://www.googleapis.com/compute/v1/projects... UP
27 2017-03-14T04:48:48.314-07:00 us-west1-c 2212 compute#zone us-west1-c https://www.googleapis.com/compute/v1/projects... https://www.googleapis.com/compute/v1/projects... UP
28 2016-06-10T09:30:55.192-07:00 us-west1-b 2211 compute#zone us-west1-b https://www.googleapis.com/compute/v1/projects... https://www.googleapis.com/compute/v1/projects... UP
29 2016-06-10T09:30:55.189-07:00 us-west1-a 2210 compute#zone us-west1-a https://www.googleapis.com/compute/v1/projects... https://www.googleapis.com/compute/v1/projects... UP

In [ ]: