Example #1
0
	def execute(self, container):
		"""
			Restart container if running, depend on 2 commands :
				- StopCommand : to stop container
				- RunCommand : to start container
		"""

		if not container.runnable:
			return

		self.__printer.info("Restart", "Restarting " + container.internal_name)

		## First, we stop the container
		stop_command = StopCommand()
		return_value = stop_command.execute(container)
		
		## Something happend while stopping container
		## so we need to stop here
		if return_value:
			self.__printer.warning("Restart", "Oops, seems like we can't stop container")
			return self.RETURN_WONT_DO

		# refreshing container status
		container.refresh_status()
		
		## Everything's fine, let's start this again
		run_command = RunCommand()
		run_command.execute(container)	
		
		return self.RETURN_SUCCESS
Example #2
0
    def prepare_exec(self):
        # extracting list of vms that will be used to extract values
        vmObj = TransformXmlToVM()
        vmObj.readXml("/home/khaled/listeVMsTest.xml")
        vms = vmObj.getVM()
        self.host = "%s,%s,%s" % (vms[0].host, vms[0].user, vms[0].password)
        print "VM:"
        print self.host

        # extracting of command from xml file:
        cmdCl = TransformXmlToCmd()
        cmdCl.readXml("/home/khaled/cmdCrTest.xml")

        # preapring list of indicator used
        listCr = []
        listCr.append("disk")
        self.cmd = cmdCl.getcmd(listCr)
        # cmd is a list containing objects that contain the indicator and her command
        # print 'commande extraite'
        print self.cmd[0].cmd
        # preparing connexion to run commands
        self.cnx = RunCommand()

        # adding hosts extracted early
        self.cnx.do_add_host(self.host)
        self.cnx.do_connect()
Example #3
0
def GenerateDebugOutput(sim_name):
    Print.new_step("Generate debug output")
    # generates cmake_output.log and / or make_output.log (depends if cmake
    # ran sucessfully or not)
    if BuildCommand(debug=True):
        # generates runtime_output.log
        RunCommand(debug=True)
        # generates root dictionary log(s)
        CopyRootDictionaries()
    # generates system_info.log
    GenerateSystemInfoLog()
Example #4
0
def main():
    """
    If not using fabric could start with below ssh prep. would need more work to use standalone without Fabric

    below will just make a sql file
    setup to use a -s flag and run remote commands;
    :return: sql file has been written to local dir
    """

    parser = argparse.ArgumentParser()
    parser.add_argument("-s", "--ssh", help="run ssh and mysql commands",
                        action="store_true")
    parser.add_argument('vars', nargs='*')
    flags = parser.parse_args()
    if flags.ssh:
        print "Runnning local ssh  and mysql commands (-s used) ... "
        args = sys.argv[2:]
    else:
        args = sys.argv[1:]

    # command line args order :<optional -s> target_env, target_project, ip/regex, ipformat, sql_mode
    w = Whitelist(*args)
    print "Writing sql query file ...."
    w.setup()

    if flags.ssh:
        print "Rsyncing mysql file over.."
        sync = RunCommand(w.rsync_cmd())
        sync.issue_cmd()
        print "Starting local ssh commands"
        run = RunCommand(w.ssh_mysql_cmd())
        run.issue_cmd()
Example #5
0
class execution:
    def __init__(self):
        pass

    def prepare_exec(self):
        # extracting list of vms that will be used to extract values
        vmObj = TransformXmlToVM()
        vmObj.readXml("/home/khaled/listeVMsTest.xml")
        vms = vmObj.getVM()
        self.host = "%s,%s,%s" % (vms[0].host, vms[0].user, vms[0].password)
        print "VM:"
        print self.host

        # extracting of command from xml file:
        cmdCl = TransformXmlToCmd()
        cmdCl.readXml("/home/khaled/cmdCrTest.xml")

        # preapring list of indicator used
        listCr = []
        listCr.append("disk")
        self.cmd = cmdCl.getcmd(listCr)
        # cmd is a list containing objects that contain the indicator and her command
        # print 'commande extraite'
        print self.cmd[0].cmd
        # preparing connexion to run commands
        self.cnx = RunCommand()

        # adding hosts extracted early
        self.cnx.do_add_host(self.host)
        self.cnx.do_connect()

    # executing command after its extracting and establishing connexion
    def execute(self, cmde):
        # Excuting command on remote host
        # the command is gotten from the previous method saved in the self vble
        r = self.cnx.do_run(self.cmd[0].cmd)
        print "affichage"
        print r[0]
        print "fin"
