예제 #1
0
    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))
예제 #2
0
    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))
예제 #3
0
파일: resource.py 프로젝트: russokj/f5-cccl
    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))
예제 #4
0
    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))
예제 #5
0
파일: resource.py 프로젝트: russokj/f5-cccl
    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))
예제 #6
0
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
예제 #7
0
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]
예제 #8
0
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]
예제 #9
0
파일: resource.py 프로젝트: russokj/f5-cccl
    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))
예제 #10
0
    def name(self):
        u"""Override the name property to get quoted format.

        This handles the '%' route domain marker.
        """
        return urlquote(self._data['name'])
예제 #11
0
    def name(self):
        u"""Override the name property to get quoted format.

        This handles the '%' route domain marker.
        """
        return urlquote(self._data['name'])