|
| 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® utility module |
| 18 | +
|
| 19 | +REST URI |
| 20 | + ``http://localhost/mgmt/tm/util/dig`` |
| 21 | +
|
| 22 | +GUI Path |
| 23 | + N/A |
| 24 | +
|
| 25 | +REST Kind |
| 26 | + ``tm:util:dig:*`` |
| 27 | +""" |
| 28 | + |
| 29 | +from f5.bigip.mixins import CommandExecutionMixin |
| 30 | +from f5.bigip.resource import UnnamedResource |
| 31 | +from f5.utils.util_exceptions import UtilError |
| 32 | + |
| 33 | + |
| 34 | +class Dig(UnnamedResource, CommandExecutionMixin): |
| 35 | + """BIG-IP® utility command |
| 36 | +
|
| 37 | + .. note:: |
| 38 | +
|
| 39 | + This is an unnamed resource so it has no ~Partition~Name pattern |
| 40 | + at the end of its URI. |
| 41 | + """ |
| 42 | + |
| 43 | + def __init__(self, util): |
| 44 | + super(Dig, self).__init__(util) |
| 45 | + self._meta_data['required_command_parameters'].update(('utilCmdArgs',)) |
| 46 | + self._meta_data['required_json_kind'] = 'tm:util:dig:runstate' |
| 47 | + self._meta_data['allowed_commands'].append('run') |
| 48 | + |
| 49 | + def _exec_cmd(self, command, **kwargs): |
| 50 | + kwargs['command'] = command |
| 51 | + self._check_exclusive_parameters(**kwargs) |
| 52 | + requests_params = self._handle_requests_params(kwargs) |
| 53 | + self._check_command_parameters(**kwargs) |
| 54 | + |
| 55 | + session = self._meta_data['bigip']._meta_data['icr_session'] |
| 56 | + response = session.post( |
| 57 | + self._meta_data['uri'], json=kwargs, **requests_params) |
| 58 | + self._local_update(response.json()) |
| 59 | + |
| 60 | + if 'commandResult' in self.__dict__: |
| 61 | + if 'Invalid option' in self.commandResult: |
| 62 | + raise UtilError('%s' % self.commandResult) |
| 63 | + else: |
| 64 | + return self |
| 65 | + else: |
| 66 | + return self |
0 commit comments