Exemplo n.º 1
0
	def query_manage_remain(self, type):
		try:
			last_seg = IPrms_Segment.where(segmenttype=type).select_tail()
			first_seg = IPrms_Segment.where(segmenttype=type).select_head()
			sign_total = IP_Detail.where(type=type).count()
			min_subnet_id = self.get_subnet_id(first_seg.min)
			max_subnet_id = self.get_subnet_id(last_seg.max)
			if min_subnet_id == max_subnet_id:
				dev_max = self.get_host_id(first_seg.max)
			else:
				dev_max = (max_subnet_id-min_subnet_id+1) * 255
			remain_num = dev_max - sign_total
			print "管理网段剩余可分配设备数量:%s个" % (remain_num)
			return remain_num
		except:
			print "尚未分配管理网段"
Exemplo n.º 2
0
	def query_conn_remain(self):
		try:
			seg_total = IPrms_Segment.where(segmenttype='CONN').count()
			tmp = IPrms_Segment.where(segmenttype='CONN').select_head()
			mask_id = self.get_host_id(tmp.subnetmask)
			subnet_id = self.get_subnet_id(tmp.subnetmask)
			if subnet_id == 255: 
				total = seg_total * (256-mask_id)
			else:
				total = seg_total * 256 * (256-mask_id)
			signed_num = IP_Detail.where(type='CONN').count()
			remain_num = total - signed_num
			print "互联网段剩余可分配ip地址数量:%s个" % (remain_num)
			return remain_num
		except:
			print "尚未分配互联网段"
Exemplo n.º 3
0
		def regist_device():
			signed_total = IP_Detail.where(type=type).count()
			tmp = IPrms_Segment.where(segmenttype=type).select_head()
			net_addr = self.get_net_addr(tmp.segmentname)
			sub_mask = tmp.subnetmask
			tmp_seg = tmp.segmentname
			subnet_id = self.get_subnet_id(tmp_seg)
			dev_id = dev_start_id
			#为了防止ip分配因堆叠ip存在而错误,计算堆叠ip数量
			pile_ip_num = IP_Detail.where(remark='PILE_MGT_IP').count() / 2
			host_id_start = signed_total - pile_ip_num + 1
			host_id_end = host_id_start + dev_num
			check = 0
			fullseg = 255 * check
			for i in range(host_id_start, host_id_end, 1):
				if i > 255:
					check = i / 256
					fullseg = 255 * check
				#fullseg用来减去255的倍数得到下一子网段的正确主机号,参数check用来使子网号保持正确
				ip = '%s.%s.%s' % (net_addr, subnet_id+check, i-fullseg)
				gateway = '%s.%s.1' % (net_addr, subnet_id+check)
				#la管理分配存入ip_detail表
				ip_detail = IP_Detail()
				ip_detail.address = ip
				ip_detail.gateway = gateway
				ip_detail.subnetmask = sub_mask
				ip_detail.netdevicename = '%s%s' % (dev_name, dev_id)
				ip_detail.port = type
				ip_detail.type = type
				ip_detail_list.append(ip_detail)
				dev_id = dev_id + 1
