def handle(self, *args, **options): vlan_id = options['vlan_id'] start_ip = options['start_ip'] num = options['num'] try: vlan = Vlan.objects.get(pk=vlan_id) except: print('vlan_id error.') return start_ip_int = self._ip_str2int(start_ip) if not start_ip_int: print('start_ip error.') return False mac_ip_list = [] for i in range(num): ip_int = start_ip_int + i strip = self._ip_int2str(ip_int) mac = self._get_mac(ip_int) print(strip, mac) macip = MacIP() macip.vlan_id = vlan_id macip.mac = mac macip.ipv4 = strip macip.enable = True macip.save() mac_ip_list.append((mac, strip, ip_int)) self._write_dhcpd(vlan, mac_ip_list, 'dhcp_conf_' + start_ip + '[' + str(num) + '].conf')
def handle(self, *args, **options): vlan_id = options["vlan_id"] start_ip = options["start_ip"] num = options["num"] try: vlan = Vlan.objects.get(pk=vlan_id) except: print("vlan_id error.") return start_ip_int = self._ip_str2int(start_ip) if not start_ip_int: print("start_ip error.") return False mac_ip_list = [] for i in range(num): ip_int = start_ip_int + i strip = self._ip_int2str(ip_int) mac = self._get_mac(ip_int) print(strip, mac) macip = MacIP() macip.vlan_id = vlan_id macip.mac = mac macip.ipv4 = strip macip.enable = True macip.save() mac_ip_list.append((mac, strip, ip_int)) self._write_dhcpd(vlan, mac_ip_list, "dhcp_conf_" + start_ip + "[" + str(num) + "].conf")
def create_ip(vlan, mac, ipv4): ip = MacIP() ip.vlan = vlan ip.mac = mac ip.ipv4 = ipv4 ip.save() return ip