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): 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 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)