Exemplo n.º 4
0
		def regist_device():
			signed_total = IP_Detail.where(type='CONN').count()
			tmp = IP_Detail.where(netdevicename=dev1_name, type='CONN').select_head()
			#有设备注册,追加注册
			if tmp:
				net_addr = self.get_net_addr(tmp.address)
				subnet_id = self.get_subnet_id(tmp.address)
				sub_mask = tmp.subnetmask
				#获取最后一个设备的ID号
				tmp_tail = IP_Detail.where(netdevicename=dev1_name, type='CONN').select_tail()
				dev1_id = tmp_tail.netdeviceid + 1
			#之前无设备注册
			else:
				tmp = IPrms_Segment.where(segmenttype='CONN').select_head()
				net_addr = self.get_net_addr(tmp.segmentname)
				subnet_id = self.get_subnet_id(tmp.segmentname)
				sub_mask = tmp.subnetmask
				dev1_id = 1
			host_id_start = signed_total
			host_id_end = host_id_start + 2 * dev1_num * dev2_num
			gateway_ip = ''
			type = 'CONN'
			check = 0
			fullseg = 255 * check
			dev2_id = 1
			for i in range(host_id_start, host_id_end, 1):
				if i > 255:
					check = i / 256
					fullseg = 256 * check 
				ip = '%s.%s.%s' % (net_addr, subnet_id+check, i-fullseg)
				source_dev_name = dev1_name
				source_dev_id = dev1_id
				dest_dev_name = dev2_name
				dest_dev_id = dev2_id
				#判断该ip是否是源ip
				if issourceip(ip):
					dev = source_dev_name
					dev_id = source_dev_id
					port = 'CO%s' % (dev2_id)
				else:
					dev = dest_dev_name
					dev_id = dest_dev_id
					port = '%s%s' % (source_dev_name, dev_id)
					dev2_id = dev2_id + 1
				'''ip_detail表注册'''
				ip_detail = IP_Detail()
				ip_detail.address = ip
				ip_detail.gateway = gateway_ip
				ip_detail.subnetmask = sub_mask
				ip_detail.netdevicename = dev
				ip_detail.netdeviceid = dev_id
				ip_detail.port = port
				ip_detail.type = type
				ip_detail_list.append(ip_detail)
				if dev2_id > dev2_num:
					dev2_id = 1
					dev1_id = dev1_id + 1
			print "完成设备端口互联资源规划"
Exemplo n.º 5
0
	def query_server_remain(self, mask):
		try:
			#在数据库iprms_segment中保存服务大网段SE1的信息,查询时获取大网段信息
			se = IPrms_Segment.where(segmenttype='SE1').select_head()
			if se:
				se_seg = se.segmentname
				se_max_ip = se.max
				se_min_ip = se.min
				subnet_end = self.get_subnet_id(se_max_ip)
			else:
				#若未分配服务大网段,则无法注册,查询结果为0
				return 0

			subnet_end = self.get_subnet_id(se_max_ip)
			tail = IPrms_IP.where(state='Available').select_tail()
			if tail:
				tail_ip = tail.ip
				subnet_start = self.get_subnet_id(tail_ip)
			else:
				tmp = IPrms_Segment.where(segmenttype='CONN').select_tail()
				if tmp:
					tmp_seg = tmp.segmentname
					subnet_start = self.get_subnet_id(tmp_seg) + 1
				else:
					subnet_start = self.get_subnet_id(se_min_ip)
			#计算出剩余未分配ip地址的数量
			remain_ip = (subnet_end-subnet_start) * 255
			if mask > 32 or mask < 16:
				print "错误:输入大网段子网掩码数值超过合法范围(16-32)"
				return
			elif mask >= 16 and mask < 24:
				seg_num = 2 ** (24-mask)
				remain_num = (remain_ip/255) / seg_num
			else:
				seg_num = 256 / (2**(32-mask))
				remain_num = (remain_ip/255) * seg_num
			print "服务网段剩余可分配/%s设备数量:%s个" % (mask, remain_num)
			return remain_num
		except:
			print "尚未分配服务网段"
			return 0
Exemplo n.º 6
0
	def server_seg_alloc(self, type, net_addr, subnet_id, host_id, mask):
		print "正在计算并分配服务器大网段空间......"
		subnet_start = subnet_id
		if mask > 32 or mask < 16:
			print "错误:输入大网段子网掩码数值超过合法范围(16-32)"
		if mask >= 16 and mask < 24:
			subnet_num = 2 ** (24-mask)
			host_end = 255
		else:
			subnet_num = 1
			host_end = 2 ** (32-mask)
		subnet_end = subnet_start + subnet_num - 1
		iprms_segment = IPrms_Segment()
		iprms_segment.segmentname = '%s.%s.%s/%s' % (net_addr, subnet_id, host_id, mask)
		iprms_segment.subnetmask = self.cal_sub_mask(mask)
		iprms_segment.gateway = ''
		iprms_segment.vlan = ''
		iprms_segment.segmenttype = type
		iprms_segment.min = '%s.%s.%s' % (net_addr, subnet_id, host_id)
		iprms_segment.max = '%s.%s.%s' % (net_addr, subnet_end, host_end)
		#jiwu提出不需要保存服务器大网段信息,如果暂时不存,那么在查询(server_query)的时候写死参数
		iprms_segment.save()
		print "服务大网段%s.%s.%s/%s分配完成" % (net_addr, subnet_id, host_id, mask)
