예제 #1
0
    def _set_properties(self, resource):
        """Helper method for :meth:`from_api_repr`, :meth:`create`, etc.

        :type resource: dict
        :param resource: change set representation returned from the API.
        """
        resource = resource.copy()
        self._additions = tuple(
            [ResourceRecordSet.from_api_repr(added_res, self.zone) for added_res in resource.pop("additions", ())]
        )
        self._deletions = tuple(
            [ResourceRecordSet.from_api_repr(added_res, self.zone) for added_res in resource.pop("deletions", ())]
        )
        self._properties = resource
예제 #2
0
def _item_to_resource_record_set(iterator, resource):
    """Convert a JSON resource record set value to the native object.

    :type iterator: :class:`~google.cloud.iterator.Iterator`
    :param iterator: The iterator that has retrieved the item.

    :type resource: dict
    :param resource: An item to be converted to a resource record set.

    :rtype: :class:`~.resource_record_set.ResourceRecordSet`
    :returns: The next resource record set in the page.
    """
    return ResourceRecordSet.from_api_repr(resource, iterator.zone)
예제 #3
0
def _item_to_resource_record_set(iterator, resource):
    """Convert a JSON resource record set value to the native object.

    :type iterator: :class:`~google.cloud.iterator.Iterator`
    :param iterator: The iterator that has retrieved the item.

    :type resource: dict
    :param resource: An item to be converted to a resource record set.

    :rtype: :class:`~.resource_record_set.ResourceRecordSet`
    :returns: The next resource record set in the page.
    """
    return ResourceRecordSet.from_api_repr(resource, iterator.zone)
예제 #4
0
    def list_resource_record_sets(self,
                                  max_results=None,
                                  page_token=None,
                                  client=None):
        """List resource record sets for this zone.

        See:
        https://cloud.google.com/dns/api/v1/resourceRecordSets/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: string
        :param page_token: opaque marker for the next "page" of zones. If
                           not passed, the API will return the first page of
                           zones.

        :type client: :class:`google.cloud.dns.client.Client` or ``NoneType``
        :param client: the client to use.  If not passed, falls back to the
                       ``client`` stored on the current zone.

        :rtype: tuple, (list, str)
        :returns: list of
                  :class:`google.cloud.dns.resource_record_set.ResourceRecordSet`,
                  plus a "next page token" string:  if the token is not None,
                  indicates that more zones can be retrieved with another
                  call (pass that value as ``page_token``).
        """
        params = {}

        if max_results is not None:
            params['maxResults'] = max_results

        if page_token is not None:
            params['pageToken'] = page_token

        path = '/projects/%s/managedZones/%s/rrsets' % (self.project,
                                                        self.name)
        client = self._require_client(client)
        conn = client.connection
        resp = conn.api_request(method='GET', path=path, query_params=params)
        zones = [
            ResourceRecordSet.from_api_repr(resource, self)
            for resource in resp['rrsets']
        ]
        return zones, resp.get('nextPageToken')
예제 #5
0
    def resource_record_set(self, name, record_type, ttl, rrdatas):
        """Construct a resource record set bound to this zone.

        :type name: string
        :param name: Name of the record set.

        :type record_type: string
        :param record_type: RR type

        :type ttl: integer
        :param ttl: TTL for the RR, in seconds

        :type rrdatas: list of string
        :param rrdatas: resource data for the RR

        :rtype: :class:`google.cloud.dns.resource_record_set.ResourceRecordSet`
        :returns: a new ``ResourceRecordSet`` instance
        """
        return ResourceRecordSet(name, record_type, ttl, rrdatas, zone=self)
예제 #6
0
    def list_resource_record_sets(self, max_results=None, page_token=None,
                                  client=None):
        """List resource record sets for this zone.

        See:
        https://cloud.google.com/dns/api/v1/resourceRecordSets/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: string
        :param page_token: opaque marker for the next "page" of zones. If
                           not passed, the API will return the first page of
                           zones.

        :type client: :class:`google.cloud.dns.client.Client` or ``NoneType``
        :param client: the client to use.  If not passed, falls back to the
                       ``client`` stored on the current zone.

        :rtype: tuple, (list, str)
        :returns: list of
                  :class:`google.cloud.dns.resource_record_set.ResourceRecordSet`,
                  plus a "next page token" string:  if the token is not None,
                  indicates that more zones can be retrieved with another
                  call (pass that value as ``page_token``).
        """
        params = {}

        if max_results is not None:
            params['maxResults'] = max_results

        if page_token is not None:
            params['pageToken'] = page_token

        path = '/projects/%s/managedZones/%s/rrsets' % (
            self.project, self.name)
        client = self._require_client(client)
        conn = client.connection
        resp = conn.api_request(method='GET', path=path, query_params=params)
        zones = [ResourceRecordSet.from_api_repr(resource, self)
                 for resource in resp['rrsets']]
        return zones, resp.get('nextPageToken')