示例#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.HostGroup(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
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>", logout=True)
        return
    source = yaml_parser(group_file)
    if source:
        logger.debug("source:\n%s" % source)
        for key, val in source.items():
            logger.debug("%s:%s" % (key, val))
            obj = models.HostGroup(name=key)
            logger.info(obj)
            # 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()
        logger.info("create groups sucess!")
示例#3
0
def create_groups(argv):
    '''
    create groups
    :param argv:
    :return:
    '''
    if '-f' in argv:
        group_file = argv[argv.index('-f') + 1]
    else:
        print_err(
            "Invalid usage, should be:\ncreate group -f <the new group file>",
            quit=True)
    source = yaml_parser(group_file)
    if source:
        print(source)
        for key, val in source.items():
            print(key, val)
            obj = models.HostGroup(name=key)
            if val.get('bind_host'):
                bind_hosts = common_filters.bind_hosts_filter()
                obj.bind_hosts = bind_hosts
            if val.get('user_profiles'):
                user_profiles = common_filters
                obj.user_profiles = user_profiles
            session.add(obj)
        session.commit()