Esempio n. 1
0
 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)
Esempio n. 2
0
    def put(self, request, iname):
        try:
            if (not NetworkInterface.objects.filter(name=iname).exists()):
                e_msg = ('Interface with name: %s does not exist.' % iname)
                handle_exception(Exception(e_msg), request)
            ni = NetworkInterface.objects.get(name=iname)

            itype = request.DATA['itype']
            if (itype != 'management'):
                itype = 'io'
            boot_proto = request.DATA['boot_protocol']
            ni.onboot = 'yes'
            if (boot_proto == 'dhcp'):
                config_network_device(ni.alias, ni.mac)
            elif (boot_proto == 'static'):
                ipaddr = request.DATA['ipaddr']
                for i in NetworkInterface.objects.filter(ipaddr=ipaddr):
                    if (i.id != ni.id):
                        e_msg = ('IP: %s already in use by another '
                                 'interface: %s' % (ni.ipaddr, i.name))
                        handle_exception(Exception(e_msg), request)
                netmask = request.DATA['netmask']
                gateway = request.DATA['gateway']
                dns_servers = request.DATA['dns_servers'].split(',')
                domain = request.DATA['domain']
                config_network_device(ni.alias, ni.mac, boot_proto='static',
                                      ipaddr=ipaddr, netmask=netmask,
                                      gateway=gateway,
                                      dns_servers=dns_servers, domain=domain)
            else:
                e_msg = ('Boot protocol must be dhcp or static. not: %s' %
                         boot_proto)
                handle_exception(Exception(e_msg), request)
            self._restart_wrapper(ni, request)
            dconfig = get_net_config_fedora([ni.name])[0]
            ni.boot_proto = dconfig['bootproto']
            ni.netmask = dconfig['netmask']
            ni.ipaddr = dconfig['ipaddr']
            ni.itype = itype
            ni.gateway = dconfig['gateway']
            ni.dns_servers = dconfig['dns_servers']
            ni.domain = dconfig['domain']
            ni.save()
            if (itype == 'management'):
                a = Appliance.objects.get(current_appliance=True)
                a.ip = ni.ipaddr
                a.save()
                update_samba_discovery(ni.ipaddr, settings.AVAHI_SMB_CONF)
                try:
                    update_issue(ni.ipaddr)
                except:
                    logger.error('Unable to update /etc/issue')
            return Response(NetworkInterfaceSerializer(ni).data)
        except RockStorAPIException:
            raise
        except Exception, e:
            handle_exception(e, request)
Esempio n. 3
0
    def put(self, request, iname):
        with self._handle_exception(request):
            if (not NetworkInterface.objects.filter(name=iname).exists()):
                e_msg = ('Netowrk interface(%s) does not exist.' % iname)
                handle_exception(Exception(e_msg), request)
            ni = NetworkInterface.objects.get(name=iname)

            itype = request.data['itype']
            if (itype != 'management'):
                itype = 'io'
            boot_proto = request.data['boot_protocol']
            ni.onboot = 'yes'
            if (boot_proto == 'dhcp'):
                config_network_device(ni.alias, ni.mac)
            elif (boot_proto == 'static'):
                ipaddr = request.data['ipaddr']
                for i in NetworkInterface.objects.filter(ipaddr=ipaddr):
                    if (i.id != ni.id):
                        e_msg = ('IP: %s already in use by another '
                                 'interface: %s' % (ni.ipaddr, i.name))
                        handle_exception(Exception(e_msg), request)
                netmask = request.data['netmask']
                gateway = request.data['gateway']
                dns_servers = request.data['dns_servers'].split(',')
                domain = request.data['domain']
                config_network_device(ni.alias,
                                      ni.mac,
                                      boot_proto='static',
                                      ipaddr=ipaddr,
                                      netmask=netmask,
                                      gateway=gateway,
                                      dns_servers=dns_servers,
                                      domain=domain)
            else:
                e_msg = ('Boot protocol must be dhcp or static. not: %s' %
                         boot_proto)
                handle_exception(Exception(e_msg), request)
            self._restart_wrapper(ni, request)
            dconfig = get_net_config_fedora([ni.name])[ni.name]
            ni.boot_proto = dconfig['bootproto']
            ni.netmask = dconfig['netmask']
            ni.ipaddr = dconfig['ipaddr']
            ni.itype = itype
            ni.gateway = dconfig['gateway']
            ni.dns_servers = dconfig['dns_servers']
            ni.domain = dconfig['domain']
            ni.save()
            if (itype == 'management'):
                a = Appliance.objects.get(current_appliance=True)
                a.ip = ni.ipaddr
                a.save()
                try:
                    update_issue(ni.ipaddr)
                except:
                    logger.error('Unable to update /etc/issue')
            return Response(NetworkInterfaceSerializer(ni).data)
Esempio n. 4
0
    def put(self, request, iname):
        with self._handle_exception(request):
            if not NetworkInterface.objects.filter(name=iname).exists():
                e_msg = "Netowrk interface(%s) does not exist." % iname
                handle_exception(Exception(e_msg), request)
            ni = NetworkInterface.objects.get(name=iname)

            itype = request.DATA["itype"]
            if itype != "management":
                itype = "io"
            boot_proto = request.DATA["boot_protocol"]
            ni.onboot = "yes"
            if boot_proto == "dhcp":
                config_network_device(ni.alias, ni.mac)
            elif boot_proto == "static":
                ipaddr = request.DATA["ipaddr"]
                for i in NetworkInterface.objects.filter(ipaddr=ipaddr):
                    if i.id != ni.id:
                        e_msg = "IP: %s already in use by another " "interface: %s" % (ni.ipaddr, i.name)
                        handle_exception(Exception(e_msg), request)
                netmask = request.DATA["netmask"]
                gateway = request.DATA["gateway"]
                dns_servers = request.DATA["dns_servers"].split(",")
                domain = request.DATA["domain"]
                config_network_device(
                    ni.alias,
                    ni.mac,
                    boot_proto="static",
                    ipaddr=ipaddr,
                    netmask=netmask,
                    gateway=gateway,
                    dns_servers=dns_servers,
                    domain=domain,
                )
            else:
                e_msg = "Boot protocol must be dhcp or static. not: %s" % boot_proto
                handle_exception(Exception(e_msg), request)
            self._restart_wrapper(ni, request)
            dconfig = get_net_config_fedora([ni.name])[ni.name]
            ni.boot_proto = dconfig["bootproto"]
            ni.netmask = dconfig["netmask"]
            ni.ipaddr = dconfig["ipaddr"]
            ni.itype = itype
            ni.gateway = dconfig["gateway"]
            ni.dns_servers = dconfig["dns_servers"]
            ni.domain = dconfig["domain"]
            ni.save()
            if itype == "management":
                a = Appliance.objects.get(current_appliance=True)
                a.ip = ni.ipaddr
                a.save()
                try:
                    update_issue(ni.ipaddr)
                except:
                    logger.error("Unable to update /etc/issue")
            return Response(NetworkInterfaceSerializer(ni).data)
Esempio n. 5
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)
Esempio n. 6
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)
Esempio n. 7
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)
Esempio n. 8
0
 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)