Return-Path: X-Original-To: apmail-libcloud-notifications-archive@www.apache.org Delivered-To: apmail-libcloud-notifications-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 4F301173F4 for ; Mon, 6 Apr 2015 10:02:23 +0000 (UTC) Received: (qmail 28937 invoked by uid 500); 6 Apr 2015 10:02:01 -0000 Delivered-To: apmail-libcloud-notifications-archive@libcloud.apache.org Received: (qmail 28873 invoked by uid 500); 6 Apr 2015 10:02:01 -0000 Mailing-List: contact notifications-help@libcloud.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@libcloud.apache.org Delivered-To: mailing list notifications@libcloud.apache.org Received: (qmail 27998 invoked by uid 500); 6 Apr 2015 10:02:00 -0000 Delivered-To: apmail-libcloud-commits@libcloud.apache.org Received: (qmail 27981 invoked by uid 99); 6 Apr 2015 10:02:00 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 06 Apr 2015 10:02:00 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 542C4E1121; Mon, 6 Apr 2015 10:02:00 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: tomaz@apache.org To: commits@libcloud.apache.org Date: Mon, 06 Apr 2015 10:02:21 -0000 Message-Id: In-Reply-To: <76bd2d4896794d33b73e1a07076e5afa@git.apache.org> References: <76bd2d4896794d33b73e1a07076e5afa@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [22/52] [abbrv] libcloud git commit: Fixed an error in listing nodes created from user images. Added support for handling 307 Temp Redirects, rather than just failing Fixed an error in listing nodes created from user images. Added support for handling 307 Temp Redirects, rather than just failing Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/656d43e2 Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/656d43e2 Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/656d43e2 Branch: refs/heads/trunk Commit: 656d43e28d5697f255835029f8ebe3838ea0f5d4 Parents: 6048e2e Author: Michael Bennett Authored: Fri Nov 21 18:23:01 2014 -0500 Committer: Michael Bennett Committed: Fri Nov 21 18:23:01 2014 -0500 ---------------------------------------------------------------------- libcloud/common/azure.py | 12 ++++++++++++ libcloud/compute/drivers/azure.py | 18 +++++++++++++----- libcloud/test/compute/test_azure.py | 21 +++++++++++++++++++-- 3 files changed, 44 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/libcloud/blob/656d43e2/libcloud/common/azure.py ---------------------------------------------------------------------- diff --git a/libcloud/common/azure.py b/libcloud/common/azure.py index e76097c..727046e 100644 --- a/libcloud/common/azure.py +++ b/libcloud/common/azure.py @@ -41,6 +41,12 @@ API_VERSION = '2012-02-12' AZURE_TIME_FORMAT = '%a, %d %b %Y %H:%M:%S GMT' +class AzureRedirectException(Exception): + + def __init__(self, response): + self.location = response.headers['location'] + + class AzureResponse(XmlResponse): valid_response_codes = [ @@ -84,6 +90,12 @@ class AzureResponse(XmlResponse): driver=self ) + def parse_body(self): + if int(self.status) == httplib.TEMPORARY_REDIRECT and self.connection.driver.follow_redirects: + raise AzureRedirectException(self) + else: + return super(AzureResponse, self).parse_body() + class AzureRawResponse(RawResponse): pass http://git-wip-us.apache.org/repos/asf/libcloud/blob/656d43e2/libcloud/compute/drivers/azure.py ---------------------------------------------------------------------- diff --git a/libcloud/compute/drivers/azure.py b/libcloud/compute/drivers/azure.py index a25ee70..25e8e54 100644 --- a/libcloud/compute/drivers/azure.py +++ b/libcloud/compute/drivers/azure.py @@ -27,7 +27,7 @@ import base64 from libcloud.utils.py3 import urlquote as url_quote from libcloud.utils.py3 import urlunquote as url_unquote -from libcloud.common.azure import AzureServiceManagementConnection +from libcloud.common.azure import AzureServiceManagementConnection, AzureRedirectException from libcloud.compute.providers import Provider from libcloud.compute.base import Node, NodeDriver, NodeLocation, NodeSize from libcloud.compute.base import NodeImage, StorageVolume @@ -210,6 +210,7 @@ class AzureNodeDriver(NodeDriver): """ self.subscription_id = subscription_id self.key_file = key_file + self.follow_redirects = kwargs.get('follow_redirects', True) super(AzureNodeDriver, self).__init__( self.subscription_id, self.key_file, @@ -293,7 +294,7 @@ class AzureNodeDriver(NodeDriver): vips = None - if data.deployments[0].virtual_ips is not None: + if len(data.deployments) > 0 and data.deployments[0].virtual_ips is not None: vips = [vip.address for vip in data.deployments[0].virtual_ips] try: @@ -1233,11 +1234,18 @@ class AzureNodeDriver(NodeDriver): try: return self.connection.request( action="https://%s%s" % (request.host, request.path), - data=request.body, headers=request.headers, + data=request.body, + headers=request.headers, method=request.method ) + except AzureRedirectException as e: + from libcloud.utils.py3 import urlparse + parsed_url = urlparse.urlparse(e.location) + request.host = parsed_url.netloc + return self._perform_request(request) except Exception, e: - print e.message + import traceback + print "Exception performing request: {}".format(traceback.format_exc()) def _update_request_uri_query(self, request): """ @@ -2404,13 +2412,13 @@ class AzureXmlSerializer(object): return xml - """ Data Classes Borrowed from the Azure SDK for Python. """ + class WindowsAzureData(object): """ http://git-wip-us.apache.org/repos/asf/libcloud/blob/656d43e2/libcloud/test/compute/test_azure.py ---------------------------------------------------------------------- diff --git a/libcloud/test/compute/test_azure.py b/libcloud/test/compute/test_azure.py index 2f33570..0538604 100644 --- a/libcloud/test/compute/test_azure.py +++ b/libcloud/test/compute/test_azure.py @@ -1,6 +1,7 @@ import libcloud from libcloud.common.types import LibcloudError from libcloud.compute.base import NodeAuthPassword, NodeImage, NodeSize +from libcloud.compute.drivers.azure import azure_service_management_host from libcloud.common.azure import AzureServiceManagementConnection __author__ = 'david' @@ -506,8 +507,24 @@ class AzureMockHttp(MockHttp): return (httplib.OK, body, headers, httplib.responses[httplib.OK]) def _3761b98b_673d_526c_8d55_fee918758e6e_services_hostedservices_testdcabc3_deployments_dcoddkinztest02_roles(self, method, url, body, headers): - - return (httplib.TEMPORARY_REDIRECT, None, headers, httplib.responses[httplib.TEMPORARY_REDIRECT]) + redirect_host = "ussouth.management.core.windows.net" + + if not getattr(AzureMockHttp, "in_redirect", False): + setattr(AzureMockHttp, "in_redirect", True) + headers["Location"] = url.replace(azure_service_management_host, redirect_host) + return (httplib.TEMPORARY_REDIRECT, None, headers, httplib.responses[httplib.TEMPORARY_REDIRECT]) + else: + delattr(AzureMockHttp, "in_redirect") + if redirect_host not in url: + if azure_service_management_host in url: + return (httplib.TEMPORARY_REDIRECT, None, headers, httplib.responses[httplib.TEMPORARY_REDIRECT]) + else: + return (httplib.REQUEST_TIMEOUT, None, None, httplib.responses[httplib.REQUEST_TIMEOUT]) + + if method == "GET": + body = self.fixtures.load('_3761b98b_673d_526c_8d55_fee918758e6e_services_hostedservices_testdcabc2.xml') + + return (httplib.OK, body, headers, httplib.responses[httplib.OK]) def _3761b98b_673d_526c_8d55_fee918758e6e_operations_acc33f6756cda6fd96826394fce4c9f3(self, method, url, body, headers):