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 add_discovered_switches(fab_id, tiers, switch_with_ip): from bootstrap import bootstrap logger.debug("Adding discovered switches in fabric") switch_id_details = dict() switch_id_details[SPINE] = dict() switch_id_details[LEAF] = dict() switch_id_details[CORE] = dict() switch_id_details[BORDER] = dict() for spine_switch in tiers[SPINE]: logger.debug("Adding spine switch:%s in fabric", spine_switch[0]) switch = Switch() switch.tier = SPINE switch.name = spine_switch[0] switch.dummy = False switch.serial_num = spine_switch[1] find_duplicate([spine_switch[1]]) switch.topology_id = fab_id switch.mgmt_ip = switch_with_ip[spine_switch[0]] switch.model = SwitchModel.objects.get(id=1) switch.save() bootstrap.update_boot_detail(switch, match_type=DISCOVERY, discovery_rule=None, boot_time=timezone.now(), boot_status=BOOT_SUCCESS, model_type='') logger.debug("Spine added") switch_id_details[SPINE][spine_switch[0]] = switch.id for leaf_switch in tiers[LEAF]: logger.debug("Adding leaf switch:%s to fabric", leaf_switch[0]) switch = Switch() switch.tier = LEAF switch.name = leaf_switch[0] switch.serial_num = leaf_switch[1] find_duplicate([leaf_switch[1]]) switch.topology_id = fab_id switch.mgmt_ip = switch_with_ip[leaf_switch[0]] switch.model = SwitchModel.objects.get(id=1) switch.save() bootstrap.update_boot_detail(switch, match_type=DISCOVERY, discovery_rule=None, boot_time=timezone.now(), boot_status=BOOT_SUCCESS, model_type='') logger.debug("Leaf added") switch_id_details[LEAF][leaf_switch[0]] = switch.id for core_switch in tiers[CORE]: logger.debug("Adding core switch:%s in fabric", core_switch) switch = Switch() switch.tier = CORE switch.name = core_switch switch.dummy = False switch.topology_id = fab_id switch.model = SwitchModel.objects.get(id=1) switch.save() bootstrap.update_boot_detail(switch, match_type=DISCOVERY, discovery_rule=None, boot_time=timezone.now(), boot_status=BOOT_SUCCESS, model_type='') logger.debug("core added") switch_id_details[CORE][core_switch] = switch.id for border_switch in tiers[BORDER]: logger.debug("Adding border switch:%s in fabric", border_switch) switch = Switch() switch.tier = BORDER switch.name = border_switch switch.dummy = False switch.topology_id = fab_id switch.model = SwitchModel.objects.get(id=1) switch.save() bootstrap.update_boot_detail(switch, match_type=DISCOVERY, discovery_rule=None, boot_time=timezone.now(), boot_status=BOOT_SUCCESS, model_type='') logger.debug("Border added") switch_id_details[BORDER][border_switch] = switch.id return switch_id_details