Exemplo n.º 1
0
def main(argv):
    global remote_exec
    parser = option_parser()
    (options, args) = parser.parse_args()
    if options.log:
        log.setpath(options.log)

    if not options.type:
        if not precheck(options.file, options.collect, options.step):
            sys.exit(-1)

        cmd_array = []
        cmd_exec = "%s -t local" % get_cmd(options.file, options.collect, options.step, options.log)
        t = execute.EXECUTE(options.file)

        machine = False
        if options.machine:
            machine = options.machine
        elif options.collect:
            if t.parser.collect_list[options.collect].has_key("collect.hostname"):
                machine = t.parser.collect_list[options.collect]["collect.hostname"]

        if machine and machine != "":
            machine_array = machine.split(",")
            for item in machine_array:
                cmd = "%s %s '. ~/.bash_profile;cd %s;%s'" % (remote_exec, item, sysio.SCRIPT_PATH, cmd_exec)
                cmd_array.append(cmd)
        else:
            cmd_array.append(cmd_exec)

        try:
            path = "%s/deploy.py" % sysio.SCRIPT_PATH
            if os.path.exists(path):
                for cmd in cmd_array:
                    if options.user and options.password and options.key:
                        user_exec(options.user, options.key, options.password, cmd)
                    else:
                        os.system(cmd)
            else:
                log.error("deploy.py", "No such file: %s" % path)
        except Exception, e:
            log.error("deploy.py", e)
Exemplo n.º 2
0
def main(argv):
    global remote_exec,exec_file
    parser = option_parser()
    (options, args) = parser.parse_args()
    if options.log:
        log.setpath(options.log)

    ''' create executing shell script ''' 
    if options.user:
        username = options.user
    else:   
        username = getpass.getuser()
    if options.collect:
        operation = options.collect 
    elif options.step:
        operation = options.step
    else:   
        operation = "none"
    currenttime = time.strftime('%y%m%d%H%M%S',  time.localtime(time.time())) 
    exec_file = "%s/ldap/%s/%s_%s_%s.sh" % (sysio.SCRIPT_PATH,username,username,operation,currenttime)
    if not os.path.exists("%s/ldap/%s" % (sysio.SCRIPT_PATH,username)):
        os.system("mkdir %s/ldap/%s;chmod 777 %s/ldap/%s" % (sysio.SCRIPT_PATH,username,sysio.SCRIPT_PATH,username))

    if not options.type:
        if not precheck(options.file,options.collect,options.step):
            sys.exit(-1)

        cmd_array = []
        cmd_exec = "%s -t local" % get_cmd(options.file,options.collect,options.step,options.log,options.user)

        os.system("touch %(execfile)s;chmod 777 %(execfile)s" % {"execfile":exec_file})
        execute.set_path(exec_file)
        t = execute.EXECUTE(options.file, options.user)

        machine = False
        if options.machine:
            machine = options.machine
        elif options.collect:
            if t.parser.collect_list[options.collect].has_key("collect.hostname"):
                machine = t.parser.collect_list[options.collect]["collect.hostname"]

        if machine and machine != "":
            machine_array = machine.split(',')
            for item in machine_array:
                cmd = "%s %s \'. ~/.bash_profile;cd %s;%s\'" % (remote_exec,item,sysio.SCRIPT_PATH,cmd_exec)
                cmd_array.append(cmd)
        else:
            cmd_array.append(cmd_exec)

        try:
            path = "%s/deploy.py" % sysio.SCRIPT_PATH
            if os.path.exists(path):
                for cmd in cmd_array:
                    if options.user and options.password and options.key:
                        if options.deployUser:
                            user_exec(options.user,options.key,options.password,cmd,options.deployUser)
                        else:
                            user_exec(options.user,options.key,options.password,cmd,options.user)
                    else:
                        if sysio.DEPLOY_MODE == "shell":
                            os.system(cmd)
                        else:
                            (status, output) = commands.getstatusoutput(cmd)
                            if status != 0:
                                log.error("deploy.py", "执行命令:%s 失败,输出为:%s" % (cmd,output))
            else:
                log.error("deploy.py","No such file: %s" % path)
        except Exception,e:
            log.error("deploy.py","%s" % e)
Exemplo n.º 3
0
def main(argv):
    global remote_exec, exec_file
    parser = option_parser()
    (options, args) = parser.parse_args()
    if options.log:
        log.setpath(options.log)
    ''' create executing shell script '''
    if options.user:
        username = options.user
    else:
        username = getpass.getuser()
    if options.collect:
        operation = options.collect
    elif options.step:
        operation = options.step
    else:
        operation = "none"
    currenttime = time.strftime('%y%m%d%H%M%S', time.localtime(time.time()))
    exec_file = "%s/ldap/%s/%s_%s_%s.sh" % (sysio.SCRIPT_PATH, username,
                                            username, operation, currenttime)
    if not os.path.exists("%s/ldap/%s" % (sysio.SCRIPT_PATH, username)):
        os.system("mkdir %s/ldap/%s;chmod 777 %s/ldap/%s" %
                  (sysio.SCRIPT_PATH, username, sysio.SCRIPT_PATH, username))

    if not options.type:
        if not precheck(options.file, options.collect, options.step):
            sys.exit(-1)

        cmd_array = []
        cmd_exec = "%s -t local" % get_cmd(options.file, options.collect,
                                           options.step, options.log,
                                           options.user)

        os.system("touch %(execfile)s;chmod 777 %(execfile)s" %
                  {"execfile": exec_file})
        execute.set_path(exec_file)
        t = execute.EXECUTE(options.file, options.user)

        machine = False
        if options.machine:
            machine = options.machine
        elif options.collect:
            if t.parser.collect_list[options.collect].has_key(
                    "collect.hostname"):
                machine = t.parser.collect_list[
                    options.collect]["collect.hostname"]

        if machine and machine != "":
            machine_array = machine.split(',')
            for item in machine_array:
                cmd = "%s %s \'. ~/.bash_profile;cd %s;%s\'" % (
                    remote_exec, item, sysio.SCRIPT_PATH, cmd_exec)
                cmd_array.append(cmd)
        else:
            cmd_array.append(cmd_exec)

        try:
            path = "%s/deploy.py" % sysio.SCRIPT_PATH
            if os.path.exists(path):
                for cmd in cmd_array:
                    if options.user and options.password and options.key:
                        if options.deployUser:
                            user_exec(options.user, options.key,
                                      options.password, cmd,
                                      options.deployUser)
                        else:
                            user_exec(options.user, options.key,
                                      options.password, cmd, options.user)
                    else:
                        if sysio.DEPLOY_MODE == "shell":
                            os.system(cmd)
                        else:
                            (status, output) = commands.getstatusoutput(cmd)
                            if status != 0:
                                log.error("deploy.py",
                                          "执行命令:%s 失败,输出为:%s" % (cmd, output))
            else:
                log.error("deploy.py", "No such file: %s" % path)
        except Exception, e:
            log.error("deploy.py", "%s" % e)