Ejemplo n.º 1
0
def update_topology_defaults(top_id, data, user=""):
    serializer = TopologyPostDefaultsSerializer(data=data)
    if not serializer.is_valid():
        raise IgniteException(serializer.errors)

    BaseTopology.get_object(top_id, user).update_defaults(serializer.data)
    serializer = TopologySerializer(BaseTopology.get_topology(top_id))
    return serializer.data
Ejemplo n.º 2
0
def add_topology_link(top_id, data, user=""):
    serializer = LinkPostSerializer(data=data)
    if not serializer.is_valid():
        raise IgniteException(serializer.errors)

    BaseTopology.get_object(top_id, user).add_link(serializer.data)
    serializer = TopologySerializer(BaseTopology.get_topology(top_id))
    return serializer.data
Ejemplo n.º 3
0
def update_topology_defaults(top_id, data, user=""):
    serializer = TopologyPostDefaultsSerializer(data=data)
    if not serializer.is_valid():
        raise IgniteException(serializer.errors)

    BaseTopology.get_object(top_id, user).update_defaults(serializer.data)
    serializer = TopologySerializer(BaseTopology.get_topology(top_id))
    return serializer.data
Ejemplo n.º 4
0
def add_topology_link(top_id, data, user=""):
    serializer = LinkPostSerializer(data=data)
    if not serializer.is_valid():
        raise IgniteException(serializer.errors)

    BaseTopology.get_object(top_id, user).add_link(serializer.data)
    serializer = TopologySerializer(BaseTopology.get_topology(top_id))
    return serializer.data
Ejemplo n.º 5
0
def update_topology_switch(top_id, switch_id, data, user=""):
    serializer = TopologySwitchPutSerializer(data=data)
    if not serializer.is_valid():
        raise IgniteException(serializer.errors)

    BaseTopology.get_object(top_id,
                            user).update_switch(switch_id, serializer.data)
    serializer = TopologySerializer(BaseTopology.get_topology(top_id))
    return serializer.data
Ejemplo n.º 6
0
def update_topology_switch(top_id, switch_id, data, user=""):
    serializer = TopologySwitchPutSerializer(data=data)
    if not serializer.is_valid():
        raise IgniteException(serializer.errors)

    BaseTopology.get_object(top_id, user).update_switch(switch_id,
                                                        serializer.data)
    serializer = TopologySerializer(BaseTopology.get_topology(top_id))
    return serializer.data
Ejemplo n.º 7
0
def update_switch(fab_id, switch_id, data, user):
    switch = Switch.objects.get(pk=switch_id)

    # check if switch is already booted
    if switch.boot_detail:
        if any([switch.name != data[NAME], switch.model.id != data[MODEL], switch.serial_num != data[SERIAL_NUM]]):
            raise IgniteException(ERR_NO_NAME_CHANGE)

    # check if switch already exists with new name
    # switch name is searched across all fabrics
    if (switch.name != data[NAME] and
            Switch.objects.filter(topology__is_fabric=True, dummy=False,
                                  name=data[NAME])):
        raise IgniteException(ERR_SW_NAME_IN_USE)

    switch.name = data[NAME]

    # check if switch already exists with new serial num
    # note: serial numbers are unique across fabrics
    if (data[SERIAL_NUM] and switch.serial_num != data[SERIAL_NUM] and
            Switch.objects.filter(dummy=False, serial_num=data[SERIAL_NUM])):
        raise IgniteException(ERR_SERIAL_NUM_IN_USE)
    # check if serial_num exists in discovery rules
    find_dup_serial_discovery([data[SERIAL_NUM]])
    switch.serial_num = data[SERIAL_NUM]

    new_model = get_switch(data[MODEL])

    # is there a change in model?
    change = True if new_model != switch.model else False
    logger.debug("%schange in switch model", "no " if not change else "")

    # save new values
    switch.model = new_model
    switch.image_profile = (image.get_profile(data[IMAGE_PROFILE])
                            if data[IMAGE_PROFILE] else None)
    switch.config_profile = (config.get_profile(data[CONFIG_PROFILE])
                             if data[CONFIG_PROFILE] else None)
    switch.feature_profile = (feature.get_profile(data[FEATURE_PROFILE])
                              if data[FEATURE_PROFILE] else None)
    switch.workflow = (workflow.get_workflow(data[WORKFLOW])
                       if data[WORKFLOW] else None)

    switch.save()

    if change:
        BaseTopology.get_object(fab_id, user).update_model(switch)
    else:
        Fabric.objects.filter(pk=fab_id).update(updated_by=user)
Ejemplo n.º 8
0
def add_topology(data, user=""):
    serializer = TopologyPostSerializer(data=data)
    if not serializer.is_valid():
        raise IgniteException(serializer.errors)

    top = BaseTopology.create_object(serializer.data[MODEL_NAME])
    serializer = TopologySerializer(top.add_topology(serializer.data, user))
    return serializer.data
