Example #1
0
def clone_fabric(fab_id, data, user=""):

    old_fabric = Topology.objects.get(pk=fab_id)

    # create new fabric
    new_fabric = Fabric()
    new_fabric.name = data[NAME]
    new_fabric.model_name = old_fabric.model_name
    new_fabric.is_fabric = True

    if old_fabric.config_profile:
        new_fabric.config_profile = old_fabric.config_profile
    if old_fabric.feature_profile:
        new_fabric.feature_profile = old_fabric.feature_profile

    new_fabric.updated_by = user
    new_fabric.save()

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

    switch_dict = dict()

    for switch in Switch.objects.filter(topology_id=old_fabric.id
                                        ).order_by(ID):
        # save id for later
        switch_id = switch.id

        switch.id = None
        switch.topology = new_fabric
        switch.serial_num = ""
        switch.boot_detail = None

        if not switch.dummy:
            # append fabric name to switch name
            if data[NAME_OPERATION] == REPLACE:
                name = switch.name.replace(old_fabric.name, new_fabric.name)
                if Switch.objects.filter(name=name):
                    raise IgniteException(ERR_CLONE_FABRIC)
                switch.name = name
            elif data[NAME_OPERATION] == PREPEND:
                name = new_fabric.name + "_" + switch.name
                if Switch.objects.filter(name=name):
                    raise IgniteException(ERR_CLONE_FABRIC)
                switch.name = name

        switch.save()

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

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

    for link in Link.objects.filter(topology_id=old_fabric.id):
        link.id = None
        link.topology = new_fabric

        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_fabric.links.append(link)
        elif link.dummy and not link.src_switch:
            link.src_tier = link.src_ports
            link.dst_tier = link.dst_ports
            new_fabric.defaults[LINKS].append(link)
    new_fabric.save()

    return new_fabric
Example #2
0
def clone_fabric(fab_id, data, user=""):

    old_fabric = Topology.objects.get(pk=fab_id)

    # create new fabric
    new_fabric = Fabric()
    new_fabric.name = data[NAME]
    new_fabric.model_name = old_fabric.model_name
    new_fabric.is_fabric = True

    if old_fabric.config_profile:
        new_fabric.config_profile = old_fabric.config_profile
    if old_fabric.feature_profile:
        new_fabric.feature_profile = old_fabric.feature_profile

    new_fabric.updated_by = user
    new_fabric.save()

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

    switch_dict = dict()

    for switch in Switch.objects.filter(
            topology_id=old_fabric.id).order_by(ID):
        # save id for later
        switch_id = switch.id

        switch.id = None
        switch.topology = new_fabric
        switch.serial_num = ""
        switch.boot_detail = None

        if not switch.dummy:
            # append fabric name to switch name
            if data[NAME_OPERATION] == REPLACE:
                name = switch.name.replace(old_fabric.name, new_fabric.name)
                if Switch.objects.filter(name=name):
                    raise IgniteException(ERR_CLONE_FABRIC)
                switch.name = name
            elif data[NAME_OPERATION] == PREPEND:
                name = new_fabric.name + "_" + switch.name
                if Switch.objects.filter(name=name):
                    raise IgniteException(ERR_CLONE_FABRIC)
                switch.name = name

        switch.save()

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

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

    for link in Link.objects.filter(topology_id=old_fabric.id):
        link.id = None
        link.topology = new_fabric

        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_fabric.links.append(link)
        elif link.dummy and not link.src_switch:
            link.src_tier = link.src_ports
            link.dst_tier = link.dst_ports
            new_fabric.defaults[LINKS].append(link)
    new_fabric.save()

    return new_fabric
