def get_projects(): http = get_gapi_authorized_http(identity) google_projects_service = apiclient.discovery.build( 'cloudresourcemanager', 'v1', http=http) # May raise oauth2client.client.HttpAccessTokenRefreshError projects = google_projects_service.projects().list().execute() return projects
def download_file(): http = get_gapi_authorized_http(identity) google_storage_service = apiclient.discovery.build('storage', 'v1', http=http) response, billing_data = http.request(billing_file['mediaLink']) return response, billing_data
def get_files(): http = get_gapi_authorized_http(identity) google_storage_service = apiclient.discovery.build('storage', 'v1', http=http) files = google_storage_service.objects().list( bucket=billing_bucket['name']).execute() return files
def get_buckets(): http = get_gapi_authorized_http(identity) google_storage_service = apiclient.discovery.build('storage', 'v1', http=http) buckets = google_storage_service.buckets().list( project=project['number']).execute() return buckets
def get_timeseries(): http = get_gapi_authorized_http(identity) google_monitoring_service = apiclient.discovery.build( 'cloudmonitoring', 'v2beta2', http=http) res = google_monitoring_service.timeseries().list( project=project['code'], metric=metric_name, oldest=start, youngest=stop, pageToken=next_page_token).execute() return res
def get_instances(): http = get_gapi_authorized_http(identity) google_compute_service = apiclient.discovery.build('compute', 'v1', http=http) instances = [] for project in get_identity_projects_from_gcloud_api(identity): zones = google_compute_service.zones().list( project=project['code']).execute() for zone in zones['items']: try: compute_instances_infos = google_compute_service.instances( ).list(project=project['code'], zone=zone['name']).execute() except apiclient.errors.HttpError as err: continue if 'items' in compute_instances_infos: for instance in compute_instances_infos['items']: if instance['status'] == 'RUNNING': instances.append(instance) return instances
def get_instance_metrics(identity, project, since=None): http = get_gapi_authorized_http(identity) google_monitoring_service = apiclient.discovery.build('cloudmonitoring', 'v2beta2', http=http) if not since: since = datetime(1970, 1, 1) since_string = since.isoformat("T") + '+00:00' for metric in INSTANCE_METRICS: now_string = datetime.utcnow().isoformat("T") + '+00:00' for metric in get_instance_metric_type(identity, project, metric, since_string, now_string): yield metric for metric in INSTANCE_DISK_METRICS: now_string = datetime.utcnow().isoformat("T") + '+00:00' for metric in get_instance_disk_metric_type(identity, project, metric, since_string, now_string): yield metric for metric in INSTANCE_NETWORK_METRICS: now_string = datetime.utcnow().isoformat("T") + '+00:00' for metric in get_instance_network_metric_type(identity, project, metric, since_string, now_string): yield metric