Merge "Add the /v2/zones/<id>/nameservers endpoint back" into stable/kilo

This commit is contained in:
Jenkins 2015-04-24 08:00:47 +00:00 committed by Gerrit Code Review
commit 2eb8a9a667
4 changed files with 98 additions and 0 deletions

View File

@ -21,6 +21,7 @@ from designate import utils
from designate.api.v2.controllers import rest from designate.api.v2.controllers import rest
from designate.api.v2.controllers import recordsets from designate.api.v2.controllers import recordsets
from designate.api.v2.controllers.zones import tasks from designate.api.v2.controllers.zones import tasks
from designate.api.v2.controllers.zones import nameservers
from designate import objects from designate import objects
from designate.objects.adapters import DesignateAdapter from designate.objects.adapters import DesignateAdapter
@ -35,6 +36,7 @@ class ZonesController(rest.RestController):
recordsets = recordsets.RecordSetsController() recordsets = recordsets.RecordSetsController()
tasks = tasks.TasksController() tasks = tasks.TasksController()
nameservers = nameservers.NameServersController()
@pecan.expose(template='json:', content_type='application/json') @pecan.expose(template='json:', content_type='application/json')
@utils.validate_uuid('zone_id') @utils.validate_uuid('zone_id')

View File

@ -0,0 +1,41 @@
# Copyright 2013 Hewlett-Packard Development Company, L.P.
#
# Author: Kiall Mac Innes <kiall@hp.com>
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import pecan
from oslo.config import cfg
from designate.api.v2.controllers import rest
from designate.objects.adapters import DesignateAdapter
CONF = cfg.CONF
class NameServersController(rest.RestController):
@pecan.expose(template='json:', content_type='application/json')
def get_all(self, zone_id):
"""List NameServers for Zone"""
request = pecan.request
context = request.environ['context']
# This is a work around to overcome the fact that pool ns_records list
# object have 2 different representations in the v2 API
return {
"nameservers": DesignateAdapter.render(
'API_v2',
self.central_api.get_domain_servers(context, zone_id),
request=request)}

View File

@ -523,3 +523,17 @@ class ApiV2ZonesTest(ApiV2TestCase):
self.client.delete('/zones/%s' % zone['id'], status=202) self.client.delete('/zones/%s' % zone['id'], status=202)
self._assert_exception('bad_request', 400, self.client.patch_json, self._assert_exception('bad_request', 400, self.client.patch_json,
'/zones/%s' % zone['id'], body) '/zones/%s' % zone['id'], body)
def test_get_nameservers(self):
# Create a zone
zone = self.create_domain()
# Prepare an update body
response = self.client.get('/zones/%s/nameservers' % zone['id'],
headers=[('Accept', 'application/json')])
self.assertIn('nameservers', response.json)
self.assertEqual(1, len(response.json['nameservers']))
self.assertIn('hostname', response.json['nameservers'][0])
self.assertIn('priority', response.json['nameservers'][0])

View File

@ -131,6 +131,47 @@ Get Zone
:statuscode 200: Success :statuscode 200: Success
:statuscode 401: Access Denied :statuscode 401: Access Denied
Get Zone Name Servers
---------------------
.. http:get:: /zones/(uuid:id)/nameservers
Retrieves the nameservers for a zone with zone_id of id
**Example request:**
.. sourcecode:: http
GET /v2/zones/a86dba58-0043-4cc6-a1bb-69d5e86f3ca3/nameservers HTTP/1.1
Host: 127.0.0.1:9001
Accept: application/json
Content-Type: application/json
**Example response:**
.. sourcecode:: http
HTTP/1.1 200 OK
Vary: Accept
Content-Type: application/json
{
"nameservers": [
{
"hostname": "ns1.example.com.",
"priority": 1
},
{
"hostname": "ns2.example.com.",
"priority": 2
}
]
}
:statuscode 200: Success
:statuscode 401: Access Denied
List Zones List Zones
---------- ----------