google.cloud.forseti.common.gcp_api.cloudbilling module

Wrapper for Cloud Billing API client.

class CloudBillingClient(global_configs, **kwargs)[source]

Bases: object

Cloud Billing Client.

get_billing_accounts(master_account_id=None)[source]

Gets all billing accounts the authenticated user has access to.

If no master account is specified, then all billing accounts the caller has visibility to are returned. Otherwise retuns all subaccounts of the specified master billing account.

Parameters:master_account_id (str) – If set, only return subaccounts under this master billing account.
Returns:A list of BillingAccount resources. https://cloud.google.com/billing/reference/rest/v1/billingAccounts
{
“name”: string, “open”: boolean, “displayName”: string, “masterBillingAccount”: string,

}

Return type:list
Raises:ApiExecutionError – ApiExecutionError is raised if the call to the GCP API fails.
get_billing_acct_iam_policies(account_id)[source]

Gets the IAM policies for the given billing account.

Parameters:account_id (str) – The billing account id.
Returns:An IAM Policy resource. https://cloud.google.com/billing/reference/rest/v1/Policy
{
“bindings”: list, “auditConfigs”: list, “etag”: string,

}

Return type:dict
Raises:ApiExecutionError – ApiExecutionError is raised if the call to the GCP API fails.
get_billing_info(project_id)[source]

Gets the billing information for a project.

Parameters:project_id (int) – The project id for a GCP project.
Returns:A ProjectBillingInfo resource. https://cloud.google.com/billing/reference/rest/v1/ProjectBillingInfo
{
“name”: string, “projectId”: string, “billingAccountName”: string, “billingEnabled”: boolean,

}

Return type:dict
Raises:ApiExecutionError – ApiExecutionError is raised if the call to the GCP API fails.
class CloudBillingRepositoryClient(quota_max_calls=None, quota_period=60.0, use_rate_limiter=True)[source]

Bases: google.cloud.forseti.common.gcp_api._base_repository.BaseRepositoryClient

Cloud Billing API Respository.

billing_accounts

Returns a _CloudBillingBillingAccountsRepository instance.

projects

Returns a _CloudBillingProjectsRepository instance.

class _CloudBillingBillingAccountsRepository(**kwargs)[source]

Bases: google.cloud.forseti.common.gcp_api.repository_mixins.GetIamPolicyQueryMixin, google.cloud.forseti.common.gcp_api.repository_mixins.ListQueryMixin, google.cloud.forseti.common.gcp_api._base_repository.GCPRepository

Implementation of Cloud Billing BillingAccounts repository.

static get_name(account_id)[source]

Format’s a billing account ID to pass to the API

Parameters:account_id (str) – The billing account id to query, either just the id or the id prefixed with ‘billingAccounts/’.
Returns:The formatted resource name.
Return type:str
class _CloudBillingProjectsRepository(**kwargs)[source]

Bases: google.cloud.forseti.common.gcp_api._base_repository.GCPRepository

Implementation of Cloud Billing Projects repository.

get_billing_info(name, fields=None)[source]

Gets the billing information for a project.

Parameters:
  • name (str) – The project name to query in the format projects/{project_id}.
  • fields (str) – Fields to include in the response - partial response.
Returns:

The response from the API.

Return type:

dict

static get_name(project_id)[source]

Format’s a project_id to pass in to .get().

Parameters:project_id (str) – The project id to query, either just the id or the id prefixed with ‘projects/’.
Returns:The formatted resource name.
Return type:str