|
@@ -5,8 +5,10 @@ from azure.common import AzureException
|
|
|
|
|
|
|
|
from cloudbridge.cloud.base.resources import ClientPagedResultList
|
|
from cloudbridge.cloud.base.resources import ClientPagedResultList
|
|
|
from cloudbridge.cloud.base.services import BaseBlockStoreService, \
|
|
from cloudbridge.cloud.base.services import BaseBlockStoreService, \
|
|
|
- BaseComputeService, BaseImageService, BaseNetworkService, \
|
|
|
|
|
- BaseObjectStoreService, BaseRegionService, BaseSecurityGroupService, \
|
|
|
|
|
|
|
+ BaseComputeService, BaseImageService, \
|
|
|
|
|
+ BaseInstanceTypesService, BaseNetworkService, \
|
|
|
|
|
+ BaseObjectStoreService, BaseRegionService, \
|
|
|
|
|
+ BaseSecurityGroupService, \
|
|
|
BaseSecurityService, BaseSnapshotService, BaseVolumeService
|
|
BaseSecurityService, BaseSnapshotService, BaseVolumeService
|
|
|
from cloudbridge.cloud.interfaces.resources import PlacementZone, \
|
|
from cloudbridge.cloud.interfaces.resources import PlacementZone, \
|
|
|
Snapshot, Volume
|
|
Snapshot, Volume
|
|
@@ -14,8 +16,10 @@ from cloudbridge.cloud.providers.azure import helpers as azure_helpers
|
|
|
|
|
|
|
|
from msrestazure.azure_exceptions import CloudError
|
|
from msrestazure.azure_exceptions import CloudError
|
|
|
|
|
|
|
|
-from .resources import AzureBucket, AzureMachineImage, \
|
|
|
|
|
- AzureNetwork, AzureRegion, AzureSecurityGroup, \
|
|
|
|
|
|
|
+from .resources import AzureBucket, \
|
|
|
|
|
+ AzureInstanceType, AzureMachineImage, \
|
|
|
|
|
+ AzureNetwork, AzureRegion, \
|
|
|
|
|
+ AzureSecurityGroup, \
|
|
|
AzureSnapshot, AzureVolume, \
|
|
AzureSnapshot, AzureVolume, \
|
|
|
IMAGE_NAME, IMAGE_RESOURCE_ID, \
|
|
IMAGE_NAME, IMAGE_RESOURCE_ID, \
|
|
|
NETWORK_NAME, NETWORK_RESOURCE_ID, \
|
|
NETWORK_NAME, NETWORK_RESOURCE_ID, \
|
|
@@ -301,7 +305,7 @@ class AzureSnapshotService(BaseSnapshotService):
|
|
|
class AzureComputeService(BaseComputeService):
|
|
class AzureComputeService(BaseComputeService):
|
|
|
def __init__(self, provider):
|
|
def __init__(self, provider):
|
|
|
super(AzureComputeService, self).__init__(provider)
|
|
super(AzureComputeService, self).__init__(provider)
|
|
|
- # self._instance_type_svc = AzureInstanceTypesService(self.provider)
|
|
|
|
|
|
|
+ self._instance_type_svc = AzureInstanceTypesService(self.provider)
|
|
|
# self._instance_svc = AzureInstanceService(self.provider)
|
|
# self._instance_svc = AzureInstanceService(self.provider)
|
|
|
self._region_svc = AzureRegionService(self.provider)
|
|
self._region_svc = AzureRegionService(self.provider)
|
|
|
self._images_svc = AzureImageService(self.provider)
|
|
self._images_svc = AzureImageService(self.provider)
|
|
@@ -312,8 +316,7 @@ class AzureComputeService(BaseComputeService):
|
|
|
|
|
|
|
|
@property
|
|
@property
|
|
|
def instance_types(self):
|
|
def instance_types(self):
|
|
|
- raise NotImplementedError('AzureComputeService not '
|
|
|
|
|
- 'implemented this method')
|
|
|
|
|
|
|
+ return self._instance_type_svc
|
|
|
|
|
|
|
|
@property
|
|
@property
|
|
|
def instances(self):
|
|
def instances(self):
|
|
@@ -359,6 +362,26 @@ class AzureImageService(BaseImageService):
|
|
|
limit=limit, marker=marker)
|
|
limit=limit, marker=marker)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+class AzureInstanceTypesService(BaseInstanceTypesService):
|
|
|
|
|
+
|
|
|
|
|
+ def __init__(self, provider):
|
|
|
|
|
+ super(AzureInstanceTypesService, self).__init__(provider)
|
|
|
|
|
+
|
|
|
|
|
+ @property
|
|
|
|
|
+ def instance_data(self):
|
|
|
|
|
+ """
|
|
|
|
|
+ Fetch info about the available instances.
|
|
|
|
|
+ """
|
|
|
|
|
+ r = self.provider.azure_client.list_instance_types()
|
|
|
|
|
+ return r
|
|
|
|
|
+
|
|
|
|
|
+ def list(self, limit=None, marker=None):
|
|
|
|
|
+ inst_types = [AzureInstanceType(self.provider, inst_type)
|
|
|
|
|
+ for inst_type in self.instance_data]
|
|
|
|
|
+ return ClientPagedResultList(self.provider, inst_types,
|
|
|
|
|
+ limit=limit, marker=marker)
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
class AzureNetworkService(BaseNetworkService):
|
|
class AzureNetworkService(BaseNetworkService):
|
|
|
def __init__(self, provider):
|
|
def __init__(self, provider):
|
|
|
super(AzureNetworkService, self).__init__(provider)
|
|
super(AzureNetworkService, self).__init__(provider)
|
|
@@ -422,6 +445,18 @@ class AzureNetworkService(BaseNetworkService):
|
|
|
raise NotImplementedError('AzureNetworkService '
|
|
raise NotImplementedError('AzureNetworkService '
|
|
|
'not implemented this method')
|
|
'not implemented this method')
|
|
|
|
|
|
|
|
|
|
+ def delete(self, network_id):
|
|
|
|
|
+ """
|
|
|
|
|
+ Delete an existing network.
|
|
|
|
|
+ """
|
|
|
|
|
+ try:
|
|
|
|
|
+ params = azure_helpers.parse_url(NETWORK_RESOURCE_ID, network_id)
|
|
|
|
|
+ network = self.provider.azure_client. \
|
|
|
|
|
+ delete_network(params.get(NETWORK_NAME))
|
|
|
|
|
+ return True if network else False
|
|
|
|
|
+ except CloudError as cloudError:
|
|
|
|
|
+ log.exception(cloudError.message)
|
|
|
|
|
+ return False
|
|
|
|
|
|
|
|
class AzureRegionService(BaseRegionService):
|
|
class AzureRegionService(BaseRegionService):
|
|
|
def __init__(self, provider):
|
|
def __init__(self, provider):
|
|
@@ -453,3 +488,4 @@ class AzureRegionService(BaseRegionService):
|
|
|
region = AzureRegion(self.provider, azureRegion)
|
|
region = AzureRegion(self.provider, azureRegion)
|
|
|
break
|
|
break
|
|
|
return region
|
|
return region
|
|
|
|
|
+
|