def parse_acl_file(file_name): # check if all ecs-subnets match the normal ones subnets = [] split_pattern = re.compile(r'[ ;]') with open(file_name) as f: for line in f: if ('ecs' in line) or ("{" in line) or ('}' in line) or ('#' in line): continue net = IP(split_pattern.split(line)[0]) subnets.append((str(net), net.ip, net.broadcast().int())) overlap_subnets = _check_subnet_overlap_subnet(subnets) return overlap_subnets, subnets
def add_subnet(subnet, region, colo, comment, username): subnet = IP(subnet) intranet = subnet.iptype() == 'PRIVATE' net_id = subnet.net() broadcast_ip = subnet.broadcast() ips_dict_list = [] for i in subnet: if i == net_id or i == broadcast_ip: continue ips_dict_list.append({'region': region, 'fixed_ip': str(i)}) try: with db.session.begin(subtransactions=True): subnet_item = Subnets(region_name=region, subnet=subnet.strCompressed(), create_user=username, intranet=intranet, colo=colo) if comment: subnet_item.comment = comment db.session.add(subnet_item) db.session.bulk_insert_mappings(IpPool, ips_dict_list) except Exception: raise BadParam('Ip conflict with other regions', msg_ch=u'和已有的网段有交叉,请检查后重试')