def execute(self, parsed_args): domain = Domain( name=parsed_args.name, email=parsed_args.email, ) if parsed_args.description: domain.description = parsed_args.description if parsed_args.ttl is not None: domain.ttl = parsed_args.ttl return self.client.domains.create(domain)
def domain_update(request, domain_id, email, ttl, description=None): d_client = designateclient(request) if d_client is None: return None # A quirk of the designate client is that you need to start with a # base record and then update individual fields in order to persist # the data. The designate client will only send the 'changed' fields. domain = Domain(id=domain_id, name='', email='') domain.email = email domain.ttl = ttl domain.description = description return d_client.domains.update(domain)
def domain(request, domain_id=''): client = Client( auth_url="http://keystone:5000/v2.0/", username="******", password="******", tenant_name="service", endpoint="http://designate:9001/v1" ) if request.method == "GET": if domain_id: try: return HttpResponse(change_response(client.domains.get(domain_id))) except: return HttpResponse("Not found", status=404) else: return HttpResponse(change_response(client.domains.list())) elif request.method == "POST": if 'ttl' not in request.POST: defined_ttl = 3600 else: defined_ttl = int(request.POST['ttl']) if 'description' not in request.POST: defined_description = None else: defined_description = request.POST['description'] domain = Domain(name=request.POST['name'], email=request.POST['email'], ttl=defined_ttl, description=defined_description) return HttpResponse(change_response(client.domains.create(domain))) elif request.method == "PUT": params = QueryDict(request.body, encoding=request._encoding) domain = client.domains.get(domain_id) if 'name' in params: domain.name = params['name'] if 'email' in params: domain.email = params['email'] if 'ttl' in params: domain.ttl = int(params['ttl']) if 'description' in params: domain.description = params['description'] return HttpResponse(change_response(client.domains.update(domain))) elif request.method == "DELETE": client.domains.delete(domain_id) return HttpResponse("OK", status=200)