Bläddra i källkod

initial implementation of the snapshots list method.

madhugilla 9 år sedan
förälder
incheckning
eca2922f3b

+ 12 - 0
azure_test/test_azure_snapshots_service.py

@@ -0,0 +1,12 @@
+import azure_test.helpers as helpers
+from azure_test.helpers import ProviderTestBase
+
+
+class AzureSnapshotsServiceTestCase(ProviderTestBase):
+    @helpers.skipIfNoService(['block_store.snapshots'])
+    def test_azure_snapshots_list(self):
+        snapshot_list = self.provider \
+            .block_store.snapshots.list()
+        print("Snapshot List - " + str(snapshot_list))
+        self.assertTrue(
+            snapshot_list.total_results > 0)

+ 4 - 0
cloudbridge/cloud/providers/azure/azure_client.py

@@ -213,6 +213,10 @@ class AzureClient(object):
 
         return disk_response
 
+    def list_snapshots(self):
+        return self.compute_client.snapshots. \
+            list_by_resource_group(self.resource_group_name)
+
     def update_disk_tags(self, disk_name, tags, region=None):
         disk_result = self.compute_client.disks.update(
             self.resource_group_name,

+ 31 - 2
cloudbridge/cloud/providers/azure/mock_azure_client.py

@@ -1,7 +1,8 @@
 from io import BytesIO
 
 from azure.common import AzureException
-from azure.mgmt.compute.models import CreationData, Disk, DiskCreateOption
+from azure.mgmt.compute.models import CreationData, Disk, DiskCreateOption, \
+    Snapshot
 from azure.mgmt.network.models import NetworkSecurityGroup
 from azure.mgmt.network.models import SecurityRule
 from azure.mgmt.resource.resources.models import ResourceGroup
@@ -102,7 +103,32 @@ class MockAzureClient:
 
     volumes = [volume1, volume2]
 
-    snapshots = []
+    creation_data = CreationData(create_option=DiskCreateOption.empty)
+
+    snapshot1 = Snapshot(location='eastus', creation_data=creation_data)
+    snapshot1.name = 'snapshot1'
+    snapshot1.tags = {'Name': 'snapshot1'}
+    snapshot1.disk_size_gb = 1
+
+    snapshot1.id = '/subscriptions/7904d702-e01c-4826-8519-f5a25c866a96' \
+                   '/resourceGroups/CLOUDBRIDGE-AZURE' \
+                   '/providers/Microsoft.Compute/snapshots/snapshot1'
+    snapshot1.os_type = 'Linux'
+    snapshot1.account_type = 'Premium_LRS'
+
+    snapshot2 = Snapshot(location='eastus', creation_data=creation_data)
+    snapshot2.name = 'snapshot2'
+    snapshot2.tags = {'Name': 'snapshot1'}
+    snapshot2.disk_size_gb = 2
+    snapshot2.creation_data = \
+        CreationData(create_option=DiskCreateOption.empty)
+    snapshot2.id = '/subscriptions/7904d702-e01c-4826-8519-f5a25c866a96' \
+                   '/resourceGroups/CLOUDBRIDGE-AZURE' \
+                   '/providers/Microsoft.Compute/snapshots/snapshot2'
+    snapshot2.os_type = 'Windows'
+    snapshot2.account_type = ' Standard_LRS'
+
+    snapshots = [snapshot1, snapshot2]
 
     def __init__(self, provider):
         self._provider = provider
@@ -271,3 +297,6 @@ class MockAzureClient:
 
     def update_disk_tags(self, disk_name, tags):
         pass
+
+    def list_snapshots(self):
+        return self.snapshots

+ 11 - 5
cloudbridge/cloud/providers/azure/services.py

@@ -6,14 +6,14 @@ from cloudbridge.cloud.base.resources import ClientPagedResultList
 from cloudbridge.cloud.base.services import BaseBlockStoreService, \
     BaseObjectStoreService, BaseSecurityGroupService, \
     BaseSecurityService, BaseSnapshotService, BaseVolumeService
-from cloudbridge.cloud.interfaces.resources import PlacementZone,\
+from cloudbridge.cloud.interfaces.resources import PlacementZone, \
     Snapshot
 from cloudbridge.cloud.providers.azure import helpers as azure_helpers
 
 from msrestazure.azure_exceptions import CloudError
 
-from .resources import AzureBucket, AzureSecurityGroup,\
-    AzureVolume,\
+from .resources import AzureBucket, AzureSecurityGroup, \
+    AzureSnapshot, AzureVolume, \
     NETWORK_SECURITY_GROUP_RESOURCE_ID, SECURITY_GROUP_NAME, \
     VOLUME_NAME, VOLUME_RESOURCE_ID
 
@@ -219,8 +219,14 @@ class AzureSnapshotService(BaseSnapshotService):
                                   'implemented this method')
 
     def list(self, limit=None, marker=None):
-        raise NotImplementedError('AzureSnapShotService not '
-                                  'implemented this method')
+        """
+               List all snapshots.
+        """
+        snaps = [AzureSnapshot(self.provider, obj)
+                 for obj in
+                 self.provider.
+                     azure_client.list_snapshots()]
+        return ClientPagedResultList(self.provider, snaps, limit, marker)
 
     def create(self, name, volume, description=None):
         raise NotImplementedError('AzureSnapShotService not '