Example #1
0
void DiscoveryManager::recreate_host_endpoint_from_db(const Uuid& fabric_uuid,
                                                      const Uuid& switch_uuid,
                                                      const Port& port) const {

    log_debug("pnc-discovery", "Recreate host endpoint from db");

    PncStabilizer stabilizer{};
    Switch pcie_switch = get_manager<Switch>().get_entry(switch_uuid);

    FabricEntity fabric_db{fabric_uuid};

    auto endpoints_uuids = fabric_db.get_multiple_values(db_keys::ENDPOINTS);
    auto zones_uuids = fabric_db.get_multiple_values(db_keys::ZONES);

    for (const auto& endpoint_uuid : endpoints_uuids) {

        EndpointEntity endpoint_db{endpoint_uuid};

        auto role_db = endpoint_db.get(db_keys::ENDPOINT_ROLE);

        if (literals::Endpoint::INITIATOR == role_db) {

            log_debug("pnc-discovery", "Found host endpoint in fabric db, endpoint uuid: " << endpoint_uuid);

            auto port_uuid_db = endpoint_db.get(db_keys::PORT);

            const Uuid predicted_port_uuid = stabilizer.dry_stabilize(port, pcie_switch);

            if (predicted_port_uuid == port_uuid_db) {

                EndpointBuilder endpoint_builder;
                endpoint_builder.init(fabric_uuid);

                Endpoint endpoint = endpoint_builder.add_host_entity().build();
                endpoint.set_uuid(endpoint_uuid);
                endpoint.set_status(attribute::Status(enums::State::Enabled, enums::Health::OK));

                agent_framework::discovery::IdentifierBuilder::set_uuid(endpoint, endpoint_uuid);

                log_and_add<Endpoint>(endpoint);

                get_m2m_manager<Endpoint, Port>().add_entry(endpoint_uuid, port.get_uuid());

                log_debug("pnc-discovery", "Created host endpoint from fabric db, endpoint uuid: " << endpoint_uuid);

                agent::pnc::discovery::utils::update_endpoint_zone_binding_from_db(zones_uuids, endpoint_uuid);

                break;
            }
        }
    }
}