Commit a4adc867 by Belákovics Ádám

vegleges4

parent 653a3cb7
#-------------------------------------------------
#
# Project created by QtCreator 2017-04-24T16:19:49
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = QList
TEMPLATE = app
# The following define makes your compiler emit warnings if you use
# any feature of Qt which as been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += main.cpp\
mainwindow.cpp \
computewidget.cpp \
controller.cpp \
vmchooserdialog.cpp
HEADERS += mainwindow.h \
computewidget.h \
controller.h \
vmchooserdialog.h \
computedata.h
FORMS += mainwindow.ui \
computewidget.ui \
vmchooserdialog.ui
RESOURCES += \
resource.qrc
CONFIG += c++11
INCLUDEPATH += $$PWD/libocci/restclient-cpp/include
INCLUDEPATH += $$PWD/libocci
DEPENDPATH += $$PWD/libocci
LIBS += -L$$PWD/libocci/ -locci -lrestclient-cpp -lcurl -lgobject-2.0 -llasso -lgq
INCLUDEPATH += $$PWD/libocci
DEPENDPATH += $$PWD/libocci
This diff is collapsed. Click to expand it.
compute.png

498 Bytes

#ifndef COMPUTEDATA
#define COMPUTEDATA
struct ComputeData{
double memory;
int cpu;
int cores;
std::string hostname;
std::string username;
std::string password;
};
#endif // COMPUTEDATA
#include "computewidget.h"
#include "ui_computewidget.h"
ComputeWidget::ComputeWidget(QWidget *parent) :
QWidget(parent),
ui(new Ui::ComputeWidget)
{
ui->setupUi(this);
ui->lComputeIcon->setPixmap(QPixmap(":/new/icons/compute.png").scaled(80, 55, Qt::KeepAspectRatio));
}
void ComputeWidget::setID(std::string _id){
id = _id;
}
void ComputeWidget::setName(std::string _name){
name = _name;
ui->lHostName->setText(_name.c_str());
}
ComputeWidget::~ComputeWidget()
{
delete ui;
}
void ComputeWidget::on_bRenew_clicked()
{
emit renew(id);
}
void ComputeWidget::on_bWakeUp_clicked()
{
emit wakeup(id);
}
void ComputeWidget::on_bSleep_clicked()
{
emit sleep(id);
}
void ComputeWidget::on_pushButton_clicked()
{
//TODO
}
void ComputeWidget::on_bStart_clicked()
{
emit start(id);
}
#ifndef COMPUTEWIDGET_H
#define COMPUTEWIDGET_H
#include <QWidget>
#include <QPixmap>
namespace Ui {
class ComputeWidget;
}
class ComputeWidget : public QWidget
{
Q_OBJECT
public:
std::string id;
std::string name;
explicit ComputeWidget(QWidget *parent = 0);
void setID(std::string id);
void setName(std::string name);
~ComputeWidget();
signals:
void start(std::string id);
void sleep(std::string id);
void wakeup(std::string id);
void renew(std::string id);
private slots:
void on_bRenew_clicked();
void on_bWakeUp_clicked();
void on_bSleep_clicked();
void on_pushButton_clicked();
void on_bStart_clicked();
private:
Ui::ComputeWidget *ui;
};
#endif // COMPUTEWIDGET_H
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ComputeWidget</class>
<widget class="QWidget" name="ComputeWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>672</width>
<height>196</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>100</height>
</size>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<layout class="QGridLayout" name="gridLayout">
<item row="7" column="3" rowspan="2">
<widget class="QPushButton" name="bRenew">
<property name="text">
<string>Renew</string>
</property>
</widget>
</item>
<item row="5" column="3" rowspan="2">
<widget class="QPushButton" name="bWakeUp">
<property name="text">
<string>Wake up</string>
</property>
</widget>
</item>
<item row="7" column="0" rowspan="2">
<widget class="QLabel" name="lHostName">
<property name="text">
<string>Virtual Machine</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item row="2" column="0" rowspan="5">
<widget class="QLabel" name="lComputeIcon">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<family>Arial</family>
</font>
</property>
<property name="text">
<string/>
</property>
<property name="scaledContents">
<bool>false</bool>
</property>
</widget>
</item>
<item row="2" column="1" rowspan="7">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="5" column="2" rowspan="2">
<widget class="QPushButton" name="bSleep">
<property name="text">
<string>Sleep</string>
</property>
</widget>
</item>
<item row="2" column="3" rowspan="3">
<widget class="QPushButton" name="bStart">
<property name="text">
<string>Start</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
#include "controller.h"
bool Controller::connect(){
session = new OcciClient::OcciSession("https://vm.ik.bme.hu:9366/occi/", true, true);
return true; //TODO validation
}
bool Controller::login(std::string username, std::string password){
session->circleOcciLogin(username, password);
if(username == "admin" && password == "admin"){ //TODO TODO lib should handle this
refresh(); //initialize data
return true;
}
return false;
}
void Controller::refresh(){
allCompute.clear();
for(auto c : OcciClient::Compute::getComputeInstances(session)){
allCompute.push_back(c);
}
}
std::vector<std::string> Controller::getVMs(){
std::vector<std::string> VMs;
for(auto c : allCompute){
VMs.push_back(c->getHostname());
}
return VMs;
}
void Controller::renewByID(std::string id){
allCompute.at(std::stoi(id))->renew();
}
void Controller::startByID(std::string id){
allCompute.at(std::stoi(id))->start();
}
void Controller::wakeupByID(std::string id){
allCompute.at(std::stoi(id))->wakeup();
}
void Controller::sleepByID(std::string id){
allCompute.at(std::stoi(id))->sleep();
}
std::string Controller::getState(std::string id){
return allCompute.at(std::stoi(id))->getState();
}
ComputeData Controller::getDataByID(std::string id){
ComputeData data;
data.memory = allCompute.at(std::stoi(id))->getMemory();
data.cpu = allCompute.at(std::stoi(id))->getCpuShare();
data.cores = allCompute.at(std::stoi(id))->getCores();
data.hostname = allCompute.at(std::stoi(id))->getCredentialHost();
data.username = allCompute.at(std::stoi(id))->getCredentialUsername();
data.password = allCompute.at(std::stoi(id))->getCredentialPassword();
return data;
}
void Controller::newCompute(Template t){
OcciClient::Compute::createComputeInstance(session, t);
}
#ifndef CONTROLLER_H
#define CONTROLLER_H
#include <QObject>
#include <vector>
#include <memory>
#include "occilib.h"
#include "computedata.h"
class Controller
{
public:
OcciClient::OcciSession* session;
std::vector<std::shared_ptr<OcciClient::Compute> > allCompute;
bool connect();
bool login(std::string username, std::string password);
void refresh();
void renewByID(std::string id);
void startByID(std::string id);
void wakeupByID(std::string id);
void sleepByID(std::string id);
void newCompute(Template);
ComputeData getDataByID(std::string id);
std::string getState(std::string id);
std::vector<std::string> getVMs();
};
#endif // CONTROLLER_H
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.showMaximized();
return a.exec();
}
<RCC>
<qresource prefix="/new/icons">
<file>compute.png</file>
<file>cloud icon.png</file>
</qresource>
</RCC>
#include "vmchooserdialog.h"
#include "ui_vmchooserdialog.h"
VMChooserDialog::VMChooserDialog(QWidget *parent):QDialog(parent), ui(new Ui::VMChooserDialog)
{
connect(parent, SIGNAL(send_templates(std::vector<Template>)), this, SLOT(receive_templates(std::vector<Template>)));
ui->setupUi(this);
}
VMChooserDialog::~VMChooserDialog(){
delete ui;
}
void VMChooserDialog::on_buttonBox_accepted()
{
emit send_chosen_template(templates.at(ui->lwTemplates->currentIndex().row()));
this->done(1);
}
void VMChooserDialog::on_buttonBox_rejected()
{
this->done(-1);
}
void VMChooserDialog::receive_templates(std::vector<Template> _templates){
templates = _templates;
for(auto t : templates){
ui->lwTemplates->addItem(QString::fromUtf8(t.c_str()));
}
}
#ifndef VMCHOOSERDIALOG_H
#define VMCHOOSERDIALOG_H
#include <QDialog>
#include "occilib.h"
namespace Ui{
class VMChooserDialog;
}
class VMChooserDialog : public QDialog
{
Q_OBJECT
public:
explicit VMChooserDialog(QWidget *parent = 0);
~VMChooserDialog();
signals:
void send_chosen_template(Template);
private slots:
void receive_templates(std::vector<Template> templates);
void on_buttonBox_accepted();
void on_buttonBox_rejected();
private:
Ui::VMChooserDialog* ui;
std::vector<Template> templates;
};
#endif // VMCHOOSERDIALOG_H
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>VMChooserDialog</class>
<widget class="VMChooserDialog" name="VMChooserDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>458</width>
<height>355</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="0">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="1">
<widget class="QListWidget" name="lwTemplates"/>
</item>
<item row="2" column="1">
<spacer name="verticalSpacer_3">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="3" column="1">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
<item row="0" column="1">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="2">
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>VMChooserDialog</class>
<extends>QWidget</extends>
<header>vmchooserdialog.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>
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