Просмотр исходного кода

Fixed adding floating ip to an instance issue

vikramdoda 9 лет назад
Родитель
Сommit
c86b10f85c

+ 1 - 1
cloudbridge/cloud/providers/azure/azure_client.py

@@ -114,7 +114,7 @@ class AzureClient(object):
 
 
     def create_storage_account(self, name, params):
     def create_storage_account(self, name, params):
         return self.storage_client.storage_accounts. \
         return self.storage_client.storage_accounts. \
-            create(self.resource_group, name, params).result()
+            create(self.resource_group, name.lower(), params).result()
 
 
     def list_locations(self):
     def list_locations(self):
         return self.subscription_client.subscriptions. \
         return self.subscription_client.subscriptions. \

+ 54 - 9
cloudbridge/cloud/providers/azure/resources.py

@@ -807,7 +807,7 @@ class AzureMachineImage(BaseMachineImage):
     def min_disk(self):
     def min_disk(self):
         """
         """
         Returns the minimum size of the disk that's required to
         Returns the minimum size of the disk that's required to
-        boot this image (in GB)
+        boot this image (in GB).
 
 
         :rtype: ``int``
         :rtype: ``int``
         :return: The minimum disk size needed by this image
         :return: The minimum disk size needed by this image
@@ -910,6 +910,10 @@ class AzureNetwork(BaseNetwork):
 
 
     @property
     @property
     def cidr_block(self):
     def cidr_block(self):
+        """
+        Address space associated with this network
+        :return:
+        """
         return self._network.address_space.address_prefixes[0]
         return self._network.address_space.address_prefixes[0]
 
 
     def delete(self):
     def delete(self):
@@ -925,9 +929,20 @@ class AzureNetwork(BaseNetwork):
             return False
             return False
 
 
     def subnets(self):
     def subnets(self):
+        """
+        List all the subnets in this network
+        :return:
+        """
         return self._provider.network.subnets.list(network=self.id)
         return self._provider.network.subnets.list(network=self.id)
 
 
     def create_subnet(self, cidr_block, name=None, zone=None):
     def create_subnet(self, cidr_block, name=None, zone=None):
+        """
+        Create the subnet with cidr_block
+        :param cidr_block:
+        :param name:
+        :param zone:
+        :return:
+        """
         return self._provider.network.subnets.\
         return self._provider.network.subnets.\
             create(network=self.id, cidr_block=cidr_block, name=name)
             create(network=self.id, cidr_block=cidr_block, name=name)
 
 
@@ -1076,6 +1091,10 @@ class AzureSubnet(BaseSubnet):
         return self._url_params.get(NETWORK_NAME)
         return self._url_params.get(NETWORK_NAME)
 
 
     def delete(self):
     def delete(self):
