def getConnectionManageRefresh(self, guacHostname, username, password, url_path, method): logging.debug("getConnectionManageStatus(): instantiated") self.writeStatus = ConnectionManage.CONNECTION_MANAGE_REFRESHING try: self.lock.acquire() self.usersConnsStatus.clear() guacConn = Guacamole(guacHostname, username=username, password=password, url_path=url_path, method=method) #username, connName/VMName, userStatus (admin/etc.), connStatus (connected/not) users = guacConn.get_users() connIDsNames = {} activeConns = {} allConnections = guacConn.get_connections() if 'childConnections' in allConnections: for conn in guacConn.get_connections()['childConnections']: connIDsNames[conn['identifier']] = conn['name'] guac_activeConns = guacConn.get_active_connections() for conn in guac_activeConns: activeConns[( guac_activeConns[conn]["username"], guac_activeConns[conn]["connectionIdentifier"])] = True for user in users: #user status first perm = guacConn.get_permissions(user) user_perm = "not_found" if "READ" in perm['userPermissions'][user]: user_perm = "Non-Admin" if "ADMINISTER" in perm['userPermissions'][user]: user_perm = "Admin" #next, get the list of connections and the names of those connections and their status associated with those connections for connID in perm['connectionPermissions']: active = "not_connected" #if the connection is in an active state (exists in our activeConns dict), then state it as such if (user, connID) in activeConns: active = "connected" self.usersConnsStatus[(user, connIDsNames[connID])] = { "user_status": user_perm, "connStatus": active } except Exception as e: logging.error( "Error in getConnectionManageStatus(). Did not remove connection or relation!" ) exc_type, exc_value, exc_traceback = sys.exc_info() trace_back = traceback.extract_tb(exc_traceback) #traceback.print_exception(exc_type, exc_value, exc_traceback) return None finally: self.lock.release() self.writeStatus = ConnectionManage.CONNECTION_MANAGE_COMPLETE
def runClearAllConnections(self, guacHostname, username, password, url_path, method): self.writeStatus = ConnectionManage.CONNECTION_MANAGE_REMOVING #sample guacConn = Guacamole(192.168.99.102',username='******',password='******',url_path='/guacamole',method='http') logging.debug("runClearAllConnections(): guacHostname: " + str(guacHostname) + " username/pass: "******" url_path: " + url_path + " method: " + str(method)) guacConn = Guacamole(guacHostname, username=username, password=password, url_path=url_path, method=method) if guacConn == None: logging.error("Error with guac connection... skipping: " + str(guacHostname) + " " + str(username)) self.writeStatus = ConnectionManage.CONNECTION_MANAGE_COMPLETE return -1 # Get list of all users usernames = guacConn.get_users() for username in usernames: logging.debug("Removing Username: "******"runClearAllConnections(): Error in runClearAllConnections(): when trying to remove user." ) exc_type, exc_value, exc_traceback = sys.exc_info() #traceback.print_exception(exc_type, exc_value, exc_traceback) # Remove All Connections connections = guacConn.get_connections() logging.debug("Retrieved Connections: " + str(connections)) if "childConnections" in connections: for connection in connections["childConnections"]: logging.debug("Removing Connection: " + str(connection)) try: guacConn.delete_connection(connection["identifier"]) except Exception: logging.error( "runClearAllConnections(): Error in runClearAllConnections(): when trying to remove connection." ) exc_type, exc_value, exc_traceback = sys.exc_info() #traceback.print_exception(exc_type, exc_value, exc_traceback) self.writeStatus = ConnectionManage.CONNECTION_MANAGE_COMPLETE
def runCreateConnections(self, configname, guacHostname, musername, mpassword, url_path, method, maxConnections, maxConnectionsPerUser, width, height, bitdepth, creds_file, itype, name): logging.debug("runCreateConnections(): instantiated") #call guac backend API to make connections as specified in config file and then set the complete status rolledoutjson = self.eco.getExperimentVMRolledOut(configname) validconnsnames = self.eco.getValidVMsFromTypeName( configname, itype, name, rolledoutjson) userpool = UserPool() usersConns = userpool.generateUsersConns(configname, creds_file=creds_file) try: self.writeStatus = ConnectionManage.CONNECTION_MANAGE_CREATING logging.debug("runCreateConnection(): guacHostname: " + str(guacHostname) + " username/pass: "******" url_path: " + url_path + " method: " + str(method) + " creds_file: " + creds_file) guacConn = Guacamole(guacHostname, username=musername, password=mpassword, url_path=url_path, method=method) if guacConn == None: logging.error( "runCreateConnection(): Error with guac connection... skipping: " + str(guacHostname) + " " + str(musername)) self.writeStatus = ConnectionManage.CONNECTION_MANAGE_COMPLETE return -1 user_dict = guacConn.get_users() try: for (username, password) in usersConns: for conn in usersConns[(username, password)]: cloneVMName = conn[0] vmServerIP = conn[1] vrdpPort = conn[2] #only if this is a specific connection to create; based on itype and name if cloneVMName in validconnsnames: #if user doesn't exist, create it if username not in user_dict: logging.debug("Creating User: "******"already_exists": logging.debug( "User already exists; skipping...") #add to the list of known users user_dict[username] = "" except Exception: logging.error( "runCreateConnections(): Error in runCreateConnections(): when trying to add user." ) exc_type, exc_value, exc_traceback = sys.exc_info( ) traceback.print_exception( exc_type, exc_value, exc_traceback) #add the connection association result = self.createConnAssociation( guacConn, cloneVMName, username, vmServerIP, vrdpPort, maxConnections, maxConnectionsPerUser, width, height, bitdepth) if result == "already_exists": logging.debug( "Connection already exists; skipping...") except Exception: logging.error( "runCreateConnections(): Error in runCreateConnections(): when trying to add connection." ) exc_type, exc_value, exc_traceback = sys.exc_info() traceback.print_exception(exc_type, exc_value, exc_traceback) logging.debug("runCreateConnections(): Complete...") self.writeStatus = ConnectionManage.CONNECTION_MANAGE_COMPLETE except Exception: logging.error( "runCreateConnections(): Error in runCreateConnections(): An error occured " ) exc_type, exc_value, exc_traceback = sys.exc_info() traceback.print_exception(exc_type, exc_value, exc_traceback) self.writeStatus = ConnectionManage.CONNECTION_MANAGE_COMPLETE return finally: self.writeStatus = ConnectionManage.CONNECTION_MANAGE_COMPLETE