You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by an...@apache.org on 2017/04/12 23:17:32 UTC

[3/5] libcloud git commit: Add the ability to list resource groups

Add the ability to list resource groups


Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/58d8bff8
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/58d8bff8
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/58d8bff8

Branch: refs/heads/trunk
Commit: 58d8bff883196b7dcc228848082439a83395e427
Parents: 994456a
Author: Joseph Hall <pe...@gmail.com>
Authored: Tue Apr 11 09:53:33 2017 -0600
Committer: Anthony Shaw <an...@apache.org>
Committed: Thu Apr 13 09:16:02 2017 +1000

----------------------------------------------------------------------
 libcloud/compute/drivers/azure_arm.py | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/58d8bff8/libcloud/compute/drivers/azure_arm.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/azure_arm.py b/libcloud/compute/drivers/azure_arm.py
index a45d03d..7e733b7 100644
--- a/libcloud/compute/drivers/azure_arm.py
+++ b/libcloud/compute/drivers/azure_arm.py
@@ -71,6 +71,20 @@ class AzureVhdImage(NodeImage):
                 % (self.id, self.name, self.location))
 
 
+class AzureResourceGroup(object):
+    """Represent an Azure resource group."""
+
+    def __init__(self, id, name, location, extra):
+        self.id = id
+        self.name = name
+        self.location = location
+        self.extra = extra
+
+    def __repr__(self):
+        return (('<AzureResourceGroup: id=%s, name=%s, location=%s ...>')
+                % (self.id, self.name, self.location))
+
+
 class AzureNetwork(object):
     """Represent an Azure virtual network."""
 
@@ -823,6 +837,20 @@ class AzureNodeDriver(NodeDriver):
                                     params={"api-version": "2015-06-15"})
         return [(img["id"], img["name"]) for img in r.object]
 
+    def ex_list_resource_groups(self):
+        """
+        List resource groups.
+
+        :return: A list of resource groups.
+        :rtype: ``list`` of :class:`.Azureresource_group`
+        """
+
+        action = "/subscriptions/%s/resourceGroups/" % (self.subscription_id)
+        r = self.connection.request(action,
+                                    params={"api-version": "2016-09-01"})
+        return [AzureResourceGroup(net["id"], net["name"], net["location"],
+                             net["properties"]) for net in r.object["value"]]
+
     def ex_list_networks(self):
         """
         List virtual networks.