Exemplo n.º 7
0
		def regist_device():
			signed_total = IP_Detail.where(type=type).count()
			signed_dev_num = IP_Detail.where(netdevicename=dev_name, type=type).count()
			tmp = IPrms_Segment.where(segmenttype=type).select_head()
			net_addr = self.get_net_addr(tmp.segmentname)
			sub_mask = tmp.subnetmask
			tmp_seg = tmp.segmentname
			subnet_id = self.get_subnet_id(tmp_seg)
			dev_id = 1
			host_id = signed_total + 1
			#已经有设备注册过的情况
			if signed_dev_num != 0:
				#如果有事先注册的设备,那么子网序号以及主机号从最后一次注册的顺序开始
				#tmp = IP_Detail.where(netdevicename=dev_name, netdeviceid=signed_dev_num).select_head()
				subnet_id = self.get_subnet_id(tmp.segmentname)
				dev_id = signed_dev_num + 1
			host_id_start = host_id
			host_id_end = host_id_start + dev_num
			check = 0
			fullseg = 255 * check
			for i in range(host_id_start, host_id_end, 1):
				if i > 255:
					check = i / 256
					fullseg = 255 * check 
				#fullseg用来减去255的倍数得到下一子网段的正确主机号,参数check用来使子网号保持正确
				ip = '%s.%s.%s' % (net_addr, subnet_id+check, i-fullseg)
				gateway = '%s.%s.1' % (net_addr, subnet_id+check)
				#la管理分配存入ip_detail表
				ip_detail = IP_Detail()
				ip_detail.address = ip
				ip_detail.gateway = gateway
				ip_detail.subnetmask = sub_mask
				ip_detail.netdevicename = dev_name
				ip_detail.netdeviceid = dev_id
				ip_detail.port = type
				ip_detail.type = type
				ip_detail_list.append(ip_detail)
				dev_id = dev_id + 1
Exemplo n.º 8
0
	def manage_seg_alloc(self, net_addr, subnet_id, host_id, mask, type):
		print "正在计算并分配管理大网段空间......"
		if mask > 32 or mask < 16:
			print "错误:输入网段子网掩码数值超过合法范围(16-32)"
			return
		elif mask >= 16 and mask < 24:
			subnet_num = 2 ** (24-mask)
			seg_length = 2 ** (24-mask)
			host_max = 255
		else:
			subnet_num = 1
			seg_length = 1
			host_max = (2**(32-mask)) - 1
		#根据掩码号计算子网掩码
		sub_mask = self.cal_sub_mask(mask)
		seg_id = IPrms_Segment.where().count()
		subnet_id_start = subnet_id
		subnet_id_end = subnet_id + subnet_num
		host_id_start = 1
		host_id_end = host_id_start + host_max
		for i in range(subnet_id_start, subnet_id_end, 1):
			if (i-subnet_id) % seg_length == 0:
				#分配管理网段时在iprms_ip、iprms_segment中划分好所有信息
				seg_id = seg_id + 1
				iprms_segment = IPrms_Segment()
				iprms_segment.segmentname = '%s.%s.%s/%s' % (net_addr, i, host_id, mask)
				iprms_segment.segmenttype = type
				iprms_segment.subnetmask = sub_mask
				iprms_segment.gateway = 'x.x.x.x'
				iprms_segment.netdevicename = ''
				iprms_segment.vlan = '-'
				iprms_segment.min = '%s.%s.0' % (net_addr, i)
				iprms_segment.max = '%s.%s.%s' % (net_addr, i+seg_length-1, host_max)
				iprms_segment.save()
			for j in range(host_id_start, host_id_end, 1):
				ip = '%s.%s.%s' % (net_addr, i, j)
				dev_max = j * (i+1)
				iprms_ip = IPrms_IP()
				iprms_ip.segmentid = seg_id
				iprms_ip.ip = ip
				iprms_ip.state = 'Specific'
				iprms_ip.save()
		print "管理大网段分配完成,你最多可以为%s个设备分配管理IP" % (dev_max)