Ejemplo n.º 9
0
def add_topology(data, user=""):
    serializer = TopologyPostSerializer(data=data)
    if not serializer.is_valid():
        raise IgniteException(serializer.errors)

    top = BaseTopology.create_object(serializer.data[MODEL_NAME])
    serializer = TopologySerializer(top.add_topology(serializer.data, user))
    return serializer.data
Ejemplo n.º 10
0
def get_instance_value(instance_value, switch, switch_name):
    logger.debug("Get Instance value for %s" % instance_value)

    if instance_value == HOST_NAME:
        if switch:
            return switch.name
        return switch_name

    if instance_value == VPC_PEER_SRC:

        if not switch.mgmt_ip:
            raise IgniteException("%s- %s"
                                  % (ERR_MGMT_IP_NOT_DETERMINED,
                                     switch.name))

        return switch.mgmt_ip

    if not switch.topology:
        raise IgniteException("%s- %s"
                              % (ERR_SWITCH_FABRIC_NOT_DETERMINED,
                                 switch.name))

    topo = BaseTopology.get_object(switch.topology.id)

    if instance_value == VPC_PEER_DST:
        peer_switch = topo.get_vpc_peer_switch(switch)

        if not peer_switch.mgmt_ip:

            if not switch.mgmt_ip:
                raise IgniteException("%s- %s"
                                      % (ERR_MGMT_IP_NOT_DETERMINED,
                                         switch.name))

            return get_peer_mgmt_ip(switch, peer_switch)
        else:

            if not peer_switch.mgmt_ip:
                raise IgniteException("%s- %s"
                                      % (ERR_PEER_MGMT_IP_NOT_DETERMINED,
                                         switch.name))
            return peer_switch.mgmt_ip

    if instance_value == VPC_PEER_PORTS:
        return (topo.get_vpc_peer_ports(switch))

    if instance_value == UPLINK_PORTS:
        return (topo.get_uplink_ports(switch))

    if instance_value == DOWNLINK_PORTS:
        return (topo.get_downlink_ports(switch))

    raise IgniteException("%s- %s Instance %s"
                          % (ERR_FAILED_TO_GET_INSTANCE_PARAM_VALUE,
                             switch.name, instance_value))
Ejemplo n.º 11
0
def get_instance_value(instance_value, switch, switch_name):
    logger.debug("Get Instance value for %s" % instance_value)

    if instance_value == HOST_NAME:
        if switch:
            return switch.name
        return switch_name

    if instance_value == VPC_PEER_SRC:

        if not switch.mgmt_ip:
            raise IgniteException("%s- %s" %
                                  (ERR_MGMT_IP_NOT_DETERMINED, switch.name))

        return switch.mgmt_ip

    if not switch.topology:
        raise IgniteException("%s- %s" %
                              (ERR_SWITCH_FABRIC_NOT_DETERMINED, switch.name))

    topo = BaseTopology.get_object(switch.topology.id)

    if instance_value == VPC_PEER_DST:
        peer_switch = topo.get_vpc_peer_switch(switch)

        if not peer_switch.mgmt_ip:

            if not switch.mgmt_ip:
                raise IgniteException(
                    "%s- %s" % (ERR_MGMT_IP_NOT_DETERMINED, switch.name))

            return get_peer_mgmt_ip(switch, peer_switch)
        else:

            if not peer_switch.mgmt_ip:
                raise IgniteException(
                    "%s- %s" % (ERR_PEER_MGMT_IP_NOT_DETERMINED, switch.name))
            return peer_switch.mgmt_ip

    if instance_value == VPC_PEER_PORTS:
        return (topo.get_vpc_peer_ports(switch))

    if instance_value == UPLINK_PORTS:
        return (topo.get_uplink_ports(switch))

    if instance_value == DOWNLINK_PORTS:
        return (topo.get_downlink_ports(switch))

    raise IgniteException(
        "%s- %s Instance %s" %
        (ERR_FAILED_TO_GET_INSTANCE_PARAM_VALUE, switch.name, instance_value))
Ejemplo n.º 12
0
def get_fabric(fab_id):
    # get topology info, then add fabric info
    top = BaseTopology.get_topology(fab_id)
    top.site = top.fabric.site
    return top
Ejemplo n.º 13
0
def delete_topology_link(top_id, link_id, user=""):
    BaseTopology.get_object(top_id, user).delete_link(link_id)
    serializer = TopologySerializer(BaseTopology.get_topology(top_id))
    return serializer.data