Example #3
0
def add_fabric(data, user):
    # get topology
    top = Topology.objects.get(pk=data[TOPOLOGY])

    logger.debug("fabric name = %s, topology name = %s, model = %s",
                 data[NAME], top.name, top.model_name)

    # create new fabric
    fabric = Fabric()
    fabric.name = data[NAME]
    fabric.model_name = top.model_name
    fabric.is_fabric = True

    if data[CONFIG_PROFILE]:
        fabric.config_profile = config.get_profile(data[CONFIG_PROFILE])
    if data[FEATURE_PROFILE]:
        fabric.feature_profile = feature.get_profile(data[FEATURE_PROFILE])
    fabric.updated_by = user
    fabric.save()

    cfg = dict()
    feat = dict()
    wf = dict()

    # store tier default config & feature profile
    for item in data[SWITCHES]:
        # if profile id is zero, then store null
        # it means - do not apply config/feature/workflow for this tier
        if item[CONFIG_PROFILE]:
            cfg[item[TIER]] = config.get_profile(item[CONFIG_PROFILE])
        else:
            cfg[item[TIER]] = None

        if item[FEATURE_PROFILE]:
            feat[item[TIER]] = feature.get_profile(item[FEATURE_PROFILE])
        else:
            feat[item[TIER]] = None

        if item[WORKFLOW]:
            wf[item[TIER]] = workflow.get_workflow(item[WORKFLOW])
        else:
            wf[item[TIER]] = None

    # fabric defaults, switches & links objects
    fabric.defaults = dict()
    fabric.defaults[SWITCHES] = list()
    fabric.defaults[LINKS] = list()
    fabric.switches = list()
    fabric.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=top.id).order_by(ID):
        # save id for later
        switch_id = switch.id

        switch.id = None
        switch.topology = fabric

        if switch.dummy:
            # set config & feature profile for fabric default switch
            switch.config_profile = cfg[switch.tier]
            switch.feature_profile = feat[switch.tier]
            switch.workflow = wf[switch.tier]
        else:
            # append fabric name to switch name
            switch.name = fabric.name + "_" + switch.name

        switch.save()

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

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

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

        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:
            fabric.links.append(link)
        elif link.dummy and not link.src_switch:
            link.src_tier = link.src_ports
            link.dst_tier = link.dst_ports
            fabric.defaults[LINKS].append(link)

    return fabric
Example #4
0
def add_fabric(data, user):
    # get topology
    top = Topology.objects.get(pk=data[TOPOLOGY])

    logger.debug("fabric name = %s, topology name = %s, model = %s",
                 data[NAME], top.name, top.model_name)

    # create new fabric
    fabric = Fabric()
    fabric.name = data[NAME]
    fabric.model_name = top.model_name
    fabric.is_fabric = True

    if data[CONFIG_PROFILE]:
        fabric.config_profile = config.get_profile(data[CONFIG_PROFILE])
    if data[FEATURE_PROFILE]:
        fabric.feature_profile = feature.get_profile(data[FEATURE_PROFILE])
    fabric.updated_by = user
    fabric.save()

    cfg = dict()
    feat = dict()
    wf = dict()

    # store tier default config & feature profile
    for item in data[SWITCHES]:
        # if profile id is zero, then store null
        # it means - do not apply config/feature/workflow for this tier
        if item[CONFIG_PROFILE]:
            cfg[item[TIER]] = config.get_profile(item[CONFIG_PROFILE])
        else:
            cfg[item[TIER]] = None

        if item[FEATURE_PROFILE]:
            feat[item[TIER]] = feature.get_profile(item[FEATURE_PROFILE])
        else:
            feat[item[TIER]] = None

        if item[WORKFLOW]:
            wf[item[TIER]] = workflow.get_workflow(item[WORKFLOW])
        else:
            wf[item[TIER]] = None

    # fabric defaults, switches & links objects
    fabric.defaults = dict()
    fabric.defaults[SWITCHES] = list()
    fabric.defaults[LINKS] = list()
    fabric.switches = list()
    fabric.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=top.id).order_by(ID):
        # save id for later
        switch_id = switch.id

        switch.id = None
        switch.topology = fabric

        if switch.dummy:
            # set config & feature profile for fabric default switch
            switch.config_profile = cfg[switch.tier]
            switch.feature_profile = feat[switch.tier]
            switch.workflow = wf[switch.tier]
        else:
            # append fabric name to switch name
            switch.name = fabric.name + "_" + switch.name

        switch.save()

        # store topology switch id to switch mapping
        switch_dict[switch_id] = switch
        if switch.dummy:
            fabric.defaults[SWITCHES].append(switch)
        else:
            fabric.switches.append(switch)

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

        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:
            fabric.links.append(link)
        elif link.dummy and not link.src_switch:
            link.src_tier = link.src_ports
            link.dst_tier = link.dst_ports
            fabric.defaults[LINKS].append(link)

    return fabric