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 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__())
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)
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)
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)
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__())
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 _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 _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)
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() try: self._update_nginx(ni.ipaddr) except Exception, e: logger.error('Failed to update Nginx. Exception: %s' % e.__str__()) elif (itype == 'io' and ni.itype == 'management'): try: self._update_nginx() except Exception, e: logger.error('Failed to update Nginx. Exception: %s' % e.__str__()) 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__()) return Response(NetworkInterfaceSerializer(ni).data)