+        """
+        Delete the subnet
+        :return:
+        """
         try:
         try:
             self._provider.azure_client.\
             self._provider.azure_client.\
                 delete_subnet(self.network_id,
                 delete_subnet(self.network_id,
@@ -1115,6 +1134,11 @@ class AzureInstance(BaseInstance):
             self._vm.tags = {}
             self._vm.tags = {}
 
 
     def _get_network_attributes(self):
     def _get_network_attributes(self):
+        """
+        This method used identify the public , private ip addresses
+        and security groups associated with network interfaces.
+        :return:
+        """
         self._private_ips = []
         self._private_ips = []
         self._public_ips = []
         self._public_ips = []
         self._security_group_ids = []
         self._security_group_ids = []
@@ -1213,6 +1237,10 @@ class AzureInstance(BaseInstance):
     def terminate(self):
     def terminate(self):
         """
         """
         Permanently terminate this instance.
         Permanently terminate this instance.
+        After deleting the VM. we are deleting the network interface
+        associated to the instance, public ip addresses associated to
+        the instance and also removing OS disk and data disks where
+        tag with name 'delete_on_terminate' has value True.
         """
         """
         self._provider.azure_client.deallocate_vm(self.id)
         self._provider.azure_client.deallocate_vm(self.id)
         self._provider.azure_client.delete_vm(self.id)
         self._provider.azure_client.delete_vm(self.id)
@@ -1264,9 +1292,6 @@ class AzureInstance(BaseInstance):
         """
         """
         Get the security groups associated with this instance.
         Get the security groups associated with this instance.
         """
         """
-        # boto instance.groups field returns a ``Group`` object so need to
-        # convert that into a ``SecurityGroup`` object before creating a
-        # cloudbridge SecurityGroup object
         return [self._provider.security.security_groups.get(group_id)
         return [self._provider.security.security_groups.get(group_id)
                 for group_id in self._security_group_ids]
                 for group_id in self._security_group_ids]
 
 
@@ -1287,6 +1312,8 @@ class AzureInstance(BaseInstance):
     def create_image(self, name, private_key_path=None):
     def create_image(self, name, private_key_path=None):
         """
         """
         Create a new image based on this instance.
         Create a new image based on this instance.
+        Documentation for create image available at
+        https://docs.microsoft.com/en-us/azure/virtual-machines/linux/capture-image  # noqa
         """
         """
 
 
         if not self._state == 'VM generalized':
         if not self._state == 'VM generalized':
@@ -1327,9 +1354,14 @@ class AzureInstance(BaseInstance):
                 sftp.close()
                 sftp.close()
 
 
     def add_floating_ip(self, ip_address):
     def add_floating_ip(self, ip_address):
+        """
+        Attaches public ip to the instance
+        :param ip_address:
+        :return:
+        """
         try:
         try:
             ip_addresses = [ip for ip in
             ip_addresses = [ip for ip in
-                            self._provider.azure_client.list_public_ips()
+                            self._provider.azure_client.list_floating_ips()
                             if ip.ip_address and ip.ip_address == ip_address]
                             if ip.ip_address and ip.ip_address == ip_address]
             if len(ip_addresses) > 0:
             if len(ip_addresses) > 0:
                 """
                 """
@@ -1349,7 +1381,7 @@ class AzureInstance(BaseInstance):
 
 
     def remove_floating_ip(self, ip_address=None):
     def remove_floating_ip(self, ip_address=None):
         """
         """
-        Remove a elastic IP address from this instance.
+        Remove a public IP address from this instance.
         """
         """
         try:
         try:
             nic = self._provider.azure_client.get_nic(self._nic_ids[0])
             nic = self._provider.azure_client.get_nic(self._nic_ids[0])
@@ -1368,7 +1400,7 @@ class AzureInstance(BaseInstance):
         This method adds the security group to VM instance.
         This method adds the security group to VM instance.
         In Azure, security group added to Network interface.
         In Azure, security group added to Network interface.
         Azure supports to add only one security group to
         Azure supports to add only one security group to
-        network interface, we are adding the provided security group 4
+        network interface, we are adding the provided security group
         if not associated any security group to NIC
         if not associated any security group to NIC
         else replacing the existing security group.
         else replacing the existing security group.
         '''
         '''
@@ -1384,6 +1416,19 @@ class AzureInstance(BaseInstance):
         self._provider.azure_client.create_nic(self._nic_ids[0], nic)
         self._provider.azure_client.create_nic(self._nic_ids[0], nic)
 
 
     def remove_security_group(self, sg):
     def remove_security_group(self, sg):
+
+        '''
+                :param sg:
+                :return: None
+
+                This method removes the security group to VM instance.
+                In Azure, security group added to Network interface.
+                Azure supports to add only one security group to
+                network interface, we are removing the provided security group
+                if it associated to NIC
+                else we are ignoring.
+                '''
+
         nic = self._provider.azure_client.get_nic(self._nic_ids[0])
         nic = self._provider.azure_client.get_nic(self._nic_ids[0])
         sg = (self._provicer.security.security_groups.get(sg)
         sg = (self._provicer.security.security_groups.get(sg)
               if isinstance(sg, str) else sg)
               if isinstance(sg, str) else sg)
@@ -1473,8 +1518,8 @@ class AzureInstanceType(BaseInstanceType):
     @property
     @property
     def num_ephemeral_disks(self):
     def num_ephemeral_disks(self):
         """
         """
-        Python sdk does not return num_ephemeral_disks details.
-        In Azure, we cannot explicitly add ephemeral disks.
+        Azure by default add one ephemeral disks. We can not add
+        more ephemeral disks to VM explicitly
         So, we are taking assumption and populating it as Zero.
         So, we are taking assumption and populating it as Zero.
         """
         """
         return 0
         return 0