|
| 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® Guest (vcmp) module |
| 19 | +
|
| 20 | +REST URI |
| 21 | + ``http://localhost/mgmt/tm/vcmp/virtual-disk/`` |
| 22 | +
|
| 23 | +GUI Path |
| 24 | + ``Virtual Disk List`` |
| 25 | +
|
| 26 | +REST Kind |
| 27 | + ``tm:vcmp:virtual-disk:*`` |
| 28 | +""" |
| 29 | + |
| 30 | +from f5.bigip.resource import Collection |
| 31 | +from f5.bigip.resource import Resource |
| 32 | +from f5.sdk_exception import DisallowedCreationParameter |
| 33 | +from f5.sdk_exception import DisallowedReadParameter |
| 34 | +from f5.sdk_exception import F5SDKError |
| 35 | +from f5.sdk_exception import UnsupportedMethod |
| 36 | + |
| 37 | + |
| 38 | +class Virtual_Disks(Collection): |
| 39 | + def __init__(self, vcmp): |
| 40 | + super(Virtual_Disks, self).__init__(vcmp) |
| 41 | + self._meta_data['allowed_lazy_attributes'] = [Virtual_Disk] |
| 42 | + self._meta_data['required_json_kind'] = 'tm:vcmp:virtual-disk:virtual-diskcollectionstate' |
| 43 | + self._meta_data['attribute_registry'] = { |
| 44 | + 'tm:vcmp:virtual-disk:virtual-diskstate': Virtual_Disk |
| 45 | + } |
| 46 | + |
| 47 | + |
| 48 | +class Virtual_Disk(Resource): |
| 49 | + def __init__(self, collection): |
| 50 | + super(Virtual_Disk, self).__init__(collection) |
| 51 | + self._meta_data['required_json_kind'] = 'tm:vcmp:virtual-disk:virtual-diskstate' |
| 52 | + |
| 53 | + def load(self, **kwargs): |
| 54 | + """Loads a given resource |
| 55 | +
|
| 56 | + Loads a given resource provided a 'name' and an optional 'slot' |
| 57 | + parameter. The 'slot' parameter is not a required load parameter |
| 58 | + because it is provided as an optional way of constructing the |
| 59 | + correct 'name' of the vCMP resource. |
| 60 | +
|
| 61 | + :param kwargs: |
| 62 | + :return: |
| 63 | + """ |
| 64 | + kwargs['transform_name'] = True |
| 65 | + kwargs = self._mutate_name(kwargs) |
| 66 | + return self._load(**kwargs) |
| 67 | + |
| 68 | + def exists(self, **kwargs): |
| 69 | + kwargs['transform_name'] = True |
| 70 | + kwargs = self._mutate_name(kwargs) |
| 71 | + return self._exists(**kwargs) |
| 72 | + |
| 73 | + def delete(self, **kwargs): |
| 74 | + kwargs['transform_name'] = True |
| 75 | + kwargs = self._mutate_name(kwargs) |
| 76 | + return self._delete(**kwargs) |
| 77 | + |
| 78 | + def modify(self, **kwargs): |
| 79 | + raise UnsupportedMethod( |
| 80 | + "%s does not support the modify method" % self.__class__.__name__ |
| 81 | + ) |
| 82 | + |
| 83 | + def create(self, **kwargs): |
| 84 | + raise UnsupportedMethod( |
| 85 | + "%s does not support the create method" % self.__class__.__name__ |
| 86 | + ) |
| 87 | + |
| 88 | + def update(self, **kwargs): |
| 89 | + raise UnsupportedMethod( |
| 90 | + "%s does not support the update method" % self.__class__.__name__ |
| 91 | + ) |
| 92 | + |
| 93 | + def _check_load_parameters(self, **kwargs): |
| 94 | + """Override method for one in resource.py to check partition |
| 95 | +
|
| 96 | + The partition cannot be included as a parameter to load a guest. |
| 97 | + Raise an exception if a consumer gives the partition parameter. |
| 98 | +
|
| 99 | + :raises: DisallowedReadParameter |
| 100 | + """ |
| 101 | + |
| 102 | + if 'partition' in kwargs: |
| 103 | + msg = "'partition' is not allowed as a load parameter. Vcmp " \ |
| 104 | + "guests are accessed by name." |
| 105 | + raise DisallowedReadParameter(msg) |
| 106 | + super(Virtual_Disk, self)._check_load_parameters(**kwargs) |
| 107 | + |
| 108 | + def _check_create_parameters(self, **kwargs): |
| 109 | + """Override method for one in resource.py to check partition |
| 110 | +
|
| 111 | + The partition cannot be included as a parameter to create a guest. |
| 112 | + Raise an exception if a consumer gives the partition parameter. |
| 113 | +
|
| 114 | + :raises: DisallowedCreationParameter |
| 115 | + """ |
| 116 | + |
| 117 | + if 'partition' in kwargs: |
| 118 | + msg = "'partition' is not allowed as a create parameter. Vcmp " \ |
| 119 | + "guests are created with the 'name' at least." |
| 120 | + raise DisallowedCreationParameter(msg) |
| 121 | + super(Virtual_Disk, self)._check_create_parameters(**kwargs) |
| 122 | + |
| 123 | + def _mutate_name(self, kwargs): |
| 124 | + slot = kwargs.pop('slot', None) |
| 125 | + if slot is not None: |
| 126 | + try: |
| 127 | + kwargs['name'] = '{0}/{1}'.format(kwargs['name'], int(slot)) |
| 128 | + except ValueError: |
| 129 | + raise F5SDKError( |
| 130 | + "The provided 'slot' must be a number" |
| 131 | + ) |
| 132 | + return kwargs |
0 commit comments