def post_all(self): """Create ZoneTransferAccept""" request = pecan.request response = pecan.response context = request.environ['context'] body = request.body_dict zone_transfer_accept = DesignateAdapter.parse( 'API_v2', body, ZoneTransferAccept()) zone_transfer_accept.validate() # Create the zone_transfer_request zone_transfer_accept = self.central_api.create_zone_transfer_accept( context, zone_transfer_accept) response.status_int = 201 LOG.info(_LI("Created %(zone_transfer_accept)s"), {'zone_transfer_accept': zone_transfer_accept}) zone_transfer_accept = DesignateAdapter.render( 'API_v2', zone_transfer_accept, request=request) response.headers['Location'] = zone_transfer_accept['links']['self'] # Prepare and return the response body return zone_transfer_accept
def patch_one(self, fip_key): """ Set or unset a PTR """ request = pecan.request response = pecan.response context = request.environ['context'] try: body = request.body_dict except Exception as e: if e.message != 'TODO: Unsupported Content Type': raise else: # Got a blank body body = dict() region, id_ = fip_key_to_data(fip_key) fip = DesignateAdapter.parse('API_v2', body, objects.FloatingIP()) fip.validate() LOG.info(_LI("Updated %(fip)s"), {'fip': fip}) fip = self.central_api.update_floatingip(context, region, id_, fip) response.status_int = 202 if fip: return DesignateAdapter.render('API_v2', fip, request=request)
def post_all(self, zone_id): """Create ZoneTransferRequest""" request = pecan.request response = pecan.response context = request.environ['context'] try: body = request.body_dict except exceptions.EmptyRequestBody: body = dict() body['zone_id'] = zone_id zone_transfer_request = DesignateAdapter.parse('API_v2', body, ZoneTransferRequest()) zone_transfer_request.validate() # Create the zone_transfer_request zone_transfer_request = self.central_api.create_zone_transfer_request( context, zone_transfer_request) response.status_int = 201 zone_transfer_request = DesignateAdapter.render('API_v2', zone_transfer_request, request=request, context=context) response.headers['Location'] = zone_transfer_request['links']['self'] # Prepare and return the response body return zone_transfer_request
def patch_one(self, tsigkey_id): """Update TsigKey""" request = pecan.request context = request.environ['context'] body = request.body_dict response = pecan.response if request.content_type == 'application/json-patch+json': raise NotImplemented('json-patch not implemented') # Fetch the existing tsigkey entry tsigkey = self.central_api.get_tsigkey(context, tsigkey_id) tsigkey = DesignateAdapter.parse('API_v2', body, tsigkey) # Validate the new set of data tsigkey.validate() # Update and persist the resource tsigkey = self.central_api.update_tsigkey(context, tsigkey) LOG.info("Updated %(tsigkey)s", {'tsigkey': tsigkey}) response.status_int = 200 return DesignateAdapter.render('API_v2', tsigkey, request=request)
def patch_one(self, pool_id): """Update the specific pool""" LOG.warning(_LW("Use of this API Method is DEPRICATED. This will have " "unforseen side affects when used with the " "designate-manage pool commands")) request = pecan.request context = request.environ['context'] body = request.body_dict response = pecan.response if request.content_type == 'application/json-patch+json': raise NotImplemented('json-patch not implemented') # Fetch the existing pool pool = self.central_api.get_pool(context, pool_id) pool = DesignateAdapter.parse('API_v2', body, pool) pool.validate() pool = self.central_api.update_pool(context, pool) LOG.info(_LI("Updated %(pool)s"), {'pool': pool}) response.status_int = 202 return DesignateAdapter.render('API_v2', pool, request=request)
def post_all(self): """Create ZoneTransferAccept""" request = pecan.request response = pecan.response context = request.environ['context'] body = request.body_dict zone_transfer_accept = DesignateAdapter.parse( 'API_v2', body, ZoneTransferAccept()) zone_transfer_accept.validate() # Create the zone_transfer_request zone_transfer_accept = self.central_api.create_zone_transfer_accept( context, zone_transfer_accept) response.status_int = 201 LOG.info(_LI("Created %(zone_transfer_accept)s"), {'zone_transfer_accept': zone_transfer_accept}) zone_transfer_accept = DesignateAdapter.render( 'API_v2', zone_transfer_accept, request=request) response.headers['Location'] = zone_transfer_accept['links']['self'] # Prepare and return the response body return zone_transfer_accept
def patch_one(self, zone_transfer_request_id): """Update ZoneTransferRequest""" request = pecan.request context = request.environ['context'] body = request.body_dict response = pecan.response if request.content_type == 'application/json-patch+json': raise NotImplemented('json-patch not implemented') # Fetch the existing zone_transfer_request zone_transfer_request = self.central_api.get_zone_transfer_request( context, zone_transfer_request_id) zone_transfer_request = DesignateAdapter.parse( 'API_v2', body, zone_transfer_request) zone_transfer_request.validate() zone_transfer_request = self.central_api.update_zone_transfer_request( context, zone_transfer_request) response.status_int = 200 return DesignateAdapter.render( 'API_v2', zone_transfer_request, request=request, context=context)
def get_all(self, **params): """List RBAC rules that comply with either object or project ids for a Tenant""" request = pecan.request context = request.environ['context'] object_id = None project_id = None try: body = request.body_dict rbac_obj = DesignateAdapter.parse('API_v2', body, RBACBaseObject()) object_id = rbac_obj.object_id project_id = rbac_obj.project_id except Exception as e: if str(e) != 'TODO: Unsupported Content Type': raise else: # Got a blank body body = dict() rules = self.central_api.list_rbac_rules(object_id=object_id, project_id=project_id) LOG.info("Retrieved %(rbacrules)s", {'rbacrules': rules}) return DesignateAdapter.render('API_v2', rules, request=request)
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): request = pecan.request response = pecan.response context = request.environ['context'] body = request.body_dict rbac_obj = DesignateAdapter.parse('API_v2', body, RBACBaseObject()) rbac_obj.validate() # Create the blacklist rbac_obj = self.central_api.create_rbacrule( context, rbac_obj) LOG.info("Created %(rbac)s", {'rbac': rbac_obj}) response.status_int = 201 rbac_obj = DesignateAdapter.render( 'API_v2', rbac_obj, request=request) #response.headers['Location'] = rbac_obj['links']['self'] # Prepare and return the response body return rbac
def post_all(self): """Create Blacklisted Zone""" request = pecan.request response = pecan.response context = request.environ['context'] body = request.body_dict blacklist = DesignateAdapter.parse('API_v2', body, Blacklist()) blacklist.validate() # Create the blacklist blacklist = self.central_api.create_blacklist( context, blacklist) LOG.info("Created %(blacklist)s", {'blacklist': blacklist}) response.status_int = 201 blacklist = DesignateAdapter.render( 'API_v2', blacklist, request=request) response.headers['Location'] = blacklist['links']['self'] # Prepare and return the response body return blacklist
def post_all(self): """Create a Pool""" LOG.warning( _LW("Use of this API Method is DEPRECATED. This will have " "unforeseen side affects when used with the " "designate-manage pool commands")) request = pecan.request response = pecan.response context = request.environ['context'] body = request.body_dict pool = DesignateAdapter.parse('API_v2', body, Pool()) pool.validate() # Create the pool pool = self.central_api.create_pool(context, pool) LOG.info(_LI("Created %(pool)s"), {'pool': pool}) pool = DesignateAdapter.render('API_v2', pool, request=request) response.status_int = 201 response.headers['Location'] = pool['links']['self'] # Prepare and return the response body return pool
def post_all(self, zone_id): """Create ZoneTransferRequest""" request = pecan.request response = pecan.response context = request.environ['context'] try: body = request.body_dict except exceptions.EmptyRequestBody: body = dict() zone = self.central_api.get_zone(context, zone_id) body['zone_name'] = zone.name body['zone_id'] = zone_id zone_transfer_request = DesignateAdapter.parse( 'API_v2', body, ZoneTransferRequest()) zone_transfer_request.validate() # Create the zone_transfer_request zone_transfer_request = self.central_api.create_zone_transfer_request( context, zone_transfer_request) response.status_int = 201 LOG.info("Created %(zone_transfer_request)s", {'zone_transfer_request': zone_transfer_request}) zone_transfer_request = DesignateAdapter.render( 'API_v2', zone_transfer_request, request=request, context=context) response.headers['Location'] = zone_transfer_request['links']['self'] # Prepare and return the response body return zone_transfer_request
def patch_one(self, pool_id): """Update the specific pool""" LOG.warning(_LW("Use of this API Method is DEPRICATED. This will have " "unforseen side affects when used with the " "designate-manage pool commands")) request = pecan.request context = request.environ['context'] body = request.body_dict response = pecan.response if request.content_type == 'application/json-patch+json': raise NotImplemented('json-patch not implemented') # Fetch the existing pool pool = self.central_api.get_pool(context, pool_id) pool = DesignateAdapter.parse('API_v2', body, pool) pool.validate() pool = self.central_api.update_pool(context, pool) response.status_int = 202 return DesignateAdapter.render('API_v2', pool, request=request)
def patch_one(self, tsigkey_id): """Update TsigKey""" request = pecan.request context = request.environ['context'] body = request.body_dict response = pecan.response if request.content_type == 'application/json-patch+json': raise NotImplemented('json-patch not implemented') # Fetch the existing tsigkey entry tsigkey = self.central_api.get_tsigkey(context, tsigkey_id) tsigkey = DesignateAdapter.parse('API_v2', body, tsigkey) # Validate the new set of data tsigkey.validate() # Update and persist the resource tsigkey = self.central_api.update_tsigkey(context, tsigkey) LOG.info("Updated %(tsigkey)s", {'tsigkey': tsigkey}) response.status_int = 200 return DesignateAdapter.render('API_v2', tsigkey, request=request)
def test_parse_rrset_object_preserves_changes_multiple_rrs(self): old_ips = ['1.1.1.1', '2.2.2.2'] new_ips = ['2.2.2.2', '8.8.8.8'] original_records = objects.RecordList( objects=[ objects.Record(data=ip) for ip in old_ips ] ) rs = objects.RecordSet( name='www.example.org.', type='A', records=original_records ) body = { 'records': new_ips } rs = DesignateAdapter.parse('API_v2', body, rs) self.assertIn('records', rs.obj_what_changed()) def get_data(record_list): return set([r.data for r in record_list]) self.assertEqual(set(old_ips), get_data(rs.obj_get_original_value('records'))) self.assertEqual(set(new_ips), get_data(rs.obj_get_changes()['records']))
def test_parse_rrset_object_preserves_changes(self): old_ip = '1.1.1.1' new_ip = '8.8.8.8' original_records = objects.RecordList(objects=[ objects.Record(data=old_ip), ]) record_set = objects.RecordSet(name='www.example.org.', type='A', records=original_records) body = {'records': [new_ip]} record_set = DesignateAdapter.parse('API_v2', body, record_set) self.assertIn('records', record_set.obj_what_changed()) def get_data(record_list): return set([r.data for r in record_list]) self.assertEqual({old_ip}, get_data( record_set.obj_get_original_value('records'))) self.assertEqual({new_ip}, get_data(record_set.obj_get_changes()['records']))
def post_all(self): """Create Blacklisted Zone""" request = pecan.request response = pecan.response context = request.environ['context'] body = request.body_dict blacklist = DesignateAdapter.parse('API_v2', body, Blacklist()) blacklist.validate() # Create the blacklist blacklist = self.central_api.create_blacklist( context, blacklist) LOG.info("Created %(blacklist)s", {'blacklist': blacklist}) response.status_int = 201 blacklist = DesignateAdapter.render( 'API_v2', blacklist, request=request) response.headers['Location'] = blacklist['links']['self'] # Prepare and return the response body return blacklist
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 patch_one(self, fip_key): """ Set or unset a PTR """ request = pecan.request response = pecan.response context = request.environ['context'] try: body = request.body_dict except Exception as e: if e.message != 'TODO: Unsupported Content Type': raise else: # Got a blank body body = dict() region, id_ = fip_key_to_data(fip_key) fip = DesignateAdapter.parse('API_v2', body, objects.FloatingIP()) fip.validate() fip = self.central_api.update_floatingip(context, region, id_, fip) response.status_int = 202 if fip: return DesignateAdapter.render('API_v2', fip, request=request)
def post_all(self): """Create a Pool""" LOG.warning(_LW("Use of this API Method is DEPRICATED. This will have " "unforseen side affects when used with the " "designate-manage pool commands")) request = pecan.request response = pecan.response context = request.environ['context'] body = request.body_dict pool = DesignateAdapter.parse('API_v2', body, Pool()) pool.validate() # Create the pool pool = self.central_api.create_pool(context, pool) LOG.info(_LI("Created %(pool)s"), {'pool': pool}) pool = DesignateAdapter.render('API_v2', pool, request=request) response.status_int = 201 response.headers['Location'] = pool['links']['self'] # Prepare and return the response body return pool
def post_all(self, zone_id): """Create ZoneTransferRequest""" request = pecan.request response = pecan.response context = request.environ['context'] try: body = request.body_dict except Exception as e: if six.text_type(e) != 'TODO: Unsupported Content Type': raise else: # Got a blank body body = dict() body['zone_id'] = zone_id zone_transfer_request = DesignateAdapter.parse( 'API_v2', body, ZoneTransferRequest()) zone_transfer_request.validate() # Create the zone_transfer_request zone_transfer_request = self.central_api.create_zone_transfer_request( context, zone_transfer_request) response.status_int = 201 zone_transfer_request = DesignateAdapter.render( 'API_v2', zone_transfer_request, request=request, context=context) response.headers['Location'] = zone_transfer_request['links']['self'] # Prepare and return the response body return zone_transfer_request
def patch_one(self, zone_id): """Update Zone""" # TODO(kiall): This needs cleanup to say the least.. request = pecan.request context = request.environ['context'] body = request.body_dict response = pecan.response # TODO(kiall): Validate we have a sane UUID for zone_id # Fetch the existing zone zone = self.central_api.get_zone(context, zone_id) # Don't allow updates to zones that are being deleted if zone.action == "DELETE": raise exceptions.BadRequest('Can not update a deleting zone') if request.content_type == 'application/json-patch+json': # Possible pattern: # # 1) Load existing zone. # 2) Apply patch, maintain list of changes. # 3) Return changes, after passing through the code ^ for plain # JSON. # # Difficulties: # # 1) "Nested" resources? records inside a recordset. # 2) What to do when a zone doesn't exist in the first place? # 3) ...? raise NotImplemented('json-patch not implemented') else: # Update the zone object with the new values zone = DesignateAdapter.parse('API_v2', body, zone) zone.validate() # If masters are specified then we set zone.transferred_at to None # which will cause a new transfer if 'attributes' in zone.obj_what_changed(): zone.transferred_at = None # Update and persist the resource if zone.type == 'SECONDARY' and 'email' in zone.obj_what_changed(): msg = "Changed email is not allowed." raise exceptions.InvalidObject(msg) increment_serial = zone.type == 'PRIMARY' zone = self.central_api.update_zone( context, zone, increment_serial=increment_serial) LOG.info(_LI("Updated %(zone)s"), {'zone': zone}) if zone.status == 'PENDING': response.status_int = 202 else: response.status_int = 200 return DesignateAdapter.render('API_v2', zone, request=request)
def patch_one(self, tenant_id): """Modify a Quota""" request = pecan.request context = request.environ['context'] body = request.body_dict quotas = DesignateAdapter.parse('API_v2', body, QuotaList()) for quota in quotas: self.central_api.set_quota(context, tenant_id, quota.resource, quota.hard_limit) quotas = self.central_api.get_quotas(context, tenant_id) quotas = QuotaList.from_dict(quotas) return DesignateAdapter.render('API_v2', quotas)
def post_all(self): """Create Zone""" request = pecan.request response = pecan.response context = request.environ['context'] zone = request.body_dict # We need to check the zone type before validating the schema since if # it's the type is SECONDARY we need to set the email to the mgmt email if isinstance(zone, dict): if 'type' not in zone: zone['type'] = 'PRIMARY' if zone['type'] == 'SECONDARY': mgmt_email = CONF['service:central'].managed_resource_email zone['email'] = mgmt_email zone = DesignateAdapter.parse('API_v2', zone, objects.Domain()) zone.validate() # # TODO(ekarlso): Fix this once setter or so works. # masters = values.pop('masters', []) # zone = objects.Domain.from_dict(values) # zone.set_masters(masters) # Create the zone zone = self.central_api.create_domain(context, zone) # Prepare the response headers # If the zone has been created asynchronously if zone['status'] == 'PENDING': response.status_int = 202 else: response.status_int = 201 # Prepare and return the response body zone = DesignateAdapter.render('API_v2', zone, request=request) response.headers['Location'] = zone['links']['self'] return zone
def post_all(self): """Create Zone""" request = pecan.request response = pecan.response context = request.environ['context'] zone = request.body_dict # We need to check the zone type before validating the schema since if # it's the type is SECONDARY we need to set the email to the mgmt email if isinstance(zone, dict): if 'type' not in zone: zone['type'] = 'PRIMARY' if zone['type'] == 'SECONDARY': mgmt_email = CONF['service:central'].managed_resource_email zone['email'] = mgmt_email zone = DesignateAdapter.parse('API_v2', zone, objects.Domain()) zone.validate() # # TODO(ekarlso): Fix this once setter or so works. # masters = values.pop('masters', []) # zone = objects.Domain.from_dict(values) # zone.set_masters(masters) # Create the zone zone = self.central_api.create_domain(context, zone) # Prepare the response headers # If the zone has been created asynchronously if zone['status'] == 'PENDING': response.status_int = 202 else: response.status_int = 201 # Prepare and return the response body zone = DesignateAdapter.render('API_v2', zone, request=request) response.headers['Location'] = zone['links']['self'] return zone
def put_one(self, zone_id, recordset_id): """Update RecordSet""" request = pecan.request context = request.environ['context'] body = request.body_dict response = pecan.response # Fetch the existing recordset recordset = self.central_api.get_recordset(context, zone_id, recordset_id) # TODO(graham): Move this further down the stack if recordset.managed and not context.edit_managed_records: raise exceptions.BadRequest('Managed records may not be updated') # SOA recordsets cannot be updated manually if recordset['type'] == 'SOA': raise exceptions.BadRequest( 'Updating SOA recordsets is not allowed') # NS recordsets at the zone root cannot be manually updated if recordset['type'] == 'NS': zone = self.central_api.get_zone(context, zone_id) if recordset['name'] == zone['name']: raise exceptions.BadRequest( 'Updating a root zone NS record is not allowed') # Convert to APIv2 Format recordset = DesignateAdapter.parse('API_v2', body, recordset) recordset.validate() # Persist the resource recordset = self.central_api.update_recordset(context, recordset) LOG.info(_LI("Updated %(recordset)s"), {'recordset': recordset}) if recordset['status'] == 'PENDING': response.status_int = 202 else: response.status_int = 200 return DesignateAdapter.render('API_v2', recordset, request=request)
def post_all(self): """Create a Pool""" request = pecan.request response = pecan.response context = request.environ['context'] body = request.body_dict pool = DesignateAdapter.parse('API_v2', body, Pool()) pool.validate() # Create the pool pool = self.central_api.create_pool(context, pool) pool = DesignateAdapter.render('API_v2', pool, request=request) response.status_int = 201 response.headers['Location'] = pool['links']['self'] # Prepare and return the response body return pool
def post_all(self): """Create a Pool""" request = pecan.request response = pecan.response context = request.environ['context'] body = request.body_dict pool = DesignateAdapter.parse('API_v2', body, Pool()) pool.validate() # Create the pool pool = self.central_api.create_pool(context, pool) pool = DesignateAdapter.render('API_v2', pool, request=request) response.status_int = 201 response.headers['Location'] = pool['links']['self'] # Prepare and return the response body return pool
def put_one(self, zone_id, recordset_id): """Update RecordSet""" request = pecan.request context = request.environ['context'] body = request.body_dict response = pecan.response # Fetch the existing recordset recordset = self.central_api.get_recordset(context, zone_id, recordset_id) # TODO(graham): Move this further down the stack if recordset.managed and not context.edit_managed_records: raise exceptions.BadRequest('Managed records may not be updated') # SOA recordsets cannot be updated manually if recordset['type'] == 'SOA': raise exceptions.BadRequest( 'Updating SOA recordsets is not allowed') # NS recordsets at the zone root cannot be manually updated if recordset['type'] == 'NS': zone = self.central_api.get_domain(context, zone_id) if recordset['name'] == zone['name']: raise exceptions.BadRequest( 'Updating a root zone NS record is not allowed') # Convert to APIv2 Format recordset = DesignateAdapter.parse('API_v2', body, recordset) recordset.validate() # Persist the resource recordset = self.central_api.update_recordset(context, recordset) if recordset['status'] == 'PENDING': response.status_int = 202 else: response.status_int = 200 return DesignateAdapter.render('API_v2', recordset, request=request)
def post_all(self): """Create Tld""" request = pecan.request response = pecan.response context = request.environ['context'] body = request.body_dict tld = DesignateAdapter.parse('API_v2', body, Tld()) tld.validate() # Create the tld tld = self.central_api.create_tld(context, tld) response.status_int = 201 tld = DesignateAdapter.render('API_v2', tld, request=request) response.headers['Location'] = tld['links']['self'] # Prepare and return the response body return tld
def post_all(self): """Create TsigKey""" request = pecan.request response = pecan.response context = request.environ['context'] body = request.body_dict tsigkey = DesignateAdapter.parse('API_v2', body, TsigKey()) tsigkey.validate() # Create the tsigkey tsigkey = self.central_api.create_tsigkey(context, tsigkey) tsigkey = DesignateAdapter.render('API_v2', tsigkey, request=request) response.headers['Location'] = tsigkey['links']['self'] response.status_int = 201 # Prepare and return the response body return tsigkey
def post_all(self): """Create Tld""" request = pecan.request response = pecan.response context = request.environ['context'] body = request.body_dict tld = DesignateAdapter.parse('API_v2', body, Tld()) tld.validate() # Create the tld tld = self.central_api.create_tld(context, tld) response.status_int = 201 tld = DesignateAdapter.render('API_v2', tld, request=request) response.headers['Location'] = tld['links']['self'] # Prepare and return the response body return tld
def patch_one(self, tld_id): """Update Tld""" request = pecan.request context = request.environ['context'] body = request.body_dict response = pecan.response if request.content_type == 'application/json-patch+json': raise NotImplemented('json-patch not implemented') # Fetch the existing tld tld = self.central_api.get_tld(context, tld_id) tld = DesignateAdapter.parse('API_v2', body, tld) tld.validate() tld = self.central_api.update_tld(context, tld) response.status_int = 200 return DesignateAdapter.render('API_v2', tld, request=request)
def post_all(self): """Create TsigKey""" request = pecan.request response = pecan.response context = request.environ['context'] body = request.body_dict tsigkey = DesignateAdapter.parse('API_v2', body, TsigKey()) tsigkey.validate() # Create the tsigkey tsigkey = self.central_api.create_tsigkey( context, tsigkey) tsigkey = DesignateAdapter.render('API_v2', tsigkey, request=request) response.headers['Location'] = tsigkey['links']['self'] response.status_int = 201 # Prepare and return the response body return tsigkey
def patch_one(self, tld_id): """Update Tld""" request = pecan.request context = request.environ['context'] body = request.body_dict response = pecan.response if request.content_type == 'application/json-patch+json': raise NotImplemented('json-patch not implemented') # Fetch the existing tld tld = self.central_api.get_tld(context, tld_id) tld = DesignateAdapter.parse('API_v2', body, tld) tld.validate() tld = self.central_api.update_tld(context, tld) response.status_int = 200 return DesignateAdapter.render('API_v2', tld, request=request)
def patch_one(self, pool_id): """Update the specific pool""" request = pecan.request context = request.environ['context'] body = request.body_dict response = pecan.response if request.content_type == 'application/json-patch+json': raise NotImplemented('json-patch not implemented') # Fetch the existing pool pool = self.central_api.get_pool(context, pool_id) pool = DesignateAdapter.parse('API_v2', body, pool) pool.validate() pool = self.central_api.update_pool(context, pool) response.status_int = 202 return DesignateAdapter.render('API_v2', pool, request=request)
def patch_one(self, blacklist_id): """Update Blacklisted Zone""" request = pecan.request context = request.environ['context'] body = request.body_dict response = pecan.response if request.content_type == 'application/json-patch+json': raise NotImplemented('json-patch not implemented') # Fetch the existing blacklist entry blacklist = self.central_api.get_blacklist(context, blacklist_id) blacklist = DesignateAdapter.parse('API_v2', body, blacklist) blacklist.validate() blacklist = self.central_api.update_blacklist(context, blacklist) response.status_int = 200 return DesignateAdapter.render('API_v2', blacklist, request=request)
def patch_one(self, pool_id): """Update the specific pool""" request = pecan.request context = request.environ['context'] body = request.body_dict response = pecan.response if request.content_type == 'application/json-patch+json': raise NotImplemented('json-patch not implemented') # Fetch the existing pool pool = self.central_api.get_pool(context, pool_id) pool = DesignateAdapter.parse('API_v2', body, pool) pool.validate() pool = self.central_api.update_pool(context, pool) response.status_int = 200 return DesignateAdapter.render('API_v2', pool, request=request)
def patch_one(self, blacklist_id): """Update Blacklisted Zone""" request = pecan.request context = request.environ['context'] body = request.body_dict response = pecan.response if request.content_type == 'application/json-patch+json': raise NotImplemented('json-patch not implemented') # Fetch the existing blacklist entry blacklist = self.central_api.get_blacklist(context, blacklist_id) blacklist = DesignateAdapter.parse('API_v2', body, blacklist) blacklist.validate() blacklist = self.central_api.update_blacklist(context, blacklist) response.status_int = 200 return DesignateAdapter.render('API_v2', blacklist, request=request)
def post_all(self): """Create Zone""" request = pecan.request response = pecan.response context = request.environ['context'] zone = request.body_dict if isinstance(zone, dict): if 'type' not in zone: zone['type'] = 'PRIMARY' zone = DesignateAdapter.parse('API_v2', zone, objects.Zone()) zone.validate() if zone.type == 'SECONDARY': mgmt_email = CONF['service:central'].managed_resource_email zone['email'] = mgmt_email # Create the zone zone = self.central_api.create_zone(context, zone) LOG.info(_LI("Created %(zone)s"), {'zone': zone}) # Prepare the response headers # If the zone has been created asynchronously if zone['status'] == 'PENDING': response.status_int = 202 else: response.status_int = 201 # Prepare and return the response body zone = DesignateAdapter.render('API_v2', zone, request=request) response.headers['Location'] = zone['links']['self'] return zone
def put_one(self, zone_id, recordset_id): """Update RecordSet""" request = pecan.request context = request.environ['context'] body = request.body_dict response = pecan.response # Fetch the existing recordset recordset = self.central_api.get_recordset(context, zone_id, recordset_id) # SOA recordsets cannot be updated manually if recordset['type'] == 'SOA': raise exceptions.BadRequest( 'Updating SOA recordsets is not allowed') # NS recordsets at the zone root cannot be manually updated if recordset['type'] == 'NS': zone = self.central_api.get_domain(context, zone_id) if recordset['name'] == zone['name']: raise exceptions.BadRequest( 'Updating a root zone NS record is not allowed') # Convert to APIv2 Format recordset = DesignateAdapter.parse('API_v2', body, recordset) recordset.validate() # Persist the resource recordset = self.central_api.update_recordset(context, recordset) if recordset['status'] == 'PENDING': response.status_int = 202 else: response.status_int = 200 return DesignateAdapter.render('API_v2', recordset, request=request)
def test_parse_rrset_object_preserves_changes_multiple_rrs(self): old_ips = ['1.1.1.1', '2.2.2.2'] new_ips = ['2.2.2.2', '8.8.8.8'] original_records = objects.RecordList( objects=[objects.Record(data=ip) for ip in old_ips]) rs = objects.RecordSet(name='www.example.org.', type='A', records=original_records) body = {'records': new_ips} rs = DesignateAdapter.parse('API_v2', body, rs) self.assertIn('records', rs.obj_what_changed()) def get_data(record_list): return set([r.data for r in record_list]) self.assertEqual(set(old_ips), get_data(rs.obj_get_original_value('records'))) self.assertEqual(set(new_ips), get_data(rs.obj_get_changes()['records']))
def patch_one(self, rbac_id): """Update RBAC rule""" request = pecan.request context = request.environ['context'] body = request.body_dict response = pecan.response if request.content_type == 'application/json-patch+json': raise NotImplemented('json-patch not implemented') # Fetch the existing rbac entry rbac = self.central_api.get_rbacrule(context, rbac_id) rbac = DesignateAdapter.parse('API_v2', body, rbac) rbac.validate() rbac = self.central_api.update_rbacrule(context, rbac) LOG.info("Updated %(rbac)s", {'rbac': rbac}) response.status_int = 200 return DesignateAdapter.render('API_v2', rbac, request=request)
def patch_one(self, tenant_id): """Modify a Quota""" request = pecan.request context = request.environ['context'] body = request.body_dict # NOTE(pas-ha) attempting to verify the validity of the project-id # on a best effort basis # this will raise only if KeystoneV3 endpoint is not found at all, # or the creds are passing but the project is not found if cfg.CONF['service:api'].quotas_verify_project_id: keystone.verify_project_id(context, tenant_id) quotas = DesignateAdapter.parse('API_v2', body, QuotaList()) for quota in quotas: self.central_api.set_quota(context, tenant_id, quota.resource, quota.hard_limit) quotas = self.central_api.get_quotas(context, tenant_id) quotas = QuotaList.from_dict(quotas) return DesignateAdapter.render('API_v2', quotas)
def update(self, file, delete, dry_run): print('Updating Pools Configuration') print('****************************') output_msg = [''] with open(file, 'r') as stream: xpools = yaml.safe_load(stream) if dry_run: output_msg.append("The following changes will occur:") output_msg.append("*********************************") for xpool in xpools: try: if 'id' in xpool: try: pool = self.central_api.get_pool( self.context, xpool['id']) except Exception: LOG.critical( _LC("Bad ID Supplied for pool %s"), xpool['name']) continue else: pool = self.central_api.find_pool( self.context, {"name": xpool['name']}) LOG.info(_LI('Updating existing pool: %s'), pool) # TODO(kiall): Move the below into the pool object pool = DesignateAdapter.parse('YAML', xpool, pool) if dry_run: output_msg.append("Update Pool: %s" % pool) else: pool = self.central_api.update_pool(self.context, pool) except exceptions.PoolNotFound: pool = DesignateAdapter.parse('YAML', xpool, objects.Pool()) # pool = objects.Pool.from_dict(xpool) if dry_run: output_msg.append("Create Pool: %s" % pool) else: LOG.info(_LI('Creating new pool: %s'), pool) self.central_api.create_pool(self.context, pool) except messaging.exceptions.MessagingTimeout: LOG.critical(_LC("No response received from designate-central." " Check it is running, and retry")) if delete: pools = self.central_api.find_pools(self.context) pools_in_db = {pool.name for pool in pools} pools_in_yaml = {xpool['name'] for xpool in xpools} pools_to_delete = pools_in_db - pools_in_yaml for pool in pools_to_delete: try: p = self.central_api.find_pool( self.context, criterion={'name': pool}) if dry_run: output_msg.append("Delete Pool: %s" % p) else: LOG.info(_LI('Deleting %s'), p) self.central_api.delete_pool(self.context, p.id) except messaging.exceptions.MessagingTimeout: LOG.critical(_LC("No response received from " "designate-central. " "Check it is running, and retry")) for line in output_msg: print(line)
def update(self, file, delete, dry_run): self._startup() print('Updating Pools Configuration') print('****************************') output_msg = [''] with open(file, 'r') as stream: xpools = yaml.safe_load(stream) if dry_run: output_msg.append("The following changes will occur:") output_msg.append("*********************************") for xpool in xpools: try: if 'id' in xpool: try: pool = self.central_api.get_pool( self.context, xpool['id']) except Exception: LOG.critical("Bad ID Supplied for pool %s", xpool['name']) continue else: pool = self.central_api.find_pool( self.context, {"name": xpool['name']}) LOG.info('Updating existing pool: %s', pool) # TODO(kiall): Move the below into the pool object pool = DesignateAdapter.parse('YAML', xpool, pool) # TODO(graham): We should be doing a full validation, but right # now there is quirks validating through nested objects. for ns_record in pool.ns_records: try: ns_record.validate() except exceptions.InvalidObject as e: LOG.error(e.errors.to_list()[0]['message']) sys.exit(1) if dry_run: output_msg.append("Update Pool: %s" % pool) else: pool = self.central_api.update_pool(self.context, pool) except exceptions.PoolNotFound: pool = DesignateAdapter.parse('YAML', xpool, objects.Pool()) for ns_record in pool.ns_records: try: ns_record.validate() except exceptions.InvalidObject as e: LOG.error(e.errors.to_list()[0]['message']) sys.exit(1) if dry_run: output_msg.append("Create Pool: %s" % pool) else: LOG.info('Creating new pool: %s', pool) self.central_api.create_pool(self.context, pool) except messaging.exceptions.MessagingTimeout: LOG.critical("No response received from designate-central. " "Check it is running, and retry") sys.exit(1) if delete: pools = self.central_api.find_pools(self.context) pools_in_db = {pool.name for pool in pools} pools_in_yaml = {xpool['name'] for xpool in xpools} pools_to_delete = pools_in_db - pools_in_yaml for pool in pools_to_delete: try: p = self.central_api.find_pool( self.context, criterion={'name': pool}) if dry_run: output_msg.append("Delete Pool: %s" % p) else: LOG.info('Deleting %s', p) self.central_api.delete_pool(self.context, p.id) except messaging.exceptions.MessagingTimeout: LOG.critical( "No response received from designate-central. " "Check it is running, and retry") sys.exit(1) for line in output_msg: print(line)
def update(self, file, delete, dry_run): print('Updating Pools Configuration') print('****************************') output_msg = [''] with open(file, 'r') as stream: xpools = yaml.safe_load(stream) if dry_run: output_msg.append("The following changes will occur:") output_msg.append("*********************************") for xpool in xpools: try: if 'id' in xpool: try: pool = self.central_api.get_pool( self.context, xpool['id']) except Exception: LOG.critical(_LC("Bad ID Supplied for pool %s"), xpool['name']) continue else: pool = self.central_api.find_pool(self.context, {"name": xpool['name']}) LOG.info(_LI('Updating existing pool: %s'), pool) # TODO(kiall): Move the below into the pool object pool = DesignateAdapter.parse('YAML', xpool, pool) if dry_run: output_msg.append("Update Pool: %s" % pool) else: pool = self.central_api.update_pool(self.context, pool) except exceptions.PoolNotFound: pool = DesignateAdapter.parse('YAML', xpool, objects.Pool()) # pool = objects.Pool.from_dict(xpool) if dry_run: output_msg.append("Create Pool: %s" % pool) else: LOG.info(_LI('Creating new pool: %s'), pool) self.central_api.create_pool(self.context, pool) except messaging.exceptions.MessagingTimeout: LOG.critical( _LC("No response recieved from designate-central." " Check it is running, and retry")) if delete: pools = self.central_api.find_pools(self.context) pools_in_db = {pool.name for pool in pools} pools_in_yaml = {xpool['name'] for xpool in xpools} pools_to_delete = pools_in_db - pools_in_yaml for pool in pools_to_delete: try: p = self.central_api.find_pool(self.context, criterion={'name': pool}) if dry_run: output_msg.append("Delete Pool: %s" % p) else: LOG.info(_LI('Deleting %s'), p) self.central_api.delete_pool(self.context, p.id) except messaging.exceptions.MessagingTimeout: LOG.critical( _LC("No response recieved from " "designate-central. " "Check it is running, and retry")) for line in output_msg: print(line)
def update(self, file, delete, dry_run): self._startup() print('Updating Pools Configuration') print('****************************') output_msg = [''] with open(file, 'r') as stream: xpools = yaml.safe_load(stream) if dry_run: output_msg.append("The following changes will occur:") output_msg.append("*********************************") for xpool in xpools: try: if 'id' in xpool: try: pool = self.central_api.get_pool( self.context, xpool['id']) except Exception: LOG.critical("Bad ID Supplied for pool %s", xpool['name']) continue else: pool = self.central_api.find_pool(self.context, {"name": xpool['name']}) LOG.info('Updating existing pool: %s', pool) # TODO(kiall): Move the below into the pool object pool = DesignateAdapter.parse('YAML', xpool, pool) # TODO(graham): We should be doing a full validation, but right # now there is quirks validating through nested objects. for ns_record in pool.ns_records: try: ns_record.validate() except exceptions.InvalidObject as e: LOG.error(e.errors.to_list()[0]['message']) sys.exit(1) if dry_run: output_msg.append("Update Pool: %s" % pool) else: pool = self.central_api.update_pool(self.context, pool) except exceptions.PoolNotFound: pool = DesignateAdapter.parse('YAML', xpool, objects.Pool()) for ns_record in pool.ns_records: try: ns_record.validate() except exceptions.InvalidObject as e: LOG.error(e.errors.to_list()[0]['message']) sys.exit(1) if dry_run: output_msg.append("Create Pool: %s" % pool) else: LOG.info('Creating new pool: %s', pool) self.central_api.create_pool(self.context, pool) except messaging.exceptions.MessagingTimeout: LOG.critical("No response received from designate-central. " "Check it is running, and retry") sys.exit(1) if delete: pools = self.central_api.find_pools(self.context) pools_in_db = {pool.name for pool in pools} pools_in_yaml = {xpool['name'] for xpool in xpools} pools_to_delete = pools_in_db - pools_in_yaml for pool in pools_to_delete: try: p = self.central_api.find_pool(self.context, criterion={'name': pool}) if dry_run: output_msg.append("Delete Pool: %s" % p) else: LOG.info('Deleting %s', p) self.central_api.delete_pool(self.context, p.id) except messaging.exceptions.MessagingTimeout: LOG.critical( "No response received from designate-central. " "Check it is running, and retry") sys.exit(1) for line in output_msg: print(line)