Exemple #1
0
void endpoint::Drive::del(const server::Request& request, server::Response& response) {
    static const constexpr char TRANSACTION_NAME[] = "DeleteDrive";

    const auto drive = psme::rest::model::find<agent_framework::model::Chassis, agent_framework::model::Drive>(
        request.params).get();

    auto gami_req = agent_framework::model::requests::DeleteDrive(drive.get_uuid());

    const auto& gami_agent = psme::core::agent::AgentManager::get_instance()->get_agent(drive.get_agent_id());

    auto remove_drive = [&, gami_agent] {
        // try removing drive from agent's model
        gami_agent->execute<agent_framework::model::responses::DeleteDrive>(gami_req);

        // remove drive from REST model, DO NOT use drive reference after this line!
        psme::rest::model::handler::HandlerManager::get_instance()->get_handler(
            agent_framework::model::enums::Component::Drive)->
            remove(drive.get_uuid());

        response.set_status(server::status_2XX::NO_CONTENT);
    };

    gami_agent->execute_in_transaction(TRANSACTION_NAME, remove_drive);

}
Exemple #2
0
void endpoint::AclCollection::post(const server::Request& request, server::Response& response) {
    static const constexpr char TRANSACTION_NAME[] = "PostAclCollection";
    validators::JsonValidator::validate_empty_request(request);

    auto parent_switch =
        model::find<agent_framework::model::EthernetSwitch>(request.params).get();

    const requests::AddAcl add_acl_request{
        parent_switch.get_uuid(),
        attribute::Array<std::string>(),
        attribute::Oem()
    };

    const auto& gami_agent = psme::core::agent::AgentManager::get_instance()->get_agent(parent_switch.get_agent_id());

    auto add_acl = [&, gami_agent] {
        const auto add_acl_response = gami_agent->execute<responses::AddAcl>(add_acl_request);

        const auto acl_id = model::handler::HandlerManager::get_instance()->
            get_handler(enums::Component::Acl)->
            load(gami_agent, parent_switch.get_uuid(),
                 enums::Component::EthernetSwitch, add_acl_response.get_acl(), true);

        endpoint::utils::set_location_header(request, response, PathBuilder(request).append(acl_id).build());
        response.set_status(server::status_2XX::CREATED);
    };

    gami_agent->execute_in_transaction(TRANSACTION_NAME, add_acl);
}
void endpoint::StaticMacCollection::post(const server::Request& req, server::Response& res) {

    auto parent_port = model::Find<agent_framework::model::SwitchPort>
                            (req.params[PathParam::SWITCH_PORT_ID])
                            .via<agent_framework::model::Switch>
                            (req.params[PathParam::ETHERNET_SWITCH_ID]).get_one();

    const auto json = validate_post_request(req);

    const requests::AddPortStaticMac add_port_static_mac_request{
           parent_port->get_uuid(),
           json[constants::StaticMac::MAC_ADDRESS].as_string(),
           json.is_member(constants::StaticMac::VLAN_ID) ? json[constants::StaticMac::VLAN_ID].as_uint() : Json::Value::null,
           attribute::Oem()
    };

    const auto add_port_static_mac_response = AgentManager::get_instance()
           ->call_method<responses::AddPortStaticMac>(parent_port->get_agent_id(), add_port_static_mac_request);

    const auto static_mac_id = model::handler::HandlerManager::get_instance()->
           get_handler(enums::Component::StaticMac)->
           load(AgentManager::get_instance()->get_agent(parent_port->get_agent_id()),
                parent_port->get_uuid(), add_port_static_mac_response.get_static_mac(), true);

    endpoint::utils::set_location_header(res, req, PathBuilder(req).append(static_mac_id).build());

    res.set_status(server::status_2XX::CREATED);
}
Exemple #4
0
void endpoint::AclBind<true>::post(const server::Request& request,
    server::Response& response) {
    const auto acl_port_pair = get_acl_and_port_uuid(request);

    if (NetworkManager::get_instance()->get_acl_port_manager().entry_exists(acl_port_pair.first, acl_port_pair.second)) {
        THROW(agent_framework::exceptions::InvalidParameters, "rest",
              "Port " + std::to_string(NetworkManager::get_instance()->get_port_manager().uuid_to_rest_id(acl_port_pair.second))
              + " is already bound to ACL " + request.params[PathParam::ACL_ID]);
    }

    const requests::AddAclPort add_acl_port_request{
        acl_port_pair.first,
        attribute::Array<std::string>(std::vector<std::string>{acl_port_pair.second}),
        attribute::Oem()
    };

    const auto agent_id = model::Find<agent_framework::model::Switch>
        (request.params[PathParam::ETHERNET_SWITCH_ID]).get().get_agent_id();

    const auto add_acl_port_response = AgentManager::get_instance()
        ->call_method<responses::AddAclPort>(agent_id, add_acl_port_request);

    NetworkManager::get_instance()->get_acl_port_manager().add_entry(acl_port_pair.first, acl_port_pair.second, agent_id);
    response.set_status(server::status_2XX::NO_CONTENT);
}
Exemple #5
0
void endpoint::Rule::del(const server::Request& req, server::Response& res) {
    static const constexpr char TRANSACTION_NAME[] = "DeleteRule";

    auto rule = psme::rest::model::find<agent_framework::model::EthernetSwitch, agent_framework::model::Acl, agent_framework::model::AclRule>(
        req.params).get();

    auto delete_acl_rule_request = requests::DeleteAclRule(rule.get_uuid());

    const auto& gami_agent = psme::core::agent::AgentManager::get_instance()->get_agent(rule.get_agent_id());

    auto delete_rule = [&, gami_agent] {
        // try removing ACL from agent's model
        gami_agent->execute<responses::DeleteAclRule>(delete_acl_rule_request);

        // remove the resource from application's model
        HandlerManager::get_instance()->get_handler(enums::Component::AclRule)->remove(rule.get_uuid());

        res.set_status(server::status_2XX::NO_CONTENT);
    };
    gami_agent->execute_in_transaction(TRANSACTION_NAME, delete_rule);
}
Exemple #6
0
void endpoint::AclBind<true>::post(const server::Request& request, server::Response& response) {
    static const constexpr char TRANSACTION_NAME[] = "PostAclBind";

    const auto json = JsonValidator::validate_request_body<schema::AclPostSchema>(request);
    const auto acl_port_pair = get_acl_and_port_uuid(request, json);

    if (NetworkComponents::get_instance()->get_acl_port_manager().entry_exists(acl_port_pair.first,
                                                                               acl_port_pair.second)) {
        THROW(agent_framework::exceptions::InvalidValue, "rest",
              "Port " + std::to_string(
                  NetworkComponents::get_instance()->get_port_manager().uuid_to_rest_id(acl_port_pair.second))
              + " is already bound to ACL " + request.params[PathParam::ACL_ID]);
    }

    const requests::AddAclPort add_acl_port_request{
        acl_port_pair.first,
        attribute::Array<std::string>(std::vector<std::string>{acl_port_pair.second}),
        attribute::Oem()
    };

    const auto parent_switch =
        model::find<agent_framework::model::EthernetSwitch>(request.params).get();
    const auto agent_id = parent_switch.get_agent_id();
    const auto& gami_agent = psme::core::agent::AgentManager::get_instance()->get_agent(agent_id);

    auto add_acl_port = [&, gami_agent] {
        const auto add_acl_port_response = gami_agent->execute<responses::AddAclPort>(add_acl_port_request);

        model::handler::HandlerManager::get_instance()->
            get_handler(enums::Component::Acl)->
            load(gami_agent, parent_switch.get_uuid(),
                 enums::Component::EthernetSwitch, acl_port_pair.first, true);

        NetworkComponents::get_instance()->get_acl_port_manager().add_entry(acl_port_pair.first, acl_port_pair.second,
                                                                            agent_id);
        response.set_status(server::status_2XX::NO_CONTENT);
    };

    gami_agent->execute_in_transaction(TRANSACTION_NAME, add_acl_port);
}