def __contextualize_vm(self, vm, ip): # SSH keys for users are passed to the VM right after it is started vm_keys = VirtualMachineKeys.objects.filter(slice_uuid=vm.sliceId, project_uuid=vm.projectId) params = { "vm_address": str(ip) , "vm_user": "******", "vm_password": "******", } vm_context = VMContextualize(**params) try: user_keys = {} for vm_key in vm_keys: user_name = str(vm_key.get_user_name()) if user_name not in user_keys: user_keys[user_name] = [ vm_key.get_ssh_key() ] else: user_keys[user_name].append(vm_key.get_ssh_key()) logging.debug("Adding %s's public key(s) into VM. Key contents: %s" % (vm_key.get_user_name(), user_keys[str(vm_key.get_user_name())])) # Placing a number of keys per user, multiple users if len(user_keys) > 0: with self.__mutex_process: # FIXME Sometimes do not work properly and keys are not getting to the VM ServiceProcess.startMethodInNewProcess(vm_context.contextualize_add_pub_keys, [user_keys], self.__agent_callback_url) except Exception as e: raise e
def __contextualize_vm(self, vm, ip): # SSH keys for users are passed to the VM right after it is started vm_keys = VirtualMachineKeys.objects.filter(slice_uuid=vm.sliceId, project_uuid=vm.projectId) params = { "vm_address": str(ip), "vm_user": "******", "vm_password": "******", } vm_context = VMContextualize(**params) try: user_keys = {} for vm_key in vm_keys: user_name = str(vm_key.get_user_name()) if user_name not in user_keys: user_keys[user_name] = [vm_key.get_ssh_key()] else: user_keys[user_name].append(vm_key.get_ssh_key()) logging.debug( "Adding %s's public key(s) into VM. Key contents: %s" % (vm_key.get_user_name(), user_keys[str( vm_key.get_user_name())])) # Placing a number of keys per user, multiple users if len(user_keys) > 0: with self.__mutex_process: # FIXME Sometimes do not work properly and keys are not getting to the VM ServiceProcess.startMethodInNewProcess( vm_context.contextualize_add_pub_keys, [user_keys], self.__agent_callback_url) except Exception as e: raise e
def send_sync(callBackUrl=None, xml=None): callBackUrl = ( "https://" + settings.XMLRPC_USER + ":" + settings.XMLRPC_PASS + "@" + settings.VTAM_IP + ":" + settings.VTAM_PORT + "/xmlrpc/plugin" ) try: logging.debug("XML RECEIVED: \n%s" % xml) rspec = XmlHelper.parseXmlString(xml) except Exception as e: logging.error("sendSync() could not parse \n") logging.error(e) return # SyncThread.startMethodAndJoin(DispatcherLauncher.processXmlQuerySync, rspec, url = callBackUrl) # ServiceThread.startMethodInNewThread(DispatcherLauncher.processXmlQuery ,rspec, url = callBackUrl) exception = False ErrorMsg = "" count = 0 timeout = 10 * 60 # timeout set at 10 minutes try: ServiceProcess.startMethodInNewProcess(DispatcherLauncher.processXmlQuerySync, [rspec, callBackUrl], None) actionModel = None except Exception as e: ErrorMsg = e exception = True while True and not exception: time.sleep(5) try: actionModel = ActionModel.objects.get(uuid=rspec.query.provisioning.action[0].id) print actionModel.getStatus() if actionModel.getStatus() == "SUCCESS": return True elif actionModel.getStatus() in ["FAILED", "UNKNOWN"]: return "The creation of the VM has FAILED" except Exception as e: return "An error has ocurred during the VM creation ", e if count < timeout: count += 5 else: return "TIMEOUT" if exception: return ErrorMsg
def send_sync(callBackUrl=None, xml=None): callBackUrl = "https://" + settings.XMLRPC_USER + ":" + settings.XMLRPC_PASS + "@" + settings.VTAM_IP + ":" + settings.VTAM_PORT + "/xmlrpc/plugin" try: logging.debug("XML RECEIVED: \n%s" % xml) rspec = XmlHelper.parseXmlString(xml) except Exception as e: logging.error("sendSync() could not parse \n") logging.error(e) return #SyncThread.startMethodAndJoin(DispatcherLauncher.processXmlQuerySync, rspec, url = callBackUrl) #ServiceThread.startMethodInNewThread(DispatcherLauncher.processXmlQuery ,rspec, url = callBackUrl) exception = False ErrorMsg = "" count = 0 timeout = 10 * 60 #timeout set at 10 minutes try: ServiceProcess.startMethodInNewProcess( DispatcherLauncher.processXmlQuerySync, [rspec, callBackUrl], None) actionModel = None except Exception as e: ErrorMsg = e exception = True while True and not exception: time.sleep(5) try: actionModel = ActionModel.objects.get( uuid=rspec.query.provisioning.action[0].id) print actionModel.getStatus() if actionModel.getStatus() == "SUCCESS": return True elif actionModel.getStatus() in ["FAILED", "UNKNOWN"]: return "The creation of the VM has FAILED" except Exception as e: return "An error has ocurred during the VM creation ", e if count < timeout: count += 5 else: return "TIMEOUT" if exception: return ErrorMsg