Ejemplo n.º 14
0
def delete_topology_switch(top_id, switch_id, user=""):
    BaseTopology.get_object(top_id, user).delete_switch(switch_id)
    serializer = TopologySerializer(BaseTopology.get_topology(top_id))
    return serializer.data
Ejemplo n.º 15
0
def set_submit(fab_id, data, user):
    BaseTopology.set_submit(fab_id, data, user)
Ejemplo n.º 16
0
def get_all_topologies(submit):
    top_list = BaseTopology.get_all_topologies(submit)
    serializer = TopologyBriefSerializer(top_list, many=True)
    return serializer.data
Ejemplo n.º 17
0
def add_link(fab_id, data, user):
    BaseTopology.get_object(fab_id, user).add_link(data)
Ejemplo n.º 18
0
def update_link(fab_id, link_id, data, user):
    BaseTopology.get_object(fab_id, user).update_link(link_id, data)
Ejemplo n.º 19
0
def delete_switch(fab_id, switch_id, user):
    BaseTopology.get_object(fab_id, user).delete_switch(switch_id)
Ejemplo n.º 20
0
def clear_topology(top_id, user=""):
    BaseTopology.clear_topology(top_id, user)
    serializer = TopologySerializer(BaseTopology.get_topology(top_id))
    return serializer.data
Ejemplo n.º 21
0
def get_topology_detail(fab_id):
    return BaseTopology.get_topology_detail(fab_id)
Ejemplo n.º 22
0
def get_all_switches(fab_id, build=True):
    return BaseTopology.get_object(fab_id).get_all_switches(build)
Ejemplo n.º 23
0
def update_defaults(fab_id, data, user):
    BaseTopology.get_object(fab_id, user).update_defaults(data)
Ejemplo n.º 24
0
def add_switches(fab_id, data, user):
    BaseTopology.get_object(fab_id, user).add_switches(data)
Ejemplo n.º 25
0
def get_all_topologies(submit):
    top_list = BaseTopology.get_all_topologies(submit)
    serializer = TopologyBriefSerializer(top_list, many=True)
    return serializer.data
Ejemplo n.º 26
0
def decommission_switch(fab_id, switch_id, user):
    BaseTopology.get_object(fab_id, user).decommission_switch(switch_id)
Ejemplo n.º 27
0
def update_link(fab_id, link_id, data, user):
    BaseTopology.get_object(fab_id, user).update_link(link_id, data)
Ejemplo n.º 28
0
def set_submit(fab_id, data, user):
    BaseTopology.set_submit(fab_id, data, user)
Ejemplo n.º 29
0
def get_topology(top_id):
    top = BaseTopology.get_topology(top_id)
    serializer = TopologySerializer(top)
    return serializer.data
Ejemplo n.º 30
0
def add_switches(fab_id, data, user):
    BaseTopology.get_object(fab_id, user).add_switches(data)
Ejemplo n.º 31
0
def delete_topology(top_id):
    BaseTopology.delete_topology(top_id)
Ejemplo n.º 32
0
def get_topology(top_id):
    top = BaseTopology.get_topology(top_id)
    serializer = TopologySerializer(top)
    return serializer.data
Ejemplo n.º 33
0
def delete_link(fab_id, link_id, user):
    BaseTopology.get_object(fab_id, user).delete_link(link_id, True)
Ejemplo n.º 34
0
def update_topology_name(top_id, data, user=""):
    serializer = NameSerializer(data=data)
    if not serializer.is_valid():
        raise IgniteException(serializer.errors)

    BaseTopology.update_topology_name(top_id, serializer.data, user)
Ejemplo n.º 35
0
def update_topology_name(top_id, data, user=""):
    serializer = NameSerializer(data=data)
    if not serializer.is_valid():
        raise IgniteException(serializer.errors)

    BaseTopology.update_topology_name(top_id, serializer.data, user)
Ejemplo n.º 36
0
def delete_fabric(fab_id):
    BaseTopology.delete_topology(fab_id)
Ejemplo n.º 37
0
def delete_topology(top_id):
    BaseTopology.delete_topology(top_id)
Ejemplo n.º 38
0
def get_fabric(fab_id):
    # get topology info, then add fabric info
    top = BaseTopology.get_topology(fab_id)
    top.site = top.fabric.site
    top.maintenance_group_count = maintenance_group_count(fab_id)
    return top
