diff --git a/src/.vscode/settings.json b/src/.vscode/settings.json new file mode 100644 index 0000000..0c83701 --- /dev/null +++ b/src/.vscode/settings.json @@ -0,0 +1,6 @@ +{ + "files.associations": { + "iostream": "cpp", + "ostream": "cpp" + } +} \ No newline at end of file diff --git a/src/Service.h b/src/Service.h index fc081af..ad082ec 100644 --- a/src/Service.h +++ b/src/Service.h @@ -6,8 +6,7 @@ #define SERVICE_H #include -#include -#include +#include #include using namespace std; diff --git a/src/Services.cpp b/src/Services.cpp index 03e7309..6528df1 100644 --- a/src/Services.cpp +++ b/src/Services.cpp @@ -72,8 +72,8 @@ vector 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 servers; while(getline(streamServices,line)){ servers.clear(); @@ -81,11 +81,13 @@ vector 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); diff --git a/src/deployer b/src/deployer index e44acd3..2941b78 100755 Binary files a/src/deployer and b/src/deployer differ diff --git a/src/main.cpp b/src/main.cpp index 6eb5a74..cf5802f 100644 --- a/src/main.cpp +++ b/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" < 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; } diff --git a/src/servers.csv b/src/servers.csv new file mode 100644 index 0000000..42c7d2f --- /dev/null +++ b/src/servers.csv @@ -0,0 +1,3 @@ +ID,Name,IP1,IP2,IP3 +1,ordinosaure,10.0.0.1 +2,shlag_cluster,ordinosaure diff --git a/src/services.csv b/src/services.csv index c2deb64..c9c122f 100644 --- a/src/services.csv +++ b/src/services.csv @@ -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, diff --git a/test/ServicesTest/Services.cpp b/test/ServicesTest/Services.cpp index 03e7309..a0a6dcc 100644 --- a/test/ServicesTest/Services.cpp +++ b/test/ServicesTest/Services.cpp @@ -72,8 +72,8 @@ vector 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 servers; while(getline(streamServices,line)){ servers.clear(); @@ -85,7 +85,9 @@ vector 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); diff --git a/test/ServicesTest/main.cpp b/test/ServicesTest/main.cpp index 14b654b..07c8318 100644 --- a/test/ServicesTest/main.cpp +++ b/test/ServicesTest/main.cpp @@ -14,24 +14,13 @@ int main() list s5; list s6; list s7; - list 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; diff --git a/test/ServicesTest/test b/test/ServicesTest/test new file mode 100755 index 0000000..2da754c Binary files /dev/null and b/test/ServicesTest/test differ diff --git a/test/ServicesTest/testSample.csv b/test/ServicesTest/testSample.csv index 4019acc..1a6acba 100644 --- a/test/ServicesTest/testSample.csv +++ b/test/ServicesTest/testSample.csv @@ -5,5 +5,3 @@ 5;username5; 6;;; 7;username7 - -