Skip to content

Commit 7675810

Browse files
NikitaFedoraevcaphrim007
authored andcommitted
Add support for tm sys cluster. (#1408)
* Add support for tm sys cluster. * Cganged style issue for sys cluster and test. * Changed import order to alphabetical.
1 parent 0184ddb commit 7675810

4 files changed

Lines changed: 134 additions & 0 deletions

File tree

f5/bigip/tm/sys/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
from f5.bigip.resource import OrganizingCollection
3131
from f5.bigip.tm.sys.application import Application
3232
from f5.bigip.tm.sys.clock import Clock
33+
from f5.bigip.tm.sys.cluster import Cluster
3334
from f5.bigip.tm.sys.config import Config
3435
from f5.bigip.tm.sys.crypto import Crypto
3536
from f5.bigip.tm.sys.daemon_log_settings import Daemon_Log_Settings
@@ -66,6 +67,7 @@ def __init__(self, tm):
6667
self._meta_data['allowed_lazy_attributes'] = [
6768
Application,
6869
Clock,
70+
Cluster,
6971
Config,
7072
Crypto,
7173
Daemon_Log_Settings,

f5/bigip/tm/sys/cluster.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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® system cluster module
19+
20+
REST URI
21+
``https://localhost/mgmt/tm/sys/cluster``
22+
23+
GUI Path
24+
``System --> Clusters``
25+
26+
REST Kind
27+
``tm:sys:cluster:*``
28+
"""
29+
30+
from f5.bigip.resource import OrganizingCollection
31+
from f5.bigip.resource import UnnamedResource
32+
33+
34+
class Cluster(OrganizingCollection):
35+
"""BIG-IP® license unnamed resource"""
36+
def __init__(self, sys):
37+
super(Cluster, self).__init__(sys)
38+
self._meta_data['required_json_kind'] =\
39+
"tm:sys:cluster:clustercollectionstate"
40+
self._meta_data['allowed_lazy_attributes'] = [Default]
41+
42+
43+
class Default(UnnamedResource):
44+
"""BIG-IP® Analytics settings resource"""
45+
def __init__(self, settings):
46+
super(Default, self).__init__(settings)
47+
self._meta_data['required_json_kind'] = \
48+
'tm:sys:cluster:clusterstate'
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
from icontrol.exceptions import iControlUnexpectedHTTPError
17+
18+
19+
def test_cluster_load(request, mgmt_root):
20+
# Load will produce exception on non-cluster BIGIP.l
21+
# iControlUnexpectedHTTPError: 404 Unexpected Error: Not Found for uri:
22+
try:
23+
assert str(mgmt_root.tm.sys.cluster.default.load().kind) == 'tm:sys:cluster:clusterstate'
24+
except iControlUnexpectedHTTPError as err:
25+
assert('01020036:3: The requested cluster (default) was not found.' in err.message)
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+
17+
import mock
18+
import pytest
19+
20+
from f5.bigip.tm.sys.cluster import Cluster
21+
from f5.bigip.tm.sys.cluster import Default
22+
from f5.sdk_exception import InvalidResource
23+
from f5.sdk_exception import UnsupportedMethod
24+
25+
26+
@pytest.fixture
27+
def FakeCluster():
28+
fake_sys = mock.MagicMock()
29+
return Cluster(fake_sys)
30+
31+
32+
@pytest.fixture
33+
def FakeClusterDefault():
34+
fake_sys = mock.MagicMock()
35+
return Default(fake_sys)
36+
37+
38+
def test_create_raises(FakeCluster):
39+
with pytest.raises(InvalidResource) as EIO:
40+
FakeCluster.create()
41+
assert str(EIO.value) == "Only Resources support 'create'."
42+
43+
44+
def test_delete_raises(FakeCluster):
45+
with pytest.raises(InvalidResource) as EIO:
46+
FakeCluster.delete()
47+
assert str(EIO.value) == "Only Resources support 'delete'."
48+
49+
50+
def test_default_create_raises(FakeClusterDefault):
51+
with pytest.raises(UnsupportedMethod) as EIO:
52+
FakeClusterDefault.create()
53+
assert str(EIO.value) == "Default does not support the create method"
54+
55+
56+
def test_default_delete_raises(FakeClusterDefault):
57+
with pytest.raises(UnsupportedMethod) as EIO:
58+
FakeClusterDefault.delete()
59+
assert str(EIO.value) == "Default does not support the delete method"

0 commit comments

Comments
 (0)