def create_dns_record(request):
"""
Create a new record under a specific zone
---
"""
auth_context = auth_context_from_request(request)
cloud_id = request.matchdict['cloud']
# Try to get the specific cloud for which we will create the zone.
try:
cloud = Cloud.objects.get(owner=auth_context.owner, id=cloud_id)
except me.DoesNotExist:
raise CloudNotFoundError
zone_id = request.matchdict['zone']
try:
zone = Zone.objects.get(owner=auth_context.owner, id=zone_id)
except Zone.DoesNotExist:
raise NotFoundError('Zone does not exist')
auth_context.check_perm("cloud", "read", cloud_id)
auth_context.check_perm("zone", "read", zone_id)
auth_context.check_perm("zone", "create_records", zone_id)
tags = auth_context.check_perm("record", "add", None)
# Get the params and create the new record
params = params_from_request(request)
dns_cls = RECORDS[params['type']]
rec = dns_cls.add(owner=auth_context.owner, zone=zone, **params).as_dict()
if tags:
resolve_id_and_set_tags(auth_context.owner, 'record', rec['id'], tags,
cloud_id=cloud_id, zone_id=zone_id)
# Schedule a UI update
trigger_session_update(auth_context.owner, ['zones'])
return rec
评论列表
文章目录