libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anthonys...@apache.org
Subject [5/7] libcloud git commit: Merge branch 'github-1033' into trunk Closes #1033
Date Wed, 12 Apr 2017 23:27:43 GMT
Merge branch 'github-1033' into trunk
Closes #1033


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

Branch: refs/heads/trunk
Commit: c92c66f4bc9b7279e4ccb2c3a8f02a138bdb2300
Parents: 4938430 010b755
Author: Anthony Shaw <anthonyshaw@apache.org>
Authored: Thu Apr 13 09:20:55 2017 +1000
Committer: Anthony Shaw <anthonyshaw@apache.org>
Committed: Thu Apr 13 09:20:55 2017 +1000

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


http://git-wip-us.apache.org/repos/asf/libcloud/blob/c92c66f4/libcloud/compute/drivers/azure_arm.py
----------------------------------------------------------------------
diff --cc libcloud/compute/drivers/azure_arm.py
index 57f55f4,03d8b2f..d6ca90c
--- a/libcloud/compute/drivers/azure_arm.py
+++ b/libcloud/compute/drivers/azure_arm.py
@@@ -71,19 -71,20 +71,33 @@@ 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 AzureNetworkSecurityGroup(object):
+     """Represent an Azure network security group."""
+ 
+     def __init__(self, id, name, location, extra):
+         self.id = id
+         self.name = name
+         self.location = location
+         self.extra = extra
+ 
+     def __repr__(self):
+         return (
+             ('<AzureNetworkSecurityGroup: id=%s, name=%s, location=%s ...>')
+             % (self.id, self.name, self.location))
+ 
  
  class AzureNetwork(object):
      """Represent an Azure virtual network."""
@@@ -837,21 -838,95 +851,110 @@@ 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:`.AzureResourceGroup`
 +        """
 +
 +        action = "/subscriptions/%s/resourceGroups/" % (self.subscription_id)
 +        r = self.connection.request(action,
 +                                    params={"api-version": "2016-09-01"})
 +        return [AzureResourceGroup(grp["id"], grp["name"], grp["location"],
 +                                   grp["properties"])
 +                for grp in r.object["value"]]
 +
+     def ex_list_network_security_groups(self, resource_group):
+         """
+         List network security groups.
+ 
+         :param resource_group: List security groups in a specific resource
+         group.
+         :type resource_group: ``str``
+ 
+         :return: A list of network security groups.
+         :rtype: ``list`` of :class:`.AzureNetworkSecurityGroup`
+         """
+ 
+         action = "/subscriptions/%s/resourceGroups/%s/providers/" \
+                  "Microsoft.Network/networkSecurityGroups" \
+                  % (self.subscription_id, resource_group)
+         r = self.connection.request(action,
+                                     params={"api-version": "2015-06-15"})
+         return [AzureNetworkSecurityGroup(net["id"],
+                                           net["name"],
+                                           net["location"],
+                                           net["properties"])
+                 for net in r.object["value"]]
+ 
+     def ex_create_network_security_group(self, name, resource_group,
+                                          location=None):
+         """
+         Update tags on any resource supporting tags.
+ 
+         :param name: Name of the network security group to create
+         :type name: ``str``
+ 
+         :param resource_group: The resource group to create the network
+         security group in
+         :type resource_group: ``str``
+ 
+         :param location: The location at which to create the network security
+         group (if None, use default location specified as 'region' in __init__)
+         :type location: :class:`.NodeLocation`
+         """
+ 
+         if location is None and self.default_location:
+             location = self.default_location
+         else:
+             raise ValueError("location is required.")
+ 
+         target = "/subscriptions/%s/resourceGroups/%s/" \
+                  "providers/Microsoft.Network/networkSecurityGroups/%s" \
+                  % (self.subscription_id, resource_group, name)
+         data = {
+             "location": location.id,
+         }
+         self.connection.request(target,
+                                 params={"api-version": "2016-09-01"},
+                                 data=data,
+                                 method='PUT')
+ 
+     def ex_delete_network_security_group(self, name, resource_group,
+                                          location=None):
+         """
+         Update tags on any resource supporting tags.
+ 
+         :param name: Name of the network security group to delete
+         :type name: ``str``
+ 
+         :param resource_group: The resource group to create the network
+         security group in
+         :type resource_group: ``str``
+ 
+         :param location: The location at which to create the network security
+         group (if None, use default location specified as 'region' in __init__)
+         :type location: :class:`.NodeLocation`
+         """
+ 
+         if location is None and self.default_location:
+             location = self.default_location
+         else:
+             raise ValueError("location is required.")
+ 
+         target = "/subscriptions/%s/resourceGroups/%s/" \
+                  "providers/Microsoft.Network/networkSecurityGroups/%s" \
+                  % (self.subscription_id, resource_group, name)
+         data = {
+             "location": location.id,
+         }
+         self.connection.request(target,
+                                 params={"api-version": "2016-09-01"},
+                                 data=data,
+                                 method='DELETE')
+ 
      def ex_list_networks(self):
          """
          List virtual networks.


Mime
View raw message