コード例 #1
0
def create_groups(argvs):
    '''
    create groups
    :param argvs:
    :return:
    '''
    if '-f' in argvs:
        group_file = argvs[argvs.index("-f") + 1]
    else:
        print_err(
            "invalid usage, should be:\ncreategroups -f <the new groups file>",
            quit=True)
    source = yaml_parser(group_file)
    if source:
        for key, val in source.items():
            print(key, val)
            obj = models.Group(name=key)
            if val.get('bind_hosts'):
                bind_hosts = common_filters.bind_hosts_filter(val)
                obj.bind_hosts = bind_hosts

            if val.get('user_profiles'):
                user_profiles = common_filters.user_profiles_filter(val)
                obj.user_profiles = user_profiles
            session.add(obj)
        session.commit()
コード例 #2
0
ファイル: views.py プロジェクト: fionaliupw/pythonstudy
def create_users(argvs):
    if '-f' in argvs:
        user_file = argvs[argvs.index("-f") + 1]
    else:
        print_err(
            "invalid usage, should be:\ncreateusers -f <the new users file>",
            quit=True)

    source = yaml_parser(user_file)
    if source:
        for key, val in source.items():
            print(key, val)
            obj = models.UserProfile(username=key,
                                     password=val.get('password'))
            if val.get('groups'):
                groups = session.query(models.Group).filter(
                    models.Group.name.in_(val.get('groups'))).all()
                if not groups:
                    print_err("none of [%s] exist in group table." %
                              val.get('groups'),
                              quit=True)
                obj.groups = groups
            if val.get('bind_hosts'):
                bind_hosts = common_filters.bind_hosts_filter(val)
                obj.bind_hosts = bind_hosts
            #print(obj)
            session.add(obj)
        session.commit()
コード例 #3
0
def create_users(argv):
    '''
    create jumpserver access user
    :param argv:
    :return:
    '''
    if '-f' in argv:
        user_file = argv[argv.index('-f') + 1]
    else:
        print_err(
            "invalid usage, should be:\ncreateusers -f <the new users file>",
            quit=True)

    source = yaml_parser(user_file)
    if source:
        print(source)
        for key, val in source.items():
            print(key, val)
            obj = models.UserProfile(username=key,
                                     password=val.get('password'))
            if val.get('groups'):
                host_groups = session.query(models.HostGroup).filter(
                    models.HostGroup.name.in_(val.get('groups'))).all()
                if not host_groups:
                    print_err("none of [%s] exist in group table." %
                              val.get('groups'),
                              quit=True)
                obj.host_groups = host_groups
            if val.get('bind_hosts'):
                bind_hosts = common_filters.bind_hosts_filter(val)
                obj.bind_hosts = bind_hosts
            session.add(obj)
        session.commit()
コード例 #4
0
ファイル: views.py プロジェクト: chenjinpeng1/python
def create_users(argvs):
    '''
    create little_finger access user
    :param argvs:
    :return:
    '''
    if '-f' in argvs:
        user_file  = argvs[argvs.index("-f") +1 ]
    else:
        print_err("invalid usage, should be:\ncreateusers -f <the new users file>",quit=True)

    source = yaml_parser(user_file)
    if source:
        for key,val in source.items():
            print(key,val)
            obj = models.UserProfile(username=key,password=val.get('password'))
            if val.get('groups'):
                groups = session.query(models.Group).filter(models.Group.name.in_(val.get('groups'))).all()
                if not groups:
                    print_err("none of [%s] exist in group table." % val.get('groups'),quit=True)
                obj.groups = groups
            if val.get('bind_hosts'):
                bind_hosts = common_filters.bind_hosts_filter(val)
                obj.bind_hosts = bind_hosts
            #print(obj)
            session.add(obj)
        session.commit()