Exemplo n.º 9
0
		def regist_device():
			#选择第一个未使用的ip,获取alloc的信息作为注册开始信息
			tmp = IPrms_IP.where(state='Off').select_head()
			net_addr = self.get_net_addr(tmp.ip)
			subnet_id_start = self.get_subnet_id(tmp.ip)
			seg_length = 2 ** (32-mask)
			if mask > 16 and mask < 24:
				seg_length = 256
				subnet_id_end = subnet_id_start + (2**(24-mask)) * dev_num - 1
				host_id_end = 255
				#subnet_num指一个设备所占的最多子网数量
				subnet_num = 2 ** (24-mask)
			else:
				subnet_num = 1
				seg_length = 2 ** (32-mask)
				x = 256 / seg_length
				if dev_num % x == 0:
					subnet_id_end = subnet_id_start + dev_num / x - 1
					host_id_end = 255
				else:
					subnet_id_end = subnet_id_start + dev_num / x
					host_id_end = (dev_num%x) * seg_length
			sub_mask = self.cal_sub_mask(mask)
			vlan = vlan_name
			dev_id1 = dev_start_id1
			dev_id2 = dev_start_id2
			seg_id = IPrms_Segment.where().count()
			#将堆叠设备号加入注册队列
			register_queue = []
			tuple_index = 0
			for i in range(dev_start_id1, dev_end_id1 + 1, 2):
				pile_dev_id = (dev_id1, dev_id2)
				register_queue.append(pile_dev_id)
				dev_id1 = dev_id1 + 2
				dev_id2 = dev_id2 + 2
			for i in range(subnet_id_start, subnet_id_end+1, 1):
				for j in range(0, 256*subnet_num, 1):
					#满足三个条件即注册信息到表:1.主机号为下一个网段号的主机号 2.够分配下一个网段 3.一个设备的分配跨过了正确数目子网号
					if j % seg_length == 0 and j + seg_length <= 256 and (i-subnet_id_start) % subnet_num == 0:
						#当到达最后一个子网,所有设备都注册后,这时检索到的ip将跳过,不再注册到iprms_segment与ip_detail中
						if i == subnet_id_end and j >= host_id_end:
							pass
						else:
							net_seg = '%s.%s.%s/%s' % (net_addr, i, j, mask)
							gateway_ip = '%s.%s.%s' % (net_addr, i, j + 1)
							min_value = '%s.%s.%s' % (net_addr, i, j)
							max_value = '%s.%s.%s' % (net_addr, i+subnet_num-1, j+seg_length-1)
							dev_id1 = register_queue[tuple_index][0]
							dev_id2 = register_queue[tuple_index][1]
							'''iprms_segment表注册'''
							iprms_segment = IPrms_Segment()
							iprms_segment.segmentname = net_seg
							iprms_segment.segmenttype = type
							iprms_segment.gateway = gateway_ip
							iprms_segment.subnetmask = sub_mask
							iprms_segment.netdevicename = '%s%s/%s%s' % (dev_name, dev_id1, dev_name, dev_id2)
							#iprms_segment.netdeviceid = dev_id
							iprms_segment.vlan = vlan_name
							iprms_segment.ipattribute = ip_attr
							iprms_segment.min = min_value
							iprms_segment.max = max_value
							iprms_segment_list.append(iprms_segment)
							'''ip_detail表注册'''
							for dev_id in register_queue[tuple_index]:
								ip_detail = IP_Detail()
								ip_detail.address = gateway_ip
								ip_detail.gateway = gateway_ip
								ip_detail.subnetmask = sub_mask
								ip_detail.netdevicename = '%s%s' % (dev_name, dev_id)
								#ip_detail.netdeviceid = dev_id
								ip_detail.port = 'VLAN%s' % vlan_name
								ip_detail.type = type
								ip_detail_list.append(ip_detail)
							seg_id = seg_id + 1
							tuple_index = tuple_index + 1
					'''iprms_ip表注册'''
					ip = '%s.%s.%s' % (net_addr, i, j)
					state = 'Available'
					segmentid = seg_id
					#判断是否为网关ip
					if j % seg_length == 1:
						state = 'Specific'
					if i == subnet_id_end and j > host_id_end:
						#对于一个子网域剩下未分配的ip,系统将把其全部浪费掉,状态由Off转为Unavaliable
						state = 'Unavailable'
						segmentid = 0
					iprms_ip_list.append([ip, state, segmentid])
			print "完成服务器网络资源自动分配"
