예제 #1
0
파일: views.py 프로젝트: senglobe/ignite
 def post(self, request, format=None):
     serializer = TopologySerializer(data=request.data)
     me = RequestValidator(request.META)
     if serializer.is_valid():
         topology_obj = Topology()
         topology_obj.user_id = me.user_is_exist().user_id
         topology_obj.name = request.data['name']
         topology_obj.submit = request.data['submit']
         topology_obj.topology_json = json.dumps(request.data['topology_json'])
         try:
             topology_obj.config_json = json.dumps(request.data['config_json'])
         except:
             topology_obj.config_json = json.dumps([])
         topology_obj.save()
         serializer = TopologyGetSerializer(topology_obj)
         return Response(serializer.data, status=status.HTTP_201_CREATED)
     return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
예제 #2
0
파일: views.py 프로젝트: salran40/POAP
 def post(self, request, format=None):
     serializer = TopologySerializer(data=request.data)
     me = RequestValidator(request.META)
     if serializer.is_valid():
         topology_obj = Topology()
         topology_obj.user_id = me.user_is_exist().user_id
         topology_obj.name = request.data['name']
         topology_obj.submit = request.data['submit']
         topology_obj.topology_json = json.dumps(
             request.data['topology_json'])
         try:
             topology_obj.config_json = json.dumps(
                 request.data['config_json'])
         except:
             topology_obj.config_json = json.dumps([])
         try:
             topology_obj.defaults = json.dumps(request.data['defaults'])
         except:
             topology_obj.defaults = json.dumps({})
         topology_obj.save()
         serializer = TopologyGetSerializer(topology_obj)
         return Response(serializer.data, status=status.HTTP_201_CREATED)
     return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
예제 #3
0
def clone_topology(topo_id, data, user=""):
    old_topology = Topology.objects.get(pk=topo_id)

    # create new fabric
    new_topology = Topology()
    new_topology.name = data[NAME]
    new_topology.model_name = old_topology.model_name
    new_topology.updated_by = user
    new_topology.is_fabric = False
    new_topology.save()

    # fabric defaults, switches & links objects
    new_topology.defaults = dict()
    new_topology.defaults[SWITCHES] = list()
    new_topology.defaults[LINKS] = list()
    new_topology.switches = list()
    new_topology.links = list()

    # map of topology switch id to fabric switch object
    # needed when creating fabric links
    switch_dict = dict()

    # duplicate all topology switches into fabric
    for switch in Switch.objects.filter(topology_id=old_topology.id).order_by(ID):
        # save id for later
        switch_id = switch.id

        switch.id = None
        switch.topology = new_topology

        switch.save()

        # store topology switch id to switch mapping
        switch_dict[switch_id] = switch

        if switch.dummy:
            new_topology.defaults[SWITCHES].append(switch)
        else:
            new_topology.switches.append(switch)

    # duplicate all topology links into fabric
    for link in Link.objects.filter(topology_id=old_topology.id):
        link.id = None
        link.topology = new_topology

        if link.src_switch:
            link.src_switch = switch_dict[link.src_switch.id]
            link.dst_switch = switch_dict[link.dst_switch.id]
        else:
            link.src_switch = None
            link.dst_switch = None
        link.save()

        if not link.dummy:
            new_topology.links.append(link)
        elif link.dummy and not link.src_switch:
            link.src_tier = link.src_ports
            link.dst_tier = link.dst_ports
            new_topology.defaults[LINKS].append(link)
    new_topology.save()

    return new_topology
예제 #4
0
파일: topology.py 프로젝트: whchoi98/ignite
def clone_topology(topo_id, data, user=""):
    old_topology = Topology.objects.get(pk=topo_id)

    # create new fabric
    new_topology = Topology()
    new_topology.name = data[NAME]
    new_topology.model_name = old_topology.model_name
    new_topology.updated_by = user
    new_topology.is_fabric = False
    new_topology.save()

    # fabric defaults, switches & links objects
    new_topology.defaults = dict()
    new_topology.defaults[SWITCHES] = list()
    new_topology.defaults[LINKS] = list()
    new_topology.switches = list()
    new_topology.links = list()

    # map of topology switch id to fabric switch object
    # needed when creating fabric links
    switch_dict = dict()

    # duplicate all topology switches into fabric
    for switch in Switch.objects.filter(
            topology_id=old_topology.id).order_by(ID):
        # save id for later
        switch_id = switch.id

        switch.id = None
        switch.topology = new_topology

        switch.save()

        # store topology switch id to switch mapping
        switch_dict[switch_id] = switch

        if switch.dummy:
            new_topology.defaults[SWITCHES].append(switch)
        else:
            new_topology.switches.append(switch)

    # duplicate all topology links into fabric
    for link in Link.objects.filter(topology_id=old_topology.id):
        link.id = None
        link.topology = new_topology

        if link.src_switch:
            link.src_switch = switch_dict[link.src_switch.id]
            link.dst_switch = switch_dict[link.dst_switch.id]
        else:
            link.src_switch = None
            link.dst_switch = None
        link.save()

        if not link.dummy:
            new_topology.links.append(link)
        elif link.dummy and not link.src_switch:
            link.src_tier = link.src_ports
            link.dst_tier = link.dst_ports
            new_topology.defaults[LINKS].append(link)
    new_topology.save()

    return new_topology