Commit cd9fd697 by Fukász Rómeó Ervin

minor fixes in the library sources

added parent class of resource (entity)
added leasetime mixin support (suspend and remove attributes, renew action)
parent e1a16dd7
...@@ -6,7 +6,7 @@ CPPFLAGS=-fPIC --std=c++11 -Ofast -Irestclient-cpp/include ...@@ -6,7 +6,7 @@ CPPFLAGS=-fPIC --std=c++11 -Ofast -Irestclient-cpp/include
LDFLAGS=--shared LDFLAGS=--shared
LIBS=-lrestclient-cpp -lcurl LIBS=-lrestclient-cpp -lcurl
SONAME=_occi.so SONAME=_occi.so
SOURCES=occilib.cpp SOURCES=compute.cpp entity.cpp network.cpp occisession.cpp resource.cpp storage.cpp template.cpp
SWIG=swig SWIG=swig
SWIG_INTERFACES=occilib.i SWIG_INTERFACES=occilib.i
...@@ -22,6 +22,10 @@ default: python ...@@ -22,6 +22,10 @@ default: python
python: python:
python setup.py build python setup.py build
lib: deps
$(CPP) $(CPPFLAGS) -c $(SOURCES)
$(AR) rcs libocci.a *.o
restclient-cpp: restclient-cpp:
git clone --depth=1 $(RESTCLIENT_CPP_URL) -b $(RESTCLIENT_CPP_TAG) git clone --depth=1 $(RESTCLIENT_CPP_URL) -b $(RESTCLIENT_CPP_TAG)
bash gen_restclient-cpp_version.sh $(RESTCLIENT_CPP_TAG) bash gen_restclient-cpp_version.sh $(RESTCLIENT_CPP_TAG)
...@@ -38,6 +42,7 @@ clean: ...@@ -38,6 +42,7 @@ clean:
rm -f $(WRAPPER_SOURCES) rm -f $(WRAPPER_SOURCES)
rm -f $(SONAME) rm -f $(SONAME)
rm -f occi.py rm -f occi.py
rm -f occi.pyc
rm -Rf build rm -Rf build
mrproper: clean clean_deps mrproper: clean clean_deps
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
// with CIRCLE. If not, see <http://www.gnu.org/licenses/>. // with CIRCLE. If not, see <http://www.gnu.org/licenses/>.
#include <string> #include <string>
#include <memory>
#include "json.hpp" #include "json.hpp"
#include "resource.h" #include "resource.h"
#include "template.h" #include "template.h"
...@@ -25,6 +25,8 @@ ...@@ -25,6 +25,8 @@
using std::string; using std::string;
using nlohmann::json; using nlohmann::json;
using std::shared_ptr;
using std::make_shared;
using namespace OcciClient; using namespace OcciClient;
...@@ -43,6 +45,8 @@ void Compute::parseJsonInstance(json instance) { ...@@ -43,6 +45,8 @@ void Compute::parseJsonInstance(json instance) {
this->credentialUsername = getAttributeFromRendering<string>(instance, "org.circlecloud.occi.credentials.username"); this->credentialUsername = getAttributeFromRendering<string>(instance, "org.circlecloud.occi.credentials.username");
this->credentialPassword = getAttributeFromRendering<string>(instance, "org.circlecloud.occi.credentials.password"); this->credentialPassword = getAttributeFromRendering<string>(instance, "org.circlecloud.occi.credentials.password");
this->credentialCommand = getAttributeFromRendering<string>(instance, "org.circlecloud.occi.credentials.command"); this->credentialCommand = getAttributeFromRendering<string>(instance, "org.circlecloud.occi.credentials.command");
this->leasetimeSuspend = getAttributeFromRendering<string>(instance, "org.circlecloud.occi.leasetime.suspend");
this->leasetimeRemove = getAttributeFromRendering<string>(instance, "org.circlecloud.occi.leasetime.remove");
this->rendering = instance; this->rendering = instance;
} }
...@@ -55,15 +59,13 @@ void Compute::invokeAction(json actionData) { ...@@ -55,15 +59,13 @@ void Compute::invokeAction(json actionData) {
parseJsonInstance(inst); parseJsonInstance(inst);
} }
public: shared_ptr<Compute> Compute::getComputeInstance(OcciSession* session, string id) {
static shared_ptr<Compute> Compute::getComputeInstance(OcciSession* session, string id) {
auto uri = "compute/" + id + "/"; auto uri = "compute/" + id + "/";
auto instance = session->get(uri); auto instance = session->get(uri);
return make_shared<Compute>(Compute(session, instance)); return make_shared<Compute>(Compute(session, instance));
} }
static 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 + "\"]}");
auto instance = session->put(uri, data); auto instance = session->put(uri, data);
...@@ -122,6 +124,14 @@ string Compute::getCredentialCommand(){ ...@@ -122,6 +124,14 @@ string Compute::getCredentialCommand(){
return this->credentialCommand; return this->credentialCommand;
} }
string Compute::getLeasetimeSuspend(){
return this->leasetimeSuspend;
}
string Compute::getLeasetimeRemove(){
return this->leasetimeRemove;
}
void Compute::start() { void Compute::start() {
json actionData = { json actionData = {
{"action", "http://schemas.ogf.org/occi/infrastructure/compute/action#start"} {"action", "http://schemas.ogf.org/occi/infrastructure/compute/action#start"}
...@@ -182,3 +192,10 @@ void Compute::shutoff() { ...@@ -182,3 +192,10 @@ void Compute::shutoff() {
}; };
invokeAction(actionData); invokeAction(actionData);
} }
void Compute::renew() {
json actionData = {
{"action", "http://circlecloud.org/occi/infrastructure/compute/action#renew"},
};
invokeAction(actionData);
}
...@@ -37,13 +37,14 @@ namespace OcciClient { ...@@ -37,13 +37,14 @@ namespace OcciClient {
int cores; int cores;
std::string hostname; std::string hostname;
std::string architecture; std::string architecture;
std::string credentialProtocol; std::string credentialProtocol;
int credentialPort; int credentialPort;
std::string credentialHost; std::string credentialHost;
std::string credentialPassword; std::string credentialPassword;
std::string credentialUsername; std::string credentialUsername;
std::string credentialCommand; std::string credentialCommand;
std::string leasetimeSuspend;
std::string leasetimeRemove;
void parseJsonInstance(nlohmann::json instance); void parseJsonInstance(nlohmann::json instance);
...@@ -83,6 +84,10 @@ namespace OcciClient { ...@@ -83,6 +84,10 @@ namespace OcciClient {
std::string getCredentialCommand(); std::string getCredentialCommand();
std::string getLeasetimeSuspend();
std::string getLeasetimeRemove();
void start(); void start();
void wakeup(); void wakeup();
...@@ -96,6 +101,8 @@ namespace OcciClient { ...@@ -96,6 +101,8 @@ namespace OcciClient {
void shutdown(); void shutdown();
void shutoff(); void shutoff();
void renew();
}; };
} }
......
// Copyright 2017 Budapest University of Technology and Economics (BME IK)
//
// This file is part of CIRCLE Cloud.
//
// CIRCLE is free software: you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free
// Software Foundation, either version 3 of the License, or (at your option)
// any later version.
//
// CIRCLE is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along
// with CIRCLE. If not, see <http://www.gnu.org/licenses/>.
#include <string>
#include "json.hpp"
#include "occisession.h"
#include "entity.hpp"
using std::string;
using nlohmann::json;
using namespace OcciClient;
void Entity::parseJsonInstance(json instance) {
this->id = getID(instance);
if (instance.find("title") != instance.end()) {
this->title = instance["title"].get<string>();
}
this->rendering = instance;
}
Entity::Entity(OcciSession* session, string kind, json instance) {
this->session = session;
this->kind = kind;
parseJsonInstance(instance);
}
string Entity::getID(json& rendering) {
try {
return rendering["id"];
}
catch (std::domain_error) {
return "";
}
}
string Entity::getId(){
return this->id;
}
string Entity::getTitle(){
return this->title;
}
json Entity::invokeAction(OcciSession* session, string kind, string id, json actionData) {
auto uri = kind + "/" + id + "/";
return session->post(uri, actionData);
}
json Entity::invokeAction(json actionData){
return invokeAction(this->session, this->kind, this->id, actionData);
}
json Entity::getRendering(){
return this->rendering;
}
void Entity::destroyInstance() {
auto uri = this->kind + "/" + this->id + "/";
session->del(uri);
}
// Copyright 2017 Budapest University of Technology and Economics (BME IK)
//
// This file is part of CIRCLE Cloud.
//
// CIRCLE is free software: you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free
// Software Foundation, either version 3 of the License, or (at your option)
// any later version.
//
// CIRCLE is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along
// with CIRCLE. If not, see <http://www.gnu.org/licenses/>.
#ifndef OCCILIB_ENTITY_H_
#define OCCILIB_ENTITY_H_
#include <string>
#include "json.hpp"
#include "occisession.h"
namespace OcciClient{
class Entity{
protected:
OcciSession* session;
std::string id;
std::string title;
nlohmann::json rendering;
std::string kind;
void parseJsonInstance(nlohmann::json instance);
std::string getID(nlohmann::json& rendering);
template <typename T> T getAttributeFromRendering(nlohmann::json& rendering, const std::string which, const T defaultValue = T()) {
try {
return rendering["attributes"][which].get<T>();
}
catch (std::exception e){
return defaultValue;
}
}
Entity(OcciSession* session, std::string kind, nlohmann::json instance);
public:
std::string getId();
std::string getTitle();
static nlohmann::json invokeAction(OcciSession* session, std::string kind, std::string id, nlohmann::json actionData);
nlohmann::json invokeAction(nlohmann::json actionData);
nlohmann::json getRendering();
void destroyInstance();
};
}
#endif // OCCILIB_ENTITY_H_
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
// with CIRCLE. If not, see <http://www.gnu.org/licenses/>. // with CIRCLE. If not, see <http://www.gnu.org/licenses/>.
#include <string> #include <string>
#include <memory>
#include "json.hpp" #include "json.hpp"
#include "resource.h" #include "resource.h"
...@@ -24,6 +24,8 @@ ...@@ -24,6 +24,8 @@
using std::string; using std::string;
using nlohmann::json; using nlohmann::json;
using std::shared_ptr;
using std::make_shared;
using namespace OcciClient; using namespace OcciClient;
void Network::parseJsonInstance(json instance) { void Network::parseJsonInstance(json instance) {
......
...@@ -20,16 +20,11 @@ ...@@ -20,16 +20,11 @@
#define OCCILIB_H_ #define OCCILIB_H_
#include "occisession.h" #include "occisession.h"
#include "entity.hpp"
#include "resource.h" #include "resource.h"
#include "compute.h" #include "compute.h"
#include "template.h" #include "template.h"
#include "storage.h"
namespace OcciClient { #include "network.h"
class OcciSession;
class Resource;
class Compute;
}
#endif // OCCILIB_H_ #endif // OCCILIB_H_
%module occi %module occi
%{ %{
/* Includes the header in the wrapper code */ /* Includes the header in the wrapper code */
#include "entity.hpp"
#include "resource.h" #include "resource.h"
#include "compute.h" #include "compute.h"
#include "template.h" #include "template.h"
...@@ -17,11 +18,13 @@ ...@@ -17,11 +18,13 @@
%include "occisession.i" %include "occisession.i"
%shared_ptr(OcciClient::Entity)
%shared_ptr(OcciClient::Resource) %shared_ptr(OcciClient::Resource)
%shared_ptr(OcciClient::Compute) %shared_ptr(OcciClient::Compute)
%shared_ptr(OcciClient::Storage) %shared_ptr(OcciClient::Storage)
%shared_ptr(OcciClient::Network) %shared_ptr(OcciClient::Network)
%include "entity.hpp"
%include "resource.h" %include "resource.h"
%include "compute.h" %include "compute.h"
%include "template.h" %include "template.h"
......
...@@ -16,70 +16,17 @@ ...@@ -16,70 +16,17 @@
// with CIRCLE. If not, see <http://www.gnu.org/licenses/>. // with CIRCLE. If not, see <http://www.gnu.org/licenses/>.
#include <string> #include <string>
#include "json.hpp" #include "json.hpp"
#include "occisession.h" #include "entity.hpp"
#include "resource.h" #include "resource.h"
using std::string; using std::string;
using nlohmann::json; using nlohmann::json;
using namespace OcciClient; using namespace OcciClient;
void Resource::parseJsonInstance(json instance) { Resource::Resource(OcciSession* session, string kind, json instance)
this->id = getID(instance); : Entity(session, kind, instance){}
if (instance.find("title") != instance.end()) {
this->title = instance["title"].get<string>();
}
this->rendering = instance;
}
Resource::Resource(OcciSession* session, string kind, json instance) {
this->session = session;
this->kind = kind;
parseJsonInstance(instance);
}
string Resource::getID(json& rendering) {
try {
return rendering["id"];
}
catch (std::domain_error) {
return "";
}
}
template <typename T> T Resource::getAttributeFromRendering(json& rendering, const string which, const T defaultValue) {
try {
return rendering["attributes"][which].get<T>();
}
catch (std::exception e){
return defaultValue;
}
}
string Resource::getId(){
return this->id;
}
string Resource::getTitle(){
return this->title;
}
json Resource::invokeAction(OcciSession* session, string kind, string id, json actionData) {
auto uri = kind + "/" + id + "/";
return session->post(uri, actionData);
}
json Resource::invokeAction(json actionData){
return invokeAction(this->session, this->kind, this->id, actionData);
}
json Resource::getRendering(){
return this->rendering;
}
void Resource::destroyInstance() { string Resource::getSummary(){
auto uri = this->kind + "/" + this->id + "/"; return this->summary;
session->del(uri);
} }
...@@ -15,50 +15,33 @@ ...@@ -15,50 +15,33 @@
// You should have received a copy of the GNU General Public License along // You should have received a copy of the GNU General Public License along
// with CIRCLE. If not, see <http://www.gnu.org/licenses/>. // with CIRCLE. If not, see <http://www.gnu.org/licenses/>.
#ifndef OCCILIB_RESOURCE_H
#define OCCILIB_RESOURCE_H
#ifndef OCCILIB_RESOURCE_H_
#define OCCILIB_RESOURCE_H_
#include <string> #include <string>
#include "json.hpp" #include "json.hpp"
#include "entity.hpp"
#include "occisession.h" #include "occisession.h"
namespace OcciClient{ namespace OcciClient {
using std::string;
class Resource{ class Resource : public Entity {
protected:
OcciSession* session; private:
string id;
string title;
nlohmann::json rendering;
string kind;
void parseJsonInstance(nlohmann::json instance); std::string summary;
Resource(OcciSession* session, string kind, nlohmann::json instance); protected:
string getID(nlohmann::json& rendering);
template <typename T> T getAttributeFromRendering(nlohmann::json& rendering, const string which, const T defaultValue = T()); Resource(OcciSession* session, std::string kind, nlohmann::json instance);
public: public:
string getId(); std::string getSummary();
string getTitle();
static nlohmann::json invokeAction(OcciSession* session, string kind, string id, nlohmann::json actionData);
nlohmann::json invokeAction(nlohmann::json actionData);
nlohmann::json getRendering();
void destroyInstance();
}; };
} }
#endif // OCCILIB_RESOURCE_H_ #endif // OCCILIB_RESOURCE_H
...@@ -17,14 +17,14 @@ _occi = Extension('_occi', ...@@ -17,14 +17,14 @@ _occi = Extension('_occi',
library_dirs=['.'], library_dirs=['.'],
swig_opts=['-c++'], swig_opts=['-c++'],
extra_compile_args=['-std=c++11', '-Ofast'], extra_compile_args=['-std=c++11', '-Ofast'],
libraries=['restclient-cpp', 'curl'] libraries=['occi', 'restclient-cpp', 'curl']
) )
class Build(build_ext): class Build(build_ext):
def run(self): def run(self):
check_call(['make', 'deps']) check_call(['make', 'lib'])
build_ext.run(self) build_ext.run(self)
setup( setup(
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
// with CIRCLE. If not, see <http://www.gnu.org/licenses/>. // with CIRCLE. If not, see <http://www.gnu.org/licenses/>.
#include <string> #include <string>
#include <memory>
#include "json.hpp" #include "json.hpp"
#include "resource.h" #include "resource.h"
...@@ -24,6 +24,8 @@ ...@@ -24,6 +24,8 @@
using std::string; using std::string;
using nlohmann::json; using nlohmann::json;
using std::shared_ptr;
using std::make_shared;
using namespace OcciClient; using namespace OcciClient;
void Storage::parseJsonInstance(json instance) { void Storage::parseJsonInstance(json instance) {
......
...@@ -22,14 +22,16 @@ ...@@ -22,14 +22,16 @@
#include "occisession.h" #include "occisession.h"
#include "json.hpp" #include "json.hpp"
#include "template.h"
using nlohmann::json; using nlohmann::json;
using std::string; using std::string;
using std::vector; using std::vector;
using namespace OcciClient; using namespace OcciClient;
vector<Template> getTemplates(OcciSession* session){ vector<Template> OcciClient::getTemplates(OcciSession* session){
json mixins = session->queryInterface()["mixins"]; json mixins = session->queryInterface()["mixins"];
auto result = std::vector<Template>(); auto result = vector<Template>();
for (auto& mixin : mixins) { for (auto& mixin : mixins) {
if (mixin["depends"] == "http://schemas.ogf.org/occi/infrastructure#os_tpl") { if (mixin["depends"] == "http://schemas.ogf.org/occi/infrastructure#os_tpl") {
result.push_back(mixin["scheme"].get<string>() + mixin["term"].get<string>()); result.push_back(mixin["scheme"].get<string>() + mixin["term"].get<string>());
......
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