Beispiel #1
0
 def clean_interface_name_uniqueness(self, name):
     node_interfaces = self.node.interface_set.filter(name=name)
     if self.instance is not None and self.instance.id is not None:
         node_interfaces = node_interfaces.exclude(id=self.instance.id)
     if node_interfaces.exists():
         msg = "Node %s already has an interface named '%s'." % (self.node,
                                                                 name)
         set_form_error(self, 'name', msg)
Beispiel #2
0
 def _validate_parent_vlans_match(self, parents):
     # When creating the bond set VLAN to the same as the parents
     # and check that the parents all belong to the same VLAN.
     if self.instance.id is None:
         vlan = self.cleaned_data.get('vlan')
         parent_vlans = {parent.vlan for parent in parents}
         if parent_vlans != set([vlan]):
             set_form_error(self, 'parents',
                            "All parents must belong to the same VLAN.")
Beispiel #3
0
 def validate_parental_fidelity(self, parents):
     """Check that all of the parent interfaces are not already in a
     relationship before committing them to this child.
     """
     dilinquents = self.get_delinquent_children(parents)
     if len(dilinquents) != 0:
         set_form_error(
             self, 'parents', "Interfaces already in-use: %s." %
             (', '.join(sorted(dilinquents))))
Beispiel #4
0
 def clean(self):
     cleaned_data = super(VLANInterfaceForm, self).clean()
     if self.fields_ok(['vlan', 'parents']):
         new_vlan = self.cleaned_data.get('vlan')
         if new_vlan:
             # VLAN needs to be the in the same fabric as the parent.
             parent = self.cleaned_data.get('parents')[0]
             if parent.vlan.fabric_id != new_vlan.fabric_id:
                 set_form_error(
                     self, "vlan",
                     "A VLAN interface can only belong to a tagged VLAN on "
                     "the same fabric as its parent interface.")
             name = build_vlan_interface_name(
                 self.cleaned_data.get('parents').first(), new_vlan)
             self.clean_interface_name_uniqueness(name)
     return cleaned_data
Beispiel #5
0
 def clean(self):
     cleaned_data = super().clean()
     if self.fields_ok(["vlan", "parents"]):
         new_vlan = self.cleaned_data.get("vlan")
         if new_vlan:
             # VLAN needs to be the in the same fabric as the parent.
             parent = self.cleaned_data.get("parents")[0]
             if parent.vlan.fabric_id != new_vlan.fabric_id:
                 set_form_error(
                     self,
                     "vlan",
                     "A VLAN interface can only belong to a tagged VLAN on "
                     "the same fabric as its parent interface.",
                 )
             new_name = cleaned_data.get("name")
             if self.fields_ok(["name"]):
                 if not new_name and self.instance.id is None:
                     # No name provided and new instance. Auto-generate the name.
                     cleaned_data["name"] = build_vlan_interface_name(
                         cleaned_data.get("parents").first(), new_vlan)
                 self.clean_interface_name_uniqueness(cleaned_data["name"])
     return cleaned_data
Beispiel #6
0
 def clean_parents_all_same_node(self, parents):
     if parents:
         parent_nodes = set(parent.get_node() for parent in parents)
         if len(parent_nodes) > 1:
             msg = "Parents are related to different nodes."
             set_form_error(self, 'name', msg)