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
LDFLAGS=--shared
LIBS=-lrestclient-cpp -lcurl
SONAME=_occi.so
SOURCES=occilib.cpp
SOURCES=compute.cpp entity.cpp network.cpp occisession.cpp resource.cpp storage.cpp template.cpp
SWIG=swig
SWIG_INTERFACES=occilib.i
......@@ -22,6 +22,10 @@ default: python
python:
python setup.py build
lib: deps
$(CPP) $(CPPFLAGS) -c $(SOURCES)
$(AR) rcs libocci.a *.o
restclient-cpp:
git clone --depth=1 $(RESTCLIENT_CPP_URL) -b $(RESTCLIENT_CPP_TAG)
bash gen_restclient-cpp_version.sh $(RESTCLIENT_CPP_TAG)
......@@ -38,6 +42,7 @@ clean:
rm -f $(WRAPPER_SOURCES)
rm -f $(SONAME)
rm -f occi.py
rm -f occi.pyc
rm -Rf build
mrproper: clean clean_deps
......
......@@ -16,7 +16,7 @@
// with CIRCLE. If not, see <http://www.gnu.org/licenses/>.
#include <string>
#include <memory>
#include "json.hpp"
#include "resource.h"
#include "template.h"
......@@ -25,6 +25,8 @@
using std::string;
using nlohmann::json;
using std::shared_ptr;
using std::make_shared;
using namespace OcciClient;
......@@ -43,6 +45,8 @@ void Compute::parseJsonInstance(json instance) {
this->credentialUsername = getAttributeFromRendering<string>(instance, "org.circlecloud.occi.credentials.username");
this->credentialPassword = getAttributeFromRendering<string>(instance, "org.circlecloud.occi.credentials.password");
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;
}
......@@ -55,15 +59,13 @@ void Compute::invokeAction(json actionData) {
parseJsonInstance(inst);
}
public:
static shared_ptr<Compute> Compute::getComputeInstance(OcciSession* session, string id) {
shared_ptr<Compute> Compute::getComputeInstance(OcciSession* session, string id) {
auto uri = "compute/" + id + "/";
auto instance = session->get(uri);
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/";
json data = json::parse("{\"mixins\": [\"" + t + "\"]}");
auto instance = session->put(uri, data);
......@@ -122,6 +124,14 @@ string Compute::getCredentialCommand(){
return this->credentialCommand;
}
string Compute::getLeasetimeSuspend(){
return this->leasetimeSuspend;
}
string Compute::getLeasetimeRemove(){
return this->leasetimeRemove;
}
void Compute::start() {
json actionData = {
{"action", "http://schemas.ogf.org/occi/infrastructure/compute/action#start"}
......@@ -182,3 +192,10 @@ void Compute::shutoff() {
};
invokeAction(actionData);
}
void Compute::renew() {
json actionData = {
{"action", "http://circlecloud.org/occi/infrastructure/compute/action#renew"},
};
invokeAction(actionData);
}
......@@ -37,13 +37,14 @@ namespace OcciClient {
int cores;
std::string hostname;
std::string architecture;
std::string credentialProtocol;
int credentialPort;
std::string credentialHost;
std::string credentialPassword;
std::string credentialUsername;
std::string credentialCommand;
std::string leasetimeSuspend;
std::string leasetimeRemove;
void parseJsonInstance(nlohmann::json instance);
......@@ -83,6 +84,10 @@ namespace OcciClient {
std::string getCredentialCommand();
std::string getLeasetimeSuspend();
std::string getLeasetimeRemove();
void start();
void wakeup();
......@@ -96,6 +101,8 @@ namespace OcciClient {
void shutdown();
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 @@
// with CIRCLE. If not, see <http://www.gnu.org/licenses/>.
#include <string>
#include <memory>
#include "json.hpp"
#include "resource.h"
......@@ -24,6 +24,8 @@
using std::string;
using nlohmann::json;
using std::shared_ptr;
using std::make_shared;
using namespace OcciClient;
void Network::parseJsonInstance(json instance) {
......
......@@ -20,16 +20,11 @@
#define OCCILIB_H_
#include "occisession.h"
#include "entity.hpp"
#include "resource.h"
#include "compute.h"
#include "template.h"
namespace OcciClient {
class OcciSession;
class Resource;
class Compute;
}
#include "storage.h"
#include "network.h"
#endif // OCCILIB_H_
%module occi
%{
/* Includes the header in the wrapper code */
#include "entity.hpp"
#include "resource.h"
#include "compute.h"
#include "template.h"
......@@ -17,11 +18,13 @@
%include "occisession.i"
%shared_ptr(OcciClient::Entity)
%shared_ptr(OcciClient::Resource)
%shared_ptr(OcciClient::Compute)
%shared_ptr(OcciClient::Storage)
%shared_ptr(OcciClient::Network)
%include "entity.hpp"
%include "resource.h"
%include "compute.h"
%include "template.h"
......
......@@ -16,70 +16,17 @@
// with CIRCLE. If not, see <http://www.gnu.org/licenses/>.
#include <string>
#include "json.hpp"
#include "occisession.h"
#include "entity.hpp"
#include "resource.h"
using std::string;
using nlohmann::json;
using namespace OcciClient;
void Resource::parseJsonInstance(json instance) {
this->id = getID(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;
}
Resource::Resource(OcciSession* session, string kind, json instance)
: Entity(session, kind, instance){}
void Resource::destroyInstance() {
auto uri = this->kind + "/" + this->id + "/";
session->del(uri);
string Resource::getSummary(){
return this->summary;
}
......@@ -15,50 +15,33 @@
// 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_RESOURCE_H
#define OCCILIB_RESOURCE_H
#ifndef OCCILIB_RESOURCE_H_
#define OCCILIB_RESOURCE_H_
#include <string>
#include "json.hpp"
#include "entity.hpp"
#include "occisession.h"
namespace OcciClient{
using std::string;
class Resource{
protected:
OcciSession* session;
string id;
string title;
nlohmann::json rendering;
string kind;
namespace OcciClient {
void parseJsonInstance(nlohmann::json instance);
class Resource : public Entity {
Resource(OcciSession* session, string kind, nlohmann::json instance);
private:
string getID(nlohmann::json& rendering);
std::string summary;
template <typename T> T getAttributeFromRendering(nlohmann::json& rendering, const string which, const T defaultValue = T());
protected:
public:
Resource(OcciSession* session, std::string kind, nlohmann::json instance);
string getId();
public:
string getTitle();
std::string getSummary();
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',
library_dirs=['.'],
swig_opts=['-c++'],
extra_compile_args=['-std=c++11', '-Ofast'],
libraries=['restclient-cpp', 'curl']
libraries=['occi', 'restclient-cpp', 'curl']
)
class Build(build_ext):
def run(self):
check_call(['make', 'deps'])
check_call(['make', 'lib'])
build_ext.run(self)
setup(
......
......@@ -16,7 +16,7 @@
// with CIRCLE. If not, see <http://www.gnu.org/licenses/>.
#include <string>
#include <memory>
#include "json.hpp"
#include "resource.h"
......@@ -24,6 +24,8 @@
using std::string;
using nlohmann::json;
using std::shared_ptr;
using std::make_shared;
using namespace OcciClient;
void Storage::parseJsonInstance(json instance) {
......
......@@ -22,14 +22,16 @@
#include "occisession.h"
#include "json.hpp"
#include "template.h"
using nlohmann::json;
using std::string;
using std::vector;
using namespace OcciClient;
vector<Template> getTemplates(OcciSession* session){
vector<Template> OcciClient::getTemplates(OcciSession* session){
json mixins = session->queryInterface()["mixins"];
auto result = std::vector<Template>();
auto result = vector<Template>();
for (auto& mixin : mixins) {
if (mixin["depends"] == "http://schemas.ogf.org/occi/infrastructure#os_tpl") {
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