libcloud/common/dimensiondata.py [356:517]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
            else:
                # Overwrite default version using the version user specified
                self.active_api_version = api_version

    def add_default_headers(self, headers):
        headers["Authorization"] = "Basic %s" % b64encode(
            b("{}:{}".format(self.user_id, self.key))
        ).decode("utf-8")
        headers["Content-Type"] = "application/xml"
        return headers

    def request_api_1(self, action, params=None, data="", headers=None, method="GET"):
        action = "{}/{}/{}".format(self.api_path_version_1, self.api_version_1, action)

        return super().request(
            action=action, params=params, data=data, method=method, headers=headers
        )

    def request_api_2(self, path, action, params=None, data="", headers=None, method="GET"):
        action = "{}/{}/{}/{}".format(
            self.api_path_version_2,
            self.active_api_version,
            path,
            action,
        )

        return super().request(
            action=action, params=params, data=data, method=method, headers=headers
        )

    def raw_request_with_orgId_api_1(
        self, action, params=None, data="", headers=None, method="GET"
    ):
        action = "{}/{}".format(self.get_resource_path_api_1(), action)
        return super().request(
            action=action,
            params=params,
            data=data,
            method=method,
            headers=headers,
            raw=True,
        )

    def request_with_orgId_api_1(self, action, params=None, data="", headers=None, method="GET"):
        action = "{}/{}".format(self.get_resource_path_api_1(), action)

        return super().request(
            action=action, params=params, data=data, method=method, headers=headers
        )

    def request_with_orgId_api_2(self, action, params=None, data="", headers=None, method="GET"):
        action = "{}/{}".format(self.get_resource_path_api_2(), action)

        return super().request(
            action=action, params=params, data=data, method=method, headers=headers
        )

    def paginated_request_with_orgId_api_2(
        self, action, params=None, data="", headers=None, method="GET", page_size=250
    ):
        """
        A paginated request to the MCP2.0 API
        This essentially calls out to request_with_orgId_api_2 for each page
        and yields the response to make a generator
        This generator can be looped through to grab all the pages.

        :param action: The resource to access (i.e. 'network/vlan')
        :type  action: ``str``

        :param params: Parameters to give to the action
        :type  params: ``dict`` or ``None``

        :param data: The data payload to be added to the request
        :type  data: ``str``

        :param headers: Additional header to be added to the request
        :type  headers: ``str`` or ``dict`` or ``None``

        :param method: HTTP Method for the request (i.e. 'GET', 'POST')
        :type  method: ``str``

        :param page_size: The size of each page to be returned
                          Note: Max page size in MCP2.0 is currently 250
        :type  page_size: ``int``
        """
        if params is None:
            params = {}
        params["pageSize"] = page_size

        resp = self.request_with_orgId_api_2(action, params, data, headers, method).object
        yield resp
        if len(resp) <= 0:
            return

        pcount = resp.get("pageCount")  # pylint: disable=no-member
        psize = resp.get("pageSize")  # pylint: disable=no-member
        pnumber = resp.get("pageNumber")  # pylint: disable=no-member

        while int(pcount) >= int(psize):
            params["pageNumber"] = int(pnumber) + 1
            resp = self.request_with_orgId_api_2(action, params, data, headers, method).object
            pcount = resp.get("pageCount")  # pylint: disable=no-member
            psize = resp.get("pageSize")  # pylint: disable=no-member
            pnumber = resp.get("pageNumber")  # pylint: disable=no-member
            yield resp

    def get_resource_path_api_1(self):
        """
        This method returns a resource path which is necessary for referencing
        resources that require a full path instead of just an ID, such as
        networks, and customer snapshots.
        """
        return "{}/{}/{}".format(
            self.api_path_version_1,
            self.api_version_1,
            self._get_orgId(),
        )

    def get_resource_path_api_2(self):
        """
        This method returns a resource path which is necessary for referencing
        resources that require a full path instead of just an ID, such as
        networks, and customer snapshots.
        """
        return "{}/{}/{}".format(
            self.api_path_version_2,
            self.active_api_version,
            self._get_orgId(),
        )

    def wait_for_state(self, state, func, poll_interval=2, timeout=60, *args, **kwargs):
        """
        Wait for the function which returns a instance with field status/state
        to match.

        Keep polling func until one of the desired states is matched

        :param state: Either the desired state (`str`) or a `list` of states
        :type  state: ``str`` or ``list``

        :param  func: The function to call, e.g. ex_get_vlan. Note: This
                      function needs to return an object which has ``status``
                      attribute.
        :type   func: ``function``

        :param  poll_interval: The number of seconds to wait between checks
        :type   poll_interval: `int`

        :param  timeout: The total number of seconds to wait to reach a state
        :type   timeout: `int`

        :param  args: The arguments for func
        :type   args: Positional arguments

        :param  kwargs: The arguments for func
        :type   kwargs: Keyword arguments

        :return: Result from the calling function.
        """
        cnt = 0
        result = None
        object_state = None
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



