Ejemplo n.º 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()
Ejemplo n.º 2
0
 def create_groups(group_file):
     source = yaml_parser(group_file)
     if source:
         for key, val in source.items():
             print(key, val)
             obj = models.Group(name=key)
             if val.get('user_profiles'):
                 user_profiles = common.user_profiles_filter(val)
                 obj.user_profiles = user_profiles
             if val.get('bind_hosts'):
                 bind_hosts = common.bind_hosts_filter(val)
                 obj.bind_hosts = bind_hosts
             session.add(obj)
         session.commit()
Ejemplo n.º 3
0
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()