-
Notifications
You must be signed in to change notification settings - Fork 0
/
dialognewcont.cpp
73 lines (61 loc) · 2.07 KB
/
dialognewcont.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <iostream>
#include "dialognewcont.h"
#include "ui_dialognewcont.h"
#include "mainwindow.h"
using namespace std;
dialogNewCont::dialogNewCont(QWidget *parent) :
QDialog(parent),
ui(new Ui::dialogNewCont)
{
ui->setupUi(this);
this->setWindowFlags(this->windowFlags() & ~Qt::WindowContextHelpButtonHint);
setWindowTitle(tr("New Container"));
uiMan = new manager();
setupBtns();
popComboBox();
}
dialogNewCont::~dialogNewCont()
{
delete ui;
}
void dialogNewCont::setupBtns(){
connect(ui->buttonBox, SIGNAL (accepted()), this, SLOT (apply()));
connect(ui->buttonBox, SIGNAL (rejected()), this, SLOT (abort()));
}
void dialogNewCont::popComboBox(){
vector<string> nets = uiMan->readNetworksNames();
for (vector <string>::iterator it=nets.begin(); it != nets.end(); ++it) {
QString name = QString::fromStdString(*it);
if (name != "" && name != "" && name != "bridge" && name != "host") {
ui->comboBox->addItem(name);
//cout << *it << endl;
}
}
}
void dialogNewCont::abort() {
delete this;
}
void dialogNewCont::apply() {
QString net = ui->comboBox->currentText();
QString name = ui->lineEdit->text();
string netS = net.toStdString();
string nameS = name.toStdString();
if( nameS != "" || uiMan->isNotWhiteSpace(nameS)){
string id = uiMan->getDocker()->addCont(nameS, netS);
//cout << id;
uiMan->getDocker()->routeDel(nameS, "default");
vector <string> iFaces = uiMan->readContIfs(nameS);
for (vector <string>::iterator it=iFaces.begin(); it != iFaces.end(); ++it){
QString iFace = QString::fromStdString(*it);
string eth = iFace.toStdString() + " 0.0.0.0";
cout << eth;
uiMan->getDocker()->ifconfig(nameS, eth);
}
/*for(int i = 0; i<10 ; i++) {
string eth = "eth" + to_string(i) + " 0.0.0.0"; //ifconfig | grep "eth" | awk -F'[: ]+' '{ print $1 }'
uiMan->getDocker()->ifconfig(nameS, eth);
}*/
emit refresh();
}
delete this;
}