Commit 45003561 by Fukász Rómeó Ervin

removed test files from the repository

implemented network and storage classes
parent 3c83876c
*.pyc *.pyc
*.py
*.sw[pon]
*.o
*.cxx
*.so
...@@ -24,45 +24,41 @@ ...@@ -24,45 +24,41 @@
#include "resource.h" #include "resource.h"
#include "template.h" #include "template.h"
#include <iostream>
namespace OcciClient { namespace OcciClient {
using std::string;
class Compute : public Resource { class Compute : public Resource {
private: private:
string state; std::string state;
string stateMessage; std::string stateMessage;
double memory; double memory;
int cpuShare; int cpuShare;
int cores; int cores;
string hostname; std::string hostname;
string architecture; std::string architecture;
string credentialProtocol; std::string credentialProtocol;
int credentialPort; int credentialPort;
string credentialHost; std::string credentialHost;
string credentialPassword; std::string credentialPassword;
string credentialUsername; std::string credentialUsername;
string credentialCommand; std::string credentialCommand;
void parseJsonInstance(nlohmann::json instance) { void parseJsonInstance(nlohmann::json instance) {
Resource::parseJsonInstance(instance); Resource::parseJsonInstance(instance);
this->state = getAttributeFromRendering<string>(instance, "occi.compute.state"); this->state = getAttributeFromRendering<std::string>(instance, "occi.compute.state");
this->stateMessage = getAttributeFromRendering<string>(instance, "occi.compute.state.message"); this->stateMessage = getAttributeFromRendering<std::string>(instance, "occi.compute.state.message");
this->memory = getAttributeFromRendering<double>(instance, "occi.compute.memory"); this->memory = getAttributeFromRendering<double>(instance, "occi.compute.memory");
this->cpuShare = getAttributeFromRendering<int>(instance, "occi.compute.share"); this->cpuShare = getAttributeFromRendering<int>(instance, "occi.compute.share");
this->cores = getAttributeFromRendering<int>(instance, "occi.compute.cores"); this->cores = getAttributeFromRendering<int>(instance, "occi.compute.cores");
this->hostname = getAttributeFromRendering<string>(instance, "occi.compute.hostname"); this->hostname = getAttributeFromRendering<std::string>(instance, "occi.compute.hostname");
this->architecture = getAttributeFromRendering<string>(instance, "occi.compute.architecture"); this->architecture = getAttributeFromRendering<std::string>(instance, "occi.compute.architecture");
this->credentialProtocol = getAttributeFromRendering<string>(instance, "org.circlecloud.occi.credentials.protocol"); this->credentialProtocol = getAttributeFromRendering<std::string>(instance, "org.circlecloud.occi.credentials.protocol");
this->credentialPort = getAttributeFromRendering<int>(instance, "org.circlecloud.occi.credentials.port"); this->credentialPort = getAttributeFromRendering<int>(instance, "org.circlecloud.occi.credentials.port");
this->credentialHost = getAttributeFromRendering<string>(instance, "org.circlecloud.occi.credentials.host"); this->credentialHost = getAttributeFromRendering<std::string>(instance, "org.circlecloud.occi.credentials.host");
this->credentialUsername = getAttributeFromRendering<string>(instance, "org.circlecloud.occi.credentials.username"); this->credentialUsername = getAttributeFromRendering<std::string>(instance, "org.circlecloud.occi.credentials.username");
this->credentialPassword = getAttributeFromRendering<string>(instance, "org.circlecloud.occi.credentials.password"); this->credentialPassword = getAttributeFromRendering<std::string>(instance, "org.circlecloud.occi.credentials.password");
this->credentialCommand = getAttributeFromRendering<string>(instance, "org.circlecloud.occi.credentials.command"); this->credentialCommand = getAttributeFromRendering<std::string>(instance, "org.circlecloud.occi.credentials.command");
this->rendering = instance; this->rendering = instance;
} }
...@@ -71,9 +67,14 @@ namespace OcciClient { ...@@ -71,9 +67,14 @@ namespace OcciClient {
parseJsonInstance(instance); parseJsonInstance(instance);
} }
void invokeAction(nlohmann::json actionData) {
auto inst = Resource::invokeAction(actionData);
parseJsonInstance(inst);
}
public: public:
static std::shared_ptr<Compute> getComputeInstance(OcciSession* session, string id) { static std::shared_ptr<Compute> getComputeInstance(OcciSession* session, std::string id) {
auto uri = "compute/" + id + "/"; auto uri = "compute/" + id + "/";
auto instance = session->get(uri); auto instance = session->get(uri);
return std::make_shared<Compute>(Compute(session, instance)); return std::make_shared<Compute>(Compute(session, instance));
...@@ -86,11 +87,11 @@ namespace OcciClient { ...@@ -86,11 +87,11 @@ namespace OcciClient {
return std::make_shared<Compute>(Compute(session, instance)); return std::make_shared<Compute>(Compute(session, instance));
} }
string getState(){ std::string getState(){
return this->state; return this->state;
} }
string getStateMessage(){ std::string getStateMessage(){
return this->stateMessage; return this->stateMessage;
} }
...@@ -106,15 +107,15 @@ namespace OcciClient { ...@@ -106,15 +107,15 @@ namespace OcciClient {
return this->cores; return this->cores;
} }
string getHostname(){ std::string getHostname(){
return this->hostname; return this->hostname;
} }
string getArchitecture(){ std::string getArchitecture(){
return this->architecture; return this->architecture;
} }
string getCredentialProtocol(){ std::string getCredentialProtocol(){
return this->credentialProtocol; return this->credentialProtocol;
} }
...@@ -122,27 +123,22 @@ namespace OcciClient { ...@@ -122,27 +123,22 @@ namespace OcciClient {
return this->credentialPort; return this->credentialPort;
} }
string getCredentialHost(){ std::string getCredentialHost(){
return this->credentialHost; return this->credentialHost;
} }
string getCredentialPassword(){ std::string getCredentialPassword(){
return this->credentialPassword; return this->credentialPassword;
} }
string getCredentialUsername(){ std::string getCredentialUsername(){
return this->credentialUsername; return this->credentialUsername;
} }
string getCredentialCommand(){ std::string getCredentialCommand(){
return this->credentialCommand; return this->credentialCommand;
} }
void invokeAction(nlohmann::json actionData) {
auto inst = Resource::invokeAction(actionData);
parseJsonInstance(inst);
}
void start() { void start() {
nlohmann::json actionData = { nlohmann::json actionData = {
{"action", "http://schemas.ogf.org/occi/infrastructure/compute/action#start"} {"action", "http://schemas.ogf.org/occi/infrastructure/compute/action#start"}
......
// 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/>.
class Link {
}
// 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_NETWORK_H_
#define OCCILIB_NETWORK_H_
#include <string>
#include "json.hpp"
#include "resource.h"
namespace OcciClient {
class Network : public Resource {
private:
std::string state;
std::string stateMessage;
int vlan;
std::string address;
std::string gateway;
std::string allocation;
void parseJsonInstance(nlohmann::json instance) {
Resource::parseJsonInstance(instance);
this->state = getAttributeFromRendering<std::string>(instance, "occi.network.state");
this->stateMessage = getAttributeFromRendering<std::string>(instance, "occi.network.state.message");
this->vlan = getAttributeFromRendering<int>(instance, "occi.network.vlan");
this->address = getAttributeFromRendering<std::string>(instance, "occi.network.address");
this->gateway = getAttributeFromRendering<std::string>(instance, "occi.network.gateway");
this->allocation = getAttributeFromRendering<std::string>(instance, "occi.network.allocation");
this->rendering = instance;
}
Network(OcciSession* session, nlohmann::json instance)
: Resource(session, "network", instance) {
parseJsonInstance(instance);
}
void invokeAction(nlohmann::json actionData) {
auto inst = Resource::invokeAction(actionData);
parseJsonInstance(inst);
}
public:
static std::shared_ptr<Network> getNetworkInstance(OcciSession* session, std::string id) {
auto uri = "network/" + id + "/";
auto instance = session->get(uri);
return std::make_shared<Network>(Network(session, instance));
}
std::string getState(){
return this->state;
}
std::string getStateMessage(){
return this->stateMessage;
}
int getVlan(){
return this->vlan;
}
std::string getAddress(){
return this->address;
}
std::string getGateway(){
return this->gateway;
}
std::string getAllocation(){
return this->allocation;
}
};
}
#endif // OCCILIB_NETWORK_H
%module occi %module occi
%{ %{
/* Includes the header in the wrapper code */ /* Includes the header in the wrapper code */
#include "occisession.h"
#include "resource.h" #include "resource.h"
#include "compute.h" #include "compute.h"
#include "template.h" #include "template.h"
#include "storage.h"
#include "network.h"
%} %}
...@@ -14,20 +15,18 @@ ...@@ -14,20 +15,18 @@
%include "std_vector.i" %include "std_vector.i"
%include "std_shared_ptr.i" %include "std_shared_ptr.i"
// a del python kulcsszo ezert warningot kapunk a generalaskor %include "occisession.i"
// az OcciSession::del() metodusa amugy sem tartozik a
// publikus interfeszhez
%ignore OcciClient::OcciSession::del;
%shared_ptr(OcciClient::Resource) %shared_ptr(OcciClient::Resource)
%shared_ptr(OcciClient::Compute) %shared_ptr(OcciClient::Compute)
%shared_ptr(OcciClient::Storage)
%shared_ptr(OcciClient::Network)
%newobject nlohmann::json;
%include "occisession.h"
%include "resource.h" %include "resource.h"
%include "compute.h" %include "compute.h"
%include "template.h" %include "template.h"
%include "storage.h"
%include "network.h"
namespace std { namespace std {
%template(TemplateVector) vector<Template>; %template(TemplateVector) vector<Template>;
......
...@@ -29,11 +29,11 @@ ...@@ -29,11 +29,11 @@
namespace OcciClient { namespace OcciClient {
// using nlohmann::json;
using std::string; using std::string;
enum class RequestType{Get, Post, Delete, Put}; enum class RequestType{Get, Post, Delete, Put};
class OcciSession { class OcciSession {
private: private:
...@@ -97,15 +97,12 @@ namespace OcciClient { ...@@ -97,15 +97,12 @@ namespace OcciClient {
result = "{}"_json; result = "{}"_json;
throw std::domain_error("Didn't get a nlohmann::json response from the OCCI server."); throw std::domain_error("Didn't get a nlohmann::json response from the OCCI server.");
} }
try { try {
throw std::logic_error(result["error"].get<string>()); throw std::logic_error(result["error"].get<string>());
} }
catch (std::domain_error e) { catch (std::domain_error e) {
return result; return result;
} }
return result;
} }
nlohmann::json get(string uri) { nlohmann::json get(string uri) {
...@@ -124,10 +121,10 @@ namespace OcciClient { ...@@ -124,10 +121,10 @@ namespace OcciClient {
return doRequest(uri, RequestType::Delete); return doRequest(uri, RequestType::Delete);
} }
nlohmann::json circleOcciLogin(string username, string password){ void circleOcciLogin(string username, string password){
get("login/"); get("login/");
string body = "{\"username\": \"" + username + "\", \"password\": \"" + password + "\"}"; string body = "{\"username\": \"" + username + "\", \"password\": \"" + password + "\"}";
return post("login/", nlohmann::json::parse(body)); post("login/", nlohmann::json::parse(body));
} }
nlohmann::json queryInterface(){ nlohmann::json queryInterface(){
......
%{
#include "occisession.h"
%}
namespace OcciClient{
class OcciSession{
public:
OcciSession(const char* url, bool insecure = false, bool csrf = false);
~OcciSession();
void circleOcciLogin(std::string username, std::string password);
};
}
...@@ -26,7 +26,6 @@ ...@@ -26,7 +26,6 @@
namespace OcciClient{ namespace OcciClient{
// using nlohmann::json;
using std::string; using std::string;
class Resource{ class Resource{
...@@ -40,7 +39,9 @@ namespace OcciClient{ ...@@ -40,7 +39,9 @@ namespace OcciClient{
void parseJsonInstance(nlohmann::json instance) { void parseJsonInstance(nlohmann::json instance) {
this->id = getID(instance); this->id = getID(instance);
if (instance.find("title") != instance.end()) {
this->title = instance["title"].get<string>(); this->title = instance["title"].get<string>();
}
this->rendering = instance; this->rendering = instance;
} }
......
// 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_STORAGE_H_
#define OCCILIB_STORAGE_H_
#include <string>
#include "json.hpp"
#include "resource.h"
namespace OcciClient {
class Storage : public Resource {
private:
double size; // in GB
std::string state;
std::string stateMessage;
void parseJsonInstance(nlohmann::json instance) {
Resource::parseJsonInstance(instance);
this->state = getAttributeFromRendering<std::string>(instance, "occi.storage.state");
this->stateMessage = getAttributeFromRendering<std::string>(instance, "occi.storage.state.message");
this->size = getAttributeFromRendering<double>(instance, "occi.storage.size");
this->rendering = instance;
}
Storage(OcciSession* session, nlohmann::json instance)
: Resource(session, "storage", instance) {
parseJsonInstance(instance);
}
void invokeAction(nlohmann::json actionData) {
auto inst = Resource::invokeAction(actionData);
parseJsonInstance(inst);
}
public:
static std::shared_ptr<Storage> getStorageInstance(OcciSession* session, std::string id) {
auto uri = "storage/" + id + "/";
auto instance = session->get(uri);
return std::make_shared<Storage>(Storage(session, instance));
}
std::string getState(){
return this->state;
}
std::string getStateMessage(){
return this->stateMessage;
}
double getSize(){
return this->size;
}
};
}
#endif // OCCILIB_STORAGE_H
...@@ -21,7 +21,6 @@ ...@@ -21,7 +21,6 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include <iostream>
#include "occisession.h" #include "occisession.h"
#include "json.hpp" #include "json.hpp"
......
#include <iostream>
#include "occilib.h"
using OcciClient::OcciSession;
using OcciClient::Compute;
using std::endl;
using std::cout;
using std::shared_ptr;
int main() {
shared_ptr<OcciSession> session(new OcciSession("https://vm.ik.bme.hu:15766/occi/", true, true));
session->circleOcciLogin("admin", "retekretek");
cout << "Templates: ";
auto ts = OcciClient::getTemplates(session.get());
for (auto& t : ts){
cout << t << ", ";
}
cout << endl;
auto comp = Compute::getComputeInstance(session.get(), "96");
comp->wakeup();
cout << comp->getStateMessage() << endl;
comp->sleep();
cout << comp->getStateMessage() << endl;
cout << "To connect to this compute instance use the \"" << comp->getCredentialCommand() << "\" command." << endl;
auto comp2 = Compute::createComputeInstance(session.get(), ts.back());
cout << "id: " << comp2->getId() << ", title: " << comp2->getTitle() << endl;
comp2->destroyInstance();
auto comp3 = Compute::getComputeInstance(session.get(), "96");
// not exists :'(
}
from occi import OcciSession, getTemplates, Compute
session = OcciSession("https://vm.ik.bme.hu:15766/occi/", True, True)
session.circleOcciLogin("admin", "retekretek")
ts = getTemplates(session)
for i in ts:
print(i)
comp = Compute.getComputeInstance(session, "96")
print("title: %s" % comp.getTitle())
comp.wakeup()
print(comp.getStateMessage())
comp.sleep()
print(comp.getStateMessage())
print("To connect to this compute instance use the "
"'%s' command." % comp.getCredentialCommand())
comp2 = Compute.createComputeInstance(session, ts.back())
print("id: %s, title: %s" % (comp2.getId(), comp2.getTitle()))
comp2.destroyInstance()
comp3 = Compute.getComputeInstance(session, "2000")
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