Skip to content

Commit a0f8859

Browse files
authored
Adds LTM DNS api (#1416)
Issues: Fixes #1415 Problem: DNS API and nameserver sub-api were not in the SDK Analysis: This adds them Tests: functional
1 parent 29d128c commit a0f8859

3 files changed

Lines changed: 116 additions & 0 deletions

File tree

f5/bigip/tm/ltm/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
from f5.bigip.tm.ltm.auth import Auth
3333
from f5.bigip.tm.ltm.data_group import Data_Group
3434
from f5.bigip.tm.ltm.default_node_monitor import Default_Node_Monitor
35+
from f5.bigip.tm.ltm.dns import Dns
3536
from f5.bigip.tm.ltm.ifile import Ifiles
3637
from f5.bigip.tm.ltm.lsn_pools import LSN_Log_Profiles
3738
from f5.bigip.tm.ltm.lsn_pools import LSN_Pools
@@ -59,6 +60,7 @@ def __init__(self, tm):
5960
Auth,
6061
Data_Group,
6162
Default_Node_Monitor,
63+
Dns,
6264
Ifiles,
6365
LSN_Log_Profiles,
6466
LSN_Pools,

f5/bigip/tm/ltm/dns.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# coding=utf-8
2+
#
3+
# Copyright 2018 F5 Networks Inc.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
18+
"""BIG-IP® LTM DNS submodule.
19+
20+
REST URI
21+
``http://localhost/mgmt/tm/ltm/dns/``
22+
23+
GUI Path
24+
``DNS --> Delivery``
25+
26+
REST Kind
27+
``tm:ltm:dns:*``
28+
"""
29+
30+
from f5.bigip.resource import Collection
31+
from f5.bigip.resource import OrganizingCollection
32+
from f5.bigip.resource import Resource
33+
34+
35+
class Dns(OrganizingCollection):
36+
def __init__(self, ltm):
37+
super(Dns, self).__init__(ltm)
38+
self._meta_data['allowed_lazy_attributes'] = [
39+
Nameservers,
40+
]
41+
42+
43+
class Nameservers(Collection):
44+
def __init__(self, dns):
45+
super(Nameservers, self).__init__(dns)
46+
self._meta_data['allowed_lazy_attributes'] = [Nameserver]
47+
self._meta_data['attribute_registry'] = {
48+
'tm:ltm:dns:nameserver:nameserverstate': Nameserver
49+
}
50+
51+
52+
class Nameserver(Resource):
53+
def __init__(self, nameservers):
54+
super(Nameserver, self).__init__(nameservers)
55+
self._meta_data['required_json_kind'] = 'tm:ltm:dns:nameserver:nameserverstate'
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Copyright 2018 F5 Networks Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
16+
import pytest
17+
18+
from distutils.version import LooseVersion
19+
from requests.exceptions import HTTPError
20+
21+
22+
@pytest.fixture(scope='function')
23+
def nameserver(mgmt_root):
24+
resource = mgmt_root.tm.ltm.dns.nameservers.nameserver.create(
25+
name='ns1',
26+
address='1.1.1.1',
27+
port=53
28+
)
29+
yield resource
30+
resource.delete()
31+
32+
33+
@pytest.mark.skipif(
34+
LooseVersion(pytest.config.getoption('--release')) < LooseVersion('12.0.0'),
35+
reason='This collection is fully implemented on 12.0.0 or greater.'
36+
)
37+
class TestAuditLogs(object):
38+
def test_update_refresh(self, nameserver):
39+
assert nameserver.kind == 'tm:ltm:dns:nameserver:nameserverstate'
40+
assert nameserver.port == 53
41+
nameserver.update(port=1234)
42+
nameserver.refresh()
43+
assert nameserver.port == 1234
44+
45+
def test_load_no_object(self, mgmt_root):
46+
with pytest.raises(HTTPError) as err:
47+
mgmt_root.tm.ltm.dns.nameservers.nameserver.load(name='not-found')
48+
assert err.value.response.status_code == 404
49+
50+
def test_load(self, nameserver, mgmt_root):
51+
r1 = mgmt_root.tm.ltm.dns.nameservers.nameserver.load(name='ns1')
52+
assert r1.kind == 'tm:ltm:dns:nameserver:nameserverstate'
53+
r2 = mgmt_root.tm.ltm.dns.nameservers.nameserver.load(name='ns1')
54+
assert r1.kind == r2.kind
55+
assert r1.selfLink == r2.selfLink
56+
57+
def test_collection(self, nameserver, mgmt_root):
58+
collection = mgmt_root.tm.ltm.dns.nameservers.get_collection()
59+
assert len(collection) == 1

0 commit comments

Comments
 (0)