Skip to content

Commit a4e9045

Browse files
committed
Issue #1456 - Add sys/hardware endpoint
Problem: sys/hardware endpoint missing Solution: This PR adds the endpoint Files Changed: - f5/bigip/tm/sys/__init__.py (changed) - f5/bigip/tm/sys/hardware.py (added) - f5/bigip/tm/sys/test/functional/test_hardware.py (added) - f5/bigip/tm/sys/test/unit/test_hardware.py (added)
1 parent df296ad commit a4e9045

4 files changed

Lines changed: 117 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
@@ -42,6 +42,7 @@
4242
from f5.bigip.tm.sys.file import File
4343
from f5.bigip.tm.sys.folder import Folders
4444
from f5.bigip.tm.sys.global_settings import Global_Settings
45+
from f5.bigip.tm.sys.hardware import Hardware
4546
from f5.bigip.tm.sys.host_info import Host_Info
4647
from f5.bigip.tm.sys.httpd import Httpd
4748
from f5.bigip.tm.sys.icall import Icall
@@ -80,6 +81,7 @@ def __init__(self, tm):
8081
File,
8182
Folders,
8283
Global_Settings,
84+
Hardware,
8385
Host_Info,
8486
Httpd,
8587
Icall,

f5/bigip/tm/sys/hardware.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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 hardware module
19+
20+
REST URI
21+
``http://localhost/mgmt/tm/sys/hardware``
22+
23+
REST Kind
24+
``tm:sys:hardware:hardwarestats:*``
25+
"""
26+
27+
from f5.bigip.resource import UnnamedResource
28+
from f5.sdk_exception import UnsupportedMethod
29+
30+
31+
class Hardware(UnnamedResource):
32+
"""BIG-IP® system host info unnamed resource"""
33+
def __init__(self, sys):
34+
super(Hardware, self).__init__(sys)
35+
self._meta_data['object_has_stats'] = False
36+
self._meta_data['required_load_parameters'] = set()
37+
self._meta_data['required_json_kind'] =\
38+
'tm:sys:hardware:hardwarestats'
39+
40+
def update(self, **kwargs):
41+
"""Update is not supported for hardware
42+
43+
:raises: :exc:`~f5.BIG-IP.resource.UnsupportedMethod`
44+
"""
45+
raise UnsupportedMethod("{0} does not support the update method, only load and refresh".format(self.__class__.__name__))
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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 f5.bigip.tm.sys.hardware import Hardware
17+
18+
19+
class TestHardware(object):
20+
def test_load_refresh(self, mgmt_root):
21+
h1 = mgmt_root.tm.sys.hardware.load()
22+
assert isinstance(h1, Hardware)
23+
assert hasattr(h1, 'entries')
24+
assert h1.kind == 'tm:sys:hardware:hardwarestats'
25+
assert 'https://localhost/mgmt/tm/sys/hardware/platform' in h1.entries.keys()
26+
27+
h2 = mgmt_root.tm.sys.hardware.load()
28+
29+
assert isinstance(h2, Hardware)
30+
assert hasattr(h2, 'entries')
31+
assert h2.kind == 'tm:sys:hardware:hardwarestats'
32+
assert 'https://localhost/mgmt/tm/sys/hardware/platform' in h2.entries.keys()
33+
34+
h1.refresh()
35+
36+
assert h1.kind == h2.kind
37+
assert h1.entries.keys() == h2.entries.keys()
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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 import Hardware
21+
from f5.sdk_exception import UnsupportedMethod
22+
23+
24+
@pytest.fixture
25+
def fake_info():
26+
fake_sys = mock.MagicMock()
27+
return Hardware(fake_sys)
28+
29+
30+
def test_create_raises(fake_info):
31+
with pytest.raises(UnsupportedMethod) as EIO:
32+
fake_info.update()
33+
assert str(EIO.value) == "Hardware does not support the update method, only load and refresh"

0 commit comments

Comments
 (0)