def update_defaults(self, data): self._validate_defaults(data) # update default switch attributes for item in data[SWITCHES]: try: switch = Switch.objects.get(topology_id=self._top.id, dummy=True, tier=item[TIER]) except Switch.DoesNotExist: # if tier default does not exist, create one switch = Switch() switch.topology = self._top switch.dummy = True switch.name = DEFAULT switch.tier = item[TIER] switch.model = get_switch(item[MODEL]) switch.image_profile = get_profile(item[IMAGE_PROFILE]) switch.save() # update default link attributes for item in data[LINKS]: link = Link.objects.get(topology_id=self._top.id, dummy=True, src_ports=item[SRC_TIER], dst_ports=item[DST_TIER]) link.link_type = item[LINK_TYPE] link.num_links = item[NUM_LINKS] link.save()
def update_defaults(self, data): self._validate_defaults(data) # update default switch attributes for item in data[SWITCHES]: try: switch = Switch.objects.get(topology_id=self._top.id, dummy=True, tier=item[TIER]) except Switch.DoesNotExist: # if tier default does not exist, create one switch = Switch() switch.topology = self._top switch.dummy = True switch.name = DEFAULT switch.tier = item[TIER] switch.model = get_switch(item[MODEL]) switch.image_profile = get_profile(item[IMAGE_PROFILE]) switch.save() # update default link attributes for item in data[LINKS]: link = Link.objects.get( topology_id=self._top.id, dummy=True, src_ports=item[SRC_TIER], dst_ports=item[DST_TIER] ) link.link_type = item[LINK_TYPE] link.num_links = item[NUM_LINKS] link.save()
def add_topology(self, data, user): logger.debug("topology name = %s, model = %s", data[NAME], data[MODEL_NAME]) self._validate_defaults(data[DEFAULTS]) self._top = Topology() self._top.name = data[NAME] self._top.model_name = data[MODEL_NAME] self._top.is_fabric = False self._top.updated_by = user self._top.save() # defaults object self._top.defaults = dict() self._top.defaults[SWITCHES] = list() self._top.defaults[LINKS] = list() # add topology default switches with dummy=True for item in data[DEFAULTS][SWITCHES]: if item[MODEL] == 1: raise IgniteException(ERR_CAN_NOT_ASSIGN_UNKOWN_MODEL) switch = Switch() switch.topology = self._top switch.dummy = True switch.name = DEFAULT switch.tier = item[TIER] switch.model = get_switch(item[MODEL]) switch.image_profile = get_profile(item[IMAGE_PROFILE]) switch.save() # add switch to topology defaults self._top.defaults[SWITCHES].append(switch) # add topology default links with dummy=True for item in data[DEFAULTS][LINKS]: link = Link() link.topology = self._top link.dummy = True link.src_ports = item[SRC_TIER] # store tier name in ports link.dst_ports = item[DST_TIER] # store tier name in ports link.link_type = item[LINK_TYPE] link.num_links = item[NUM_LINKS] link.save() # need tier names in link object while returning link.src_tier = link.src_ports link.dst_tier = link.dst_ports # add link to topology defaults self._top.defaults[LINKS].append(link) # new topology has no switches or links self._top.switches = list() self._top.links = list() return self._top
def get_default_discovery_switch(fab_id, tier): logger.debug("creating default switch") switch_default = Switch() switch_default.topology_id = fab_id switch_default.dummy = True switch_default.name = DEFAULT switch_default.tier = tier switch_default.model = get_switch(1) switch_default.image_profile = image.get_profile(1) switch_default.save() logger.debug("default switch created") return switch_default
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 save_discovered_fabric(fab_id, data, user): logger.debug("Start saving discovered Fabric") fabric = Fabric.objects.get(pk=fab_id) fabric.name = data[NAME] fabric.config_profile = config.get_profile(1) fabric.updated_by = user fabric.submit = True fabric.save() logger.debug("fabric name = %s", data[NAME]) cfg = dict() feat = dict() wf = dict() switch_dict = dict() for switch in Switch.objects.filter(topology_id=fab_id).order_by(ID): logger.debug("Looping through all switches of Discovered fabric- %s", data[NAME]) if switch.dummy: # set default config profile for fabric default switch logger.debug( "set default config profile for fabric default switch") switch.config_profile = config.get_profile(1) else: # append fabric name to switch name logger.debug( "Defining switch name by appending it to fabric name for switch-%s", switch.name) switch.name = fabric.name + "_" + switch.name # set Unknown model to switch in fabric logger.debug("set Unknown model to switch in fabric") switch.model = get_switch(1) logger.debug("Added Unknown model to switch in fabric") switch.save() fabric.is_saved = True fabric.save() logger.debug("Fabric saved") return fabric
def save_discovered_fabric(fab_id, data, user): logger.debug("Start saving discovered Fabric") fabric = Fabric.objects.get(pk=fab_id) fabric.name = data[NAME] fabric.config_profile = config.get_profile(1) fabric.updated_by = user fabric.submit = True fabric.save() logger.debug("fabric name = %s", data[NAME]) cfg = dict() feat = dict() wf = dict() switch_dict = dict() for switch in Switch.objects.filter(topology_id=fab_id).order_by(ID): logger.debug("Looping through all switches of Discovered fabric- %s", data[NAME]) if switch.dummy: # set default config profile for fabric default switch logger.debug("set default config profile for fabric default switch") switch.config_profile = config.get_profile(1) else: # append fabric name to switch name logger.debug("Defining switch name by appending it to fabric name for switch-%s", switch.name) switch.name = fabric.name + "_" + switch.name # set Unknown model to switch in fabric logger.debug("set Unknown model to switch in fabric") switch.model = get_switch(1) logger.debug("Added Unknown model to switch in fabric") switch.save() fabric.is_saved = True fabric.save() logger.debug("Fabric saved") return fabric
def update_switch(self, switch_id, data): switch = Switch.objects.get(pk=switch_id) if data[MODEL] == 1: raise IgniteException(ERR_CAN_NOT_ASSIGN_UNKOWN_MODEL) # TODO: check if model is valid, currently UI perform this check 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 = get_profile(data[IMAGE_PROFILE]) if data[IMAGE_PROFILE] else None switch.save() if change: self.update_model(switch)
def update_switch(self, switch_id, data): switch = Switch.objects.get(pk=switch_id) if data[MODEL] == 1: raise IgniteException(ERR_CAN_NOT_ASSIGN_UNKOWN_MODEL) # TODO: check if model is valid, currently UI perform this check 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 = (get_profile(data[IMAGE_PROFILE]) if data[IMAGE_PROFILE] else None) switch.save() if change: self.update_model(switch)
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)