libcloud/common/nttcis.py [377:538]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
            else:
                # Overwrite default version using the version user specified
                self.active_api_version = api_version

    def add_default_headers(self, headers):
        headers["Authorization"] = "Basic %s" % b64encode(
            b("{}:{}".format(self.user_id, self.key))
        ).decode("utf-8")
        headers["Content-Type"] = "application/xml"
        return headers

    def request_api_1(self, action, params=None, data="", headers=None, method="GET"):
        action = "{}/{}/{}".format(self.api_path_version_1, self.api_version_1, action)

        return super().request(
            action=action, params=params, data=data, method=method, headers=headers
        )

    def request_api_2(self, path, action, params=None, data="", headers=None, method="GET"):
        action = "{}/{}/{}/{}".format(
            self.api_path_version_2,
            self.active_api_version,
            path,
            action,
        )

        return super().request(
            action=action, params=params, data=data, method=method, headers=headers
        )

    def raw_request_with_orgId_api_1(
        self, action, params=None, data="", headers=None, method="GET"
    ):
        action = "{}/{}".format(self.get_resource_path_api_1(), action)
        return super().request(
            action=action,
            params=params,
            data=data,
            method=method,
            headers=headers,
            raw=True,
        )

    def request_with_orgId_api_1(self, action, params=None, data="", headers=None, method="GET"):
        action = "{}/{}".format(self.get_resource_path_api_1(), action)

        return super().request(
            action=action, params=params, data=data, method=method, headers=headers
        )

    def request_with_orgId_api_2(self, action, params=None, data="", headers=None, method="GET"):
        action = "{}/{}".format(self.get_resource_path_api_2(), action)

        return super().request(
            action=action, params=params, data=data, method=method, headers=headers
        )

    def paginated_request_with_orgId_api_2(
        self, action, params=None, data="", headers=None, method="GET", page_size=250
    ):
        """
        A paginated request to the MCP2.0 API
        This essentially calls out to request_with_orgId_api_2 for each page
        and yields the response to make a generator
        This generator can be looped through to grab all the pages.

        :param action: The resource to access (i.e. 'network/vlan')
        :type  action: ``str``

        :param params: Parameters to give to the action
        :type  params: ``dict`` or ``None``

        :param data: The data payload to be added to the request
        :type  data: ``str``

        :param headers: Additional header to be added to the request
        :type  headers: ``str`` or ``dict`` or ``None``

        :param method: HTTP Method for the request (i.e. 'GET', 'POST')
        :type  method: ``str``

        :param page_size: The size of each page to be returned
                          Note: Max page size in MCP2.0 is currently 250
        :type  page_size: ``int``
        """
        if params is None:
            params = {}
        params["pageSize"] = page_size

        resp = self.request_with_orgId_api_2(action, params, data, headers, method).object
        yield resp
        if len(resp) <= 0:
            return

        pcount = resp.get("pageCount")  # pylint: disable=no-member
        psize = resp.get("pageSize")  # pylint: disable=no-member
        pnumber = resp.get("pageNumber")  # pylint: disable=no-member

        while int(pcount) >= int(psize):
            params["pageNumber"] = int(pnumber) + 1
            resp = self.request_with_orgId_api_2(action, params, data, headers, method).object
            pcount = resp.get("pageCount")  # pylint: disable=no-member
            psize = resp.get("pageSize")  # pylint: disable=no-member
            pnumber = resp.get("pageNumber")  # pylint: disable=no-member
            yield resp

    def get_resource_path_api_1(self):
        """
        This method returns a resource path which is necessary for referencing
        resources that require a full path instead of just an ID, such as
        networks, and customer snapshots.
        """
        return "{}/{}/{}".format(
            self.api_path_version_1,
            self.api_version_1,
            self._get_orgId(),
        )

    def get_resource_path_api_2(self):
        """
        This method returns a resource path which is necessary for referencing
        resources that require a full path instead of just an ID, such as
        networks, and customer snapshots.
        """
        return "{}/{}/{}".format(
            self.api_path_version_2,
            self.active_api_version,
            self._get_orgId(),
        )

    def wait_for_state(self, state, func, poll_interval=2, timeout=60, *args, **kwargs):
        """
        Wait for the function which returns a instance with field status/state
        to match.

        Keep polling func until one of the desired states is matched

        :param state: Either the desired state (`str`) or a `list` of states
        :type  state: ``str`` or ``list``

        :param  func: The function to call, e.g. ex_get_vlan. Note: This
                      function needs to return an object which has ``status``
                      attribute.
        :type   func: ``function``

        :param  poll_interval: The number of seconds to wait between checks
        :type   poll_interval: `int`

        :param  timeout: The total number of seconds to wait to reach a state
        :type   timeout: `int`

        :param  args: The arguments for func
        :type   args: Positional arguments

        :param  kwargs: The arguments for func
        :type   kwargs: Keyword arguments

        :return: Result from the calling function.
        """
        cnt = 0
        result = None
        object_state = None
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



