You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by to...@apache.org on 2015/08/03 19:41:09 UTC
libcloud git commit: Added storage service create and delete methods
to Azure driver
Repository: libcloud
Updated Branches:
refs/heads/trunk 7a4164612 -> 733ea2f52
Added storage service create and delete methods to Azure driver
Closes #551
Signed-off-by: Tomaz Muraus <to...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/733ea2f5
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/733ea2f5
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/733ea2f5
Branch: refs/heads/trunk
Commit: 733ea2f52391537e719778c294eb71f764214b56
Parents: 7a41646
Author: dwilson2038 <da...@gmail.com>
Authored: Mon Jul 20 20:25:03 2015 +0000
Committer: Tomaz Muraus <to...@apache.org>
Committed: Mon Aug 3 19:33:50 2015 +0200
----------------------------------------------------------------------
CHANGES.rst | 5 +
libcloud/compute/drivers/azure.py | 120 ++++++++++++++++++-
...18758e6e_services_storageservices_dss123.xml | 1 +
libcloud/test/compute/test_azure.py | 35 ++++++
4 files changed, 158 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/libcloud/blob/733ea2f5/CHANGES.rst
----------------------------------------------------------------------
diff --git a/CHANGES.rst b/CHANGES.rst
index 6c68097..96509b0 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -253,6 +253,11 @@ Compute
(LIBCLOUD-726, GITHUB-554)
[David Wilson]
+- Add ``ex_create_cloud_service`` and ``ex_destroy_cloud_service`` method to the
+ Azure driver.
+ (LIBCLOUD-724, GITHUB-551)
+ [David Wilson]
+
Storage
~~~~~~~
http://git-wip-us.apache.org/repos/asf/libcloud/blob/733ea2f5/libcloud/compute/drivers/azure.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/azure.py b/libcloud/compute/drivers/azure.py
index 6981630..b392552 100644
--- a/libcloud/compute/drivers/azure.py
+++ b/libcloud/compute/drivers/azure.py
@@ -913,7 +913,6 @@ class AzureNodeDriver(NodeDriver):
:rtype: ``bool``
"""
- # TODO: add check to ensure all nodes have been deleted
response = self._perform_cloud_service_delete(
self._get_hosted_service_path(name)
)
@@ -995,6 +994,67 @@ class AzureNodeDriver(NodeDriver):
self.raise_for_response(response, 202)
+ def ex_create_storage_service(self, name, location,
+ description=None, affinity_group=None,
+ extended_properties=None):
+ """
+ Create an azure storage service.
+
+ :param name: Name of the service to create
+ :type name: ``str``
+
+ :param location: Standard azure location string
+ :type location: ``str``
+
+ :param description: (Optional) Description of storage service.
+ :type description: ``str``
+
+ :param affinity_group: (Optional) Azure affinity group.
+ :type affinity_group: ``str``
+
+ :param extended_properties: (Optional) Additional configuration
+ options support by Azure.
+ :type extended_properties: ``dict``
+
+ :rtype: ``bool``
+ """
+
+ response = self._perform_storage_service_create(
+ self._get_storage_service_path(),
+ AzureXmlSerializer.create_storage_service_to_xml(
+ service_name=name,
+ label=self._encode_base64(name),
+ description=description,
+ location=location,
+ affinity_group=affinity_group,
+ extended_properties=extended_properties
+ )
+ )
+
+ self.raise_for_response(response, 202)
+
+ return True
+
+ def ex_destroy_storage_service(self, name):
+ """
+ Destroy storage service. Storage service must not have any active
+ blobs. Sometimes Azure likes to hold onto volumes after they are
+ deleted for an inordinate amount of time, so sleep before calling
+ this method after volume deletion.
+
+ :param name: Name of storage service.
+ :type name: ``str``
+
+ :rtype: ``bool``
+ """
+
+ response = self._perform_storage_service_delete(
+ self._get_storage_service_path(name)
+ )
+ self.raise_for_response(response, 200)
+
+ return True
+
"""
Functions not implemented
"""
@@ -1056,6 +1116,29 @@ class AzureNodeDriver(NodeDriver):
return response
+ def _perform_storage_service_create(self, path, data):
+ request = AzureHTTPRequest()
+ request.method = 'POST'
+ request.host = AZURE_SERVICE_MANAGEMENT_HOST
+ request.path = path
+ request.body = data
+ request.path, request.query = self._update_request_uri_query(request)
+ request.headers = self._update_management_header(request)
+ response = self._perform_request(request)
+
+ return response
+
+ def _perform_storage_service_delete(self, path):
+ request = AzureHTTPRequest()
+ request.method = 'DELETE'
+ request.host = AZURE_SERVICE_MANAGEMENT_HOST
+ request.path = path
+ request.path, request.query = self._update_request_uri_query(request)
+ request.headers = self._update_management_header(request)
+ response = self._perform_request(request)
+
+ return response
+
def _to_node(self, data, ex_cloud_service_name=None, virtual_ips=None):
"""
Convert the data from a Azure response object into a Node
@@ -1916,8 +1999,20 @@ class AzureXmlSerializer(object):
label,
description,
location,
- affinity_group,
- extended_properties):
+ affinity_group=None,
+ extended_properties=None):
+ if affinity_group:
+ return AzureXmlSerializer.doc_from_data(
+ 'CreateHostedService',
+ [
+ ('ServiceName', service_name),
+ ('Label', label),
+ ('Description', description),
+ ('AffinityGroup', affinity_group),
+ ],
+ extended_properties
+ )
+
return AzureXmlSerializer.doc_from_data(
'CreateHostedService',
[
@@ -1925,6 +2020,25 @@ class AzureXmlSerializer(object):
('Label', label),
('Description', description),
('Location', location),
+ ],
+ extended_properties
+ )
+
+ @staticmethod
+ def create_storage_service_to_xml(service_name,
+ label,
+ description,
+ location,
+ affinity_group,
+ extended_properties=None):
+
+ return AzureXmlSerializer.doc_from_data(
+ 'CreateStorageServiceInput',
+ [
+ ('ServiceName', service_name),
+ ('Label', label),
+ ('Description', description),
+ ('Location', location),
('AffinityGroup', affinity_group)
],
extended_properties
http://git-wip-us.apache.org/repos/asf/libcloud/blob/733ea2f5/libcloud/test/compute/fixtures/azure/_3761b98b_673d_526c_8d55_fee918758e6e_services_storageservices_dss123.xml
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/fixtures/azure/_3761b98b_673d_526c_8d55_fee918758e6e_services_storageservices_dss123.xml b/libcloud/test/compute/fixtures/azure/_3761b98b_673d_526c_8d55_fee918758e6e_services_storageservices_dss123.xml
new file mode 100644
index 0000000..8820706
--- /dev/null
+++ b/libcloud/test/compute/fixtures/azure/_3761b98b_673d_526c_8d55_fee918758e6e_services_storageservices_dss123.xml
@@ -0,0 +1 @@
+<Error xmlns="http://schemas.microsoft.com/windowsazure" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"><Code>ResourceNotFound</Code><Message>The storage account \'dss123\' was not found.</Message></Error>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/libcloud/blob/733ea2f5/libcloud/test/compute/test_azure.py
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/test_azure.py b/libcloud/test/compute/test_azure.py
index ca293b9..dc72fc3 100644
--- a/libcloud/test/compute/test_azure.py
+++ b/libcloud/test/compute/test_azure.py
@@ -294,6 +294,25 @@ class AzureNodeDriverTests(LibcloudTestCase):
with self.assertRaises(LibcloudError):
self.driver.ex_destroy_cloud_service(name="testdc1234")
+ def test_ex_create_storage_service(self):
+ result = self.driver.ex_create_storage_service(name="testdss123", location="East US")
+ self.assertTrue(result)
+
+ def test_ex_create_storage_service_service_exists(self):
+ with self.assertRaises(LibcloudError):
+ self.driver.ex_create_storage_service(
+ name="dss123",
+ location="East US"
+ )
+
+ def test_ex_destroy_storage_service(self):
+ result = self.driver.ex_destroy_storage_service(name="testdss123")
+ self.assertTrue(result)
+
+ def test_ex_destroy_storage_service_service_does_not_exist(self):
+ with self.assertRaises(LibcloudError):
+ self.driver.ex_destroy_storage_service(name="dss123")
+
def test_create_node_and_deployment_one_node(self):
kwargs = {
"ex_storage_service_name": "mtlytics",
@@ -508,6 +527,22 @@ class AzureMockHttp(MockHttp):
def _3761b98b_673d_526c_8d55_fee918758e6e_services_hostedservices_testdc123(self, method, url, body, headers):
return (httplib.OK, body, headers, httplib.responses[httplib.OK])
+ def _3761b98b_673d_526c_8d55_fee918758e6e_services_storageservices(self, method, url, body, headers):
+ # request url is the same irrespective of serviceName, only way to differentiate
+ if "<ServiceName>testdss123</ServiceName>" in body:
+ return (httplib.ACCEPTED, body, headers, httplib.responses[httplib.ACCEPTED])
+ elif "<ServiceName>dss123</ServiceName>" in body:
+ return (httplib.CONFLICT, body, headers, httplib.responses[httplib.CONFLICT])
+
+ def _3761b98b_673d_526c_8d55_fee918758e6e_services_storageservices_testdss123(self, method, url, body, headers):
+ return (httplib.OK, body, headers, httplib.responses[httplib.OK])
+
+ def _3761b98b_673d_526c_8d55_fee918758e6e_services_storageservices_dss123(self, method, url, body, headers):
+ if method == "GET":
+ body = self.fixtures.load('_3761b98b_673d_526c_8d55_fee918758e6e_services_storageservices_dss123.xml')
+
+ return (httplib.NOT_FOUND, body, headers, httplib.responses[httplib.NOT_FOUND])
+
def _3761b98b_673d_526c_8d55_fee918758e6e_services_hostedservices_testdc1234(self, method, url, body, headers):
if method == "GET":
body = self.fixtures.load('_3761b98b_673d_526c_8d55_fee918758e6e_services_hostedservices_testdc1234.xml')