Skip to content

Commit 260a307

Browse files
authored
Merge pull request #615 from caphrim007/feature.add-snmp-support
Adds snmp endpoints
2 parents bc12ca7 + 6c5bbcf commit 260a307

4 files changed

Lines changed: 765 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
@@ -40,6 +40,7 @@
4040
from f5.bigip.tm.sys.httpd import Httpd
4141
from f5.bigip.tm.sys.ntp import Ntp
4242
from f5.bigip.tm.sys.performance import Performances
43+
from f5.bigip.tm.sys.snmp import Snmp
4344
from f5.bigip.tm.sys.software import Software
4445
from f5.bigip.tm.sys.sshd import Sshd
4546
from f5.bigip.tm.sys.ucs import Ucs
@@ -60,6 +61,7 @@ def __init__(self, tm):
6061
Ntp,
6162
Failover,
6263
Dns,
64+
Snmp,
6365
Sshd,
6466
Httpd,
6567
Software,

f5/bigip/tm/sys/snmp.py

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
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® SNMP submodule.
19+
20+
REST URI
21+
``http://localhost/mgmt/tm/sys/snmp/``
22+
23+
GUI Path
24+
``System --> SNMP``
25+
26+
REST Kind
27+
``tm:snmp:*``
28+
"""
29+
30+
from f5.bigip.resource import Collection
31+
from f5.bigip.resource import Resource
32+
from f5.bigip.resource import UnnamedResource
33+
34+
35+
class Snmp(UnnamedResource):
36+
def __init__(self, sys):
37+
super(Snmp, self).__init__(sys)
38+
self._meta_data['required_load_parameters'] = set()
39+
self._meta_data['required_json_kind'] = 'tm:sys:snmp:snmpstate'
40+
self._meta_data['allowed_lazy_attributes'] = [
41+
Communities_s,
42+
Traps_s,
43+
Users_s
44+
]
45+
self._meta_data['attribute_registry'] = {
46+
'tm:sys:snmp:communities:communitiescollectionstate':
47+
Communities_s,
48+
'tm:sys:snmp:traps:trapscollectionstate': Traps_s,
49+
'tm:sys:snmp:users:userscollectionstate': Users_s
50+
}
51+
52+
53+
class Communities_s(Collection):
54+
"""BIG-IP® SNMP Communities collection."""
55+
def __init__(self, snmp):
56+
super(Communities_s, self).__init__(snmp)
57+
self._meta_data['required_json_kind'] = \
58+
'tm:sys:snmp:communities:communitiescollectionstate'
59+
self._meta_data['allowed_lazy_attributes'] = [Community]
60+
self._meta_data['attribute_registry'] = \
61+
{'tm:sys:snmp:communities:communitiesstate': Community}
62+
63+
64+
class Community(Resource):
65+
"""BIG-IP® SNMP Community resource."""
66+
def __init__(self, communities_s):
67+
super(Community, self).__init__(communities_s)
68+
self._meta_data['required_json_kind'] = \
69+
'tm:sys:snmp:communities:communitiesstate'
70+
self._meta_data['required_creation_parameters']\
71+
.update(('communityName',))
72+
73+
74+
class Traps_s(Collection):
75+
"""BIG-IP® SNMP Traps collection."""
76+
def __init__(self, snmp):
77+
super(Traps_s, self).__init__(snmp)
78+
self._meta_data['required_json_kind'] = \
79+
'tm:sys:snmp:traps:trapscollectionstate'
80+
self._meta_data['allowed_lazy_attributes'] = [Trap]
81+
self._meta_data['attribute_registry'] = \
82+
{'tm:sys:snmp:traps:trapsstate': Trap}
83+
84+
85+
class Trap(Resource):
86+
"""BIG-IP® SNMP Trap resource."""
87+
def __init__(self, traps_s):
88+
super(Trap, self).__init__(traps_s)
89+
self._meta_data['required_json_kind'] = \
90+
'tm:sys:snmp:traps:trapsstate'
91+
92+
93+
class Users_s(Collection):
94+
"""BIG-IP® SNMP Users collection."""
95+
def __init__(self, snmp):
96+
super(Users_s, self).__init__(snmp)
97+
self._meta_data['required_json_kind'] = \
98+
'tm:sys:snmp:users:userscollectionstate'
99+
self._meta_data['allowed_lazy_attributes'] = [User]
100+
self._meta_data['attribute_registry'] = \
101+
{'tm:sys:snmp:users:usersstate': User}
102+
103+
104+
class User(Resource):
105+
"""BIG-IP® SNMP User resource."""
106+
def __init__(self, users_s):
107+
super(User, self).__init__(users_s)
108+
self._meta_data['required_json_kind'] = \
109+
'tm:sys:snmp:users:usersstate'
110+
self._meta_data['required_creation_parameters'] \
111+
.update(('authProtocol',))

f5/bigip/tm/sys/test/test_snmp.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Copyright 2016 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.mixins import UnsupportedMethod
20+
from f5.bigip.tm.sys.snmp import Snmp
21+
22+
23+
@pytest.fixture
24+
def FakeSnmp():
25+
fake_sys = mock.MagicMock()
26+
return Snmp(fake_sys)
27+
28+
29+
def test_create_raises(FakeSnmp):
30+
with pytest.raises(UnsupportedMethod) as EIO:
31+
FakeSnmp.create()
32+
assert EIO.value.message == "Snmp does not support the create method"
33+
34+
35+
def test_delete_raises(FakeSnmp):
36+
with pytest.raises(UnsupportedMethod) as EIO:
37+
FakeSnmp.delete()
38+
assert EIO.value.message == "Snmp does not support the delete method"

0 commit comments

Comments
 (0)