Skip to content

Commit 9cff7a6

Browse files
authored
Adds service policy API to the sdk (#1393)
Issues: Fixes #1392 Problem: The service policy API did not exist Analysis: This adds it Tests: functional
1 parent 8c5f507 commit 9cff7a6

4 files changed

Lines changed: 148 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
@@ -35,6 +35,7 @@
3535
from f5.bigip.tm.net.route import Routes
3636
from f5.bigip.tm.net.route_domain import Route_Domains
3737
from f5.bigip.tm.net.selfip import Selfips
38+
from f5.bigip.tm.net.service_policy import Service_Policys
3839
from f5.bigip.tm.net.timer_policy import Timer_Policys
3940
from f5.bigip.tm.net.trunk import Trunks
4041
from f5.bigip.tm.net.tunnels import TunnelS
@@ -52,6 +53,7 @@ def __init__(self, tm):
5253
Routes,
5354
Route_Domains,
5455
Selfips,
56+
Service_Policys,
5557
Timer_Policys,
5658
Trunks,
5759
TunnelS,

f5/bigip/tm/net/service_policy.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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+
"""Directory: net module: service-policy.
19+
20+
REST URI
21+
``https://localhost/mgmt/tm/net/service-policy``
22+
23+
GUI Path
24+
``Network --> Service Policies --> Service Policies``
25+
26+
REST Kind
27+
``tm:net:service-policy:*``
28+
"""
29+
30+
31+
from f5.bigip.resource import Collection
32+
from f5.bigip.resource import Resource
33+
34+
35+
class Service_Policys(Collection):
36+
def __init__(self, net):
37+
super(Service_Policys, self).__init__(net)
38+
self._meta_data['minimum_version'] = '12.0.0'
39+
self._meta_data['allowed_lazy_attributes'] = [Service_Policy]
40+
self._meta_data['attribute_registry'] = {
41+
'tm:net:service-policy:service-policystate': Service_Policy
42+
}
43+
44+
45+
class Service_Policy(Resource):
46+
def __init__(self, service_policys):
47+
super(Service_Policy, self).__init__(service_policys)
48+
self._meta_data['minimum_version'] = '12.0.0'
49+
self._meta_data['required_json_kind'] = "tm:net:service-policy:service-policystate"
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
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+
import os
17+
import pytest
18+
import tempfile
19+
20+
from distutils.version import LooseVersion
21+
22+
23+
pytestmark = pytest.mark.skipif(
24+
LooseVersion(pytest.config.getoption('--release')) < LooseVersion('12.0.0'),
25+
reason='This series of tests requires BIG-IP version 12.0.0 or greater.'
26+
)
27+
28+
29+
@pytest.fixture
30+
def timer_policy(mgmt_root):
31+
file = tempfile.NamedTemporaryFile()
32+
name = os.path.basename(file.name)
33+
resource = mgmt_root.tm.net.timer_policys.timer_policy.create(
34+
name=name
35+
)
36+
yield resource
37+
resource.delete()
38+
39+
40+
@pytest.fixture
41+
def service_policy_with_timer_policy(mgmt_root, timer_policy):
42+
file = tempfile.NamedTemporaryFile()
43+
name = os.path.basename(file.name)
44+
resource = mgmt_root.tm.net.service_policys.service_policy.create(
45+
name=name,
46+
timerPolicy=timer_policy.name
47+
)
48+
yield resource
49+
resource.delete()
50+
51+
52+
@pytest.fixture
53+
def service_policy(mgmt_root):
54+
file = tempfile.NamedTemporaryFile()
55+
name = os.path.basename(file.name)
56+
resource = mgmt_root.tm.net.service_policys.service_policy.create(
57+
name=name
58+
)
59+
yield resource
60+
resource.delete()
61+
62+
63+
@pytest.fixture
64+
def service_policies(mgmt_root):
65+
collection = mgmt_root.tm.net.service_policys
66+
return collection
67+
68+
69+
class TestResource(object):
70+
def test_get_collection(self, service_policy, service_policies):
71+
assert len(list(service_policies.get_collection())) > 0
72+
73+
def test_create(self, mgmt_root):
74+
file = tempfile.NamedTemporaryFile()
75+
name = os.path.basename(file.name)
76+
resource = mgmt_root.tm.net.service_policys.service_policy.create(
77+
name=name
78+
)
79+
assert resource.name == name
80+
resource.delete()
81+
82+
def test_update(self, timer_policy, service_policy):
83+
service_policy.description = 'my description'
84+
service_policy.timerPolicy = timer_policy.name
85+
service_policy.update()
86+
assert service_policy.description == 'my description'
87+
assert service_policy.timerPolicy == '/Common/{0}'.format(timer_policy.name)
88+
89+
def test_refresh(self, service_policy):
90+
assert not hasattr(service_policy, 'description')
91+
service_policy.description = 'disabled'
92+
93+
# A refresh without an update should show no change
94+
service_policy.refresh()
95+
assert not hasattr(service_policy, 'description')

f5/bigip/tm/net/timer_policy.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
class Timer_Policys(Collection):
3636
def __init__(self, net):
3737
super(Timer_Policys, self).__init__(net)
38+
self._meta_data['minimum_version'] = '12.0.0'
3839
self._meta_data['allowed_lazy_attributes'] = [Timer_Policy]
3940
self._meta_data['attribute_registry'] = {
4041
'tm:net:timer-policy:timer-policystate': Timer_Policy
@@ -44,4 +45,5 @@ def __init__(self, net):
4445
class Timer_Policy(Resource):
4546
def __init__(self, timer_policys):
4647
super(Timer_Policy, self).__init__(timer_policys)
48+
self._meta_data['minimum_version'] = '12.0.0'
4749
self._meta_data['required_json_kind'] = "tm:net:timer-policy:timer-policystate"

0 commit comments

Comments
 (0)