Skip to content

Commit 35f7ac0

Browse files
committed
Fixes #634
Problem: GTM server endpoint was missing from the SDK. This is a first of a series of PRs meant to introduce the GTM pools to the SDK Analysis: Server endpoint was added as it was a dependency for GTM pools Tests: Flake8 Functional Tests Unit Tests Files Added/Changed: f5-common-python/f5/bigip/tm/gtm/init.py f5-common-python/f5/bigip/tm/gtm/server.py f5-common-python/f5/bigip/tm/gtm/test/test.server.py f5-common-python/test/functional/tm/gtm/test_server.py
1 parent e437243 commit 35f7ac0

4 files changed

Lines changed: 506 additions & 1 deletion

File tree

f5/bigip/tm/gtm/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
from f5.bigip.resource import OrganizingCollection
3232
from f5.bigip.tm.gtm.datacenter import Datacenters
3333
from f5.bigip.tm.gtm.rule import Rules
34+
from f5.bigip.tm.gtm.server import Servers
3435

3536

3637
class Gtm(OrganizingCollection):
@@ -39,5 +40,6 @@ def __init__(self, tm):
3940
super(Gtm, self).__init__(tm)
4041
self._meta_data['allowed_lazy_attributes'] = [
4142
Datacenters,
42-
Rules
43+
Rules,
44+
Servers,
4345
]

f5/bigip/tm/gtm/server.py

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# coding=utf-8
2+
#
3+
# Copyright 2014-2016 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® Global Traffic Manager™ (GTM®) pool module.
19+
20+
REST URI
21+
``http://localhost/mgmt/tm/gtm/server``
22+
23+
GUI Path
24+
``DNS --> GSLB : Servers``
25+
26+
REST Kind
27+
``tm:gtm:server:*``
28+
"""
29+
30+
from f5.bigip.resource import Collection
31+
from f5.bigip.resource import Resource
32+
33+
34+
class Servers(Collection):
35+
"""BIG-IP® GTM server collection"""
36+
def __init__(self, gtm):
37+
super(Servers, self).__init__(gtm)
38+
self._meta_data['allowed_lazy_attributes'] = [Server]
39+
self._meta_data['attribute_registry'] = \
40+
{'tm:gtm:server:serverstate': Server}
41+
42+
43+
class Server(Resource):
44+
"""BIG-IP® GTM server resource"""
45+
def __init__(self, servers):
46+
super(Server, self).__init__(servers)
47+
self._meta_data['required_json_kind'] = 'tm:gtm:server:serverstate'
48+
self._meta_data['required_creation_parameters'].update(
49+
('datacenter', 'addresses'))
50+
self._meta_data['attribute_registry'] = {
51+
'tm:gtm:server:virtual-servers:virtual-serverscollectionstate':
52+
Virtual_Servers_s
53+
}
54+
55+
56+
class Virtual_Servers_s(Collection):
57+
"""BIG-IP® GTM virtual server sub-collection"""
58+
def __init__(self, server):
59+
super(Virtual_Servers_s, self).__init__(server)
60+
self._meta_data['allowed_lazy_attributes'] = [Virtual_Servers]
61+
self._meta_data['required_json_kind'] = \
62+
'tm:gtm:server:virtual-servers:virtual-serverscollectionstate'
63+
self._meta_data['attribute_registry'] = {
64+
'tm:gtm:server:virtual-servers:virtual-serversstate':
65+
Virtual_Servers}
66+
67+
68+
class Virtual_Servers(Resource):
69+
"""BIG-IP® GTM virtual server resource"""
70+
def __init__(self, virtual_servers_s):
71+
super(Virtual_Servers, self).__init__(virtual_servers_s)
72+
self._meta_data['required_creation_parameters'].update((
73+
'destination',))
74+
self._meta_data['required_json_kind'] = \
75+
'tm:gtm:server:virtual-servers:virtual-serversstate'
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Copyright 2015 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 mock
17+
import pytest
18+
19+
from f5.bigip import ManagementRoot
20+
from f5.bigip.resource import MissingRequiredCreationParameter
21+
from f5.bigip.tm.gtm.server import Server
22+
from f5.bigip.tm.gtm.server import Virtual_Servers
23+
24+
25+
@pytest.fixture
26+
def FakeServer():
27+
fake_servers = mock.MagicMock()
28+
fake_server = Server(fake_servers)
29+
return fake_server
30+
31+
32+
@pytest.fixture
33+
def FakeVS():
34+
fake_server = mock.MagicMock()
35+
fake_vs = Virtual_Servers(fake_server)
36+
return fake_vs
37+
38+
39+
class TestCreate(object):
40+
def test_create_two(self, fakeicontrolsession):
41+
b = ManagementRoot('192.168.1.1', 'admin', 'admin')
42+
s1 = b.tm.gtm.servers.server
43+
s2 = b.tm.gtm.servers.server
44+
assert s1 is not s2
45+
46+
def test_create_no_args(self, FakeServer):
47+
with pytest.raises(MissingRequiredCreationParameter):
48+
FakeServer.create()
49+
50+
def test_create_no_datacenter(self, FakeServer):
51+
with pytest.raises(MissingRequiredCreationParameter):
52+
FakeServer.create(name='fakeserver',
53+
addresses=[{'name': '1.1.1.1'}])
54+
55+
def test_create_no_address(self, FakeServer):
56+
with pytest.raises(MissingRequiredCreationParameter):
57+
FakeServer.create(name='fakeserver', datacenter='fakedc')
58+
59+
60+
class Test_VS_Subcoll(object):
61+
def test_vs_attr_exists(self, fakeicontrolsession):
62+
b = ManagementRoot('192.168.1.1', 'admin', 'admin')
63+
s = b.tm.gtm.servers.server
64+
test_meta = s._meta_data['attribute_registry']
65+
kind = 'tm:gtm:server:virtual-servers:virtual-serverscollectionstate'
66+
assert kind in test_meta.keys()
67+
68+
def test_create_no_args(self, FakeVS):
69+
with pytest.raises(MissingRequiredCreationParameter):
70+
FakeVS.create()

0 commit comments

Comments
 (0)