Beispiel #1
0
    def createClientList(self, ctx, data):
        session = inevow.ISession(ctx)
        states = {
            0: 'new.png',
            1: 'connected.png',
            2: 'established.png',
            3: 'dead.png'
        }

        clTable = ClientTable(self, session.uid)

        clientList = yield session.agent.rootAgent.listClients()

        for client in clientList:
            imgState = '/images/cl-status/' + states.get(
                client.state, 'new.png')

            clTable.add({
                'id': client.id,
                'uuid': client.uuid,
                'class': client.type,
                'state': imgState,
                'endpoint': client.endpoint
            })

        clTable.setPage(0)

        returnValue(clTable)
Beispiel #2
0
 def newClientHandle(self, ctx, refreshInterval, targetTimeoutCount):
     handleid = inevow.ISession(ctx).uid + '-' + str(self.handleCounter())
     handle = self.clientHandleClass(handleid,
                                     refreshInterval, targetTimeoutCount)
     self.clientHandles[handleid] = handle
     handle.notifyOnClose().addCallback(self.deleteHandle, handleid=handleid)
     return handle
Beispiel #3
0
 def render_content(self, ctx, data):        
     session = inevow.ISession(ctx)
     role = self.getRole(ctx)
     
     if role == 0:
         returnValue(self.renderAlert('You are not authorized'))    
      
     profileTable = ProfileTable(self, session.uid)
     
     profiles = yield session.agent.expsvcAgent.listProfiles()
     
     for profileName, profile in profiles.iteritems():
         creationDate = time.ctime(tstimeToUnixTime(profile.creationDate))
         
         profileHref = url.URL.fromContext(ctx).child(str(profile.userId)).child(str(profileName))
         
         profileTable.add({'profileId': str(profile.profileId),
                           'userId': str(profile.userId),
                           'name': profileName,
                           'profileHref': profileHref,
                           'creationDate': creationDate,
                           'description': profile.description})
     
     profileTable.setPage(0)
     
     returnValue(profileTable)
Beispiel #4
0
    def agentResourcesInfo(self, ctx):
        session = inevow.ISession(ctx)

        tv = TreeView(self, session.uid)

        resNexuses = {}

        for resNexusClass, resNexusName in resNexusNames.items():
            nexus = LoadAgentResource(resNexusName, 'NEXUS')
            tv.addElement(nexus)
            resNexuses[resNexusClass] = nexus

        resObjects = {}

        agentId = self.agentInfo.agentId
        resourceInfo = yield session.agent.expsvcAgent.getAgentResources(
            agentId=agentId)

        for resName, res in resourceInfo.resources.iteritems():
            resObj = LoadAgentResource(resName, res.resType.upper())
            resObj.resClass = res.resClass
            resObjects[resName] = resObj

        for childLink in resourceInfo.childLinks:
            parent = resObjects[childLink.parentName]
            child = resObjects[childLink.childName]

            parent.addChild(child)

        for resObj in resObjects.values():
            if resObj.parent is None:
                resNexuses[resObj.resClass].addChild(resObj)

        returnValue(tv)
Beispiel #5
0
 def render_sample(self, context, data):
     request = inevow.IRequest(context)
     session = inevow.ISession(context)
     count = getattr(session, 'count', 1)
     session.count = count + 1
     return ["Welcome, person from ", request.client.host, "! You are using ",
         request.getHeader('user-agent'), " and have been here ", 
         T.span(id="count")[count], " times."]
Beispiel #6
0
 def newClientHandle(self, ctx, refreshInterval, targetTimeoutCount):
     handle = DefaultClientHandleFactory.newClientHandle(
         self, ctx, refreshInterval, targetTimeoutCount)
     handle.currentNodeId = ctx.tag.package.currentNode.id
     handle.packageName = ctx.tag.package.name
     handle.session = inevow.ISession(ctx)
     log.debug('New client handle %s. Handles %s' %
               (handle.handleId, self.clientHandles))
     return handle
Beispiel #7
0
    def render_chat(self, ctx, _):
        accountManager = minchat.MinAccountManager(self.chatui)
        ss = inevow.ISession(ctx)
        irc = IRCContainer(accountManager, ss.user)
        irc.setFragmentParent(self)

        self.chatui.initUI(irc)

        return ctx.tag[irc]
