Beispiel #1
0
    def ensure_segment(self, name):
        ns = NetworkSegment.objects.filter(parent=self.object.segment.id,
                                           name=name).first()
        if not ns:
            root = self.object.segment
            if root.profile:
                profile = root.profile.autocreated_profile or root.profile
            else:
                profile = None

            ns = NetworkSegment(parent=self.object.segment,
                                name=name,
                                profile=profile,
                                description="Autocreated by segmentation")
            ns.save()
        return ns
Beispiel #2
0
 def handle_split_floating(self, profile, ids, *args, **options):
     connect()
     p = NetworkSegmentProfile.objects.filter(name=profile).first()
     if not p:
         self.die("Profile not found")
     if p.is_persistent:
         self.die("Segment profile cannot be persistent")
     for seg_id in ids:
         seg = NetworkSegment.get_by_id(seg_id)
         if not seg:
             self.print("@@@ %s - not found. Skipping" % seg_id)
             continue
         self.print("@@@ Splitting %s (%s)" % (seg.name, seg_id))
         objects = list(
             ManagedObject.objects.filter(is_managed=True, segment=seg_id))
         for mo in objects:
             new_segment = NetworkSegment(
                 name=mo.administrative_domain.get_bioseg_floating_name(mo)
                 or "Bubble for %s" % mo.name,
                 profile=p,
                 parent=mo.administrative_domain.
                 get_bioseg_floating_parent_segment(),
             )
             new_segment.save()
             self.print("  Moving '%s' to segment '%s'" %
                        (mo.name, new_segment.name))
             mo.segment = new_segment
             mo.save()
         # Establish trials
         self.print("@@@ Scheduling trials")
         for mo in objects:
             for link in Link.object_links(mo):
                 for ro in link.managed_objects:
                     if ro == mo:
                         continue
                     self.print("  '%s' challenging '%s' over %s -- %s" %
                                (mo.segment.name, ro.segment.name, mo.name,
                                 ro.name))
                     BioSegTrial.schedule_trial(mo.segment,
                                                ro.segment,
                                                mo,
                                                ro,
                                                reason="link")
Beispiel #3
0
def get_segment(name):
    ns = NetworkSegment(name=name,
                        parent=get_root_segment(),
                        profile=get_segment_profile())
    ns.save()
    return ns
Beispiel #4
0
def get_root_segment():
    ns = NetworkSegment(name="Discovery Tests", profile=get_segment_profile())
    ns.save()
    return ns