Exemple #1
0
 def _refresh_ni(cls):
     config_d = get_net_config(all=True)
     for dconfig in config_d.values():
         ni = None
         if (NetworkInterface.objects.filter(
                 name=dconfig['name']).exists()):
             ni = NetworkInterface.objects.get(name=dconfig['name'])
             ni = cls._update_ni_obj(ni, dconfig)
         else:
             ni = NetworkInterface(
                 name=dconfig.get('name', None),
                 dname=dconfig.get('dname', None),
                 dtype=dconfig.get('dtype', None),
                 dspeed=dconfig.get('dspeed', None),
                 mac=dconfig.get('mac', None),
                 method=dconfig.get('method', None),
                 autoconnect=dconfig.get('autoconnect', None),
                 netmask=dconfig.get('netmask', None),
                 ipaddr=dconfig.get('ipaddr', None),
                 gateway=dconfig.get('gateway', None),
                 dns_servers=dconfig.get('dns_servers', None),
                 ctype=dconfig.get('ctype', None),
                 state=dconfig.get('state', None))
         ni.save()
     for ni in NetworkInterface.objects.all():
         if (ni.dname not in config_d):
             logger.debug('network interface(%s) does not exist in the '
                          'system anymore. Removing from db' % (ni.name))
             ni.delete()
Exemple #2
0
 def _net_scan(cls):
     config_d = get_net_config(all=True)
     for dconfig in config_d.values():
         ni = None
         if (NetworkInterface.objects.filter(
                 name=dconfig['name']).exists()):
             ni = NetworkInterface.objects.get(name=dconfig['name'])
             ni = cls._update_ni_obj(ni, dconfig)
         else:
             ni = NetworkInterface(name=dconfig.get('name', None),
                                   dname=dconfig.get('dname', None),
                                   dtype=dconfig.get('dtype', None),
                                   dspeed=dconfig.get('dspeed', None),
                                   mac=dconfig.get('mac', None),
                                   method=dconfig.get('method', None),
                                   autoconnect=dconfig.get('autoconnect', None),
                                   netmask=dconfig.get('netmask', None),
                                   ipaddr=dconfig.get('ipaddr', None),
                                   gateway=dconfig.get('gateway', None),
                                   dns_servers=dconfig.get('dns_servers', None),
                                   ctype=dconfig.get('ctype', None),
                                   state=dconfig.get('state', None))
         ni.save()
     devices = []
     for ni in NetworkInterface.objects.all():
         if (ni.dname 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)
Exemple #3
0
 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)
Exemple #4
0
 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)
Exemple #5
0
 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)