def read(self, bigip): u"""Retrieve a BIG-IP resource from a BIG-IP. Returns a resource object with attributes for instance on a BIG-IP system. Args: bigip (f5.bigip.ManagementRoot): F5 SDK session object Returns: resource retrieved from BIG-IP Raises: F5CcclResourceNotFoundError: resouce cannot be loaded because it does not exist on the BIG-IP """ LOGGER.info("Loading %s: /%s/%s", self.classname(), self.partition, self.name) try: obj = self._uri_path(bigip).load( name=urlquote(self.name), partition=self.partition) return obj except iControlUnexpectedHTTPError as err: self._handle_http_error(err) except F5SDKError as err: LOGGER.error("Load FAILED: /%s/%s", self.partition, self.name) raise cccl_exc.F5CcclError(str(err))
def delete(self, bigip): u"""Delete a resource on a BIG-IP system. Loads a resource and deletes it. Args: bigip: BigIP instance to use for delete resource. Raises: F5CcclResourceDeleteError: resouce cannot be deleted for an unspecified reason. F5CcclResourceNotFoundError: resouce cannot be deleted because it already exists on the BIG-IP """ LOGGER.info("Deleting %s: /%s/%s", self.classname(), self.partition, self.name) try: obj = self._uri_path(bigip).load( name=urlquote(self.name), partition=self.partition) obj.delete() except AttributeError as err: msg = "Could not delete {}, is it present on the BIG-IP?".format( str(self)) raise cccl_exc.F5CcclResourceDeleteError(msg) except iControlUnexpectedHTTPError as err: self._handle_http_error(err) except F5SDKError as err: LOGGER.error("Delete FAILED: /%s/%s", self.partition, self.name) raise cccl_exc.F5CcclResourceDeleteError(str(err))
def update(self, bigip, data=None, modify=False): u"""Update a resource (e.g., pool) on a BIG-IP system. Modifies a resource on a BIG-IP system using attributes defined in the model object. The internal data model is applied to the BIG-IP Args: bigip: BigIP instance to use for updating resource. data: Applies mostly for 'patching' or modify, but contains targets for update operation specifically modify: Specifies if this is a modify, or patch of specific Key/Value Pairs rather than the whole object Raises: F5CcclResourceUpdateError: resouce cannot be updated for an unspecified reason. F5CcclResourceNotFoundError: resouce cannot be updated because it does not exist on the BIG-IP """ if not data: data = self._data try: obj = self._uri_path(bigip).load(name=urlquote(self.name), partition=self.partition) payload = copy.copy(data) if modify: obj.modify(**payload) else: obj.update(**payload) except iControlUnexpectedHTTPError as err: self._handle_http_error(err) except F5SDKError as err: raise cccl_exc.F5CcclResourceUpdateError(str(err))
def encoded_normalize_address_with_route_domain(address, default_route_domain, inputUrlEncoded, outputUrlEncoded): """URL Encoded-aware version of normalize_address_with_route_domain""" if inputUrlEncoded: address = urlunquote(address) address = normalize_address_with_route_domain(address, default_route_domain)[0] if outputUrlEncoded: address = urlquote(address) return address
def test_encoded_normalize_address_with_route_domain(): """Test proper behavior of encoded_normalize_address_with_route_domain.""" # test wrapper for test_normalize_address_with_route_domain but with # address input/output being either url encoded or url unencoded tests = [ ["1.2.3.4%1", 2, False, False, "1.2.3.4%1"], ["1.2.3.4%1", 2, False, True, urlquote("1.2.3.4%1")], [urlquote("1.2.3.4%1"), 2, True, False, "1.2.3.4%1"], [urlquote("1.2.3.4%1"), 2, True, True, urlquote("1.2.3.4%1")], ["64:ff9b::", 2, False, False, "64:ff9b::%2"], ["64:ff9b::", 2, False, True, urlquote("64:ff9b::%2")], [urlquote("64:ff9b::"), 2, True, False, "64:ff9b::%2"], [urlquote("64:ff9b::"), 2, True, True, urlquote("64:ff9b::%2")] ] for test in tests: result = encoded_normalize_address_with_route_domain( test[0], test[1], test[2], test[3]) assert result == test[4]
def update(self, bigip, data=None, modify=False): u"""Update a resource (e.g., pool) on a BIG-IP system. Modifies a resource on a BIG-IP system using attributes defined in the model object. The internal data model is applied to the BIG-IP Args: bigip: BigIP instance to use for updating resource. data: Applies mostly for 'patching' or modify, but contains targets for update operation specifically modify: Specifies if this is a modify, or patch of specific Key/Value Pairs rather than the whole object Raises: F5CcclResourceUpdateError: resouce cannot be updated for an unspecified reason. F5CcclResourceNotFoundError: resouce cannot be updated because it does not exist on the BIG-IP """ LOGGER.info("Updating %s: /%s/%s", self.classname(), self.partition, self.name) if not data: data = self._data try: obj = self._uri_path(bigip).load( name=urlquote(self.name), partition=self.partition) payload = copy.copy(data) if modify: obj.modify(**payload) else: obj.update(**payload) except iControlUnexpectedHTTPError as err: self._handle_http_error(err) except F5SDKError as err: LOGGER.error("Update FAILED: /%s/%s", self.partition, self.name) raise cccl_exc.F5CcclResourceUpdateError(str(err))
def name(self): u"""Override the name property to get quoted format. This handles the '%' route domain marker. """ return urlquote(self._data['name'])