def post(self, request): default_if = get_default_interface() config_list = get_net_config_fedora(network_devices()) for dconfig in config_list: ni = None if (NetworkInterface.objects.filter(name=dconfig['name']).exists()): ni = NetworkInterface.objects.get(name=dconfig['name']) ni.alias = dconfig['alias'] ni.mac = dconfig['mac'] ni.boot_proto = dconfig['bootproto'] ni.onboot=dconfig['onboot'] ni.network=dconfig['network'] ni.netmask=dconfig['netmask'] ni.ipaddr=dconfig['ipaddr'] else: ni = NetworkInterface(name=dconfig['name'], alias=dconfig['alias'], mac=dconfig['mac'], boot_proto=dconfig['bootproto'], onboot=dconfig['onboot'], network=dconfig['network'], netmask=dconfig['netmask'], ipaddr=dconfig['ipaddr']) if (default_if == ni.name): ni.itype = 'management' update_samba_discovery(dconfig['ipaddr'], settings.AVAHI_SMB_CONF) try: update_issue(dconfig['ipaddr']) except: logger.error('Unable to update /etc/issue') ni.save() devices = NetworkInterface.objects.all() serializer = NetworkInterfaceSerializer(devices) return Response(serializer.data)
def _net_scan(self): default_if = get_default_interface() config_d = get_net_config_fedora(network_devices()) for dconfig in config_d.values(): ni = None if NetworkInterface.objects.filter(name=dconfig["name"]).exists(): ni = NetworkInterface.objects.get(name=dconfig["name"]) ni.alias = dconfig["alias"] ni.mac = dconfig["mac"] ni.boot_proto = dconfig["bootproto"] ni.onboot = dconfig["onboot"] ni.network = dconfig["network"] ni.netmask = dconfig["netmask"] ni.ipaddr = dconfig["ipaddr"] ni.gateway = dconfig["gateway"] ni.dns_servers = dconfig["dns_servers"] ni.domain = dconfig["domain"] else: ni = NetworkInterface( name=dconfig["name"], alias=dconfig["alias"], mac=dconfig["mac"], boot_proto=dconfig["bootproto"], onboot=dconfig["onboot"], network=dconfig["network"], netmask=dconfig["netmask"], ipaddr=dconfig["ipaddr"], gateway=dconfig["gateway"], dns_servers=dconfig["dns_servers"], domain=dconfig["domain"], ) if default_if == ni.name: ni.itype = "management" try: update_issue(dconfig["ipaddr"]) except: logger.error("Unable to update /etc/issue") ni.save() devices = [] for ni in NetworkInterface.objects.all(): if ni.name not in config_d: logger.debug( "network interface(%s) does not exist in the " "system anymore. Removing from db" % (ni.name) ) ni.delete() else: devices.append(ni) serializer = NetworkInterfaceSerializer(devices, many=True) return Response(serializer.data)
def post(self, request): for d in network_devices(): if (NetworkInterface.objects.filter(name=d).exists()): continue dconfig = get_net_config(d) new_device = NetworkInterface(name=d, mac=dconfig['mac'], boot_proto=dconfig['bootproto'], onboot=dconfig['onboot'], network=dconfig['network'], netmask=dconfig['netmask'], ipaddr=dconfig['ipaddr']) new_device.save() devices = NetworkInterface.objects.all() serializer = NetworkInterfaceSerializer(devices) return Response(serializer.data)
def _net_scan(): default_if = get_default_interface() config_d = get_net_config_fedora(network_devices()) for dconfig in config_d.values(): ni = None if (NetworkInterface.objects.filter( name=dconfig['name']).exists()): ni = NetworkInterface.objects.get(name=dconfig['name']) ni.alias = dconfig['alias'] ni.mac = dconfig['mac'] ni.boot_proto = dconfig['bootproto'] ni.onboot = dconfig['onboot'] ni.network = dconfig['network'] ni.netmask = dconfig['netmask'] ni.ipaddr = dconfig['ipaddr'] ni.gateway = dconfig['gateway'] ni.dns_servers = dconfig['dns_servers'] ni.domain = dconfig['domain'] else: ni = NetworkInterface(name=dconfig['name'], alias=dconfig['alias'], mac=dconfig['mac'], boot_proto=dconfig['bootproto'], onboot=dconfig['onboot'], network=dconfig['network'], netmask=dconfig['netmask'], ipaddr=dconfig['ipaddr'], gateway=dconfig['gateway'], dns_servers=dconfig['dns_servers'], domain=dconfig['domain']) if (default_if == ni.name): ni.itype = 'management' try: update_issue(dconfig['ipaddr']) except: logger.error('Unable to update /etc/issue') ni.save() devices = [] for ni in NetworkInterface.objects.all(): if (ni.name not in config_d): logger.debug('network interface(%s) does not exist in the ' 'system anymore. Removing from db' % (ni.name)) ni.delete() else: devices.append(ni) serializer = NetworkInterfaceSerializer(devices, many=True) return Response(serializer.data)
def post(self, request): default_if = get_default_interface() config_list = get_net_config_fedora(network_devices()) for dconfig in config_list: ni = None if (NetworkInterface.objects.filter( name=dconfig['name']).exists()): ni = NetworkInterface.objects.get(name=dconfig['name']) ni.alias = dconfig['alias'] ni.mac = dconfig['mac'] ni.boot_proto = dconfig['bootproto'] ni.onboot = dconfig['onboot'] ni.network = dconfig['network'] ni.netmask = dconfig['netmask'] ni.ipaddr = dconfig['ipaddr'] ni.gateway = dconfig['gateway'] ni.dns_servers = dconfig['dns_servers'] ni.domain = dconfig['domain'] else: ni = NetworkInterface(name=dconfig['name'], alias=dconfig['alias'], mac=dconfig['mac'], boot_proto=dconfig['bootproto'], onboot=dconfig['onboot'], network=dconfig['network'], netmask=dconfig['netmask'], ipaddr=dconfig['ipaddr'], gateway=dconfig['gateway'], dns_servers=dconfig['dns_servers'], domain=dconfig['domain']) if (default_if == ni.name): ni.itype = 'management' update_samba_discovery(dconfig['ipaddr'], settings.AVAHI_SMB_CONF) try: update_issue(dconfig['ipaddr']) except: logger.error('Unable to update /etc/issue') ni.save() devices = NetworkInterface.objects.all() serializer = NetworkInterfaceSerializer(devices) return Response(serializer.data)