|
| 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 | +"""BIG-IP® system config module |
| 18 | +
|
| 19 | +REST URI |
| 20 | + ``http://localhost/mgmt/tm/sys/ucs` |
| 21 | +
|
| 22 | +GUI Path |
| 23 | + N/A |
| 24 | +
|
| 25 | +REST Kind |
| 26 | + ``tm:sys:ucs:*`` |
| 27 | +""" |
| 28 | + |
| 29 | +from f5.bigip.mixins import CommandExecutionMixin |
| 30 | +from f5.bigip.mixins import InvalidCommand |
| 31 | +from f5.bigip.resource import UnnamedResource |
| 32 | +from requests.exceptions import HTTPError |
| 33 | + |
| 34 | + |
| 35 | +class Ucs(UnnamedResource, CommandExecutionMixin): |
| 36 | + """BIG-IP® system UCS resource |
| 37 | +
|
| 38 | + .. note:: |
| 39 | + Given the fact that 11.6.0 UCS via rest is |
| 40 | + broken, this feature will be supported in 12.0.0 and above. |
| 41 | + Listing of installed UCS has been fixed in 12.1.0. |
| 42 | + This resource is a collection which does not allow listing |
| 43 | + of each ucs as a resource. 'Items' attribute of the loaded object |
| 44 | + is used to access the list of installed UCS files. |
| 45 | +
|
| 46 | + Caveat: |
| 47 | + Loading UCS will result in ICRD restarting, therefore |
| 48 | + due to ID476518 502 Bad Gateway is generated, this is |
| 49 | + working as intended, at least until some architecture |
| 50 | + changes have been made. |
| 51 | +
|
| 52 | +
|
| 53 | + """ |
| 54 | + def __init__(self, sys): |
| 55 | + super(Ucs, self).__init__(sys) |
| 56 | + self._meta_data['required_load_parameters'] = set() |
| 57 | + self._meta_data['allowed_commands'].extend(['load', 'save']) |
| 58 | + self._meta_data['required_json_kind'] = '' |
| 59 | + self._meta_data['minimum_version'] = '12.0.0' |
| 60 | + |
| 61 | + def exec_cmd(self, command, **kwargs): |
| 62 | + """Due to ID476518 the load command need special treatment""" |
| 63 | + cmds = self._meta_data['allowed_commands'] |
| 64 | + |
| 65 | + if command not in self._meta_data['allowed_commands']: |
| 66 | + error_message = "The command value {0} does not exist" \ |
| 67 | + "Valid commands are {1}".format(command, cmds) |
| 68 | + raise InvalidCommand(error_message) |
| 69 | + |
| 70 | + if command == 'load': |
| 71 | + kwargs['command'] = command |
| 72 | + self._check_exclusive_parameters(**kwargs) |
| 73 | + requests_params = self._handle_requests_params(kwargs) |
| 74 | + self._check_command_parameters(**kwargs) |
| 75 | + session = self._meta_data['bigip']._meta_data['icr_session'] |
| 76 | + try: |
| 77 | + |
| 78 | + session.post( |
| 79 | + self._meta_data['uri'], json=kwargs, **requests_params) |
| 80 | + |
| 81 | + except HTTPError as err: |
| 82 | + if err.response.status_code != 502: |
| 83 | + raise |
| 84 | + return |
| 85 | + |
| 86 | + else: |
| 87 | + return self._exec_cmd(command, **kwargs) |
| 88 | + |
| 89 | + def load(self, **kwargs): |
| 90 | + """Method to list the UCS on the system |
| 91 | +
|
| 92 | + Since this is only fixed in 12.1.0 and up |
| 93 | + we implemented version check here |
| 94 | + """ |
| 95 | + |
| 96 | + # Check if we are using 12.1.0 version or above when using this method |
| 97 | + self._is_version_supported_method('12.1.0') |
| 98 | + newinst = self._stamp_out_core() |
| 99 | + newinst._refresh(**kwargs) |
| 100 | + |
| 101 | + return newinst |
0 commit comments