Skip to content

Commit d42acc3

Browse files
committed
Merge pull request #426 from caphrim007/add-software-update-api
Add the software update API endpoint
2 parents 59303eb + df42824 commit d42acc3

9 files changed

Lines changed: 185 additions & 4 deletions

File tree

f5/bigip/tm/sys/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
from f5.bigip.tm.sys.httpd import Httpd
4040
from f5.bigip.tm.sys.ntp import Ntp
4141
from f5.bigip.tm.sys.performance import Performances
42+
from f5.bigip.tm.sys.software import Software
4243
from f5.bigip.tm.sys.sshd import Sshd
4344

4445

@@ -57,5 +58,6 @@ def __init__(self, tm):
5758
Failover,
5859
Dns,
5960
Sshd,
60-
Httpd
61+
Httpd,
62+
Software
6163
]
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# coding=utf-8
2+
#
3+
# Copyright 2015 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® System Software module
19+
20+
REST URI
21+
``http://localhost/mgmt/tm/sys/software``
22+
23+
GUI Path
24+
``System``
25+
26+
REST Kind
27+
``tm:sys:software:*``
28+
"""
29+
30+
from f5.bigip.resource import OrganizingCollection
31+
from f5.bigip.tm.sys.software.update import Update
32+
33+
34+
class Software(OrganizingCollection):
35+
def __init__(self, tm):
36+
super(Software, self).__init__(tm)
37+
self._meta_data['allowed_lazy_attributes'] = [
38+
Update
39+
]
40+
41+
def __getattribute__(self, name):
42+
if name == 'update':
43+
return Update(self)
44+
return super(Software, self).__getattribute__(name)

f5/bigip/tm/sys/software/test/__init__.py

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

f5/bigip/tm/sys/software/update.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# coding=utf-8
2+
#
3+
# Copyright 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® system software update module
19+
20+
REST URI
21+
``http://localhost/mgmt/tm/sys/software/update``
22+
23+
GUI Path
24+
``System --> Software Management --> Update Check``
25+
26+
REST Kind
27+
``tm:sys:software:update:updatestate``
28+
"""
29+
30+
from f5.bigip.mixins import UnnamedResourceMixin
31+
from f5.bigip.resource import ResourceBase
32+
33+
34+
class Update(UnnamedResourceMixin, ResourceBase):
35+
"""BIG-IP® system software update unnamed resource
36+
37+
.. note::
38+
39+
This is an unnamed resource so it has not ~Partition~Name pattern
40+
at the end of its URI.
41+
"""
42+
def __init__(self, sys):
43+
super(Update, self).__init__(sys)
44+
self._meta_data['required_load_parameters'] = set()
45+
self._meta_data['required_json_kind'] = \
46+
'tm:sys:software:update:updatestate'

f5/utils/decorators.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@
1919

2020
from f5.utils.util_exceptions import UtilError
2121

22+
2223
class MaximumAttemptsReached(UtilError):
23-
def __init__(*args, **kwargs):
24-
# TODO: Add logging here!
24+
def __init__(self, *args, **kwargs):
25+
# TODO(Add logging here!)
2526
super(MaximumAttemptsReached, self).__init__(*args, **kwargs)
2627

2728

f5/utils/util_exceptions.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515

1616
from f5.sdk_exception import F5SDKError
1717

18+
1819
class UtilError(F5SDKError):
1920
'''A base exception for all utility exceptions in this library.'''
20-
def __init__(self, *arg, **kwargs):
21+
def __init__(self, *args, **kwargs):
2122
super(UtilError, self).__init__(*args, **kwargs)

test/functional/tm/sys/software/__init__.py

Whitespace-only changes.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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 pytest
17+
18+
19+
@pytest.fixture
20+
def cleaner(request, bigip):
21+
initial = bigip.sys.software.update.load()
22+
23+
def teardown():
24+
initial.update()
25+
request.addfinalizer(teardown)
26+
27+
28+
class TestUpdate(object):
29+
def test_load(self, cleaner, bigip):
30+
su = bigip.sys.software.update.load()
31+
assert su.autoCheck == 'enabled'
32+
su.refresh()
33+
assert su.autoCheck == 'enabled'
34+
35+
def test_update_autocheck(self, cleaner, bigip):
36+
su = bigip.sys.software.update.load()
37+
su.update(autoCheck='disabled')
38+
assert su.autoCheck == 'disabled'
39+
su.update(autoCheck='enabled')
40+
assert su.autoCheck == 'enabled'
41+
42+
def test_update_frequency(self, cleaner, bigip):
43+
frequencies = ['daily', 'monthly', 'weekly']
44+
su = bigip.sys.software.update.load()
45+
46+
for frequency in frequencies:
47+
su.update(frequency=frequency)
48+
assert su.frequency == frequency

0 commit comments

Comments
 (0)