Beispiel #8
0
    def render_gmtools(self, ctx, _):
        ss = inevow.ISession(ctx)
        gmt = gmtools.GMTools(ss.user)
        enc = stainedglass.Enclosure(windowTitle="GM Tools", 
                userClass="gmtools draggable")
        enc.setFragmentParent(self)
        gmt.setFragmentParent(enc)

        return ctx.tag[enc[gmt]]
    def childFactory(self, context, name):
        entry = inevow.ISession(context).getLoggedInRoot().loggedIn

        filt = uriUnquote(name)

        e = ldapsyntax.LDAPEntry(client=entry.client, dn=self.baseObject)
        d = e.search(filterText=filt, sizeLimit=20)
        d.addCallback(ReallyMassPasswordChangePage)
        return d
Beispiel #10
0
    def render_loginFailure(self, ctx, data):
        session = inevow.ISession(ctx)

        if getattr(session, 'loginFailure', ''):
            ret = T.div[T.div(
                _class='alert alert-error')[session.loginFailure], ]
            del session.loginFailure
            return ret

        return ''
Beispiel #11
0
    def renderHTTP(self, context):
        session = inevow.ISession(context)

        try:
            delattr(session, 'agent')
            delattr(session, 'userName')
            delattr(session, 'userRole')
        except AttributeError:
            pass

        return url.here.up()
Beispiel #12
0
    def workloadType(self, ctx, wltypeName):
        session = inevow.ISession(ctx)
        if self.workloadTypes is None:
            self.workloadTypes = yield session.agent.expsvcAgent.getWorkloadTypes(
                agentId=self.agentId)

        wltype = self.workloadTypes[wltypeName]

        wlcDescriptions = [T.li[wlclasses[wlc][1]] for wlc in wltype.wlclass]

        ctx.fillSlots('name', wltypeName)
        ctx.fillSlots('module', wltype.module)
        ctx.fillSlots('path', wltype.path)
        ctx.fillSlots('classes', T.ul()[wlcDescriptions])

        self.data_workloadParams = []

        for paramName, param in wltype.params.iteritems():
            if param.flags & TSWLParamCommon.WLPF_OPTIONAL:
                paramName = T.span[paramName, T.sup['OPT']]

            wlpType = WLParamHelper.getTypeName(param)

            minVal, maxVal = WLParamHelper.getIntegerRange(param)
            lenVal = WLParamHelper.getStringLength(param)
            range = 'None'

            if minVal is not None and maxVal is not None:
                range = '[%s...%s]' % (_wlparamToStr(
                    minVal, param), _wlparamToStr(maxVal, param))
            elif lenVal is not None:
                range = 'len: %s' % lenVal

            default = WLParamHelper.getDefaultValue(param)
            if default is not None:
                default = _wlparamToStr(default, param)
            else:
                default = 'None'

            self.data_workloadParams.append({
                'param': paramName,
                'type': wlpType,
                'range': range,
                'default': default,
                'description': param.description
            })

        wltparams = loaders.xmlfile(webappPath('agent/wltypeparam.html'))

        returnValue(wltparams)
Beispiel #13
0
    def childFactory(self, context, name):
        dn = uriUnquote(name)
        session = inevow.ISession(context)
        userEntry = session.getLoggedInRoot().loggedIn

        move = session.getComponent(IMove)
        if move is None:
            move = []
            session.setComponent(IMove, move)

        e = ldapsyntax.LDAPEntryWithClient(dn=dn, client=userEntry.client)
        move.append(e)
        u = url.URL.fromContext(context).sibling('search')
        return u
Beispiel #14
0
    def update(self, ctx):
        '''Emit paginated view update'''
        session = inevow.ISession(ctx)

        # Verify if live request came from same session, our view was created
        # Nevow doesn't do it :(
        if session.uid == self.sessionUid:
            # nevow.livepage has problems with flattening complex objects
            # so render it into string prematurely
            flt = flat.flatten(self.render_mainTable(ctx, None), ctx)

            yield livepage.set('pagination',
                               self.render_pagination(ctx, None)), livepage.eol
            yield livepage.set('mainTable', flt)
Beispiel #15
0
    def login(self, ctx, userName, password):
        session = inevow.ISession(ctx)

        session.agent = TSWebAgent.createAgent(
            'web', config.get('tsserver', 'host'),
            config.getInt('tsserver', 'port'))
        session.agent.setAuthData(userName, password)

        d = Deferred()
        d.addCallback(self.loginResponse, session)

        session.agent.setEventListener(d)

        return d
