Skip to content

Commit c6df0cd

Browse files
f5-rahmcaphrim007
authored andcommitted
Issue #783 - Adding sys/sflow endpoints (#1296)
* Issue #783 - Adding sys/sflow endpoints Files Added - sys/sflow.py - sys/test/functional/test_sflow.py - sys/test/unit/test_sflow.py Files Changed - sys/__init__.py * Issue #783 - python 3.x compatibility fix in unit test
1 parent 3f2439c commit c6df0cd

4 files changed

Lines changed: 389 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
@@ -45,6 +45,7 @@
4545
from f5.bigip.tm.sys.ntp import Ntp
4646
from f5.bigip.tm.sys.performance import Performances
4747
from f5.bigip.tm.sys.provision import Provision
48+
from f5.bigip.tm.sys.sflow import Sflow
4849
from f5.bigip.tm.sys.snmp import Snmp
4950
from f5.bigip.tm.sys.software import Software
5051
from f5.bigip.tm.sys.sshd import Sshd
@@ -73,6 +74,7 @@ def __init__(self, tm):
7374
Ntp,
7475
Performances,
7576
Provision,
77+
Sflow,
7678
Snmp,
7779
Software,
7880
Sshd,

f5/bigip/tm/sys/sflow.py

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
# coding=utf-8
2+
#
3+
# Copyright 2017 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+
"""BIG-IP® system sflow module
18+
19+
REST URI
20+
``http://localhost/mgmt/tm/sys/sflow``
21+
22+
GUI Path
23+
``System->sFlow``
24+
25+
REST Kind
26+
``tm:sys:sflow:*``
27+
"""
28+
29+
# from distutils.version import LooseVersion
30+
from f5.bigip.resource import Collection
31+
from f5.bigip.resource import OrganizingCollection
32+
from f5.bigip.resource import Resource
33+
from f5.bigip.resource import UnnamedResource
34+
# from f5.sdk_exception import UnsupportedMethod
35+
36+
37+
class Sflow(OrganizingCollection):
38+
def __init__(self, sys):
39+
super(Sflow, self).__init__(sys)
40+
self._meta_data['allowed_lazy_attributes'] = [
41+
Global_Settings,
42+
Receivers]
43+
44+
45+
class Global_Settings(OrganizingCollection):
46+
def __init__(self, sflow):
47+
super(Global_Settings, self).__init__(sflow)
48+
self._meta_data['allowed_lazy_attributes'] = [
49+
Http,
50+
Interface,
51+
System,
52+
Vlan]
53+
54+
55+
class Http(UnnamedResource):
56+
def __init__(self, global_settings):
57+
super(Http, self).__init__(global_settings)
58+
self._meta_data['required_load_parameters'] = set()
59+
self._meta_data['required_json_kind'] =\
60+
'tm:sys:sflow:global-settings:http:httpstate'
61+
62+
63+
class Interface(UnnamedResource):
64+
def __init__(self, global_settings):
65+
super(Interface, self).__init__(global_settings)
66+
self._meta_data['required_load_parameters'] = set()
67+
self._meta_data['required_json_kind'] =\
68+
'tm:sys:sflow:global-settings:interface:interfacestate'
69+
70+
71+
class System(UnnamedResource):
72+
def __init__(self, global_settings):
73+
super(System, self).__init__(global_settings)
74+
self._meta_data['required_load_parameters'] = set()
75+
self._meta_data['required_json_kind'] =\
76+
'tm:sys:sflow:global-settings:system:systemstate'
77+
78+
79+
class Vlan(UnnamedResource):
80+
def __init__(self, global_settings):
81+
super(Vlan, self).__init__(global_settings)
82+
self._meta_data['required_load_parameters'] = set()
83+
self._meta_data['required_json_kind'] =\
84+
'tm:sys:sflow:global-settings:vlan:vlanstate'
85+
86+
87+
class Receivers(Collection):
88+
def __init__(self, sflow):
89+
super(Receivers, self).__init__(sflow)
90+
self._meta_data['allowed_lazy_attributes'] = [Receiver]
91+
self._meta_data['attribute_registry'] =\
92+
{'tm:sys:sflow:receiver:receiverstate': Receiver}
93+
94+
95+
class Receiver(Resource):
96+
def __init__(self, receivers):
97+
super(Receiver, self).__init__(receivers)
98+
self._meta_data['required_creation_parameters'].update(
99+
('name', 'address'))
100+
self._meta_data['required_json_kind'] =\
101+
'tm:sys:sflow:receiver:receiverstate'
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
2+
# Copyright 2017 F5 Networks Inc.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
17+
18+
def set_sflow_http_settings_test(request, mgmt_root):
19+
def teardown():
20+
sf_http.pollInterval = sf_http_int
21+
sf_http.update()
22+
request.addfinalizer(teardown)
23+
sf_http = mgmt_root.tm.sys.sflow.global_settings.http.load()
24+
sf_http_int = sf_http.pollInterval
25+
return sf_http
26+
27+
28+
def set_sflow_interface_settings_test(request, mgmt_root):
29+
def teardown():
30+
sf_interface.pollInterval = sf_interface_int
31+
sf_interface.update()
32+
request.addfinalizer(teardown)
33+
sf_interface = mgmt_root.tm.sys.sflow.global_settings.interface.load()
34+
sf_interface_int = sf_interface.pollInterval
35+
return sf_interface
36+
37+
38+
def set_sflow_system_settings_test(request, mgmt_root):
39+
def teardown():
40+
sf_system.pollInterval = sf_system_int
41+
sf_system.update()
42+
request.addfinalizer(teardown)
43+
sf_system = mgmt_root.tm.sys.sflow.global_settings.system.load()
44+
sf_system_int = sf_system.pollInterval
45+
return sf_system
46+
47+
48+
def set_sflow_vlan_settings_test(request, mgmt_root):
49+
def teardown():
50+
sf_vlan.pollInterval = sf_vlan_int
51+
sf_vlan.update()
52+
request.addfinalizer(teardown)
53+
sf_vlan = mgmt_root.tm.sys.sflow.global_settings.vlan.load()
54+
sf_vlan_int = sf_vlan.pollInterval
55+
return sf_vlan
56+
57+
58+
def set_sflow_receiver_test(request, mgmt_root):
59+
def teardown():
60+
sflow_receiver.delete()
61+
request.addfinalizer(teardown)
62+
63+
sflow_receiver = mgmt_root.tm.sys.sflow.receivers.receiver.create(
64+
name='sr1', address='172.16.44.20'
65+
)
66+
return sflow_receiver
67+
68+
69+
class TestSflowHttp_Setting(object):
70+
def test_RUL(self, request, mgmt_root):
71+
# Load
72+
h1 = set_sflow_http_settings_test(request, mgmt_root)
73+
h2 = mgmt_root.tm.sys.sflow.global_settings.http.load()
74+
assert h1.pollInterval == 10
75+
assert h1.pollInterval == h2.pollInterval
76+
77+
# Update
78+
h1.pollInterval = 20
79+
h1.update()
80+
assert h1.pollInterval == 20
81+
assert h2.pollInterval == 10
82+
83+
# Refresh
84+
h2.refresh()
85+
assert h2.pollInterval == h1.pollInterval
86+
87+
88+
class TestSflowInterface_Setting(object):
89+
def test_RUL(self, request, mgmt_root):
90+
# Load
91+
h1 = set_sflow_interface_settings_test(request, mgmt_root)
92+
h2 = mgmt_root.tm.sys.sflow.global_settings.interface.load()
93+
assert h1.pollInterval == 10
94+
assert h1.pollInterval == h2.pollInterval
95+
96+
# Update
97+
h1.pollInterval = 20
98+
h1.update()
99+
assert h1.pollInterval == 20
100+
assert h2.pollInterval == 10
101+
102+
# Refresh
103+
h2.refresh()
104+
assert h2.pollInterval == h1.pollInterval
105+
106+
107+
class TestSflowSystem_Setting(object):
108+
def test_RUL(self, request, mgmt_root):
109+
# Load
110+
h1 = set_sflow_system_settings_test(request, mgmt_root)
111+
h2 = mgmt_root.tm.sys.sflow.global_settings.system.load()
112+
assert h1.pollInterval == 10
113+
assert h1.pollInterval == h2.pollInterval
114+
115+
# Update
116+
h1.pollInterval = 20
117+
h1.update()
118+
assert h1.pollInterval == 20
119+
assert h2.pollInterval == 10
120+
121+
# Refresh
122+
h2.refresh()
123+
assert h2.pollInterval == h1.pollInterval
124+
125+
126+
class TestSflowVlan_Setting(object):
127+
def test_RUL(self, request, mgmt_root):
128+
# Load
129+
h1 = set_sflow_vlan_settings_test(request, mgmt_root)
130+
h2 = mgmt_root.tm.sys.sflow.global_settings.vlan.load()
131+
assert h1.pollInterval == 10
132+
assert h1.pollInterval == h2.pollInterval
133+
134+
# Update
135+
h1.pollInterval = 20
136+
h1.update()
137+
assert h1.pollInterval == 20
138+
assert h2.pollInterval == 10
139+
140+
# Refresh
141+
h2.refresh()
142+
assert h2.pollInterval == h1.pollInterval
143+
144+
145+
class TestSflowReceiver(object):
146+
def test_CURDLE(self, request, mgmt_root):
147+
# Assume create/delete tested by setup/teardown
148+
r1 = set_sflow_receiver_test(request, mgmt_root)
149+
150+
# Exists
151+
assert mgmt_root.tm.sys.sflow.receivers.receiver.exists(name='sr1')
152+
153+
# Load
154+
r2 = mgmt_root.tm.sys.sflow.receivers.receiver.load(name='sr1')
155+
assert r1.name == r2.name
156+
157+
# Update
158+
r1.address = '172.16.44.21'
159+
r1.update()
160+
assert r1.address != r2.address
161+
162+
# Refresh
163+
r2.refresh()
164+
assert r1.address == r2.address

0 commit comments

Comments
 (0)