def setUp(self):
     super(DesignateDriverTest, self).setUp()
     self.domains = [
         Domain(name='www.example.com',
                id='11111111-1111-1111-1111-111111111111',
                email='*****@*****.**'),
         Domain(name='www.trove.com',
                id='22222222-2222-2222-2222-222222222222',
                email='*****@*****.**'),
         Domain(name='www.openstack.com',
                id='33333333-3333-3333-3333-333333333333',
                email='*****@*****.**')
     ]
     self.records = [
         Record(name='record1',
                type='A',
                data='10.0.0.1',
                ttl=3600,
                priority=1),
         Record(name='record2',
                type='CNAME',
                data='10.0.0.2',
                ttl=1800,
                priority=2),
         Record(name='record3',
                type='A',
                data='10.0.0.3',
                ttl=3600,
                priority=1)
     ]
     self.create_des_client_patch = patch.object(
         driver, 'create_designate_client', MagicMock(return_value=None))
     self.create_des_client_mock = self.create_des_client_patch.start()
     self.addCleanup(self.create_des_client_patch.stop)
 def setUp(self):
     super(DesignateDriverTest, self).setUp()
     self.domains = [
         Domain(name='www.example.com',
                id='11111111-1111-1111-1111-111111111111',
                email='*****@*****.**'),
         Domain(name='www.trove.com',
                id='22222222-2222-2222-2222-222222222222',
                email='*****@*****.**'),
         Domain(name='www.openstack.com',
                id='33333333-3333-3333-3333-333333333333',
                email='*****@*****.**')
     ]
     self.records = [
         Record(name='record1',
                type='A',
                data='10.0.0.1',
                ttl=3600,
                priority=1),
         Record(name='record2',
                type='CNAME',
                data='10.0.0.2',
                ttl=1800,
                priority=2),
         Record(name='record3',
                type='A',
                data='10.0.0.3',
                ttl=3600,
                priority=1)
     ]
    def execute(self, parsed_args):
        domain = Domain(
            name=parsed_args.name,
            email=parsed_args.email,
        )

        if parsed_args.ttl:
            domain.ttl = parsed_args.ttl

        return self.client.domains.create(domain)
    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 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)
Exemple #6
0
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 test_convert_domain_to_zone(self):
     name = 'www.example.com'
     id = '39413651-3b9e-41f1-a4df-e47d5e9f67be'
     email = '*****@*****.**'
     domain = Domain(name=name, id=id, email=email)
     converter = driver.DesignateObjectConverter()
     converted_domain = converter.domain_to_zone(domain)
     self.assertEqual(name, converted_domain.name)
     self.assertEqual(id, converted_domain.id)
Exemple #8
0
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)
Exemple #9
0
def domain_create(request, name, email, ttl=None, description=None):
    d_client = designateclient(request)
    if d_client is None:
        return None

    options = {
        'description': description,
    }

    # TTL needs to be optionally added as argument because the client
    # won't accept a None value
    if ttl is not None:
        options['ttl'] = ttl

    domain = Domain(name=name, email=email, **options)

    return d_client.domains.create(domain)
def main(argv):
    cli_utils.setup_logging()
    parser = argparse.ArgumentParser()
    parser.add_argument('-r',
                        '--resolver',
                        help='Resolver address. '
                        'Usually designate-bind address.',
                        required=False)
    parser.add_argument('-d',
                        '--domain_name',
                        help='DNS Domain Name. '
                        'Must end in a .',
                        default='mojo.serverstack.')
    parser.add_argument('-e',
                        '--email',
                        help='Email address',
                        default='*****@*****.**')
    parser.add_argument('-b',
                        '--bind-service',
                        help='Bind Service Name',
                        default='designate-bind')

    options = parser.parse_args()
    bind_service_name = cli_utils.parse_arg(options, 'bind_service')
    resolver = cli_utils.parse_arg(options, 'resolver')

    bind_unit = mojo_utils.get_juju_units(bind_service_name)[0]
    if not resolver:
        resolver = mojo_utils.get_juju_unit_ip(bind_unit)
    domain_name = cli_utils.parse_arg(options, 'domain_name')
    email = cli_utils.parse_arg(options, 'email')
    nameserver = 'ns1.{}'.format(domain_name)

    logging.info('Setting up designate {} {}'.format(nameserver, resolver))

    os_version = openstack_utils.get_current_os_versions(
        'keystone')['keystone']
    try:
        cacert = os.path.join(os.environ.get('MOJO_LOCAL_DIR'), 'cacert.pem')
        os.stat(cacert)
    except FileNotFoundError:
        cacert = None
    keystone_session = openstack_utils.get_overcloud_keystone_session(
        verify=cacert)
    neutronc = openstack_utils.get_neutron_session_client(keystone_session)

    if os_version >= 'queens':
        designatec = mojo_os_utils.get_designate_session_client(
            keystone_session, client_version='2')
        zone = mojo_os_utils.create_or_return_zone(designatec, domain_name,
                                                   email)
        mojo_os_utils.create_or_return_recordset(designatec, zone['id'], 'www',
                                                 'A', [resolver])
    else:
        designatec = mojo_os_utils.get_designate_session_client(
            keystone_session, client_version='1')
        if not mojo_os_utils.get_designate_server_id(designatec, nameserver):
            logging.info('Creating server {}'.format(nameserver))
            server = Server(name=nameserver)
            server_id = designatec.servers.create(server)
            assert (server_id is not None)
        else:
            logging.info('{} server already exists.'.format(nameserver))

        domain_id = mojo_os_utils.get_designate_domain_id(
            designatec, domain_name)
        if not domain_id:
            logging.info('Creating domain {}'.format(domain_name))
            domain = Domain(name=domain_name, email=email)
            domain_id = designatec.domains.create(domain)
            assert (domain_id is not None)
        else:
            logging.info('{} domain already exists.'.format(domain_name))

        if not mojo_os_utils.get_designate_record_id(designatec, domain_id,
                                                     nameserver):
            logging.info('Creating NS record {}'.format(nameserver))
            ns_record = Record(name=nameserver, type="A", data=resolver)
            record_id = designatec.records.create(domain_id, ns_record)
            assert (record_id is not None)
        else:
            logging.info('{} record already exists.'.format(nameserver))

    logging.info('Update network to use domain {}'.format(domain_name))
    net_uuid = openstack_utils.get_net_uuid(neutronc, 'private')
    mojo_os_utils.update_network_dns(neutronc, net_uuid, domain_name)
