Пример #1
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.get('itype', 'unassigned')
            method = request.data.get('method')
            ni.onboot = 'yes'
            if (method == 'auto'):
                config_network_device(ni.name)
            elif (method == 'manual'):
                ipaddr = request.data.get('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 = self._validate_netmask(request)
                gateway = request.data.get('gateway', None)
                dns_servers = request.data.get('dns_servers', None)
                config_network_device(ni.name,
                                      dtype=ni.dtype,
                                      method='manual',
                                      ipaddr=ipaddr,
                                      netmask=netmask,
                                      gateway=gateway,
                                      dns_servers=dns_servers)
            else:
                e_msg = (
                    'Method must be auto(for dhcp) or manual(for static IP). not: %s'
                    % method)
                handle_exception(Exception(e_msg), request)
            dconfig = get_net_config(name=ni.name)[ni.dname]
            ni = self._update_ni_obj(ni, dconfig)
            if (itype == 'management' and ni.itype != 'management'):
                for i in NetworkInterface.objects.filter(itype='management'):
                    if (i.name != ni.name):
                        e_msg = ('Another interface(%s) is already configured '
                                 'for management. You must disable it first '
                                 'before making this change.' % i.name)
                        handle_exception(Exception(e_msg), request)
                a = Appliance.objects.get(current_appliance=True)
                a.ip = ni.ipaddr
                a.save()
            ni.itype = itype
            ni.save()
            if (ni.itype == 'management'):
                try:
                    update_issue(ni.ipaddr)
                except Exception, e:
                    logger.error('Unable to update /etc/issue. Exception: %s' %
                                 e.__str__())

                try:
                    self._update_nginx(ni.ipaddr)
                except Exception, e:
                    logger.error('Failed to update Nginx. Exception: %s' %
                                 e.__str__())
Пример #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)
            ipaddr = request.DATA['ipaddr']
            for i in NetworkInterface.objects.filter(ipaddr=ipaddr):
                if (i.id != ni.id):
                    e_msg = ('IP: %s already in use' % ipaddr)
                    handle_exception(Exception(e_msg), request)

            ni.boot_proto = 'static'
            ni.onboot = 'yes'
            ni.network = request.DATA['network']
            ni.netmask = request.DATA['netmask']
            ni.ipaddr = ipaddr
            ni.save()
            config_network_device(ni.name, ni.mac, ni.ipaddr, ni.netmask)
            restart_network()
            return Response(NetworkInterfaceSerializer(ni).data)
        except RockStorAPIException:
            raise
        except Exception, e:
            handle_exception(e, request)
Пример #3
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)
            ipaddr = request.DATA['ipaddr']
            for i in NetworkInterface.objects.filter(ipaddr=ipaddr):
                if (i.id != ni.id):
                    e_msg = ('IP: %s already in use' % ipaddr)
                    handle_exception(Exception(e_msg), request)

            ni.boot_proto = 'static'
            ni.onboot = 'yes'
            ni.network = request.DATA['network']
            ni.netmask = request.DATA['netmask']
            ni.ipaddr = ipaddr
            ni.save()
            config_network_device(ni.name, ni.mac, ni.ipaddr, ni.netmask)
            restart_network()
            return Response(NetworkInterfaceSerializer(ni).data)
        except RockStorAPIException:
            raise
        except Exception, e:
            handle_exception(e, request)
Пример #4
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)
Пример #5
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)
Пример #6
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)
Пример #7
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.get('itype', 'unassigned')
            method = request.data.get('method')
            ni.onboot = 'yes'
            if (method == 'auto'):
                config_network_device(ni.name)
            elif (method == 'manual'):
                ipaddr = request.data.get('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 = self._validate_netmask(request)
                gateway = request.data.get('gateway', None)
                dns_servers = request.data.get('dns_servers', None)
                config_network_device(ni.name, dtype=ni.dtype, method='manual',
                                      ipaddr=ipaddr, netmask=netmask,
                                      gateway=gateway, dns_servers=dns_servers)
            else:
                e_msg = ('Method must be auto(for dhcp) or manual(for static IP). not: %s' %
                         method)
                handle_exception(Exception(e_msg), request)
            dconfig = get_net_config(name=ni.name)[ni.dname]
            ni = self._update_ni_obj(ni, dconfig)
            if (itype == 'management' and ni.itype != 'management'):
                for i in NetworkInterface.objects.filter(itype='management'):
                    if (i.name != ni.name):
                        e_msg = ('Another interface(%s) is already configured '
                                 'for management. You must disable it first '
                                 'before making this change.' % i.name)
                        handle_exception(Exception(e_msg), request)
                a = Appliance.objects.get(current_appliance=True)
                a.ip = ni.ipaddr
                a.save()
            ni.itype = itype
            ni.save()
            if (ni.itype == 'management'):
                try:
                    update_issue(ni.ipaddr)
                    self._update_nginx(ni.ipaddr)
                except Exception, e:
                    logger.error('Unable to update /etc/issue. Exception: %s' % e.__str__())

                try:
                    self._update_nginx(ni.ipaddr)
                except Exception, e:
                    logger.error('Failed to update Nginx. Exception: %s' % e.__str__())