Exemplo n.º 1
0
 def save(self):
     vlan_pint = self.cleaned_data['vlan_pint']
     vlan_vint = self.cleaned_data['vlan_vint']
     with DBSync():
         qs = models.Interfaces.objects.filter(int_interface=vlan_pint)
         if not qs.exists():
             vlan_interface = models.Interfaces(
                 int_interface=vlan_pint,
                 int_name=vlan_pint,
                 int_dhcp=False,
                 int_ipv6auto=False,
                 int_options='up',
             )
             vlan_interface.save()
         else:
             vlan_interface = qs[0]
             if 'up' not in vlan_interface.int_options:
                 vlan_interface.int_options += ' up'
                 vlan_interface.save()
         if not models.Interfaces.objects.filter(
                 int_interface=vlan_vint).exists():
             models.Interfaces.objects.create(
                 int_interface=vlan_vint,
                 int_name=vlan_vint,
                 int_dhcp=False,
                 int_ipv6auto=False,
             )
         return super(VLANForm, self).save()
Exemplo n.º 2
0
    def save(self, *args, **kwargs):

        # Search for a available slot for laggX interface
        interface_names = [
            v[0]
            for v in models.Interfaces.objects.all()
            .values_list('int_interface')
        ]
        candidate_index = 0
        while ("lagg%d" % (candidate_index)) in interface_names:
            candidate_index += 1
        lagg_name = "lagg%d" % candidate_index
        lagg_protocol = self.cleaned_data['lagg_protocol']
        lagg_member_list = self.cleaned_data['lagg_interfaces']
        with DBSync():
            model_objs = []
            try:
                # Step 1: Create an entry in interface table that
                # represents the lagg interface
                lagg_interface = models.Interfaces(
                    int_interface=lagg_name,
                    int_name=lagg_name,
                    int_dhcp=False,
                    int_ipv6auto=False
                )
                lagg_interface.save()
                model_objs.append(lagg_interface)
                # Step 2: Write associated lagg attributes
                lagg_interfacegroup = models.LAGGInterface(
                    lagg_interface=lagg_interface,
                    lagg_protocol=lagg_protocol
                )
                lagg_interfacegroup.save()
                model_objs.append(lagg_interfacegroup)
                # Step 3: Write lagg's members in the right order
                order = 0
                for interface in lagg_member_list:
                    lagg_member_entry = models.LAGGInterfaceMembers(
                        lagg_interfacegroup=lagg_interfacegroup,
                        lagg_ordernum=order,
                        lagg_physnic=interface,
                    )
                    model_objs.append(models.Interfaces.objects.create(
                        int_interface=interface,
                        int_name=f'member of {lagg_name}',
                    ))
                    lagg_member_entry.save()
                    model_objs.append(lagg_member_entry)
                    order = order + 1
            except Exception:
                for obj in reversed(model_objs):
                    obj.delete()
                raise
        self.instance = lagg_interfacegroup
        return lagg_interfacegroup
Exemplo n.º 3
0
 def save(self):
     vlan_pint = self.cleaned_data['vlan_pint']
     if len(models.Interfaces.objects.filter(int_interface=vlan_pint)) == 0:
         vlan_interface = models.Interfaces(
             int_interface=vlan_pint,
             int_name=vlan_pint,
             int_dhcp=False,
             int_ipv6auto=False,
             int_options='up',
         )
         vlan_interface.save()
     retval = super(VLANForm, self).save()
     notifier().start("network")
     return retval
Exemplo n.º 4
0
    def save(self, *args, **kwargs):

        # Search for a available slot for laggX interface
        interface_names = [
            v[0]
            for v in models.Interfaces.objects.all()
            .values_list('int_interface')
        ]
        candidate_index = 0
        while ("lagg%d" % (candidate_index)) in interface_names:
            candidate_index += 1
        lagg_name = "lagg%d" % candidate_index
        lagg_protocol = self.cleaned_data['lagg_protocol']
        lagg_member_list = self.cleaned_data['lagg_interfaces']
        with DBSync():
            with transaction.atomic():
                # Step 1: Create an entry in interface table that
                # represents the lagg interface
                lagg_interface = models.Interfaces(
                    int_interface=lagg_name,
                    int_name=lagg_name,
                    int_dhcp=False,
                    int_ipv6auto=False
                )
                lagg_interface.save()
                # Step 2: Write associated lagg attributes
                lagg_interfacegroup = models.LAGGInterface(
                    lagg_interface=lagg_interface,
                    lagg_protocol=lagg_protocol
                )
                lagg_interfacegroup.save()
                # Step 3: Write lagg's members in the right order
                order = 0
                for interface in lagg_member_list:
                    lagg_member_entry = models.LAGGInterfaceMembers(
                        lagg_interfacegroup=lagg_interfacegroup,
                        lagg_ordernum=order,
                        lagg_physnic=interface,
                        lagg_deviceoptions='up'
                    )
                    lagg_member_entry.save()
                    order = order + 1
        self.instance = lagg_interfacegroup
        return lagg_interfacegroup
Exemplo n.º 5
0
 def save(self):
     vlan_pint = self.cleaned_data['vlan_pint']
     vlan_vint = self.cleaned_data['vlan_vint']
     with DBSync():
         if len(models.Interfaces.objects.filter(int_interface=vlan_pint)) == 0:
             vlan_interface = models.Interfaces(
                 int_interface=vlan_pint,
                 int_name=vlan_pint,
                 int_dhcp=False,
                 int_ipv6auto=False,
                 int_options='up',
             )
             vlan_interface.save()
         models.Interfaces.objects.create(
             int_interface=vlan_vint,
             int_name=vlan_vint,
             int_dhcp=False,
             int_ipv6auto=False,
         )
         return super(VLANForm, self).save()