Add new DescribeQuota API in Outscale EC2 driver Signed-off-by: Javier M. Mellid <jmun...@igalia.com>
Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/e45b3d05 Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/e45b3d05 Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/e45b3d05 Branch: refs/heads/trunk Commit: e45b3d05200bd626d325c783158102dd8010f441 Parents: a3dbabd Author: Javier M. Mellid <jmun...@igalia.com> Authored: Mon Oct 3 12:33:49 2016 +0200 Committer: Anthony Shaw <anthonys...@apache.org> Committed: Fri Oct 7 13:23:41 2016 +1100 ---------------------------------------------------------------------- libcloud/compute/drivers/ec2.py | 98 ++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/libcloud/blob/e45b3d05/libcloud/compute/drivers/ec2.py ---------------------------------------------------------------------- diff --git a/libcloud/compute/drivers/ec2.py b/libcloud/compute/drivers/ec2.py index 10889c7..7a4a9d6 100644 --- a/libcloud/compute/drivers/ec2.py +++ b/libcloud/compute/drivers/ec2.py @@ -6563,6 +6563,7 @@ class OutscaleConnection(EC2Connection): Connection class for Outscale """ + version = DEFAULT_OUTSCALE_API_VERSION host = None @@ -6810,6 +6811,103 @@ class OutscaleNodeDriver(BaseEC2NodeDriver): sizes.append(NodeSize(driver=self, **attributes)) return sizes + def _to_quota(self, elem): + """ + To Quota + """ + + quota = {} + for reference_quota_item in findall(element=elem, + xpath='referenceQuotaSet/item', + namespace=OUTSCALE_NAMESPACE): + reference = findtext(element=reference_quota_item, + xpath='reference', + namespace=OUTSCALE_NAMESPACE) + quota_set = [] + for quota_item in findall(element=reference_quota_item, + xpath='quotaSet/item', + namespace=OUTSCALE_NAMESPACE): + ownerId = findtext(element=quota_item, + xpath='ownerId', + namespace=OUTSCALE_NAMESPACE) + name = findtext(element=quota_item, + xpath='name', + namespace=OUTSCALE_NAMESPACE) + displayName = findtext(element=quota_item, + xpath='displayName', + namespace=OUTSCALE_NAMESPACE) + description = findtext(element=quota_item, + xpath='description', + namespace=OUTSCALE_NAMESPACE) + groupName = findtext(element=quota_item, + xpath='groupName', + namespace=OUTSCALE_NAMESPACE) + maxQuotaValue = findtext(element=quota_item, + xpath='maxQuotaValue', + namespace=OUTSCALE_NAMESPACE) + usedQuotaValue = findtext(element=quota_item, + xpath='usedQuotaValue', + namespace=OUTSCALE_NAMESPACE) + quota_set.append({'ownerId': ownerId, + 'name': name, + 'displayName': displayName, + 'description': description, + 'groupName': groupName, + 'maxQuotaValue': maxQuotaValue, + 'usedQuotaValue': usedQuotaValue}) + quota[reference] = quota_set + + return quota + + def ex_describe_quota(self, dry_run=False, filters=None, + max_results=None, marker=None): + """ + Describes one or more of your quotas. + + :param dry_run: dry_run + :type dry_run: ``bool`` + + :param filters: The filters so that the response includes + information for only certain quotas + :type filters: ``dict`` + + :param max_results: The maximum number of items that can be + returned in a single page (by default, 100) + :type max_results: ``int`` + + :param marker: Set quota marker + :type marker: ``string`` + + :return: (is_truncated, quota) tuple + :rtype: ``(bool, dict)`` + """ + + if filters: + raise NotImplementedError( + 'quota filters are not implemented') + + if marker: + raise NotImplementedError( + 'quota marker is not implemented') + + params = {'Action': 'DescribeQuota'} + + if dry_run: + params.update({'DryRun': dry_run}) + + if max_results: + params.update({'MaxResults': max_results}) + + response = self.connection.request(self.path, params=params, + method='GET').object + + quota = self._to_quota(response) + + is_truncated = findtext(element=response, xpath='isTruncated', + namespace=OUTSCALE_NAMESPACE) + + return is_truncated, quota + class OutscaleSASNodeDriver(OutscaleNodeDriver): """