Commit 9309055b by Belákovics Ádám

additions

parent 07e818f9
......@@ -11,10 +11,7 @@ struct ComputeData{
int port;
std::string username;
std::string password;
<<<<<<< HEAD
std::string connString;
=======
>>>>>>> 7a7d24d7d5770ed8dbaa6a1766461251ff6f768c
};
#endif // COMPUTEDATA
......
<<<<<<< HEAD
#include "computewidget.h"
#include "ui_computewidget.h"
......@@ -82,59 +81,3 @@ void ComputeWidget::stateChangedHandler(std::string newState, std::string _id){
}
=======
#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_bStart_clicked()
{
emit start(id);
}
void ComputeWidget::on_bWakeUpSleep_clicked()
{
emit wakeupsleep(id);
}
void ComputeWidget::stateChangedHandler(std::string newState, std::string _id){
if(id == _id){ //check if we changed or not
if(newState == "suspended" || newState == "inactive"){
ui->bWakeUpSleep->setText("Wake up");
ui->bWakeUpSleep->setStyleSheet("background-color:green");
}
else if(newState == "active"){
ui->bWakeUpSleep->setText("Sleep");
ui->bWakeUpSleep->setStyleSheet("background-color:yellow");
}
else
throw std::runtime_error("undefined VM state!");
}
}
>>>>>>> 7a7d24d7d5770ed8dbaa6a1766461251ff6f768c
<<<<<<< HEAD
#ifndef COMPUTEWIDGET_H
#define COMPUTEWIDGET_H
......@@ -41,48 +40,3 @@ private:
};
#endif // COMPUTEWIDGET_H
=======
#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 wakeupsleep(std::string id);
void renew(std::string id);
public slots:
void stateChangedHandler(std::string newState, std::string id);
private slots:
void on_bRenew_clicked();
void on_bStart_clicked();
void on_bWakeUpSleep_clicked();
private:
Ui::ComputeWidget *ui;
};
#endif // COMPUTEWIDGET_H
>>>>>>> 7a7d24d7d5770ed8dbaa6a1766461251ff6f768c
<<<<<<< HEAD
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ComputeWidget</class>
......@@ -89,101 +88,3 @@
<resources/>
<connections/>
</ui>
=======
<?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="6" column="2" rowspan="2">
<widget class="QPushButton" name="bRenew">
<property name="text">
<string>Renew</string>
</property>
</widget>
</item>
<item row="4" column="2" rowspan="2">
<widget class="QPushButton" name="bWakeUpSleep">
<property name="text">
<string>Wake up</string>
</property>
</widget>
</item>
<item row="6" 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="4">
<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="6">
<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="2" column="2" rowspan="2">
<widget class="QPushButton" name="bStart">
<property name="text">
<string>Start</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
>>>>>>> 7a7d24d7d5770ed8dbaa6a1766461251ff6f768c
#include "controller.h"
<<<<<<< HEAD
///Implementation for class Controller
/*!
......@@ -8,22 +7,17 @@
* \param url
* \return
*/
=======
>>>>>>> 7a7d24d7d5770ed8dbaa6a1766461251ff6f768c
bool Controller::connect(std::string url){
session = new OcciClient::OcciSession(url.c_str(), true, true);
return true; //TODO validation
}
<<<<<<< HEAD
/*!
* \brief Logs in to a connected server, loads all data into the Controller
* \param username
* \param password
* \return
*/
=======
>>>>>>> 7a7d24d7d5770ed8dbaa6a1766461251ff6f768c
bool Controller::login(std::string username, std::string password){
session->circleOcciLogin(username, password);
if(username == "admin" && password == "admin"){ //TODO TODO lib should handle this
......@@ -34,11 +28,7 @@ bool Controller::login(std::string username, std::string password){
}
/*!
<<<<<<< HEAD
* \brief Refreshes all data (Computes, Templates), communicates with the server
=======
* \brief Refreshes all data, communicates with the server
>>>>>>> 7a7d24d7d5770ed8dbaa6a1766461251ff6f768c
*/
void Controller::refresh(){
allCompute.clear();
......@@ -49,7 +39,6 @@ void Controller::refresh(){
allTemplate.push_back(t);
}
<<<<<<< HEAD
///Data Access
/// ----------------------------------------------------------------------------------
......@@ -58,8 +47,6 @@ void Controller::refresh(){
* \brief Returns with an std::vector of the VM ids
* \return
*/
=======
>>>>>>> 7a7d24d7d5770ed8dbaa6a1766461251ff6f768c
std::vector<std::string> Controller::getVMs(){
std::vector<std::string> VMs;
for(auto c : allCompute){
......@@ -68,13 +55,10 @@ std::vector<std::string> Controller::getVMs(){
return VMs;
}
<<<<<<< HEAD
/*!
* \brief Returns with an std::vector of the Template ids
* \return
*/
=======
>>>>>>> 7a7d24d7d5770ed8dbaa6a1766461251ff6f768c
std::vector<std::string> Controller::getTemplates(){
std::vector<std::string> templates;
for(auto t : allTemplate){
......@@ -83,7 +67,6 @@ std::vector<std::string> Controller::getTemplates(){
return templates;
}
<<<<<<< HEAD
/*!
* \brief Returns the state of the VM specified by the id
* \param id
......@@ -118,26 +101,20 @@ ComputeData Controller::getDataByID(std::string id){
* \brief Renew action
* \param id
*/
=======
>>>>>>> 7a7d24d7d5770ed8dbaa6a1766461251ff6f768c
void Controller::renewByID(std::string id){
allCompute.at(std::stoi(id))->renew();
refresh();
}
<<<<<<< HEAD
/*!
* \brief Start action
* \param id
*/
=======
>>>>>>> 7a7d24d7d5770ed8dbaa6a1766461251ff6f768c
void Controller::startByID(std::string id){
allCompute.at(std::stoi(id))->start();
refresh();
}
<<<<<<< HEAD
/*!
* \brief Shutdown action
* \param id
......@@ -151,48 +128,24 @@ void Controller::shutdownByID(std::string id){
* \brief Wakeup action
* \param id
*/
=======
>>>>>>> 7a7d24d7d5770ed8dbaa6a1766461251ff6f768c
void Controller::wakeupByID(std::string id){
allCompute.at(std::stoi(id))->wakeup();
refresh();
}
<<<<<<< HEAD
/*!
* \brief Sleep action
* \param id
*/
=======
>>>>>>> 7a7d24d7d5770ed8dbaa6a1766461251ff6f768c
void Controller::sleepByID(std::string id){
allCompute.at(std::stoi(id))->sleep();
refresh();
}
<<<<<<< HEAD
/*!
* \brief Creates a new Compute by the Template
* \param id
*/
=======
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.port = allCompute.at(std::stoi(id))->getCredentialPort();
data.username = allCompute.at(std::stoi(id))->getCredentialUsername();
data.password = allCompute.at(std::stoi(id))->getCredentialPassword();
return data;
}
>>>>>>> 7a7d24d7d5770ed8dbaa6a1766461251ff6f768c
void Controller::newCompute(Template t){
OcciClient::Compute::createComputeInstance(session, t);
refresh();
......
......@@ -24,11 +24,8 @@ public:
void startByID(std::string id);
<<<<<<< HEAD
void shutdownByID(std::string id);
=======
>>>>>>> 7a7d24d7d5770ed8dbaa6a1766461251ff6f768c
void wakeupByID(std::string id);
void sleepByID(std::string id);
......
<<<<<<< HEAD
#include "mainwindow.h"
#include <QApplication>
......@@ -10,16 +9,3 @@ int main(int argc, char *argv[])
return a.exec();
}
=======
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.showMaximized();
return a.exec();
}
>>>>>>> 7a7d24d7d5770ed8dbaa6a1766461251ff6f768c
<<<<<<< HEAD
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "sshdialog.h"
......@@ -226,205 +225,3 @@ void MainWindow::on_bConnect_clicked()
sshdialog->setSSHConsole(console);
sshdialog->show();
}
=======
#include "mainwindow.h"
#include "ui_mainwindow.h"
///Implementation for class MainWindow
///
///---------------------------------------------------------------------------------------------------
/// Basic Methods
/*!
* \brief Constructor, sets up ui, disable tabs other than login
* \param parent
*/
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
ui->tabWidget->setTabEnabled(1, false);
ui->tabWidget->setTabEnabled(2, false);
}
/*!
* \brief Destructor
*/
MainWindow::~MainWindow()
{
delete ui;
}
///---------------------------------------------------------------------------------------------------
/// Methods for loading data to the UI
/*!
* \brief Adds a VM to the listWidget, sets its id, connects all Quick Action buttons
* \param id
* \param name
*/
void MainWindow::addVM(std::string id, std::string name){
QListWidgetItem* item = new QListWidgetItem(ui->listWidget);
ComputeWidget* cw = new ComputeWidget();
cw->setID(id);
cw->setName(name);
connect(this, SIGNAL(stateChanged(std::string, std::string)), cw, SLOT(stateChangedHandler(std::string, std::string)));
emit stateChanged(myController.getState(id), id);
connect(cw, SIGNAL(renew(std::string)), this, SLOT(renewClicked(std::string)));
connect(cw, SIGNAL(start(std::string)), this, SLOT(startClicked(std::string)));
connect(cw, SIGNAL(wakeupsleep(std::string)), this, SLOT(wakeupsleepClicked(std::string)));
item->setSizeHint(cw->minimumSize());
ui->listWidget->addItem(item);
ui->listWidget->setItemWidget(item, cw);
}
/*!
* \brief loads all data to the UI, which are stored in Controller, DOES NOT COMMUNICATE WITH THE CLOUD SERVER!!
*/
void MainWindow::loadAllData(){
VM_names = myController.getVMs();
ui->listWidget->clear();
for(size_t i = 0; i < VM_names.size(); i++)
addVM(std::to_string(i), VM_names.at(i));
ui->lwTemplates->clear();
for(auto t : myController.getTemplates())
ui->lwTemplates->addItem(t.c_str());
}
/*!
* \brief Loads all data for a VM specified by the id, does NOT communicate with the cloud server!!
* \param id
*/
void MainWindow::loadVMData(std::string id){
ui->lStatus->setText(myController.getState(id).c_str());
ComputeData data = myController.getDataByID(id.c_str());
ui->lCPU->setText(std::to_string(data.cpu).c_str());
ui->lMemory->setText(std::to_string(data.memory).c_str());
ui->lCores->setText(std::to_string(data.cores).c_str());
ui->lHostname->setText((data.hostname + ":" + std::to_string(data.port)).c_str());
ui->lUsernameVM->setText(data.username.c_str());
ui->lPasswordVM->setText(data.password.c_str());
}
///---------------------------------------------------------------------------------------------------
/// Button handlers
///Tab 0 - Login Screen
/*!
* \brief Login Button handler, connects to server, if authentication is succesful enables all tabs, and loads all data
*/
void MainWindow::on_bLogin_clicked()
{
std::string serverUrl = ui->iCloudServer->text().toStdString();
myController.connect(serverUrl);
std::string username = ui->iUsername->text().toStdString();
std::string password = ui->iPassword->text().toStdString();
if(!myController.login(username, password)){
ui->lInfo->setText("Invalid username or password...");
return;
}
ui->tabWidget->setTabEnabled(1, true);
ui->tabWidget->setTabEnabled(2, true);
loadAllData();
ui->tabWidget->setCurrentIndex(1);
}
/// Tab 1 - Virtual Machines
/*!
* \brief handles Renew button, all static data is refreshed
* \param id
*/
void MainWindow::renewClicked(std::string id){
myController.renewByID(id);
loadVMData(id);
ui->listWidget->item(std::stoi(id))->setSelected(true);
}
/*!
* \brief handles Start button (fetches data from server)
* \param id
*/
void MainWindow::startClicked(std::string id){
myController.startByID(id);
loadVMData(id);
ui->listWidget->item(std::stoi(id))->setSelected(true);
}
void MainWindow::wakeupsleepClicked(std::string id){
std::string state = myController.getState(id);
if(state == "active"){ //sleep
myController.sleepByID(id);
emit stateChanged(myController.getState(id), id);
loadVMData(id);
ui->listWidget->item(std::stoi(id))->setSelected(true);
}
else if(state == "suspended" || state == "inactive"){ //wake up
myController.wakeupByID(id);
emit stateChanged(myController.getState(id), id);
loadVMData(id);
ui->listWidget->item(std::stoi(id))->setSelected(true);
}
else{
throw std::runtime_error("undefined VM STATE!!!");
}
}
/*!
* \brief handles Renew button (fetches data from server)
* \param id
*/
void MainWindow::on_listWidget_clicked(const QModelIndex &index)
{
loadVMData(std::to_string(index.row()));
}
/*!
* \brief handles Refresh button, refreshes Controller's data and loads to the UI (fetches data from server)
*/
void MainWindow::on_bRefresh_clicked()
{
myController.refresh();
loadAllData();
}
/*!
* \brief handles new VM button, Opens a dialog for choosing from templates
*/
void MainWindow::on_bNewVM_clicked()
{
VMChooserDialog* v = new VMChooserDialog(this);
emit send_templates(getTemplates(myController.session));
connect(v, SIGNAL(send_chosen_template(Template)), this, SLOT(receive_chosen_template(Template)));
v->exec();
}
/*!
* \brief Slot for dialog, creates new VM by the chosen template
* \param t
*/
void MainWindow::receive_chosen_template(Template t){
myController.newCompute(t);
loadAllData();
}
/*!
* \brief handler, shows/hides VM password
*/
void MainWindow::on_bShowPassword_clicked()
{
if(ui->lPasswordVM->echoMode() == QLineEdit::Password){
ui->lPasswordVM->setEchoMode(QLineEdit::Normal);
ui->bShowPassword->setText("Hide");
}
else if(ui->lPasswordVM->echoMode() == QLineEdit::Normal){
ui->lPasswordVM->setEchoMode(QLineEdit::Password);
ui->bShowPassword->setText("Show");
}
else
ui->lPasswordVM->setEchoMode(QLineEdit::Password);
}
>>>>>>> 7a7d24d7d5770ed8dbaa6a1766461251ff6f768c
<<<<<<< HEAD
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
......@@ -56,59 +55,3 @@ private:
};
#endif // MAINWINDOW_H
=======
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QLabel>
#include <QPushButton>
#include <QListWidget>
#include <computewidget.h>
#include "libocci/occilib.h"
#include "controller.h"
#include "vmchooserdialog.h"
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
void addVM(std::string id, std::string name);
void loadAllData();
void loadVMData(std::string id);
signals:
void send_templates(std::vector<Template>);
void stateChanged(std::string state, std::string id);
private slots:
void on_bLogin_clicked();
void renewClicked(std::string);
void startClicked(std::string);
void wakeupsleepClicked(std::string);
void receive_chosen_template(Template);
void on_listWidget_clicked(const QModelIndex &index);
void on_bRefresh_clicked();
void on_bNewVM_clicked();
void on_bShowPassword_clicked();
private:
Ui::MainWindow *ui;
Controller myController;
std::vector<std::string> VM_names;
};
#endif // MAINWINDOW_H
>>>>>>> 7a7d24d7d5770ed8dbaa6a1766461251ff6f768c
<<<<<<< HEAD
<RCC>
<qresource prefix="/new/icons">
<file>compute.png</file>
......@@ -11,11 +10,3 @@
<file>running.png</file>
</qresource>
</RCC>
=======
<RCC>
<qresource prefix="/new/icons">
<file>compute.png</file>
<file>cloud icon.png</file>
</qresource>
</RCC>
>>>>>>> 7a7d24d7d5770ed8dbaa6a1766461251ff6f768c
......@@ -3,10 +3,6 @@
VMChooserDialog::VMChooserDialog(QWidget *parent):QDialog(parent), ui(new Ui::VMChooserDialog)
{
<<<<<<< HEAD
=======
connect(parent, SIGNAL(send_templates(std::vector<Template>)), this, SLOT(receive_templates(std::vector<Template>)));
>>>>>>> 7a7d24d7d5770ed8dbaa6a1766461251ff6f768c
ui->setupUi(this);
}
......@@ -25,11 +21,7 @@ void VMChooserDialog::on_buttonBox_rejected()
this->done(-1);
}
<<<<<<< HEAD
void VMChooserDialog::set_templates(std::vector<Template> _templates){
=======
void VMChooserDialog::receive_templates(std::vector<Template> _templates){
>>>>>>> 7a7d24d7d5770ed8dbaa6a1766461251ff6f768c
templates = _templates;
for(auto t : templates){
ui->lwTemplates->addItem(QString::fromUtf8(t.c_str()));
......
......@@ -12,20 +12,13 @@ class VMChooserDialog : public QDialog
Q_OBJECT
public:
explicit VMChooserDialog(QWidget *parent = 0);
<<<<<<< HEAD
void set_templates(std::vector<Template> templates);
=======
>>>>>>> 7a7d24d7d5770ed8dbaa6a1766461251ff6f768c
~VMChooserDialog();
signals:
void send_chosen_template(Template);
private slots:
<<<<<<< HEAD
=======
void receive_templates(std::vector<Template> templates);
>>>>>>> 7a7d24d7d5770ed8dbaa6a1766461251ff6f768c
void on_buttonBox_accepted();
......
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