gns3-wol-emulator/source/gns3/GnsNode.cpp

41 lines
919 B
C++

#include "GnsNode.hpp"
#include "GnsPort.hpp"
#include "GnsProject.hpp"
#include <cpr/cpr.h>
#include <vector>
namespace gns {
GnsNode::GnsNode(const std::shared_ptr<const GnsProject>& project, const std::string& uuid, const std::vector<GnsPort>& ports) {
this->project = project;
this->uuid = uuid;
this->ports = ports;
}
std::string GnsNode::getApiBase() const {
return this->project->getApiBase() + "nodes/" + this->getUuid() + "/";
}
std::string GnsNode::getUuid() const {
return this->uuid;
}
std::vector<GnsPort> GnsNode::getPorts() const {
return this->ports;
}
void GnsNode::start() const {
// request the API endpoint
cpr::Url endpoint = this->getApiBase() + "start";
const cpr::Response response = Post(endpoint);
// check for a valid response
if (response.error.code != cpr::ErrorCode::OK)
throw std::runtime_error(response.error.message);
}
}