Example #1
0
    def execute(self, parsed_args):
        domain_id = self.find_resourceid_by_name_or_id('domains',
                                                       parsed_args.domain_id)

        if not parsed_args.name.endswith('.'):
            # Relative name?
            domain_name = self.client.domains.get(domain_id)['name']
            absolute = parsed_args.name + '.'
            relative = absolute + domain_name
            if absolute.endswith('.' + domain_name):
                # Relative name or absolute name missing final period?
                msg = ('"%s" is a relative name but looks like an absolute '
                       'name, use --name "%s" or "%s"' %
                       (parsed_args.name, absolute, relative))
                raise ValueError(msg)
            parsed_args.name = relative

        record = Record(
            name=parsed_args.name,
            type=parsed_args.type,
            data=parsed_args.data,
        )

        if parsed_args.ttl is not None:
            record.ttl = parsed_args.ttl

        if parsed_args.priority:
            record.priority = parsed_args.priority

        if parsed_args.description:
            record.description = parsed_args.description

        return self.client.records.create(domain_id, record)
    def execute(self, parsed_args):
        domain_id = self.find_resourceid_by_name_or_id(
            'domains', parsed_args.domain_id)

        if not parsed_args.name.endswith('.'):
            # Relative name?
            domain_name = self.client.domains.get(domain_id)['name']
            absolute = parsed_args.name + '.'
            relative = absolute + domain_name
            if absolute.endswith('.' + domain_name):
                # Relative name or absolute name missing final period?
                msg = ('"%s" is a relative name but looks like an absolute '
                       'name, use --name "%s" or "%s"'
                       % (parsed_args.name, absolute, relative))
                raise ValueError(msg)
            parsed_args.name = relative

        record = Record(
            name=parsed_args.name,
            type=parsed_args.type,
            data=parsed_args.data,
        )

        if parsed_args.ttl is not None:
            record.ttl = parsed_args.ttl

        if parsed_args.priority is not None:
            record.priority = parsed_args.priority

        if parsed_args.description:
            record.description = parsed_args.description

        return self.client.records.create(domain_id, record)
Example #3
0
def record(request, domain_id='', record_id=''):
  client = Client(
    auth_url="http://keystone:5000/v2.0/",
    username="******",
    password="******",
    tenant_name="service",
    endpoint="http://designate:9001/v1"
  )
  if request.method == "GET":
    print(domain_id)
    print(record_id)
    if record_id:
      try:
        return HttpResponse(change_response(client.records.get(domain_id, record_id)))
      except:
        return HttpResponse("Not found", status=404)
    else:
      return HttpResponse(change_response(client.records.list(domain_id)))
  elif request.method == "POST":
    if 'priority' not in request.POST:
      defined_priority = None
    else:
      defined_priority = int(request.POST['priority'])
    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']
    record = Record(name=request.POST['name'], type=request.POST['type'], data=request.POST['data'], priority=defined_priority, ttl=defined_ttl, description=defined_description)
    return HttpResponse(change_response(client.records.create(domain_id, record)))
  elif request.method == "PUT":
    params = QueryDict(request.body, encoding=request._encoding)
    record = client.records.get(domain_id, record_id)    
    if 'name' in params:
      record.name = params['name']
    if 'type' in params:
      record.type = params['type']
    if 'data' in params:
      record.data = params['data']
    if 'priority' in params:
      record.priority = int(params['priority'])
    if 'ttl' in params:
      record.ttl = int(params['ttl'])
    if 'description' in params:
      domain.description = params['description']
    return HttpResponse(change_response(client.records.update(domain_id, record)))
  elif request.method == "DELETE":
    client.records.delete(domain_id, record_id)
    return HttpResponse("OK", status=200)
    def execute(self, parsed_args):
        record = Record(
            name=parsed_args.name,
            type=parsed_args.type,
            data=parsed_args.data,
        )

        if parsed_args.ttl:
            record.ttl = parsed_args.ttl

        if parsed_args.priority:
            record.priority = parsed_args.priority

        return self.client.records.create(parsed_args.domain_id, record)
    def execute(self, parsed_args):
        record = Record(
            name=parsed_args.name,
            type=parsed_args.type,
            data=parsed_args.data,
        )

        if parsed_args.ttl:
            record.ttl = parsed_args.ttl

        if parsed_args.priority:
            record.priority = parsed_args.priority

        if parsed_args.description:
            record.description = parsed_args.description

        return self.client.records.create(parsed_args.domain_id, record)
Example #6
0
def record_update(request, domain_id, record_id, **kwargs):
    d_client = designateclient(request)
    if d_client is None:
        return []

    # 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.
    record = Record(id=record_id, type='A', name='', data='')

    record.type = kwargs.get('type', None)
    record.name = kwargs.get('name', None)
    record.data = kwargs.get('data', None)
    record.priority = kwargs.get('priority', None)
    record.ttl = kwargs.get('ttl', None)
    record.description = kwargs.get('description', None)

    return d_client.records.update(domain_id, record)
Example #7
0
def record_update(request, domain_id, record_id, **kwargs):
    d_client = designateclient(request)
    if d_client is None:
        return []

    # 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.
    record = Record(
        id=record_id,
        type='A',
        name='',
        data='')

    record.type = kwargs.get('type', None)
    record.name = kwargs.get('name', None)
    record.data = kwargs.get('data', None)
    record.priority = kwargs.get('priority', None)
    record.ttl = kwargs.get('ttl', None)
    record.description = kwargs.get('description', None)

    return d_client.records.update(domain_id, record)