Ejemplo n.º 1
0
    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
Ejemplo n.º 2
0
    def runRemoveConnections(self, configname, guacHostname, username,
                             password, url_path, method, creds_file, itype,
                             name):
        self.writeStatus = ConnectionManage.CONNECTION_MANAGE_REMOVING
        logging.debug("runRemoveConnections(): 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()
        try:
            usersConns = userpool.generateUsersConns(configname,
                                                     creds_file=creds_file)
            self.writeStatus = ConnectionManage.CONNECTION_MANAGE_CREATING
            logging.debug("runRemoveConnections(): guacHostname: " +
                          str(guacHostname) + " username/pass: "******" url_path: " + url_path + " method: " +
                          str(method) + " creds_file: " + creds_file)
            guacConn = Guacamole(guacHostname,
                                 username=username,
                                 password=password,
                                 url_path=url_path,
                                 method=method)
            if guacConn == None:
                logging.error(
                    "runRemoveConnections(): Error with guac connection... skipping: "
                    + str(guacHostname) + " " + str(username))
                self.writeStatus = ConnectionManage.CONNECTION_MANAGE_COMPLETE
                return -1

            for (username, password) in usersConns:
                logging.debug("Removing Connection for Username: "******"Does not Exist":
                                logging.debug(
                                    "Connection doesn't exists; skipping...")

                    #check if any other connections exist for user, if not, remove the user too
                    try:
                        result = guacConn.get_permissions(username)
                        if len(result["connectionPermissions"]) == 0:
                            logging.debug("Removing User: "******"Does not Exist":
                                logging.debug(
                                    "User doesn't exist; skipping...")
                    except Exception:
                        logging.error(
                            "runRemoveConnections(): Error in runRemoveConnections(): when trying to remove user."
                        )
                        exc_type, exc_value, exc_traceback = sys.exc_info()
                        traceback.print_exception(exc_type, exc_value,
                                                  exc_traceback)

                except Exception:
                    logging.error(
                        "runRemoveConnections(): Error in runRemoveConnections(): when trying to remove connection."
                    )
                    exc_type, exc_value, exc_traceback = sys.exc_info()
                    traceback.print_exception(exc_type, exc_value,
                                              exc_traceback)
            logging.debug("runRemoveConnections(): Complete...")
            self.writeStatus = ConnectionManage.CONNECTION_MANAGE_COMPLETE
        except Exception:
            logging.error(
                "runRemoveConnections(): Error in runRemoveConnections(): 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