def __init__(self, project=None, credentials=None, http=None): super(Client, self).__init__(project=project, credentials=credentials, http=http) self._connection = Connection(credentials=self._credentials, http=self._http)
def __init__(self, project=None, credentials=None, http=None): super(Client, self).__init__( project=project, credentials=credentials, http=http) self._connection = Connection( credentials=self._credentials, http=self._http)
class Client(ClientWithProject): """Client to bundle configuration needed for API requests. :type project: str :param project: the project which the client acts on behalf of. Will be passed when creating a zone. If not passed, falls back to the default inferred from the environment. :type credentials: :class:`~google.auth.credentials.Credentials` :param credentials: (Optional) The OAuth2 Credentials to use for this client. If not passed (and if no ``http`` object is passed), falls back to the default inferred from the environment. :type http: :class:`~httplib2.Http` :param http: (Optional) HTTP object to make requests. Can be any object that defines ``request()`` with the same interface as :meth:`~httplib2.Http.request`. If not passed, an ``http`` object is created that is bound to the ``credentials`` for the current object. """ def __init__(self, project=None, credentials=None, http=None): super(Client, self).__init__(project=project, credentials=credentials, http=http) self._connection = Connection(credentials=self._credentials, http=self._http) def quotas(self): """Return DNS quotas for the project associated with this client. See: https://cloud.google.com/dns/api/v1/projects/get :rtype: mapping :returns: keys for the mapping correspond to those of the ``quota`` sub-mapping of the project resource. """ path = '/projects/%s' % (self.project, ) resp = self._connection.api_request(method='GET', path=path) return { key: int(value) for key, value in resp['quota'].items() if key != 'kind' } def list_zones(self, max_results=None, page_token=None): """List zones for the project associated with this client. See: https://cloud.google.com/dns/api/v1/managedZones/list :type max_results: int :param max_results: maximum number of zones to return, If not passed, defaults to a value set by the API. :type page_token: str :param page_token: opaque marker for the next "page" of zones. If not passed, the API will return the first page of zones. :rtype: :class:`~google.cloud.iterator.Iterator` :returns: Iterator of :class:`~google.cloud.dns.zone.ManagedZone` belonging to this project. """ path = '/projects/%s/managedZones' % (self.project, ) return HTTPIterator(client=self, path=path, item_to_value=_item_to_zone, items_key='managedZones', page_token=page_token, max_results=max_results) def zone(self, name, dns_name=None, description=None): """Construct a zone bound to this client. :type name: str :param name: Name of the zone. :type dns_name: str :param dns_name: (Optional) DNS name of the zone. If not passed, then calls to :meth:`zone.create` will fail. :type description: str :param description: (Optional) the description for the zone. If not passed, defaults to the value of 'dns_name'. :rtype: :class:`google.cloud.dns.zone.ManagedZone` :returns: a new ``ManagedZone`` instance. """ return ManagedZone(name, dns_name, client=self, description=description)
class Client(JSONClient): """Client to bundle configuration needed for API requests. :type project: str :param project: the project which the client acts on behalf of. Will be passed when creating a zone. If not passed, falls back to the default inferred from the environment. :type credentials: :class:`~google.auth.credentials.Credentials` :param credentials: (Optional) The OAuth2 Credentials to use for this client. If not passed (and if no ``http`` object is passed), falls back to the default inferred from the environment. :type http: :class:`~httplib2.Http` :param http: (Optional) HTTP object to make requests. Can be any object that defines ``request()`` with the same interface as :meth:`~httplib2.Http.request`. If not passed, an ``http`` object is created that is bound to the ``credentials`` for the current object. """ def __init__(self, project=None, credentials=None, http=None): super(Client, self).__init__( project=project, credentials=credentials, http=http) self._connection = Connection( credentials=self._credentials, http=self._http) def quotas(self): """Return DNS quotas for the project associated with this client. See: https://cloud.google.com/dns/api/v1/projects/get :rtype: mapping :returns: keys for the mapping correspond to those of the ``quota`` sub-mapping of the project resource. """ path = '/projects/%s' % (self.project,) resp = self._connection.api_request(method='GET', path=path) return {key: int(value) for key, value in resp['quota'].items() if key != 'kind'} def list_zones(self, max_results=None, page_token=None): """List zones for the project associated with this client. See: https://cloud.google.com/dns/api/v1/managedZones/list :type max_results: int :param max_results: maximum number of zones to return, If not passed, defaults to a value set by the API. :type page_token: str :param page_token: opaque marker for the next "page" of zones. If not passed, the API will return the first page of zones. :rtype: :class:`~google.cloud.iterator.Iterator` :returns: Iterator of :class:`~google.cloud.dns.zone.ManagedZone` belonging to this project. """ path = '/projects/%s/managedZones' % (self.project,) return HTTPIterator( client=self, path=path, item_to_value=_item_to_zone, items_key='managedZones', page_token=page_token, max_results=max_results) def zone(self, name, dns_name=None, description=None): """Construct a zone bound to this client. :type name: str :param name: Name of the zone. :type dns_name: str :param dns_name: (Optional) DNS name of the zone. If not passed, then calls to :meth:`zone.create` will fail. :type description: str :param description: (Optional) the description for the zone. If not passed, defaults to the value of 'dns_name'. :rtype: :class:`google.cloud.dns.zone.ManagedZone` :returns: a new ``ManagedZone`` instance. """ return ManagedZone(name, dns_name, client=self, description=description)