Exemplo n.º 10
0
	def conn_seg_alloc(self, net_addr, subnet_id, host_id, l_mask, s_mask):
		print "正在计算并分配互联大网段空间......"
		#检查输入掩码
		if l_mask > s_mask:
			print "错误:输入大网段掩码必须小于小网段掩码"
			return
		if l_mask > 32 or l_mask < 16:
			print "错误:输入大网段子网掩码数值超过合法范围(16-32)"
			return
		elif l_mask >= 16 and l_mask < 24:
			subnet_max = 2 ** (24-l_mask)
			host_max = 255
		else:
			subnet_max = 1
			subnet_id_start = subnet_id
			subnet_id_end = subnet_id_start + subnet_max
			host_max = seg_length
		if s_mask >= 16 and s_mask < 24:
			seg_length = 2 ** (24-s_mask)
		else:
			seg_length = 2 ** (32-s_mask)
		#seg_id是ip地址所对应的网段id
		seg_id = IPrms_Segment.where().count()
		sub_mask = self.cal_sub_mask(s_mask)
		mask = s_mask
		host_id_start = host_id
		host_id_end = 256
		subnet_id_start = subnet_id
		subnet_id_end = subnet_id_start + subnet_max
		if subnet_id + subnet_max > 255:
			print "分配互联大网段%s.%s.%s/%s资源不足" % (net_addr, subnet_id, host_id, l_mask)
			return
		for i in range(subnet_id_start, subnet_id_end, 1):
			for j in range(host_id_start, host_id_end, 1):
				if j % seg_length == 0 and j + seg_length <= 256:
					seg_id = seg_id + 1
					iprms_segment = IPrms_Segment()
					iprms_segment.segmentname = '%s.%s.%s/%s' % (net_addr, i, j, mask)
					iprms_segment.segmenttype = 'CONN'
					iprms_segment.subnetmask = sub_mask
					iprms_segment.gateway = 'x.x.x.x'
					iprms_segment.netdevicename = ''
					iprms_segment.ipattribute = ''
					iprms_segment.vlan = ''
					iprms_segment.min = '%s.%s.%s' % (net_addr, i, j)
					iprms_segment.max = '%s.%s.%s' % (net_addr, i, j+seg_length-1)
					iprms_segment.save()
				#分配互联网段时,先在iprms_ip中划分好所有ip的信息
				ip = '%s.%s.%s' % (net_addr, i, j)
				iprms_ip = IPrms_IP()
				iprms_ip.segmentid = seg_id
				iprms_ip.ip = ip
				iprms_ip.state = 'Specific'
				iprms_ip.save()
		print "互联大网段分配完成"
