Exemplo n.º 1
0
    def config(self):
        keys=exchangeKeys()
        self.mstr_key=keys.exchange(self.listVM)

        cfgMstr=configMstr()
        cfgMstr.config(self.listSlv,self.mstr.host,self.user,self.pwd)

        cfgSlv=configSlv()
        cfgSlv.config(self.listSlv,self.mstr.host,self.user,self.pwd)

        # starting hadoop daemons
        strt=RunCommand()
        strt.do_add_host(self.mstr.host+','+self.user+','+self.pwd)
        strt.do_connect()
        cmd=''
        exec_strt=strt.do_run(cmd)
        strt.do_close()
Exemplo n.º 2
0
    def exchange(self,mstr,slv,key):
        slv_hst=slv+','+mstr.user+','+mstr.password
        mstr_hst=mstr.host+','+mstr.user+','+mstr.password
        print mstr_hst
        print slv_hst
        key_slv=''
        slvC=RunCommand()
        slvC.do_add_host(slv_hst)
        slvC.do_connect()
        print 'connected to slave'
        exec_key_slv=slvC.do_run("cd .ssh \nssh-keygen -q -t rsa -f id_rsa  -C '' -N ''")
        key_slv+=slvC.do_run('cat .ssh/id_rsa.pub')[0]+'\n'
        inject_slv=slvC.do_run('echo '+key+'>.ssh/authorized_keys')
        scan_slv=slvC.do_run('ssh-keyscan '+mstr.host+'>.ssh/known_hosts')
        slvC.do_close()

        mstrC=RunCommand()
        mstrC.do_add_host(mstr_hst)
        mstrC.do_connect()
        inject_mstr=mstrC.do_run("echo '"+key_slv+"'>>.ssh/authorized_keys")
        scan_mstr=mstrC.do_run('ssh-keyscan '+slv+'>>.ssh/known_hosts')
        mstrC.do_close()
        
Exemplo n.º 3
0
    def extract(self, host, cmde, cr):

        sumExt = 0
        sumExtSqr = 0
        sumCmpt = 0
        sumCmptSqr = 0

        nbMeasures = 3

        # preparing connection to host
        exe = RunCommand()
        exe.do_add_host(host)
        logging.info("host added")
        exe.do_connect()
        logging.info("connection established")

        result = treat_result(cr)

        # executing commands for many times : nbMeasures
        for i in range(nbMeasures):
            # waiting and extracting value
            time.sleep(1)

            # execution of command

            res = exe.do_run(cmde.cmd)
            logging.info("command executed")

            # treatment of the extracted value
            valeur = result.return_result(res)
            logging.info("result of command treated")

            # determning of the sum of values dedicated for extension
            sumExt = sumExt + valeur.value
            sumExtSqr = sumExtSqr + math.pow(valeur.value, 2)
            # determining the sum of values dedicated for compacting
            sumCmpt = sumCmpt + valeur.complement
            sumCmptSqr = sumCmptSqr + math.pow(valeur.complement, 2)

        # determining the average and other parameters
        moyExt = sumExt / nbMeasures
        ecartTypeExt = sumExtSqr / nbMeasures - math.pow(moyExt, 2)
        moyCmpt = sumCmpt / nbMeasures
        ecartTypeCmpt = sumCmptSqr / nbMeasures - math.pow(moyCmpt, 2)

        # determining thresholds
        thresholdExt = float(cmde.tempsExt) * float(cmde.zExt) * ecartTypeExt
        thresholdCmpt = float(cmde.tempsCmpt) * float(cmde.zCmpt) * ecartTypeCmpt
        logging.info("consumption threshold determined")

        # extracting values to compare with thresholds
        res = exe.do_run(cmde.cmd)
        valeur = result.return_result(res)

        # creating the object that will be returned
        # this object contains value to compare and thresholds
        to_return = obj_cmp()
        to_return.cr = cr.lower()
        to_return.value = valeur
        to_return.maxExt = thresholdExt
        to_return.minCmpt = thresholdCmpt

        print "seuilExt ", thresholdExt
        print "seuilCmpt ", thresholdCmpt
        # closing connection to host
        exe.do_close()
        logging.info("connection to host closed")

        # returning obj to be compared
        return to_return