示例#1
0
    def installPackage( self, package, hostId ):
        # hostId can be either numeric (the actual id) or it can be
        # the name. In the latter case, try to find the host by its
        # name
        host = None
        try:
            if hostId.isdigit():
                host = self.hosts[ int( hostId )]
            else:
                for next in self.hosts.values():
                    if hostId == next.hostname:
                        host = next
                        break
            if not host: 
                raise Exception('Host not found')
        except:
            raise Exception( 'Host %s not found' % hostId )
            
        
        self.log.info('Installing package %s on host %s' %( package, host.hostname ))
        command = 'screen -S "install" sudo apt-get -y install "%s"\r\nexit\r\n' % package

        channel = host.invokeShell()
        screenReader = ScreenReader(self.name, channel, self.log)
        screenReader.start()        
        channel.send( command )
        screenReader.join( 60.0 )
        log = screenReader.getBuffer()

        self.log.info( 'Package %s installed' % package )

        escapedPackageName = package.replace( "'", "\'" )
        startScript = '/opt/webportal/%s/start.sh' % escapedPackageName
        stopScript  = '/opt/webportal/%s/stop.sh'  % escapedPackageName
        command = 'screen -S installer\r\n[ -e \'%s\' ]; echo "Start$?"\r\n \
[ -e \'%s\' ]; echo "Stop$?"\r\nexit\r\nexit\r\n' % ( startScript, stopScript )
        
        channel = host.invokeShell()
        screenReader = ScreenReader(self.name, channel, self.log)
        screenReader.start()        
        channel.send( command )
        screenReader.join( 30.0 )
        output = screenReader.getBuffer()
        startCommand = startScript if output.find( 'Start0' ) >= 0 else ''
        stopCommand  = stopScript  if output.find( 'Stop0'  ) >= 0 else ''
        self.log.info( 'StartScript found: %s, StopScript found: %s' % ( startCommand, \
            stopCommand ))
        #self.log.info( output )

        return log, startCommand, stopCommand
示例#2
0
    def loadParameters( self, component, action ):
        host = component.host
        channel = host.invokeShell()
        channel.send( 'screen -S load_parameters\r\n' )
        screenReader = ScreenReader( 'load_parameters', channel, self.log )
        screenReader.start()

        channel.send( action.parameterFile + ' load\r\n' )
        channel.send( 'exit\r\n' )
        screenReader.join( 15.0 )
        rawData = screenReader.getBuffer()
        try:
            start = rawData.lower().index( '<configuration>' )
            end = rawData.lower().index( '</configuration>' ) + len( '</configuration>' )
            return rawData[ start:end ]
        except ValueError,e:
            raise ValueError( 'Invalid xml format' )
示例#3
0
    def saveParameters( self, component, action, data ):
        host = component.host
        channel = host.invokeShell()
        channel.send( 'screen -S save_parameters\r\n' )
        screenReader = ScreenReader( 'save_parameters', channel, self.log )
        screenReader.start()

        xml = '<configuration>'
        nodes = []
        for key,value in data.iteritems():
            nodes.append( '<param name=\\"%s\\" value=\\"%s\\" />' % (
                self.escapeXMLValue( key ), self.escapeXMLValue( value )))
        xml += ''.join( nodes )
        xml += '</configuration>'

        command = action.parameterFile + ' save "%s"\r\n' % xml
        self.log.debug( 'Sending command %s' % command )
        channel.send( command )
        channel.send( 'exit\r\n' )
        screenReader.join( 10.0 )
        rawData = screenReader.getBuffer()

        return True