Example #1
0
    def test_create_w_alternate_client(self):
        from gcloud.dns.resource_record_set import ResourceRecordSet
        self._setUpConstants()
        RESOURCE = self._makeResource()
        PATH = 'projects/%s/managedZones/%s/changes' % (self.PROJECT,
                                                        self.ZONE_NAME)
        conn1 = _Connection()
        client1 = _Client(project=self.PROJECT, connection=conn1)
        conn2 = _Connection(RESOURCE)
        client2 = _Client(project=self.PROJECT, connection=conn2)
        zone = _Zone(client1)
        changes = self._makeOne(zone)
        changes.add_record_set(
            ResourceRecordSet('test.example.com', 'CNAME', 3600,
                              ['www.example.com'], zone))
        changes.delete_record_set(
            ResourceRecordSet('test.example.com', 'CNAME', 86400,
                              ['other.example.com'], zone))

        changes.create(client=client2)

        self.assertEqual(len(conn1._requested), 0)
        self.assertEqual(len(conn2._requested), 1)
        req = conn2._requested[0]
        self.assertEqual(req['method'], 'POST')
        self.assertEqual(req['path'], '/%s' % PATH)
        SENT = {
            'additions': RESOURCE['additions'],
            'deletions': RESOURCE['deletions'],
        }
        self.assertEqual(req['data'], SENT)
        self._verifyResourceProperties(changes, RESOURCE, zone)
Example #2
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
Example #3
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
Example #4
0
 def test_delete_record_set(self):
     from gcloud.dns.resource_record_set import ResourceRecordSet
     zone = _Zone()
     changes = self._makeOne(zone)
     rrs = ResourceRecordSet('test.example.com', 'CNAME', 3600,
                             ['www.example.com'], zone)
     changes.delete_record_set(rrs)
     self.assertEqual(list(changes.deletions), [rrs])
Example #5
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:`gcloud.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:`gcloud.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')
Example #6
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:`gcloud.dns.resource_record_set.ResourceRecordSet`
        :returns: a new ``ResourceRecordSet`` instance
        """
        return ResourceRecordSet(name, record_type, ttl, rrdatas, zone=self)
Example #7
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:`gcloud.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:`gcloud.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')