Commit 108ab4af by Fukász Rómeó Ervin

add operating system template details

parent 032b996a
...@@ -67,9 +67,9 @@ shared_ptr<Compute> Compute::getComputeInstance(OcciSession* session, string id) ...@@ -67,9 +67,9 @@ shared_ptr<Compute> Compute::getComputeInstance(OcciSession* session, string id)
return make_shared<Compute>(Compute(session, instance)); return make_shared<Compute>(Compute(session, instance));
} }
shared_ptr<Compute> Compute::createComputeInstance(OcciSession* session, Template t) { shared_ptr<Compute> Compute::createComputeInstance(OcciSession* session, Template* t) {
auto uri = "compute/1/"; auto uri = "compute/1/";
json data = json::parse("{\"mixins\": [\"" + t + "\"]}"); json data = json::parse("{\"mixins\": [\"" + t->getTemplateIdentifier() + "\"]}");
auto instance = session->put(uri, data); auto instance = session->put(uri, data);
return make_shared<Compute>(Compute(session, instance)); return make_shared<Compute>(Compute(session, instance));
} }
......
...@@ -58,7 +58,7 @@ namespace OcciClient { ...@@ -58,7 +58,7 @@ namespace OcciClient {
static std::shared_ptr<Compute> getComputeInstance(OcciSession* session, std::string id); static std::shared_ptr<Compute> getComputeInstance(OcciSession* session, std::string id);
static std::shared_ptr<Compute> createComputeInstance(OcciSession* session, Template t); static std::shared_ptr<Compute> createComputeInstance(OcciSession* session, Template* t);
static std::vector<std::shared_ptr<Compute>> getComputeInstances(OcciSession* session); static std::vector<std::shared_ptr<Compute>> getComputeInstances(OcciSession* session);
......
...@@ -25,16 +25,17 @@ ...@@ -25,16 +25,17 @@
%shared_ptr(OcciClient::Compute) %shared_ptr(OcciClient::Compute)
%shared_ptr(OcciClient::Storage) %shared_ptr(OcciClient::Storage)
%shared_ptr(OcciClient::Network) %shared_ptr(OcciClient::Network)
%shared_ptr(OcciClient::Template)
%include "entity.hpp" %include "entity.hpp"
%include "resource.h" %include "resource.h"
%include "link.h" %include "link.h"
%include "compute.h"
%include "template.h" %include "template.h"
%include "compute.h"
%include "storage.h" %include "storage.h"
%include "network.h" %include "network.h"
namespace std { namespace std {
%template(TemplateVector) vector<Template>; %template(TemplateVector) vector<shared_ptr<OcciClient::Template>>;
%template(ComputeInstanceVector) vector<shared_ptr<OcciClient::Compute>>; %template(ComputeInstanceVector) vector<shared_ptr<OcciClient::Compute>>;
} }
...@@ -18,24 +18,66 @@ ...@@ -18,24 +18,66 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include <memory>
#include "occisession.h" #include "occisession.h"
#include "json.hpp" #include "json.hpp"
#include "template.h" #include "template.h"
//TODO remove this include
#include <iostream>
using nlohmann::json; using nlohmann::json;
using std::string; using std::string;
using std::vector; using std::vector;
using namespace OcciClient; using std::shared_ptr;
using std::make_shared;
vector<Template> OcciClient::getTemplates(OcciSession* session){
json mixins = session->queryInterface()["mixins"]; namespace OcciClient{
auto result = vector<Template>();
for (auto& mixin : mixins) { vector< shared_ptr<Template> > Template::getTemplates(OcciSession* session){
if (mixin["depends"] == "http://schemas.ogf.org/occi/infrastructure#os_tpl") { json mixins = session->queryInterface()["mixins"];
result.push_back(mixin["scheme"].get<string>() + mixin["term"].get<string>()); auto result = vector< shared_ptr<Template> >();
for (auto& mixin : mixins) {
if (mixin["depends"] == "http://schemas.ogf.org/occi/infrastructure#os_tpl") {
auto tpl = make_shared<Template>(mixin);
result.push_back(tpl);
}
} }
return result;
}
Template::Template(json rendering) {
this->scheme = rendering["scheme"].get<string>();
this->term = rendering["term"].get<string>();
this->title = rendering["title"].get<string>();
this->defaultCores = rendering["attributes"]["occi.compute.cores"]["default"].get<int>();
this->defaultCpuShare = rendering["attributes"]["occi.compute.share"]["default"].get<int>();
this->defaultMemory = rendering["attributes"]["occi.compute.memory"]["default"].get<double>();
this->defaultArchitecture = rendering["attributes"]["occi.compute.architecture"]["default"].get<string>();
}
string Template::getTemplateIdentifier() {
return this->scheme + this->term;
}
std::string Template::getDefaultArchitecture() {
return this->defaultArchitecture;
}
double Template::getDefaultMemory() {
return this->defaultMemory;
}
int Template::getDefaultCores() {
return this->defaultCores;
} }
return result;
int Template::getDefaultCpuShare() {
return this->defaultCpuShare;
}
string Template::getTitle(){
return this->title;
}
} }
...@@ -21,15 +21,34 @@ ...@@ -21,15 +21,34 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include <memory>
#include "json.hpp"
#include "occisession.h" #include "occisession.h"
typedef std::string Template;
namespace OcciClient{ namespace OcciClient{
std::vector<Template> getTemplates(OcciSession* session); class Template {
private:
std::string defaultArchitecture;
double defaultMemory;
int defaultCores;
int defaultCpuShare;
std::string title;
std::string scheme;
std::string term;
public:
Template(nlohmann::json);
static std::vector< std::shared_ptr<Template> > getTemplates(OcciSession*);
std::string getDefaultArchitecture();
double getDefaultMemory();
int getDefaultCores();
int getDefaultCpuShare();
std::string getTemplateIdentifier();
std::string getTitle();
};
} }
#endif // OCCILIB_TEMPLATE_H #endif // OCCILIB_TEMPLATE_H
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment