X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=osm_ro%2Fvim_thread.py;h=1fba7a60fc573418f37cd8a6a6c050f960481203;hb=9c22f2db0d5da6fbed6fc54c01a338c799823cd6;hp=bbb81a587bf3ada15a4884a461c89baa508e665d;hpb=ed85457dd43e9a092a8766a65e47540419b1bd7f;p=osm%2FRO.git diff --git a/osm_ro/vim_thread.py b/osm_ro/vim_thread.py index bbb81a58..1fba7a60 100644 --- a/osm_ro/vim_thread.py +++ b/osm_ro/vim_thread.py @@ -82,7 +82,7 @@ class vim_thread(threading.Thread): REFRESH_BUILD = 5 # 5 seconds REFRESH_ACTIVE = 60 # 1 minute - def __init__(self, vimconn, task_lock, name=None, datacenter_name=None, datacenter_tenant_id=None, + def __init__(self, myvimconn, task_lock, name=None, datacenter_name=None, datacenter_tenant_id=None, db=None, db_lock=None, ovim=None): """Init a thread. Arguments: @@ -92,7 +92,12 @@ class vim_thread(threading.Thread): 'db', 'db_lock': database class and lock to use it in exclusion """ threading.Thread.__init__(self) - self.vim = vimconn + if isinstance(myvimconn, vimconn.vimconnException): + self.vim = None + self.error_status = "Error accesing to VIM: {}".format(myvimconn) + else: + self.vim = myvimconn + self.error_status = None self.datacenter_name = datacenter_name self.datacenter_tenant_id = datacenter_tenant_id self.ovim = ovim @@ -365,6 +370,8 @@ class vim_thread(threading.Thread): """Insert a task at list of refreshing elements. The refreshing list is ordered by threshold_time (task['modified_at'] It is assumed that this is called inside this thread """ + if not self.vim: + return if not threshold_time: threshold_time = time.time() task["modified_at"] = threshold_time @@ -407,6 +414,11 @@ class vim_thread(threading.Thread): # not needed to do anything but update database with the new status result = True database_update = None + elif not self.vim: + task["status"] == "ERROR" + task["error_msg"] = self.error_status + result = False + database_update = {"status": "VIM_ERROR", "error_msg": task["error_msg"]} elif task["item"] == 'instance_vms': if task["action"] == "CREATE": result, database_update = self.new_vm(task)