def _create_or_update_recordset(self, context, records, zone_id, name, type, ttl=None): name = name.encode('idna').decode('utf-8') try: # Attempt to create a new recordset. values = { 'name': name, 'type': type, 'ttl': ttl, } recordset = RecordSet(**values) recordset.records = RecordList(objects=records) recordset = self.central_api.create_recordset( context, zone_id, recordset ) except exceptions.DuplicateRecordSet: # Fetch and update the existing recordset. recordset = self.central_api.find_recordset(context, { 'zone_id': zone_id, 'name': name, 'type': type, }) for record in records: recordset.records.append(record) recordset = self.central_api.update_recordset( context, recordset ) LOG.debug('Creating record in %s / %s', zone_id, recordset['id']) return recordset
def _find_or_create_recordset(self, context, zone_id, name, type, ttl=None): name = name.encode('idna').decode('utf-8') try: # Attempt to create an empty recordset values = { 'name': name, 'type': type, 'ttl': ttl, } recordset = self.central_api.create_recordset( context, zone_id, RecordSet(**values)) except exceptions.DuplicateRecordSet: # Fetch the existing recordset recordset = self.central_api.find_recordset( context, { 'zone_id': zone_id, 'name': name, 'type': type, }) return recordset
def post_all(self, zone_id): """Create RecordSet""" request = pecan.request response = pecan.response context = request.environ['context'] body = request.body_dict recordset = DesignateAdapter.parse('API_v2', body, RecordSet()) recordset.validate() # SOA recordsets cannot be created manually if recordset.type == 'SOA': raise exceptions.BadRequest( "Creating a SOA recordset is not allowed") # Create the recordset recordset = self.central_api.create_recordset(context, zone_id, recordset) # Prepare the response headers if recordset['status'] == 'PENDING': response.status_int = 202 else: response.status_int = 201 recordset = DesignateAdapter.render('API_v2', recordset, request=request) response.headers['Location'] = recordset['links']['self'] # Prepare and return the response body return recordset
def post_all(self, zone_id): """Create RecordSet""" request = pecan.request response = pecan.response context = request.environ['context'] body = request.body_dict # Validate the request conforms to the schema self._resource_schema.validate(body) # Convert from APIv2 -> Central format values = self._view.load(context, request, body) # SOA recordsets cannot be created manually if values['type'] == 'SOA': raise exceptions.BadRequest( "Creating a SOA recordset is not allowed") # Create the recordset recordset = self.central_api.create_recordset(context, zone_id, RecordSet(**values)) # Prepare the response headers if recordset['status'] == 'PENDING': response.status_int = 202 else: response.status_int = 201 response.headers['Location'] = self._view._get_resource_href( request, recordset, [zone_id]) # Prepare and return the response body return self._view.show(context, request, recordset)
def _create_records(self, context, zone_id, dnspython_zone): """ Creates the records """ for record_name in dnspython_zone.nodes.keys(): for rdataset in dnspython_zone.nodes[record_name]: record_type = rdatatype.to_text(rdataset.rdtype) if record_type == 'SOA': continue # Create the recordset values = { 'domain_id': zone_id, 'name': record_name.to_text(), 'type': record_type, } recordset = self.central_api.create_recordset( context, zone_id, RecordSet(**values)) for rdata in rdataset: if (record_type == 'NS' and record_name == dnspython_zone.origin): # Don't create NS records for the domain, they've been # taken care of as servers pass else: # Everything else, including delegation NS, gets # created values = self._record2json(record_type, rdata) self.central_api.create_record(context, zone_id, recordset['id'], Record(**values))
def _create_reverse_record(self, context, managed, host_fqdn, interface): LOG.info('Create reverse record for interface: %s and address: %s', interface['label'], interface['address']) host_reverse_fqdn = self._get_reverse_fqdn(interface['address'], interface['version']) LOG.info('Create reverse record: %s', host_reverse_fqdn) reverse_domains = self._get_reverse_domains(host_reverse_fqdn) admin_context = DesignateContext.get_admin_context(all_tenants=True) for reverse_domain in reverse_domains: LOG.info('Create reverse record for domain: %s', reverse_domain.name) try: recordset = self.central_api.create_recordset( admin_context, reverse_domain.id, RecordSet(name=host_reverse_fqdn, type='PTR')) except exceptions.DuplicateRecordSet: LOG.warn('The reverse record: %s was already registered', host_reverse_fqdn) else: record_values = dict(managed, data=host_fqdn) LOG.debug('Creating reverse record in %s / %s with values %r', reverse_domain.id, recordset['id'], record_values) self.central_api.create_record(admin_context, reverse_domain.id, recordset['id'], Record(**record_values))
def post_all(self, zone_id): """ Create RecordSet """ request = pecan.request response = pecan.response context = request.environ['context'] body = request.body_dict # Validate the request conforms to the schema self._resource_schema.validate(body) # Convert from APIv2 -> Central format values = self._view.load(context, request, body) # Create the recordset recordset = self.central_api.create_recordset(context, zone_id, RecordSet(**values)) # Prepare the response headers response.status_int = 201 response.headers['Location'] = self._view._get_resource_href( request, recordset, [zone_id]) # Prepare and return the response body return self._view.show(context, request, recordset)
def _find_or_create_recordset(context, domain_id, name, type, ttl): try: recordset = _find_recordset(context, domain_id, name, type) except exceptions.RecordSetNotFound: values = { 'name': name, 'type': type, 'ttl': ttl, } recordset = get_central_api().create_recordset(context, domain_id, RecordSet(**values)) return recordset
def _create_record(self, context, managed, domain, host_fqdn, interface): LOG.info('Create record for host: %s and interface: %s', host_fqdn, interface['label']) recordset_type = 'AAAA' if interface['version'] == 6 else 'A' try: recordset = self.central_api.create_recordset( context, domain['id'], RecordSet(name=host_fqdn, type=recordset_type)) except exceptions.DuplicateRecordSet: LOG.warn('The record: %s was already registered', host_fqdn) else: record_values = dict(managed, data=interface['address']) LOG.debug('Creating record in %s / %s with values %r', domain['id'], recordset['id'], record_values) self.central_api.create_record(context, domain['id'], recordset['id'], Record(**record_values))
def _find_or_create_recordset(self, context, domain_id, name, type, ttl=None): try: recordset = self.central_api.find_recordset( context, { 'domain_id': domain_id, 'name': name, 'type': type, }) except exceptions.RecordSetNotFound: values = { 'name': name, 'type': type, 'ttl': ttl, } recordset = self.central_api.create_recordset( context, domain_id, RecordSet(**values)) return recordset