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!")
def create_bindhosts(argvs): msg = 'the new bind_hosts file' bindhost_file = parse_argvs(argvs, msg) source = yaml_parser(bindhost_file) if source: for key,val in source.items(): host_obj = session.query(models.Host).filter(models.Host.hostname==val.get('hostname')).first() assert host_obj for item in val['remote_users']: assert item.get('auth_type') if item.get('auth_type') == 'ssh-passwd': remoteuser_obj = session.query(models.RemoteUser).filter(models.RemoteUser.username==item.get('username'), models.RemoteUser.password==item.get('password')).first() else: remoteuser_obj = session.query(models.RemoteUser).filter(models.RemoteUser.username==item.get('username'), models.RemoteUser.auth_type==item.get('auth_type')).first() # print('>>>>',host_obj,remoteuser_obj) bindhost_obj = models.BindHost(host_id=host_obj.id,remote_user_id=remoteuser_obj.id) session.add(bindhost_obj) if source[key].get('groups'): groups = common_filters.groups_filter(source[key]) bindhost_obj.groups = groups if source[key].get('user_profiles'): user_profiles = common_filters.user_profiles_filter(source[key]) bindhost_obj.user_profiles = user_profiles session.commit()
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()
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()
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()