def main(argv):
    mojo_utils.setup_logging()
    parser = argparse.ArgumentParser()
    parser.add_argument('-r', '--resolver',
                        help='Resolver address. '
                             'Usually designate-bind address.',
                        required=False)
    parser.add_argument('-d', '--domain_name', help='DNS Domain Name. '
                                                    'Must end in a .',
                        default='mojo.serverstack.')
    parser.add_argument('-e', '--email', help='Email address',
                        default='*****@*****.**')
    parser.add_argument('-b', '--bind-service', help='Bind Service Name',
                        default='designate-bind')

    options = parser.parse_args()
    bind_service_name = mojo_utils.parse_mojo_arg(options, 'bind_service')
    resolver = mojo_utils.parse_mojo_arg(options, 'resolver')
    bind_unit = mojo_utils.get_juju_units(service=bind_service_name)[0]
    if not resolver:
        resolver = mojo_utils.get_juju_unit_ip(bind_unit)
    domain_name = mojo_utils.parse_mojo_arg(options, 'domain_name')
    email = mojo_utils.parse_mojo_arg(options, 'email')
    nameserver = 'ns1.{}'.format(domain_name)

    logging.info('Setting up designate {} {}'.format(nameserver, resolver))

    overcloud_novarc = mojo_utils.get_overcloud_auth()
    os_version = mojo_os_utils.get_current_os_versions('keystone')['keystone']
    # Keystone policy.json shipped the charm with liberty requires a domain
    # scoped token. Bug #1649106
    if os_version == 'liberty':
        scope = 'DOMAIN'
    else:
        scope = 'PROJECT'
    keystone_session = mojo_os_utils.get_keystone_session(overcloud_novarc,
                                                          scope=scope)
    neutronc = mojo_os_utils.get_neutron_session_client(keystone_session)

    if os_version >= 'queens':
        designatec = mojo_os_utils.get_designate_session_client(
            keystone_session,
            client_version='2')
        zone = mojo_os_utils.create_or_return_zone(
            designatec,
            domain_name,
            email)
        rs = mojo_os_utils.create_or_return_recordset(
            designatec,
            zone['id'],
            'www',
            'A',
            [resolver])
    else:
        designatec = mojo_os_utils.get_designate_session_client(
            keystone_session,
            client_version='1')
        if not mojo_os_utils.get_designate_server_id(designatec, nameserver):
            logging.info('Creating server {}'.format(nameserver))
            server = Server(name=nameserver)
            server_id = designatec.servers.create(server)
            assert(server_id is not None)
        else:
            logging.info('{} server already exists.'.format(nameserver))

        domain_id = mojo_os_utils.get_designate_domain_id(
            designatec,
            domain_name)
        if not domain_id:
            logging.info('Creating domain {}'.format(domain_name))
            domain = Domain(name=domain_name, email=email)
            domain_id = designatec.domains.create(domain)
            assert(domain_id is not None)
        else:
            logging.info('{} domain already exists.'.format(domain_name))

        if not mojo_os_utils.get_designate_record_id(designatec, domain_id,
                                                     nameserver):
            logging.info('Creating NS record {}'.format(nameserver))
            ns_record = Record(
                name=nameserver,
                type="A",
                data=resolver)
            record_id = designatec.records.create(domain_id, ns_record)
            assert(record_id is not None)
        else:
            logging.info('{} record already exists.'.format(nameserver))

    logging.info('Update network to use domain {}'.format(domain_name))
    net_uuid = mojo_os_utils.get_net_uuid(neutronc, 'private')
    mojo_os_utils.update_network_dns(neutronc, net_uuid, domain_name)