Skip to content

Commit d851cca

Browse files
authored
Merge pull request #1468 from jasonrahm/issue.1439
Issue #1439 - Add sys/memory endpoint support
2 parents a99a185 + 0464f34 commit d851cca

File tree

4 files changed

+130
-0
lines changed

4 files changed

+130
-0
lines changed

f5/bigip/tm/sys/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
from f5.bigip.tm.sys.log_config import Log_Config
5252
from f5.bigip.tm.sys.management_ip import Management_Ips
5353
from f5.bigip.tm.sys.management_route import Management_Routes
54+
from f5.bigip.tm.sys.memory import Memory
5455
from f5.bigip.tm.sys.ntp import Ntp
5556
from f5.bigip.tm.sys.performance import Performances
5657
from f5.bigip.tm.sys.provision import Provision
@@ -92,6 +93,7 @@ def __init__(self, tm):
9293
Disk,
9394
Management_Ips,
9495
Management_Routes,
96+
Memory,
9597
Ntp,
9698
Performances,
9799
Provision,

f5/bigip/tm/sys/memory.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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 memory module
19+
20+
REST URI
21+
``http://localhost/mgmt/tm/sys/memory``
22+
23+
REST Kind
24+
``tm:sys:memory:memorystats:*``
25+
"""
26+
27+
from f5.bigip.resource import UnnamedResource
28+
from f5.sdk_exception import UnsupportedMethod
29+
30+
31+
class Memory(UnnamedResource):
32+
"""BIG-IP® system memory unnamed resource"""
33+
def __init__(self, sys):
34+
super(Memory, 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:memory:memorystats'
39+
40+
def update(self, **kwargs):
41+
"""Update is not supported for memory resources
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__))
46+
47+
def modify(self, **kwargs):
48+
"""Modify is not supported for memory resources
49+
50+
:raises: :exc:`~f5.BIG-IP.resource.UnsupportedMethod`
51+
"""
52+
raise UnsupportedMethod("{0} does not support the modify 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.memory import Memory
17+
18+
19+
class TestMemory(object):
20+
def test_load_refresh(self, mgmt_root):
21+
h1 = mgmt_root.tm.sys.memory.load()
22+
assert isinstance(h1, Memory)
23+
assert hasattr(h1, 'entries')
24+
assert h1.kind == 'tm:sys:memory:memorystats'
25+
assert 'https://localhost/mgmt/tm/sys/memory/memory-host' in h1.entries.keys()
26+
27+
h2 = mgmt_root.tm.sys.memory.load()
28+
29+
assert isinstance(h2, Memory)
30+
assert hasattr(h2, 'entries')
31+
assert h2.kind == 'tm:sys:memory:memorystats'
32+
assert 'https://localhost/mgmt/tm/sys/memory/memory-host' 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: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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 Memory
21+
from f5.sdk_exception import UnsupportedMethod
22+
23+
24+
@pytest.fixture
25+
def fake_info():
26+
fake_sys = mock.MagicMock()
27+
return Memory(fake_sys)
28+
29+
30+
def test_update_raises(fake_info):
31+
with pytest.raises(UnsupportedMethod) as EIO:
32+
fake_info.update()
33+
assert str(EIO.value) == "Memory does not support the update method, only load and refresh"
34+
35+
36+
def test_modify_raises(fake_info):
37+
with pytest.raises(UnsupportedMethod) as EIO:
38+
fake_info.modify()
39+
assert str(EIO.value) == "Memory does not support the modify method, only load and refresh"

0 commit comments

Comments
 (0)