Ejemplo n.º 1
0
    def create_zone(self,
                    name,
                    private_zone=False,
                    vpc_id=None,
                    vpc_region=None):
        """
        Create a new Hosted Zone.  Returns a Zone object for the newly
        created Hosted Zone.

        :type name: str
        :param name: The name of the domain. This should be a
            fully-specified domain, and should end with a final period
            as the last label indication.  If you omit the final period,
            Amazon Route 53 assumes the domain is relative to the root.
            This is the name you have registered with your DNS registrar.
            It is also the name you will delegate from your registrar to
            the Amazon Route 53 delegation servers returned in
            response to this request.

        :type private_zone: bool
        :param private_zone: Set True if creating a private hosted zone.

        :type vpc_id: str
        :param vpc_id: When creating a private hosted zone, the VPC Id to
            associate to is required.

        :type vpc_region: str
        :param vpc_id: When creating a private hosted zone, the region of
            the associated VPC is required.
        """
        zone = self.create_hosted_zone(name,
                                       private_zone=private_zone,
                                       vpc_id=vpc_id,
                                       vpc_region=vpc_region)
        return Zone(self, zone['CreateHostedZoneResponse']['HostedZone'])
Ejemplo n.º 2
0
    def test_find_records(self):
        mock_connection = mock.Mock()
        zone = Zone(mock_connection, {})
        zone.id = None
        rr_names = ['amazon.com', 'amazon.com', 'aws.amazon.com',
                    'aws.amazon.com']
        mock_rrs = []
        # Create some mock resource records.
        for rr_name in rr_names:
            mock_rr = mock.Mock()
            mock_rr.name = rr_name
            mock_rr.type = 'A'
            mock_rr.weight = None
            mock_rr.region = None
            mock_rrs.append(mock_rr)

        # Set the last resource record to ``None``. The ``find_records`` loop
        # should never hit this.
        mock_rrs[3] = None

        mock_connection.get_all_rrsets.return_value = mock_rrs
        mock_connection._make_qualified.return_value = 'amazon.com'

        # Ensure that the ``None`` type object was not iterated over.
        try:
            result_rrs = zone.find_records('amazon.com', 'A', all=True)
        except AttributeError as e:
            self.fail("find_records() iterated too far into resource"
                      " record list.")

        # Determine that the resulting records are correct.
        self.assertEqual(result_rrs, [mock_rrs[0], mock_rrs[1]])
Ejemplo n.º 3
0
 def get_zones(self):
     """
     Returns a list of Zone objects, one for each of the Hosted
     Zones defined for the AWS account.
     """
     zones = self.get_all_hosted_zones()
     return [Zone(self, zone) for zone in
             zones['ListHostedZonesResponse']['HostedZones']]
Ejemplo n.º 4
0
 def _get_records(self):
     """
 Returns all Route53 records for the domain.
 """
     zone = Zone(self.conn.route53, {'Id': self._hosted_zone_id})
     result = zone.find_records(self._domain, RecordType.CNAME, all=True)
     # Always return a list of records.
     if not result:
         return []
     elif isinstance(result, Record):
         return [result]
     else:
         return result
Ejemplo n.º 5
0
def make_mx_record(domain):
    """
    Makes an mx record for a domain that we own.

    :return: The status returned from the add_mx call if it was successful.
    """
    if not domain_exists(domain):
        return None
    connection = EfficientRoute53Connection(settings.AWS_ACCESS_KEY_ID,
                                            settings.AWS_SECRET_KEY)
    zone = connection.get_hosted_zone_by_name(domain)
    if zone:
        zone = Zone(connection, zone['GetHostedZoneResponse']['HostedZone'])

    return zone.add_mx(domain , ['10 mx.sendgrid.net'])
Ejemplo n.º 6
0
    def create_zone(self, name):
        """
        Create a new Hosted Zone.  Returns a Zone object for the newly
        created Hosted Zone.

        :type name: str
        :param name: The name of the domain. This should be a
            fully-specified domain, and should end with a final period
            as the last label indication.  If you omit the final period,
            Amazon Route 53 assumes the domain is relative to the root.
            This is the name you have registered with your DNS registrar.
            It is also the name you will delegate from your registrar to
            the Amazon Route 53 delegation servers returned in
            response to this request.
        """
        zone = self.create_hosted_zone(name)
        return Zone(self, zone['CreateHostedZoneResponse']['HostedZone'])
Ejemplo n.º 7
0
    def create(self):

        self.response.status = 'FAILED'

        zone_name = self.properties.get('ZoneName')

        if not zone_name.endswith('.'):
            self.response.reason = 'ZoneName must end with a dot character'
            return

        conn = boto.route53.Route53Connection()

        resp = conn.create_hosted_zone(domain_name=zone_name)
        zone = Zone(self, resp['CreateHostedZoneResponse']['HostedZone'])
        delegation_set = resp['CreateHostedZoneResponse']['DelegationSet'][
            'NameServers']

        self.response.physical_resource_id = zone.id
        self.response.data = {'DelegationSet': delegation_set}
        self.response.status = 'SUCCESS'