Ejemplo n.º 1
0
    def __init__(self, *args, **kwargs):
        super(forms.ModelForm, self).__init__(*args, **kwargs)
        vintf = kwargs["instance"]
        if vintf:
            CHOICES = [[vintf.intf] * 2]
        else:
            runnin_itf = [z.intf for z in VINTF.objects.all()]
            CHOICES = []
            # retrieve the next available virtual interface name for a given real interface ( ie. eth0 -> eth0:3 )
            for itf in filter(None, [not ":" in x and x or None for x in ifconfig.getIntfs()]):
                id_next = 1
                name_next = "%s:%s" % (itf, id_next)
                while name_next in runnin_itf:
                    id_next += 1
                    name_next = "%s:%s" % (itf, id_next)
                CHOICES += [[name_next] * 2]

        self.fields["intf"] = forms.ChoiceField(choices=CHOICES)
Ejemplo n.º 2
0
 def __init__(self,*args, **kwargs):
     super(forms.ModelForm,self).__init__(*args, **kwargs)
     vintf = kwargs["instance"]
     if vintf:
         CHOICES = [[vintf.intf]*2]
     else:
         runnin_itf = [z.intf for z in VINTF.objects.all()]
         CHOICES = []
     #retrieve the next available virtual interface name for a given real interface ( ie. eth0 -> eth0:3 )
         for itf in filter(None,[not ':' in x and x or None for x in ifconfig.getIntfs()]):
             id_next = 1
             name_next = "%s:%s"%(itf,id_next)
             while name_next in runnin_itf : 
                 id_next +=1 
                 name_next = "%s:%s"%(itf,id_next)
             CHOICES += [[name_next]*2]
                     
     self.fields["intf"] = forms.ChoiceField(choices = CHOICES)
Ejemplo n.º 3
0
 def __init__(self, *args, **kwargs):
     super(forms.ModelForm, self).__init__(*args, **kwargs)
     intf = kwargs["instance"]
     runnin_itf = [z.intf for z in VINTF.objects.all()]
     CHOICES = []
     li = []
     for x in [(f["intf"], f["ip"]) for f in VINTF.objects.values("intf", "ip")] + [
         z for z in ifconfig.getIntfs().items()
     ]:
         if not x in li:
             li += [x]
     for itf in li:
         CHOICES += [(itf[1], "%s -> %s" % itf)]
     CHOICES += [("0.0.0.0", "any -> 0.0.0.0")]
     CHOICES.sort()
     self.fields["ip"] = forms.ChoiceField(choices=CHOICES)
     self.fields["srv_ka"] = forms.BooleanField(initial=intf and intf.srv_ka or True, required=False)
     self.fields["srv_ka"].widget.attrs["onchange"] = "srv_ka_changed()"
Ejemplo n.º 4
0
 def __init__(self,*args,**kwargs):
     super(forms.ModelForm,self).__init__(*args,**kwargs)
     intf = kwargs["instance"]
     runnin_itf = [z.intf for z in VINTF.objects.all()]
     CHOICES = []
     li = []
     for x in [ (f["intf"],f["ip"]) for f in VINTF.objects.values('intf','ip')] + [z for z in ifconfig.getIntfs().items()]:
         if not x in li:    
             li += [x]
     for itf in li:
         CHOICES += [(itf[1],"%s -> %s"%itf)]
     CHOICES += [("0.0.0.0","any -> 0.0.0.0")]
     CHOICES.sort()
     self.fields["ip"] = forms.ChoiceField(choices = CHOICES)
     self.fields['srv_ka'] = forms.BooleanField(initial=intf and intf.srv_ka or True,required=False)
     self.fields['srv_ka'].widget.attrs["onchange"]="srv_ka_changed()"