Beispiel #16
0
    def renderGET(self, ctx):
        (newpage, divContent) = self.generalContent()
        divContent.append(
            p(
                '',
                text("""Welcome to the HiPerSAT Infomax testbed. Here you can
try out the latest version of our Infomax implementation.""")))
        divContent.append(
            p(
                '',
                text(""" If there are no options available in the file 
selection menu the you will need to upload some files to the server
using the"""), a('href="/file"', text("File Database"))))

        divContent.append(text(self.form.renderForm()))
        divContent.append(
            p('', text("Session id: %s" % (inevow.ISession(ctx).uid))))
        return apply(newpage)
Beispiel #17
0
 def render_topMenu(self, ctx, data):
     session = inevow.ISession(ctx)
     topMenu = TopMenu()
     
     currentPath = url.URL.fromContext(ctx).pathList()[0]
     
     topMenu.menu.addItem('About', '/about', currentPath == 'about')
     
     try:
         agent = session.agent
         userName = session.userName
     except AttributeError:
         topMenu.menu.addItem('Log in', '/login', currentPath == 'login')
     else:
         topMenu.menu.addItem('Log out', '/logout')
         topMenu.setUserName(userName)
         
     return topMenu
Beispiel #18
0
    def createLoadAgentList(self, ctx, data):
        session = inevow.ISession(ctx)

        laTable = LoadAgentTable(self, session.uid)

        agentList = yield session.agent.expsvcAgent.listAgents()

        for agentUuid, agentInfo in agentList.iteritems():
            imgState = '/images/cl-status/'
            imgState += 'established.png' if agentInfo.isOnline else 'dead.png'

            agentHref = '/agent/load/' + agentUuid

            lowerOsName = agentInfo.osname.lower()

            osIcon = 'unknown.png'
            for needle, icon in osIcons:
                if needle in lowerOsName:
                    osIcon = icon
                    break
            osIcon = '/images/os-icons/' + osIcon

            laTable.add({
                'id': agentInfo.agentId,
                'state': imgState,
                'hostname': agentInfo.hostname,
                'agentHref': agentHref,
                'osIcon': osIcon,
                'osname': agentInfo.osname,
                'release': agentInfo.release,
                'arch': agentInfo.machineArch,
                'cpus': agentInfo.numCPUs,
                'cores': agentInfo.numCores,
                'memtotal': agentInfo.memTotal
            })

        laTable.setPage(0)

        returnValue(laTable)
Beispiel #19
0
    def getBasicAgentInfo(self, ctx):
        session = inevow.ISession(ctx)

        clientList = yield session.agent.rootAgent.listClients()
        agentList = yield session.agent.expsvcAgent.listAgents()

        try:
            self.agentInfo = agentList[self.agentUuid]
            self.agentId = self.agentInfo.agentId
        except KeyError:
            self.agentInfo = None
            self.agentId = -1

        # Find client info

        for client in clientList:
            if client.type == 'load' and client.uuid == self.agentUuid:
                self.clientInfo = client
                self.isOnline = True
                break
        else:
            self.clientInfo = None
            self.isOnline = False
Beispiel #20
0
    def workloadTypeList(self, ctx):
        session = inevow.ISession(ctx)
        wltTable = WorkloadTypeTable(self, session.uid)

        if self.workloadTypes is None:
            self.workloadTypes = yield session.agent.expsvcAgent.getWorkloadTypes(
                agentId=self.agentId)

        self.workloadClasses = ['CPU', 'MEM', 'DISK', 'FS', 'NET', 'OS']

        for wltypeName, wltype in self.workloadTypes.iteritems():
            wlcTags = [
                T.span(_class='badge',
                       title=wlclasses[wlc][1])[wlclasses[wlc][0]]
                for wlc in wltype.wlclass
            ]
            rawClasses = set(wlclasses[wlc][0] for wlc in wltype.wlclass)

            wltTable.add({
                'module':
                wltype.module,
                'workload':
                wltypeName,
                # url.gethere doesn't work here because when liveglue updates page
                # all links become broken.
                'wltHref':
                url.URL.fromContext(ctx).add('wlt', wltypeName),
                'classes':
                wlcTags,
                'rawClasses':
                rawClasses
            })

        wltTable.setPage(0)
        self.wltTable = wltTable

        returnValue(wltTable)
Beispiel #21
0
 def child_change_password(self, context):
     if not inevow.ISession(context).getLoggedInRoot().loggedIn:
         return login.LoginPage([str(self.baseObject), 'change_password'])
     return change_password.getResource()
