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
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
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
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)
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
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))
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))
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
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
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
def set_submit(fab_id, data, user): BaseTopology.set_submit(fab_id, data, user)
def get_all_topologies(submit): top_list = BaseTopology.get_all_topologies(submit) serializer = TopologyBriefSerializer(top_list, many=True) return serializer.data
def add_link(fab_id, data, user): BaseTopology.get_object(fab_id, user).add_link(data)
def update_link(fab_id, link_id, data, user): BaseTopology.get_object(fab_id, user).update_link(link_id, data)
def delete_switch(fab_id, switch_id, user): BaseTopology.get_object(fab_id, user).delete_switch(switch_id)
def clear_topology(top_id, user=""): BaseTopology.clear_topology(top_id, user) serializer = TopologySerializer(BaseTopology.get_topology(top_id)) return serializer.data
def get_topology_detail(fab_id): return BaseTopology.get_topology_detail(fab_id)
def get_all_switches(fab_id, build=True): return BaseTopology.get_object(fab_id).get_all_switches(build)
def update_defaults(fab_id, data, user): BaseTopology.get_object(fab_id, user).update_defaults(data)
def add_switches(fab_id, data, user): BaseTopology.get_object(fab_id, user).add_switches(data)
def decommission_switch(fab_id, switch_id, user): BaseTopology.get_object(fab_id, user).decommission_switch(switch_id)
def get_topology(top_id): top = BaseTopology.get_topology(top_id) serializer = TopologySerializer(top) return serializer.data
def delete_topology(top_id): BaseTopology.delete_topology(top_id)
def delete_link(fab_id, link_id, user): BaseTopology.get_object(fab_id, user).delete_link(link_id, True)
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)
def delete_fabric(fab_id): BaseTopology.delete_topology(fab_id)
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
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)
def set_topology_submit(top_id, user): BaseTopology.set_submit(top_id, True, user)