with isServiceOnServer
This commit is contained in:
parent
53b8139135
commit
615f72fc92
6
src/.vscode/settings.json
vendored
Normal file
6
src/.vscode/settings.json
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
{
|
||||
"files.associations": {
|
||||
"iostream": "cpp",
|
||||
"ostream": "cpp"
|
||||
}
|
||||
}
|
@ -6,8 +6,7 @@
|
||||
#define SERVICE_H
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <string>
|
||||
#include <cstring>
|
||||
#include <list>
|
||||
|
||||
using namespace std;
|
||||
|
@ -72,8 +72,8 @@ vector <Service> Services::readServicesFromCSV (string CSV) const
|
||||
string line;
|
||||
string tmpUserID; //used before converting to int
|
||||
int userID;
|
||||
string username;
|
||||
string server;
|
||||
string username="";
|
||||
string server="";
|
||||
list <string> servers;
|
||||
while(getline(streamServices,line)){
|
||||
servers.clear();
|
||||
@ -81,11 +81,13 @@ vector <Service> Services::readServicesFromCSV (string CSV) const
|
||||
continue;
|
||||
}
|
||||
stringstream streamLine(line);
|
||||
getline(streamLine,tmpUserID,';'); //extracting the userID
|
||||
getline(streamLine,tmpUserID,','); //extracting the userID
|
||||
userID=stoi(tmpUserID);
|
||||
getline(streamLine,username,';'); //extracting the username
|
||||
getline(streamLine,username,','); //extracting the username
|
||||
while(getline(streamLine,server,';')){ //extracting the server(s)
|
||||
if(!server.empty()){
|
||||
servers.push_back(server);
|
||||
}
|
||||
}
|
||||
Service entry = Service(userID,username,servers);
|
||||
result.push_back(entry);
|
||||
|
BIN
src/deployer
BIN
src/deployer
Binary file not shown.
68
src/main.cpp
68
src/main.cpp
@ -10,55 +10,83 @@
|
||||
#include "DockerModule.h"
|
||||
using namespace std;
|
||||
|
||||
void help()
|
||||
void help(char * argv0)
|
||||
{
|
||||
//temporary
|
||||
cout << "usage: ./$argv[0] action file \n with action=deploy or remove and file=path to a file or all. \n" << endl;
|
||||
cout << "usage: ./" << argv0 <<"action file \n with action=deploy or remove and file=path to a file or all. \n" << endl;
|
||||
}
|
||||
|
||||
int isServiceOnServer()
|
||||
int isServiceOnServer(Service service)
|
||||
//this method tests if a certain service is on the current server
|
||||
//it uses the bash command dig, thanks to a pipe to a separate bash process
|
||||
//it looks into the /etc/hosts file thanks to a pipe to a separate bash process
|
||||
{
|
||||
FILE *p;
|
||||
char result [100];
|
||||
|
||||
p = popen("ls -la","r"); //just to test that popen works
|
||||
char result [100]={0};
|
||||
string cmd ="getent hosts " +service.getUsername();
|
||||
p = popen(cmd.c_str(),"r");
|
||||
if( p == NULL)
|
||||
{
|
||||
cout << "Unable to verify if the service is on the server, bash process opening error." << endl;
|
||||
return -1;
|
||||
}
|
||||
while(fgets(result,100,p)!=NULL){
|
||||
//if several lines, copy result somewhere to save
|
||||
cout << result << endl;
|
||||
}
|
||||
fgets(result,100,p);
|
||||
pclose(p);
|
||||
if(strstr(result,"::1")!=nullptr){
|
||||
cout << "service on server" << endl;
|
||||
return 0;
|
||||
}
|
||||
cout << "service not on server" << endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int deployAll(){
|
||||
cout << "deploying all" <<endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int deployService(string service){
|
||||
cout << "deploying service" << endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int removeAll(){
|
||||
cout << "removing all"<<endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int removeService(const char* service){
|
||||
cout<< "removing service"<<endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
bool action_deploy=false;
|
||||
bool action_remove=false;
|
||||
bool all=false;
|
||||
//list<Module *> modules;
|
||||
if (argc != 3){
|
||||
cout << "Invalid number of arguments. \n" << endl;
|
||||
help();
|
||||
help(argv[0]);
|
||||
exit(1);
|
||||
} else {
|
||||
if (strcmp(argv[1],"deploy")==0){
|
||||
action_deploy=true;
|
||||
if(strcmp(argv[2],"all")==0){
|
||||
deployAll();
|
||||
}else{
|
||||
string service = argv[2];
|
||||
deployService(service);
|
||||
}
|
||||
} else if (strcmp(argv[1],"remove")==0){
|
||||
action_remove=true;
|
||||
if(strcmp(argv[2],"all")==0){
|
||||
removeAll();
|
||||
}else{
|
||||
removeService(argv[2]);
|
||||
}
|
||||
} else {
|
||||
cout << "Invalid argument. \n" << endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
DockerModule dmodule;
|
||||
isServiceOnServer();
|
||||
//DockerModule dmodule;
|
||||
Services services = Services();
|
||||
isServiceOnServer(services.getServices()[0]);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
3
src/servers.csv
Normal file
3
src/servers.csv
Normal file
@ -0,0 +1,3 @@
|
||||
ID,Name,IP1,IP2,IP3
|
||||
1,ordinosaure,10.0.0.1
|
||||
2,shlag_cluster,ordinosaure
|
|
@ -1,55 +1,4 @@
|
||||
1;sftp.jean-cloud.net;raku.jean-cloud.org
|
||||
#2;benevoles31.karnaval.fr;max.jean-cloud.org
|
||||
3;builder.rimarima.fr;raku.jean-cloud.org
|
||||
5;chiloe.eu;shlago.jean-cloud.org
|
||||
7;collectif-arthadie.fr;izzo.jean-cloud.org
|
||||
8;compagnienouvelle.fr;shlago.jean-cloud.org
|
||||
9;copaines.jean-cloud.net;shlago.jean-cloud.org
|
||||
11;deployer.jean-cloud.org;shlago.jean-cloud.org
|
||||
12;dnscerts.jean-cloud.org;montbonnot.jean-cloud.org
|
||||
13;etrevivant.net;shlago.jean-cloud.org
|
||||
14;feministesucl34.communistesliber;none
|
||||
15;feteducourt.jean-cloud.net;shlago.jean-cloud.org
|
||||
16;feteducourt2020.jean-cloud.net;shlago.jean-cloud.org
|
||||
17;git.jean-cloud.net;izzo.jean-cloud.org
|
||||
20;inurbe.fr;shlago.jean-cloud.org
|
||||
21;jean-cloud.net;shlago.jean-cloud.org
|
||||
22;leida.fr;shlago.jean-cloud.org
|
||||
23;lexicographe.jean-cloud.net;shlago.jean-cloud.org
|
||||
24;metamorphosemagazine.fr;shlago.jean-cloud.org
|
||||
25;mux.radiodemo.oma-radio.fr;raku.jean-cloud.org
|
||||
26;nc-backup.jean-cloud.net;raku.jean-cloud.org
|
||||
27;ns.jean-cloud.org;nowhere
|
||||
28;ns1.jean-cloud.org;izzo.jean-cloud.org
|
||||
29;nuage.jean-cloud.net;izzo.jean-cloud.org
|
||||
30;oma-radio.fr;izzo.jean-cloud.org
|
||||
31;pa1.studios.oma-radio.fr;tetede.jean-cloud.org
|
||||
32;paj.oma-radio.fr;nougaro.jean-cloud.org
|
||||
33;quadrille-elsa.jean-cloud.net;shlago.jean-cloud.org
|
||||
34;radiodemo.oma-radio.fr;raku.jean-cloud.org
|
||||
35;radionimaitre.oma-radio.fr;tetede.jean-cloud.org
|
||||
36;raplacgr.jean-cloud.net;izzo.jean-cloud.org
|
||||
37;rimarima.fr;raku.jean-cloud.org
|
||||
38;rpnow.jean-cloud.net;izzo.jean-cloud.org
|
||||
39;soundbase.radiodemo.oma-radio.fr;montbonnot.jean-cloud.org
|
||||
40;static.jean-cloud.net;izzo.jean-cloud.org
|
||||
41;velov.jean-cloud.net;shlago.jean-cloud.org
|
||||
42;wiki-cgr.jean-cloud.net;izzo.jean-cloud.org
|
||||
43;radio.karnaval.fr;tetede.jean-cloud.org
|
||||
44;wordpress.abc.jean-cloud.net;raku.jean-cloud.org
|
||||
45;jean-cloud.org;shlago.jean-cloud.org
|
||||
46;soundbase.paj.oma-radio.fr;montbonnot.jean-cloud.org
|
||||
47;backup-borg-server;montbonnot.jean-cloud.org
|
||||
48;backup-borg-client;raku.jean-cloud.org
|
||||
49;soundbase.radionimaitre.oma;montbonnot.jean-cloud.org
|
||||
50;monitoring.jean-cloud.net;montbonnot.jean-cloud.org
|
||||
51;benevoles32.karnaval.fr;izzo.jean-cloud.org
|
||||
52;nginx_exporter;shlago.jean-cloud.org
|
||||
#54;accent.jean-cloud.net;raku.jean-cloud.org
|
||||
55;gaia.jean-cloud.net;shlago.jean-cloud.org
|
||||
56;association-chahut.fr;izzo.jean-cloud.org
|
||||
57;mutubot.jean-cloud.net;izzo.jean-cloud.org
|
||||
59;lyon1.studios.oma-radio.fr;izzo.jean-cloud.org
|
||||
60;soundbase.radiokipik.org;montbonnot.jean-cloud.org
|
||||
61;radiokipik.org;izzo.jean-cloud.org
|
||||
62;mux.radiokipik.org;izzo.jean-cloud.org
|
||||
#ID,Name,Server
|
||||
1,test.sh8s.sh,ordinosaure
|
||||
2,truc.sh8s.sh,shlag_cluster
|
||||
3,other.sh8s.sh,
|
||||
|
|
@ -72,8 +72,8 @@ vector <Service> Services::readServicesFromCSV (string CSV) const
|
||||
string line;
|
||||
string tmpUserID; //used before converting to int
|
||||
int userID;
|
||||
string username;
|
||||
string server;
|
||||
string username="";
|
||||
string server="";
|
||||
list <string> servers;
|
||||
while(getline(streamServices,line)){
|
||||
servers.clear();
|
||||
@ -85,7 +85,9 @@ vector <Service> Services::readServicesFromCSV (string CSV) const
|
||||
userID=stoi(tmpUserID);
|
||||
getline(streamLine,username,';'); //extracting the username
|
||||
while(getline(streamLine,server,';')){ //extracting the server(s)
|
||||
if(!server.empty()){
|
||||
servers.push_back(server);
|
||||
}
|
||||
}
|
||||
Service entry = Service(userID,username,servers);
|
||||
result.push_back(entry);
|
||||
|
@ -14,24 +14,13 @@ int main()
|
||||
list <string> s5;
|
||||
list <string> s6;
|
||||
list <string> s7;
|
||||
list <string> s8={"server8","server8bis","server8ter"};
|
||||
|
||||
string emptyUsername;
|
||||
|
||||
expectedResult.push_back(Service(1,"username1",s1));
|
||||
expectedResult.push_back(Service(3,"username3",s3));
|
||||
expectedResult.push_back(Service(4,"username4",s4));
|
||||
expectedResult.push_back(Service(5,"username5",s5));
|
||||
expectedResult.push_back(Service(6,emptyUsername,s6));
|
||||
expectedResult.push_back(Service(6,"",s6));
|
||||
expectedResult.push_back(Service(7,"username7",s7));
|
||||
expectedResult.push_back(Service(8,"username8",s8));
|
||||
|
||||
|
||||
if(expectedResult[4]==result[4]){
|
||||
cout << "first good" << endl;
|
||||
}else{
|
||||
cout << "not good" << endl;
|
||||
}
|
||||
|
||||
if(expectedResult==result){
|
||||
cout << "Services test: OK" << endl;
|
||||
|
BIN
test/ServicesTest/test
Executable file
BIN
test/ServicesTest/test
Executable file
Binary file not shown.
@ -5,5 +5,3 @@
|
||||
5;username5;
|
||||
6;;;
|
||||
7;username7
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user