Ejemplo n.º 1
0
def create_remoteusers(argvs):
    '''
    create remoteusers
    :param argvs:
    :return:
    '''
    # 里面加了判断是否是文件
    if '-f' in argvs:
        remoteusers_file = argvs[argvs.index("-f") + 1]
    else:
        print_err(
            "invalid usage, should be:\ncreate_remoteusers -f <the new remoteusers file>",
            quit=True)

    #从yaml中 load 出来
    source = yaml_parser(remoteusers_file)
    if source:
        for key, val in source.items():
            print(key, val)
            #把 yaml中load出来的值获取到,赋值给对应的 sql中表的字段
            obj = models.RemoteUser(username=val.get('username'),
                                    auth_type=val.get('auth_type'),
                                    password=val.get('password'))
            session.add(obj)
    #再提交,真正的插入数据到表中
        session.commit()
Ejemplo n.º 2
0
def create_remoteusers(argvs):
    '''
    create remoteusers
    :param argvs:
    :return:
    '''
    if '-f' in argvs:
        remoteusers_file  = argvs[argvs.index("-f") +1 ]
    else:
        print_err("invalid usage, should be:\ncreate_remoteusers -f <the new remoteusers file>",quit=True)
    source = yaml_parser(remoteusers_file)
    if source:
        for key,val in source.items():
            print(key,val)
            obj = models.RemoteUser(username=val.get('username'),auth_type=val.get('auth_type'),password=val.get('password'))
            session.add(obj)
        session.commit()
Ejemplo n.º 3
0
def create_remoteusers(argvs):
    '''创建远程主机用户'''
    if '-f' in argvs:
        remoteusers_file = argvs[argvs.index('-f') + 1]
    else:
        print_err('create_remoteusers -f <the remote user file>', quit=True)
    source = yaml_parser(remoteusers_file)
    if source:
        for key, val in source.items():
            print(val)
            obj = models.RemoteUser(
                auth_type=val.get('auth_type'),
                username=val.get('username'),
                password=val.get('password'),
            )
            session.add(obj)
    session.commit()
Ejemplo n.º 4
0
def create_remoteusers(argvs):
    """
    create remoteusers
    :param argvs:
    :return:
    """
    if '-f' in argvs:
        remoteusers_file = argvs[argvs.index("-f") + 1]
    else:
        print_err("invalid usage, should be:\ncreate_remoteusers -f <the new remoteusers file>", logout=True)
        return
    source = yaml_parser(remoteusers_file)
    if source:
        logger.debug("source:\n%s" % source)
        for key, val in source.items():
            logger.debug("%s:%s" % (key, val))
            obj = models.RemoteUser(username=val.get('username'),
                                    auth_type=val.get('auth_type'),
                                    password=val.get('password'))
            logger.info(obj)
            session.add(obj)
        session.commit()
        logger.info("create remoteusers sucess!")