Skip to content

Commit f5c4584

Browse files
Support bandwidth controller policy
(cherry picked from commit 1ac824a)
1 parent b2da5da commit f5c4584

4 files changed

Lines changed: 172 additions & 0 deletions

File tree

f5/bigip/tm/net/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
from f5.bigip.resource import OrganizingCollection
3131
from f5.bigip.tm.net.arp import Arps
32+
from f5.bigip.tm.net.bwc import Bwc
3233
from f5.bigip.tm.net.dns_resolver import Dns_Resolvers
3334
from f5.bigip.tm.net.fdb import Fdb
3435
from f5.bigip.tm.net.interface import Interfaces
@@ -47,6 +48,7 @@ def __init__(self, tm):
4748
super(Net, self).__init__(tm)
4849
self._meta_data['allowed_lazy_attributes'] = [
4950
Arps,
51+
Bwc,
5052
Dns_Resolvers,
5153
Fdb,
5254
Interfaces,

f5/bigip/tm/net/bwc.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# coding=utf-8
2+
#
3+
# Copyright 2020 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® Network bwc module.
19+
20+
REST URI
21+
``http://localhost/mgmt/tm/net/bwc``
22+
23+
GUI Path
24+
``Acceleration --> Bandwidth Controllers``
25+
26+
REST Kind
27+
``tm:net:bwc:*``
28+
"""
29+
30+
from f5.bigip.resource import Collection
31+
from f5.bigip.resource import OrganizingCollection
32+
from f5.bigip.resource import Resource
33+
34+
35+
class Bwc(OrganizingCollection):
36+
"""BIG-IP® network bwc collection"""
37+
def __init__(self, net):
38+
super(Bwc, self).__init__(net)
39+
self._meta_data['allowed_lazy_attributes'] = [
40+
Policys,
41+
]
42+
43+
44+
class Policys(Collection):
45+
"""BIG-IP® bwc policy sub-collection"""
46+
def __init__(self, bwc):
47+
super(Policys, self).__init__(bwc)
48+
self._meta_data['allowed_lazy_attributes'] = [Policy]
49+
self._meta_data['attribute_registry'] =\
50+
{'tm:net:bwc:policy:policystate': Policy}
51+
52+
53+
class Policy(Resource):
54+
"""BIG-IP® bwc policy sub-collection resource"""
55+
def __init__(self, policy_s):
56+
super(Policy, self).__init__(policy_s)
57+
self._meta_data['required_creation_parameters'].update(('partition',))
58+
self._meta_data['required_json_kind'] =\
59+
'tm:net:bwc:policy:policystate'
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Copyright 2020 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 requests.exceptions import HTTPError
17+
18+
19+
TEST_DESCR = "TEST DESCRIPTION"
20+
21+
22+
def delete_resource(resource):
23+
try:
24+
resource.delete()
25+
except HTTPError as err:
26+
if err.response.status_code != 404:
27+
raise
28+
29+
30+
def setup_policy_test(request, mgmt_root, name, partition, maxRate):
31+
def teardown():
32+
delete_resource(policy)
33+
request.addfinalizer(teardown)
34+
35+
policy = mgmt_root.tm.net.bwc.policys.policy.create(
36+
name=name, partition=partition, maxRate=maxRate)
37+
return policy
38+
39+
40+
class TestPolicys(object):
41+
def test_policy_list(self, mgmt_root):
42+
policies = mgmt_root.tm.net.bwc.policys.get_collection()
43+
assert len(policies)
44+
for policy in policies:
45+
assert policy.generation
46+
47+
48+
class TestPolicy(object):
49+
def test_policy_CURDL(self, request, mgmt_root):
50+
# Create and Delete are tested by the setup/teardown
51+
p1 = setup_policy_test(
52+
request, mgmt_root, 'bwc-policy-test', 'Common', 1000000
53+
)
54+
55+
# Load
56+
p2 = mgmt_root.tm.net.bwc.policys.policy.load(
57+
name='bwc-policy-test', partition='Common')
58+
assert p1.name == 'bwc-policy-test'
59+
assert p1.name == p2.name
60+
assert p1.generation == p2.generation
61+
62+
# Update
63+
p1.description = TEST_DESCR
64+
p1.update()
65+
assert p1.description == TEST_DESCR
66+
assert p1.generation > p2.generation
67+
68+
# Refresh
69+
p2.refresh()
70+
assert p2.description == TEST_DESCR
71+
assert p1.generation == p2.generation
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Copyright 2015 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 import ManagementRoot
20+
from f5.bigip.tm.net.bwc import Policy
21+
from f5.sdk_exception import MissingRequiredCreationParameter
22+
23+
24+
@pytest.fixture
25+
def FakePolicy():
26+
fake_policy_s = mock.MagicMock()
27+
fake_policy = Policy(fake_policy_s)
28+
return fake_policy
29+
30+
31+
class TestCreate(object):
32+
def test_create_two(self, fakeicontrolsession):
33+
b = ManagementRoot('192.168.1.1', 'admin', 'admin')
34+
p1 = b.tm.net.bwc.policys.policy
35+
p2 = b.tm.net.bwc.policys.policy
36+
assert p1 is not p2
37+
38+
def test_create_no_args(self, FakePolicy):
39+
with pytest.raises(MissingRequiredCreationParameter):
40+
FakePolicy.create()

0 commit comments

Comments
 (0)