コード例 #5
0
def create_users(argvs):
    '''
    create 堡垒机用户数据
    create little_finger access user.txt
    :param argvs:
    :return:
    '''
    if '-f' in argvs:
        user_file = argvs[argvs.index("-f") + 1]
        host_path = os.path.join(setting.BASE_DESC, user_file)
    else:
        print_err(
            "invalid usage, should be:\ncreateusers -f <the new users file>",
            quit=True)

    source = yaml_parser(host_path)
    if source:
        for key, val in source.items():
            print(key, val)
            obj = create_table.UserProfile(user_name=key,
                                           password=val.get('password'))
            if val.get('groups'):
                groups = session.query(create_table.Group).\
                    filter(create_table.Group.group_name.in_(val.get('groups'))).all()
                if not groups:
                    print_err("none of [%s] exist in group table." %
                              val.get('groups'),
                              quit=True)
                obj.groups = groups
            if val.get('bind_hosts'):
                bind_hosts = common_filters.bind_hosts_filter(val)
                obj.bind_hosts = bind_hosts
            #print(obj)
            session.add(obj)
        session.commit()
コード例 #6
0
ファイル: views.py プロジェクト: 248808194/python
def create_users(argvs):  # 创建堡垒机本机用户
    '''
    create little_finger access user
    :param argvs:
    :return:
    '''
    if '-f' in argvs:  #先判断有没有-f参数
        user_file = argvs[argvs.index("-f") +
                          1]  #通过index计算出-f的索引值,在通过+1 获得userfile
    else:
        print_err(
            "invalid usage, should be:\ncreateusers -f <the new users file>",
            quit=True)

    source = yaml_parser(user_file)  #通过yaml_parser将文件序列化为字典赋值给source
    if source:
        for key, val in source.items():
            print(key, val)
            obj = models.UserProfile(username=key,
                                     password=val.get('password'))
            if val.get('groups'):
                groups = session.query(models.Group).filter(
                    models.Group.name.in_(val.get('groups'))).all()
                if not groups:
                    print_err("none of [%s] exist in group table." %
                              val.get('groups'),
                              quit=True)
                obj.groups = groups
            if val.get('bind_hosts'):
                bind_hosts = common_filters.bind_hosts_filter(val)
                obj.bind_hosts = bind_hosts
            #print(obj)
            session.add(obj)
        session.commit()
コード例 #7
0
ファイル: views.py プロジェクト: youkelike/JumpServer
def create_groups(argvs):
    msg = 'the new groups file'
    group_file = parse_argvs(argvs, msg)
    source = yaml_parser(group_file)
    if source:
        for key,val in source.items():
            obj = models.Group(name=key)
            if val.get('bind_hosts'):#多对多关系
                bind_hosts = common_filters.bind_hosts_filter(val)
                obj.bind_hosts = bind_hosts
            if val.get('user_profiles'):#多对多关系
                user_profiles = common_filters.user_profiles_filter(val)
                obj.user_profiles = user_profiles
            session.add(obj)
        session.commit()
コード例 #8
0
ファイル: views.py プロジェクト: youkelike/JumpServer
def create_users(argvs):
    msg = 'the new users file'
    user_file = parse_argvs(argvs, msg)

    source = yaml_parser(user_file)
    if source:
        for key,val in source.items():
            obj = models.UserProfile(username=key,password=val.get('password'))
            if val.get('groups'):#多对多关系
                groups = common_filters.groups_filter(val)
                obj.groups = groups
            if val.get('bind_hosts'):#多对多关系
                bind_hosts = common_filters.bind_hosts_filter(val)
                obj.bind_hosts = bind_hosts
            session.add(obj)
        session.commit()
コード例 #9
0
ファイル: views.py プロジェクト: chenjinpeng1/python
def create_groups(argvs):
    '''
    create groups
    :param argvs:
    :return:
    '''
    if '-f' in argvs:
        group_file  = argvs[argvs.index("-f") +1 ]
    else:
        print_err("invalid usage, should be:\ncreategroups -f <the new groups file>",quit=True)
    source = yaml_parser(group_file)
    if source:
        for key,val in source.items():
            print(key,val)
            obj = models.Group(name=key)
            if val.get('bind_hosts'):
                bind_hosts = common_filters.bind_hosts_filter(val)
                obj.bind_hosts = bind_hosts

            if val.get('user_profiles'):
                user_profiles = common_filters.user_profiles_filter(val)
                obj.user_profiles = user_profiles
            session.add(obj)
        session.commit()