3030from libcloud .compute .types import NodeState
3131
3232import threading
33+ import traceback
3334
3435catalogs = threading .local ()
3536
@@ -627,6 +628,8 @@ def vmcreate(self, obj_attr_list) :
627628 cbwarn ("Error during reservation creation: " + _fmsg )
628629
629630 except Exception , e :
631+ for line in traceback .format_exc ().splitlines () :
632+ cbwarn (line , True )
630633 _status = 23
631634 _fmsg = str (e )
632635 cbwarn ("Error reaching digitalocean: " + _fmsg )
@@ -642,7 +645,7 @@ def vmcreate(self, obj_attr_list) :
642645 cberr (_msg )
643646
644647 if "cloud_vm_uuid" in obj_attr_list :
645- obj_attr_list ["mgt_deprovisioning_request_originated " ] = int (time ())
648+ obj_attr_list ["mgt_901_deprovisioning_request_originated " ] = int (time ())
646649 self .vmdestroy (obj_attr_list )
647650 else :
648651 if _reservation :
@@ -662,14 +665,8 @@ def vmdestroy(self, obj_attr_list) :
662665 _status = 100
663666 _fmsg = "An error has occurred, but no error message was captured"
664667
665- _time_mark_drs = int (time ())
666668 _wait = int (obj_attr_list ["update_frequency" ])
667669
668- if "mgt_901_deprovisioning_request_originated" not in obj_attr_list :
669- obj_attr_list ["mgt_901_deprovisioning_request_originated" ] = _time_mark_drs
670-
671- obj_attr_list ["mgt_902_deprovisioning_request_sent" ] = _time_mark_drs - int (obj_attr_list ["mgt_901_deprovisioning_request_originated" ])
672-
673670 cbdebug ("Last known state: " + str (obj_attr_list ["last_known_state" ]))
674671
675672 _wait = int (obj_attr_list ["update_frequency" ])
@@ -683,12 +680,17 @@ def vmdestroy(self, obj_attr_list) :
683680 _msg += "...."
684681 cbdebug (_msg , True )
685682
683+ firsttime = True
684+ _time_mark_drs = int (time ())
686685 while True :
687686 _errmsg = "get_vm_instance"
688687 cbdebug ("Getting instance..." )
689688 _instance = self .get_vm_instance (obj_attr_list )
690689 if not _instance :
691690 cbdebug ("Breaking..." )
691+ if firsttime :
692+ if "mgt_901_deprovisioning_request_originated" not in obj_attr_list :
693+ obj_attr_list ["mgt_901_deprovisioning_request_originated" ] = _time_mark_drs
692694 break
693695
694696 if _instance .state == NodeState .PENDING :
@@ -701,7 +703,16 @@ def vmdestroy(self, obj_attr_list) :
701703 continue
702704
703705 try :
706+ if firsttime :
707+ if "mgt_901_deprovisioning_request_originated" not in obj_attr_list :
708+ obj_attr_list ["mgt_901_deprovisioning_request_originated" ] = _time_mark_drs
709+
704710 result = _instance .destroy ()
711+
712+ if firsttime :
713+ obj_attr_list ["mgt_902_deprovisioning_request_sent" ] = int (time ()) - int (obj_attr_list ["mgt_901_deprovisioning_request_originated" ])
714+
715+ firsttime = False
705716 except :
706717 pass
707718
@@ -740,6 +751,8 @@ def vmdestroy(self, obj_attr_list) :
740751 cberr ("CldOpsException: " + str (obj ), True )
741752
742753 except Exception , e :
754+ for line in traceback .format_exc ().splitlines () :
755+ cbwarn (line , True )
743756 _status = 23
744757 _fmsg = str (e )
745758 cberr ("Exception: " + str (e ), True )
@@ -961,6 +974,9 @@ def aidefine(self, obj_attr_list, current_step) :
961974 self .osci .pending_object_set (obj_attr_list ["cloud_name" ], "AI" , \
962975 obj_attr_list ["uuid" ], "credential_pair" , credentials_pair )
963976
977+ # Cache libcloud objects for this daemon / process before the VMs are attached
978+ self .connect (credentials_pair )
979+
964980 _fmsg = "An error has occurred, but no error message was captured"
965981
966982 self .take_action_if_requested ("AI" , obj_attr_list , current_step )
0 commit comments