Ejemplo n.º 39
0
def update_switch(fab_id, switch_id, data, user):
    switch = Switch.objects.get(pk=switch_id)

    # check if switch is already booted
    if switch.boot_detail:
        if data[CONFIG_TYPE] == RUNNING_CONFIG:
            logger.debug("input config type- " + data[CONFIG_TYPE])
            if SwitchConfig.objects.filter(switch_id=switch_id):
                switch.config_type = data[CONFIG_TYPE]
            else:
                logger.error(ERR_RUN_CONFIG_NOT_AVAL)
                raise IgniteException(ERR_RUN_CONFIG_NOT_AVAL)
        else:
            switch.config_type = data[CONFIG_TYPE]

        if any([
                switch.name != data[NAME], switch.model.id != data[MODEL],
                switch.serial_num != data[SERIAL_NUM]
        ]):
            raise IgniteException(ERR_NO_NAME_CHANGE)

    # check if switch already exists with new name
    # switch name is searched across all fabrics
    if (switch.name != data[NAME] and Switch.objects.filter(
            topology__is_fabric=True, dummy=False, name=data[NAME])):
        raise IgniteException(ERR_SW_NAME_IN_USE)

    switch.name = data[NAME]

    # check if switch already exists with new serial num
    # note: serial numbers are unique across fabrics
    if (data[SERIAL_NUM] and switch.serial_num != data[SERIAL_NUM] and
            Switch.objects.filter(dummy=False, serial_num=data[SERIAL_NUM])):
        raise IgniteException(ERR_SERIAL_NUM_IN_USE)
    # check if serial_num exists in discovery rules
    find_dup_serial_discovery([data[SERIAL_NUM]])
    switch.serial_num = data[SERIAL_NUM]

    new_model = get_switch(data[MODEL])

    # is there a change in model?
    change = True if new_model != switch.model else False
    logger.debug("%schange in switch model", "no " if not change else "")

    if change:
        if data[MODEL] == 1:
            logger.debug("Unknown switch model can not be assigned")
            raise IgniteException(ERR_CAN_NOT_ASSIGN_UNKOWN_MODEL)

    # save new values
    switch.model = new_model
    switch.image_profile = (image.get_profile(data[IMAGE_PROFILE])
                            if data[IMAGE_PROFILE] else None)
    switch.config_profile = (config.get_profile(data[CONFIG_PROFILE])
                             if data[CONFIG_PROFILE] else None)
    switch.feature_profile = (feature.get_profile(data[FEATURE_PROFILE])
                              if data[FEATURE_PROFILE] else None)
    switch.workflow = (workflow.get_workflow(data[WORKFLOW])
                       if data[WORKFLOW] else None)

    switch.save()

    if change:
        BaseTopology.get_object(fab_id, user).update_model(switch)
    else:
        Fabric.objects.filter(pk=fab_id).update(updated_by=user)
Ejemplo n.º 40
0
def set_topology_submit(top_id, user):
    BaseTopology.set_submit(top_id, True, user)
Ejemplo n.º 41
0
def delete_topology_switch(top_id, switch_id, user=""):
    BaseTopology.get_object(top_id, user).delete_switch(switch_id)
    serializer = TopologySerializer(BaseTopology.get_topology(top_id))
    return serializer.data
Ejemplo n.º 42
0
def delete_fabric(fab_id):
    BaseTopology.delete_topology(fab_id)
Ejemplo n.º 43
0
def get_all_switches(fab_id, build=True):
    return BaseTopology.get_object(fab_id).get_all_switches(build)
Ejemplo n.º 44
0
def delete_switch(fab_id, switch_id, user):
    BaseTopology.get_object(fab_id, user).delete_switch(switch_id)
Ejemplo n.º 45
0
def get_fabric(fab_id):
    # get topology info, then add fabric info
    top = BaseTopology.get_topology(fab_id)
    top.site = top.fabric.site
    top.maintenance_group_count = maintenance_group_count(fab_id)
    return top
Ejemplo n.º 46
0
def add_link(fab_id, data, user):
    BaseTopology.get_object(fab_id, user).add_link(data)
Ejemplo n.º 47
0
def set_topology_submit(top_id, user):
    BaseTopology.set_submit(top_id, True, user)
Ejemplo n.º 48
0
def delete_link(fab_id, link_id, user):
    BaseTopology.get_object(fab_id, user).delete_link(link_id, True)
Ejemplo n.º 49
0
def clear_topology(top_id, user=""):
    BaseTopology.clear_topology(top_id, user)
    serializer = TopologySerializer(BaseTopology.get_topology(top_id))
    return serializer.data
Ejemplo n.º 50
0
def update_defaults(fab_id, data, user):
    BaseTopology.get_object(fab_id, user).update_defaults(data)
Ejemplo n.º 51
0
def decommission_switch(fab_id, switch_id, user):
    BaseTopology.get_object(fab_id, user).decommission_switch(switch_id)
Ejemplo n.º 52
0
def get_topology_detail(fab_id):
    return BaseTopology.get_topology_detail(fab_id)
Ejemplo n.º 53
0
def delete_topology_link(top_id, link_id, user=""):
    BaseTopology.get_object(top_id, user).delete_link(link_id)
    serializer = TopologySerializer(BaseTopology.get_topology(top_id))
    return serializer.data