Example #6
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()
Example #7
0
 def config(self,ipList,masterIp,user,pwd):
     cs=open('core.log', 'r')
     csList=cs.readlines()
     csList[6]=csList[6].replace('IP_ADRESS',masterIp)
     csCh=''.join(csList)
     print csCh
     m=1
     ip_slv='\n'.join(ipList)
     hdp_home='/usr/local/hadoop-0.20.2'
     hst=masterIp+','+user+','+pwd
     slv=RunCommand()
     slv.do_add_host(hst)
     slv.do_connect()
     rt=slv.do_run("echo '"+csCh+"'>"+hdp_home+"/conf/core-site.xml")
     rt=slv.do_run("echo '"+ip_slv+"'>"+hdp_home+"/conf/slaves")
Example #8
0
    def config(self, ipList, masterIp, user, pwd):
        cs = open("core.log", "r")
        csList = cs.readlines()
        csList[6] = csList[6].replace("IP_ADRESS", masterIp)
        csCh = "".join(csList)
        print csCh
        m = 1
        ip_slv = ""
        hdp_home = "/usr/local/hadoop-0.20.2"

        for vm in ipList:
            hst = vm + "," + user + "," + pwd
            slv = RunCommand()
            slv.do_add_host(hst)
            slv.do_connect()
            rt = slv.do_run("echo '" + csCh + "'>" + hdp_home + "/conf/core-site.xml")
            rt = slv.do_run("echo '" + masterIp + "'>" + hdp_home + "/conf/masters")
Example #9
0
            sys.exit()
        BuildCommand()
    elif args.cmd == 'clean':
        if len(unknown) != 0:
            clean_sp.print_help()
            sys.exit()
        BuildCommand(clean=True, build=False)
    elif args.cmd == 'demo':
        demo_name = None
        destination = None
        if len(unknown) >= 1:
            demo_name = unknown[0]
        if len(unknown) >= 2:
            destination = unknown[1]
        DemoCommand(demo_name, destination)
    elif args.cmd == 'run':
        RunCommand(args=unknown)
    elif args.cmd == 'assist':
        if len(unknown) != 0:
            assist_sp.print_help()
            sys.exit()
        AssistCommand()
    elif args.version:
        print(Version.string())
        sys.exit()
    elif args.shortversion:
        print(Version.shortstring())
        sys.exit()
    else:
        parser.print_help()
Example #10
0
                                 'seperate git branch. In the end it will output '
                                 'a link that you should add to your e-mail or '
                                 'slack message when you describe your issue.' )

    sp.add_parser('build', help='Builds the simulation binary')

    sp.add_parser('clean', help='Removes all build files')

    spp = sp.add_parser('new', help='Creates a new simulation project. Downloads '
    'a template project from BioDynaMo, renames it to the given simulation name, '
    'creates a new Github repository and configures git.')
    spp.add_argument('SIMULATION_NAME', type=str, help='simulation name help')
    spp.add_argument('--no-github', action='store_true', help='Do not create a Github repository.'    )

    sp.add_parser('run', help='Executes the simulation')

    args = parser.parse_args()

    if args.cmd == 'new':
    	NewCommand(args.SIMULATION_NAME, args.no_github)
    elif args.cmd == 'build':
    	BuildCommand()
    elif args.cmd == 'clean':
    	BuildCommand(clean=True, build=False)
    elif args.cmd == 'run':
    	RunCommand()
    elif args.cmd == 'assist':
    	AssistCommand()
    else:
        parser.print_help()
Example #11
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()
        
    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
Example #13
0
    def exchange(self,vmList):
        m=1
        key_mstr=[]
        mstr=RunCommand()
        key_slv=''
        ip_slv=''
        ip_mstr=''
        for vm in vmList:
            to_exec=vm.host+','+vm.user+','+vm.password

            if m==1:
                ip_mstr=vm.host

                mstr.do_add_host(to_exec)
                mstr.do_connect()
                key=mstr.do_run("cd .ssh \nssh-keygen -q -t rsa -f id_rsa  -C '' -N ''")
                key_mstr=mstr.do_run('cat .ssh/id_rsa.pub')
                m=0
            else:
                slv=RunCommand()
                slv.do_add_host(to_exec)
                slv.do_connect()
                print 'connected to slaves'
                exec_key_slv=slv.do_run("cd .ssh \nssh-keygen -q -t rsa -f id_rsa  -C '' -N ''")
                key_slv+=slv.do_run('cat .ssh/id_rsa.pub')[0]+'\n'
                inject_slv=slv.do_run('echo '+key_mstr[0]+'>.ssh/authorized_keys')
                scan_slv=slv.do_run('ssh-keyscan '+ip_mstr+'>.ssh/known_hosts')
                ip_slv+=vm.host+'\n'

        inject_mstr=mstr.do_run("echo '"+key_slv+"'>.ssh/authorized_keys")
        prep_scan_mstr=mstr.do_run("echo '"+ip_slv+"'>hosts")
        scan_mstr=mstr.do_run("ssh-keyscan -f hosts>.ssh/known_hosts")
        return key_mstr[0]