Skip to content

Commit 8c5f507

Browse files
authored
Adds timer-policy API (#1391)
Issues: Fixes #1390 Problem: Net timer policy api did not exist Analysis: This adds it Tests: functional
1 parent c89bafb commit 8c5f507

3 files changed

Lines changed: 133 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.timer_policy import Timer_Policys
3839
from f5.bigip.tm.net.trunk import Trunks
3940
from f5.bigip.tm.net.tunnels import TunnelS
4041
from f5.bigip.tm.net.vlan import Vlans
@@ -51,6 +52,7 @@ def __init__(self, tm):
5152
Routes,
5253
Route_Domains,
5354
Selfips,
55+
Timer_Policys,
5456
Trunks,
5557
TunnelS,
5658
Vlans
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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 timer_policies(mgmt_root):
42+
collection = mgmt_root.tm.net.timer_policys
43+
return collection
44+
45+
46+
class TestResource(object):
47+
def test_get_collection(self, timer_policy, timer_policies):
48+
assert len(list(timer_policies.get_collection())) > 0
49+
50+
def test_create(self, mgmt_root):
51+
file = tempfile.NamedTemporaryFile()
52+
name = os.path.basename(file.name)
53+
resource = mgmt_root.tm.net.timer_policys.timer_policy.create(
54+
name=name
55+
)
56+
assert resource.name == name
57+
resource.delete()
58+
59+
def test_update(self, timer_policy):
60+
timer_policy.description = 'my description'
61+
timer_policy.rules = [
62+
{
63+
"name": "rule1",
64+
"description": "rule description",
65+
"ipProtocol": "all-other",
66+
"timers": [
67+
{
68+
"name": "flow-idle-timeout",
69+
"value": "346"
70+
}
71+
]
72+
}
73+
]
74+
timer_policy.update()
75+
assert timer_policy.description == 'my description'
76+
assert len(timer_policy.rules) == 1
77+
78+
def test_refresh(self, timer_policy):
79+
assert not hasattr(timer_policy, 'description')
80+
timer_policy.description = 'disabled'
81+
82+
# A refresh without an update should show no change
83+
timer_policy.refresh()
84+
assert not hasattr(timer_policy, 'description')

f5/bigip/tm/net/timer_policy.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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: timer-policy.
19+
20+
REST URI
21+
``https://localhost/mgmt/tm/net/timer-policy``
22+
23+
GUI Path
24+
``Network --> Service Policies --> Timer Policies``
25+
26+
REST Kind
27+
``tm:net:timer-policy:*``
28+
"""
29+
30+
31+
from f5.bigip.resource import Collection
32+
from f5.bigip.resource import Resource
33+
34+
35+
class Timer_Policys(Collection):
36+
def __init__(self, net):
37+
super(Timer_Policys, self).__init__(net)
38+
self._meta_data['allowed_lazy_attributes'] = [Timer_Policy]
39+
self._meta_data['attribute_registry'] = {
40+
'tm:net:timer-policy:timer-policystate': Timer_Policy
41+
}
42+
43+
44+
class Timer_Policy(Resource):
45+
def __init__(self, timer_policys):
46+
super(Timer_Policy, self).__init__(timer_policys)
47+
self._meta_data['required_json_kind'] = "tm:net:timer-policy:timer-policystate"

0 commit comments

Comments
 (0)