Exemplo n.º 11
0
		def regist_device():
			#选择最后一个被注册的ip,获取其信息推导出本次注册开始信息
			tmp = IPrms_IP.where().select_tail()
			if tmp:
				net_addr = self.get_net_addr(tmp.ip)
				subnet_id_start = self.get_subnet_id(tmp.ip) + 1
			else:
				#服务网段尚未有信息被注册
				se = IPrms_Segment.where(segmenttype='SE1').select_head()
				tmp = IPrms_Segment.where(segmenttype='CONN').select_tail()
				if tmp:
					tmp_seg = tmp.segmentname
					net_addr = self.get_net_addr(tmp_seg)
					subnet_id_start = self.get_subnet_id(tmp_seg) + 1
				else:
					se_min_ip = se.min
					subnet_start = self.get_subnet_id(se_min_ip)
			seg_length = 2 ** (32-mask)
			if mask > 16 and mask < 24:
				seg_length = 256
				subnet_id_end = subnet_id_start + (2**(24-mask)) * dev_num - 1
				host_id_end = 255
				#subnet_num指一个设备所占的最多子网数量
				subnet_num = 2 ** (24-mask)
			else:
				subnet_num = 1
				seg_length = 2 ** (32-mask)
				x = 256 / seg_length
				if dev_num % x == 0:
					subnet_id_end = subnet_id_start + dev_num / x - 1
					host_id_end = 255
				else:
					subnet_id_end = subnet_id_start + dev_num / x
					host_id_end = (dev_num%x) * seg_length
			sub_mask = self.cal_sub_mask(mask)
			vlan = vlan_name
			seg_id = IPrms_Segment.where().count()
			dev_id = dev_start_id
			for i in range(subnet_id_start, subnet_id_end+1, 1):
				for j in range(0, 256*subnet_num, 1):
					#满足三个条件即注册信息到表:1.主机号为下一个网段号的主机号 2.够分配下一个网段 3.一个设备的分配跨过了正确数目子网号
					if j % seg_length == 0 and j + seg_length <= 256 and (i-subnet_id_start) % subnet_num == 0:
						#当到达最后一个子网,所有设备都注册后,这时检索到的ip将跳过,不再注册到iprms_segment与ip_detail中
						if i == subnet_id_end and j >= host_id_end:
							pass
						else:
							net_seg = '%s.%s.%s/%s' % (net_addr, i, j, mask)
							gateway_ip = '%s.%s.%s' % (net_addr, i, j + 1)
							min_value = '%s.%s.%s' % (net_addr, i, j)
							max_value = '%s.%s.%s' % (net_addr, i+subnet_num-1, j+seg_length-1)
							'''iprms_segment表注册'''
							iprms_segment = IPrms_Segment()
							iprms_segment.segmentname = net_seg
							iprms_segment.segmenttype = type
							iprms_segment.gateway = gateway_ip
							iprms_segment.subnetmask = sub_mask
							iprms_segment.netdevicename = '%s%s' % (dev_name, dev_id)
							iprms_segment.vlan = vlan_name
							iprms_segment.ipattribute = ip_attr
							iprms_segment.min = min_value
							iprms_segment.max = max_value
							iprms_segment_list.append(iprms_segment)
							'''ip_detail表注册'''
							ip_detail = IP_Detail()
							ip_detail.address = gateway_ip
							ip_detail.gateway = gateway_ip
							ip_detail.subnetmask = sub_mask
							ip_detail.netdevicename = '%s%s' % (dev_name, dev_id)
							ip_detail.port = 'VLAN%s' % vlan_name
							ip_detail.type = type
							ip_detail_list.append(ip_detail)
							seg_id = seg_id + 1
							dev_id = dev_id + 1
					'''iprms_ip表注册'''
					if j == 0:
						pass
					else:
						iprms_ip = IPrms_IP()
						ip = '%s.%s.%s' % (net_addr, i, j)
						iprms_ip.ip = ip
						iprms_ip.state = 'Available'
						iprms_ip.segmentid = seg_id
						#判断是否为网关ip
						if j % seg_length == 1:
							iprms_ip.state = 'Specific'
						if i == subnet_id_end and j > host_id_end:
							#对于一个子网域剩下未分配的ip,系统将把其全部浪费掉,状态转为Unavaliable
							iprms_ip.state = 'Unavailable'
							iprms_ip.segmentid = 0
						iprms_ip_list.append(iprms_ip)
			print "完成服务器网络资源自动分配"
