diff --git a/VMBackup/main/HttpUtil.py b/VMBackup/main/HttpUtil.py index d27fc9c25..6117d1ba2 100644 --- a/VMBackup/main/HttpUtil.py +++ b/VMBackup/main/HttpUtil.py @@ -29,6 +29,7 @@ from common import CommonVariables from subprocess import * from Utils.WAAgentUtil import waagent +from parameterparser import ParameterParser import Utils.HandlerUtil import sys @@ -113,7 +114,7 @@ def Call(self, method, sasuri_obj, data, headers, fallback_to_curl = False): else: return CommonVariables.error_http_failure - def HttpCallGetResponse(self, method, sasuri_obj, data, headers , responseBodyRequired = False, isHostCall = False): + def HttpCallGetResponse(self, method, sasuri_obj, data, headers, responseBodyRequired = False, isHostCall = False): result = CommonVariables.error_http_failure resp = None responeBody = "" @@ -127,7 +128,13 @@ def HttpCallGetResponse(self, method, sasuri_obj, data, headers , responseBodyRe if(isHostCall): connection = httplibs.HTTPConnection(sasuri_obj.hostname, timeout = 40) # making call with port 80 to make it http call else: - connection = httplibs.HTTPSConnection(sasuri_obj.hostname, timeout = 10) + port_info = ParameterParser.port() + if(port_info != None): + # TTL is enabled, routing to a 8443 port + connection = httplibs.HTTPSConnection(sasuri_obj.hostname, port = port_info, timeout = 10) + else: + self.logger.log("Routing to a default port") + connection = httplibs.HTTPSConnection(sasuri_obj.hostname, timeout = 10) self.logger.log("Details of sas uri object hostname: " + str(sasuri_obj.hostname) + " path: " + str(sasuri_obj.path)) connection.request(method=method, url=(sasuri_obj.path + '?' + sasuri_obj.query), body=data, headers = headers) resp = connection.getresponse() diff --git a/VMBackup/main/parameterparser.py b/VMBackup/main/parameterparser.py index b4e0d001a..b1562a767 100644 --- a/VMBackup/main/parameterparser.py +++ b/VMBackup/main/parameterparser.py @@ -16,12 +16,14 @@ # See the License for the specific language governing permissions and # limitations under the License. +from pickle import NONE from common import CommonVariables import base64 import json import sys class ParameterParser(object): + port = None def __init__(self, protected_settings, public_settings, backup_logger): """ TODO: we should validate the parameter first @@ -125,4 +127,23 @@ def __init__(self, protected_settings, public_settings, backup_logger): except Exception as e: errorMsg = "Exception occurred while populating settings, Exception: %s" % (str(e)) backup_logger.log(errorMsg, True) - backup_logger.log("settings to be sent " + str(self.wellKnownSettingFlags), True) \ No newline at end of file + backup_logger.log("settings to be sent " + str(self.wellKnownSettingFlags), True) + + + createdByKey = "createdby" + createdByValue = "CRP" + if(self.backup_metadata != None): + try: + backup_logger.log("metadata received " + str(self.backup_metadata), True) + for data in self.backup_metadata: + if CommonVariables.key in data and CommonVariables.value in data: + data_key = data[CommonVariables.key].lower() + if(data_key == createdByKey): + data_value = data[CommonVariables.value].upper() + if(data_value == createdByValue): + backup_logger.log("it is a managed vm and request is being routed to Xstore's native path") + ParameterParser.port = 8443 + break + except Exception as e: + errorMsg = "Exception occurred while populating metadata, Exception: %s" % (str(e)) + backup_logger.log(errorMsg, True) \ No newline at end of file