Beispiel #22
0
 def getRole(self, ctx):
     session = inevow.ISession(ctx)
     role = getattr(session, 'userRole', 0)
     
     return role
Beispiel #23
0
 def child_reset(self, context):
     inevow.ISession(context).count = 1
     return '<html><body><span id="reset">Count reset</span></body></html>'
Beispiel #24
0
 def child_freeform_hand(self, ctx):
     carryoverHand = inevow.IHand(ctx, None)
     if carryoverHand is not None:
         inevow.ISession(ctx).setComponent(inevow.IHand, carryoverHand)
         return carryoverHand
     return inevow.IHand(inevow.ISession(ctx), None)
Beispiel #25
0
 def child_game(self, ctx, ):
     inevow.ISession(ctx).user = self.user
     return IRCPage()
Beispiel #26
0
 def render_sessionId(self, context, data):
     sess = inevow.ISession(context)
     return context.tag[sess.uid]
Beispiel #27
0
 def render_topLinks(self, ctx, _):
     ss = inevow.ISession(ctx)
     ctx.tag.fillSlots('email', ss.user.email)
     ctx.tag.fillSlots('logoutHref', url.root.child(guard.LOGOUT_AVATAR))
     ctx.tag.fillSlots('adminLink', T.a['Admin (TODO)'])
     return ctx.tag
Beispiel #28
0
 def child_(self, ctx):
     entry = inevow.ISession(ctx).getLoggedInRoot().loggedIn
     u = inevow.IRequest(ctx).URLPath()
     return u.child(str(entry.dn))
Beispiel #29
0
 def render_content(self, ctx, data): 
     session = inevow.ISession(ctx)
     
     self.data_threadpools = []
     self.data_workloads = []
     
     profile = TSExperimentProfile.createEmptyProfile()        
     profile.userId = self.userId
     
     profile = yield session.agent.expsvcAgent.getProfile(profileName = self.profileName,
                                                          profile = profile)
     
     ctx.fillSlots('profileName', self.profileName)
     ctx.fillSlots('userId', profile.userId)
     ctx.fillSlots('description', profile.description)
     
     creationDate = time.ctime(tstimeToUnixTime(profile.creationDate))
     ctx.fillSlots('creationDate', creationDate)
     
     self.agentList = yield session.agent.expsvcAgent.listAgents()
     
     # XXX: agentList uses uuids as index, JSON-TS usually have name (hostname) to object maps,
     # and we need agentId. Possibly listAgents have to be redesigned.
     urlRoot = url.URL.fromContext(ctx).click('/')
     agentRoot = urlRoot.child('agent').child('load')
     
     def _agentInfo(agentId):
         for agentUuid, agent in self.agentList.iteritems():
             if agent.agentId == agentId:
                 agentName = '%s (%d)' % (agent.hostname, agent.agentId)
                 agentHref = agentRoot.child(agentUuid) 
                                     
                 return agentName, agentHref
                 
         return '', '#'
     
     for threadpoolName, threadpool in profile.threadpools.iteritems():
         agentName, agentHref = _agentInfo(threadpool.agentId)
         
         self.data_threadpools.append({'name': threadpoolName,
                                       'agentName': agentName,
                                       'agentHref': agentHref,
                                       'numWorkers': str(threadpool.numWorkers)})
         
     for workloadName, workload in profile.workloads.iteritems():
         agentName, agentHref = _agentInfo(threadpool.agentId)
         
         workloadType = '' if workload.workloadType is None else workload.workloadType
         workloadTypeHref = agentHref.add('what', 'wltype').add('wlt', workloadType)
         
         threadpool = '' if workload.threadpool is None else workload.threadpool
         
         workloadHref = url.URL.fromContext(ctx).click(workloadName)
         
         self.data_workloads.append({'name': workloadName,
                                     'workloadHref': workloadHref,
                                     'agentName': agentName,
                                     'agentHref': agentHref,
                                     'workloadType': workloadType,
                                     'workloadTypeHref': workloadTypeHref,
                                     'threadpool': threadpool})
                                             
     
     self.profile = profile
     
     returnValue(loaders.xmlfile(webappPath('profile/info.html')))
Beispiel #30
0
 def renderHTTP(self, ctx):
     session = inevow.ISession(ctx)
     assert isinstance(session, guard.GuardSession)
     r = session.getLoggedInRoot()
     assert r is self
     return r.__class__.__name__