Exemplo n.º 12
0
		def regist_device():
			#选择最后一个被注册的ip,获取其信息推导出本次注册开始信息
			tmp = IPrms_IP.where().select_tail()
			if tmp:
				net_addr = self.get_net_addr(tmp.ip)
				subnet_id_start = self.get_subnet_id(tmp.ip) + 1
			else:
				#服务网段尚未有信息被注册
				#tmp = IPrms_Segment.where(segmenttype='SE1').select_head()
				#tmp_seg = tmp.segmentname
				#net_addr = self.get_net_addr(tmp_seg)
				#subnet_id_start = self.get_subnet_id(tmp_seg) + 8
				net_addr = '172.16'
				subnet_id_start = 8
			seg_length = 2 ** (32-mask)
			if mask > 16 and mask < 24:
				#seg_length = 256
				#subnet_id_end = subnet_id_start + (2**(24-mask)) * dev_num - 1
				host_id_end = 255
				#subnet_num指一个设备所占的最多子网数量
				subnet_num = 2 ** (24-mask)
				subnet_id_end = subnet_id_start + subnet_num
				##ip数量
				ip_num = subnet_num * 255
			else:
				subnet_num = 1
				#seg_length = 2 ** (32-mask)
				#x = 256 / seg_length
				subnet_id_end = subnet_id_start + 1
				host_id_end = dev_num
				# if dev_num % x == 0:
				# 	subnet_id_end = subnet_id_start + dev_num / x - 1
				# 	host_id_end = 255
				# else:
				# 	subnet_id_end = subnet_id_start + dev_num / x
				# 	host_id_end = (dev_num%x) * seg_length
				##ip数量
				ip_num = host_id_end + 1
			if ip_num < dev_num:
				print "Error:网段ip资源不够分配服务器设备!"
				return
			sub_mask = self.cal_sub_mask(mask)
			vlan = vlan_name
			'''iprms_segment表注册'''
			min_value = '%s.%s.%s' % (net_addr, subnet_id_start, 0)
			max_value = '%s.%s.%s' % (net_addr, subnet_id_end - 1, host_id_end)
			net_seg = '%s.%s.%s/%s' % (net_addr, subnet_id_start, 0, mask)
			iprms_segment = IPrms_Segment()
			iprms_segment.segmentname = net_seg
			iprms_segment.segmenttype = type
			iprms_segment.gateway = '%s.%s.%s' % (net_addr, subnet_id_start, 1)
			iprms_segment.subnetmask = sub_mask
			iprms_segment.netdevicename = '%s%s' % (dev_name, dev_start_id)
			iprms_segment.vlan = vlan_name
			iprms_segment.ipattribute = ip_attr
			iprms_segment.min = min_value
			iprms_segment.max = max_value
			iprms_segment_list.append(iprms_segment)

			seg_id = IPrms_Segment.where().count() + 1
			dev_id = dev_start_id
			for i in range(subnet_id_start, subnet_id_end, 1):
				for j in range(0, 256*subnet_num, 1):
					#满足三个条件即注册信息到表:1.主机号为下一个网段号的主机号 2.够分配下一个网段 3.一个设备的分配跨过了正确数目子网号
					#if j % seg_length == 0 and j + seg_length <= 256 and (i-subnet_id_start) % subnet_num == 0:
						#当到达最后一个子网,所有设备都注册后,这时检索到的ip将跳过,不再注册到iprms_segment与ip_detail中
					if i == subnet_id_end - 1 and j >= host_id_end:
						pass
					elif dev_id - dev_start_id < dev_num:
						net_seg = '%s.%s.%s/%s' % (net_addr, i, j, mask)
						gateway_ip = '%s.%s.%s' % (net_addr, i, j + 1)
						# min_value = '%s.%s.%s' % (net_addr, i, j)
						# max_value = '%s.%s.%s' % (net_addr, i+subnet_num-1, j+seg_length-1)
						'''iprms_segment表注册'''
						# iprms_segment = IPrms_Segment()
						# iprms_segment.segmentname = net_seg
						# iprms_segment.segmenttype = type
						# iprms_segment.gateway = gateway_ip
						# iprms_segment.subnetmask = sub_mask
						# iprms_segment.netdevicename = '%s%s' % (dev_name, dev_id)
						# #iprms_segment.netdeviceid = dev_id
						# iprms_segment.vlan = vlan_name
						# iprms_segment.ipattribute = ip_attr
						# iprms_segment.min = min_value
						# iprms_segment.max = max_value
						# iprms_segment_list.append(iprms_segment)
						'''ip_detail表注册'''
						ip_detail = IP_Detail()
						ip_detail.address = gateway_ip
						ip_detail.gateway = gateway_ip
						ip_detail.subnetmask = sub_mask
						ip_detail.netdevicename = '%s%s' % (dev_name, dev_id)
						ip_detail.port = 'VLAN%s' % vlan_name
						ip_detail.type = type
						ip_detail_list.append(ip_detail)
						#seg_id = seg_id + 1
						dev_id = dev_id + 1
					'''iprms_ip表注册'''
					if j == 0:
						pass
					else:
						iprms_ip = IPrms_IP()
						ip = '%s.%s.%s' % (net_addr, i, j)
						iprms_ip.ip = ip
						iprms_ip.state = 'Available'
						if i == subnet_id_end - 1 and j >= host_id_end:
							iprms_ip.segmentid = 0
						else:
							iprms_ip.segmentid = seg_id
						#判断是否为网关ip
						if j % seg_length == 1:
							iprms_ip.state = 'Specific'
						if i == subnet_id_end - 1 and j > host_id_end:
							#对于一个子网域剩下未分配的ip,系统将把其全部浪费掉,状态转为Unavaliable
							iprms_ip.state = 'Unavailable'
							iprms_ip.segmentid = 0
						iprms_ip_list.append(iprms_ip)
			print "完成服务器网络资源自动分配"