From 68e73e61944f002ef6f17dbedca72f226f907f9f Mon Sep 17 00:00:00 2001 From: bhangare Date: Tue, 4 Jul 2017 22:44:01 -0700 Subject: [PATCH] Changes in vimconn_vmware.py: Code cleanup & addressed minor issue in exception handling Change-Id: I44908e9c0157f36350db7672d53fb9126997e9a4 Signed-off-by: bhangare --- osm_ro/vimconn_vmware.py | 36 ++++++++++++++++-------------------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/osm_ro/vimconn_vmware.py b/osm_ro/vimconn_vmware.py index 257a813c..d8ca463f 100644 --- a/osm_ro/vimconn_vmware.py +++ b/osm_ro/vimconn_vmware.py @@ -1314,6 +1314,7 @@ class vimconnector(vimconn.vimconnector): vm_cpus = None vm_memory = None vm_disk = None + numas = None if flavor_id is not None: if flavor_id not in vimconnector.flavorlist: @@ -1366,16 +1367,7 @@ class vimconnector(vimconn.vimconnector): # use: 'data', 'bridge', 'mgmt' # create vApp. Set vcpu and ram based on flavor id. try: - vapptask = self.vca.create_vapp(self.tenant_name, vmname_andid, templateName, - self.get_catalogbyid(image_id, catalogs), - network_name=None, # None while creating vapp - network_mode=network_mode, - vm_name=vmname_andid, - vm_cpus=vm_cpus, # can be None if flavor is None - vm_memory=vm_memory) # can be None if flavor is None - - if vapptask is None or vapptask is False: - self.get_token() # Retry getting token + for retry in (1,2): vapptask = self.vca.create_vapp(self.tenant_name, vmname_andid, templateName, self.get_catalogbyid(image_id, catalogs), network_name=None, # None while creating vapp @@ -1384,6 +1376,12 @@ class vimconnector(vimconn.vimconnector): vm_cpus=vm_cpus, # can be None if flavor is None vm_memory=vm_memory) # can be None if flavor is None + if not vapptask and retry==1: + self.get_token() # Retry getting token + continue + else: + break + if vapptask is None or vapptask is False: raise vimconn.vimconnUnexpectedResponse( "new_vminstance(): failed to create vApp {}".format(vmname_andid)) @@ -4983,24 +4981,22 @@ class vimconnector(vimconn.vimconnector): log=False) result = vca.login(password=self.passwd, org=self.org_name) - if not result: - raise vimconn.vimconnConnectionException("Can't connect to a vCloud director as: {}".format(self.user)) - - result = vca.login(token=vca.token, org=self.org_name, org_url=vca.vcloud_session.org_url) if result is True: - self.logger.info( - "Successfully generated token for vcloud direct org: {} as user: {}".format(self.org_name, self.user)) + result = vca.login(token=vca.token, org=self.org_name, org_url=vca.vcloud_session.org_url) + if result is True: + self.logger.info( + "Successfully generated token for vcloud direct org: {} as user: {}".format(self.org_name, self.user)) + #Update vca + self.vca = vca + return except: raise vimconn.vimconnConnectionException("Can't connect to a vCloud director org: " "{} as user: {}".format(self.org_name, self.user)) - if not vca: + if not vca or not result: raise vimconn.vimconnConnectionException("self.connect() is failed while reconnecting") - #Update vca - self.vca = vca - def get_vdc_details(self): """ Get VDC details using pyVcloud Lib -- 2.25.1