# HG changeset patch # User taiki # Date 1423653789 -32400 # Node ID 61bc8410d4803e770c3bcadb59b285f76eac6ff4 add files diff -r 000000000000 -r 61bc8410d480 Makefile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Makefile Wed Feb 11 20:23:09 2015 +0900 @@ -0,0 +1,28 @@ +TARGET = ie-cloud +IEDOCKERDIR = /etc/iecloud/ +PORTRANGE1 = "10000" +PORTRANGE2 = "12000" +CFLAGS = -Wall -O2 -g +INSTALL_DIR = /usr/local/bin + +all: $(TARGET) + +$(TARGET): $(TARGET).c + $(CC) $(CFLAGS) $(TARGET).c -o $(TARGET) + sudo chown root $(TARGET) + sudo chmod 4711 $(TARGET) + +install: $(TARGET) + install $(TARGET) $(INSTALL_DIR) + install create.py $(INSTALL_DIR) + install portops.py $(INSTALL_DIR) + chmod 4711 $(INSTALL_DIR)/$(TARGET) + chmod 755 $(INSTALL_DIR)/create.py + chmod 755 $(INSTALL_DIR)/portops.py + -mkdir $(IEDOCKERDIR) + python numberfile.py $(PORTRANGE1) $(PORTRANGE2) + cp iecloudport.list $(IEDOCKERDIR) + + +clean: + rm -f $(TARGET) $(TARGET2) *.o diff -r 000000000000 -r 61bc8410d480 README.md --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/README.md Wed Feb 11 20:23:09 2015 +0900 @@ -0,0 +1,19 @@ +## docker wrapper + +### ie-docker +We can be used docker without root permission. + + +### TODO +* make test docker ps for fedora + + +### sample command + +show process list + + ie-docker ps + +run docker image + + ie-docker run -it --name [user name]_[process name] fedora:latest /bin/bash diff -r 000000000000 -r 61bc8410d480 create.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/create.py Wed Feb 11 20:23:09 2015 +0900 @@ -0,0 +1,88 @@ +#!/usr/bin/python + +import os, re +import argparse +import portops + +base_path = "/home/k138582/docker-hg/" + +def ie_mkdir(projectname): + username = os.getlogin() + m = re.match('^([ek]\d\d[58]\d\d\d)$', username) + if m is not None: + dir = base_path + "students/" + username[:3] + os.sep + username + + mkdir1(dir) + os.system("/bin/chown "+os.getlogin()+" "+ dir) + + if (len(os.listdir(dir)) > 4): + print("[!] Too many project.") + exit() + + dir = dir + os.sep + projectname + mkdir1(dir) + os.system("/bin/chown " + os.getlogin() + " " + dir) + return dir + print("[!] Permission denied. You are not permitted user.") + exit() + +# make necessary sub directory +# /etc/libvirt/qemu/teachers +# /var/log/libvirt/qemu/teachers +# /var/run/libvirt/qemu/teachers + +def mkdir1(name): + if not os.path.exists(name): + os.makedirs(name); + +def change_own(base_path): + if not os.path.isdir(base_path): + os.system("/bin/chown " + os.getlogin() + " " + base_path) + return + + for f in os.listdir(base_path): + path = os.path.join(base_path, f) + os.system("/bin/chown " + os.getlogin() + " " + path) + if os.path.isdir(path): + change_own(path) + + +def make_hgrepo(projpath): + os.chdir(projpath) + os.system("hg init") + + dockerfile = "Dockerfile" + fd = open(dockerfile, "w") + fd.write("# Using ie-docker, you sould edit this file\n") + fd.write("FROM fedora\n") + fd.close() + + os.system("hg add " + dockerfile) + os.system("hg commit -u " + os.getlogin() + " -m systemcommit") + + change_own(os.getcwd()) + +# +# main method +# + +if __name__ == "__main__": + + parser = argparse.ArgumentParser(description='Create new project for ie-docker.') + parser.add_argument('projectname', metavar='project name', help='ie-docker project name') + args = parser.parse_args() + + if not portops.reserve_port(os.getlogin(), args.projectname): + print("[!] Can't get port to use for project.") + print("[!] Check your number of projects.") + sys.exit() + + projpath = ie_mkdir(args.projectname) + + make_hgrepo(projpath) + + print("Create your project on " + projpath) + print("Exec on your client : hg clone ssh://your_account@" + os.uname()[1] + os.sep + projpath) + + +# end diff -r 000000000000 -r 61bc8410d480 ie-cloud.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ie-cloud.c Wed Feb 11 20:23:09 2015 +0900 @@ -0,0 +1,414 @@ +#include +#include + +#include +#include +#include +#include +#include + +#include +#include + +#include "ie-cloud.h" + + +void +get_port_number(const char *user_name, char const *project_name, char *port_number) +{ + FILE *fp = NULL; + if ((fp = fopen(portlist_file, "r")) == NULL) { + printf("file open error\n"); + } + + // file format: portnumber,username,projectname + char buff[BUFF_SIZE]; + char *port; + int user_name_flag = 1; + int project_name_flag = 1; + while (fgets(buff, BUFF_SIZE, fp) != NULL) { + buff[strlen(buff) - 1] = '\0'; + + port = strtok(buff, ","); + + char *ret = strtok(NULL, ","); + if (ret == NULL) continue; + user_name_flag = strncmp(user_name, ret, BUFF_SIZE); + + ret = strtok(NULL, ","); + if (ret == NULL) continue; + project_name_flag = strncmp(project_name, ret, BUFF_SIZE); + + if (user_name_flag == 0 && project_name_flag == 0) { + printf("port :%s\n", port); + strncpy(port_number, port, PORT_LENGTH); + break; + } + } + fclose(fp); + if (user_name_flag == 1 || project_name_flag == 1) { + printf("[!] can't get port number for %s", user_name); + exit(1); + } +} + + +void +parse_run_command(const int argc, char **argv, run_command_opt *opt) +{ + int i = 2; + int parse_image_flag = 0; + for (i = 2; i < argc; i++) { + if(strncmp(argv[i], "--name", 6) == 0) { // process name + strncpy(opt->ps_name, argv[i + 1], 16); + i++; + } else if (argv[i][0] == '-') { + if (argv[i][1] == 't') { + opt->tty = TRUE; + } else if (argv[i][1] == 'i') { + opt->interactive = TRUE; + } else if (argv[i][1] == 'd') { + opt->dettach = TRUE; + } else if (argv[i][1] == 'v') { + strncpy(opt->volume, argv[i + 1], 128); + i++; + } else if (argv[i][1] == 'p') { + strncpy(opt->innerport, argv[i + 1], 16); + i++; + } + } else if (parse_image_flag) { // image name + strncpy(opt->exec_ps_command, argv[i], 64); + } else { // image name + parse_image_flag = 1; + strncpy(opt->image_name, argv[i], 16); + } + } + /* + printf("run command opt ::memory-%s innerport-%s outerport-%s tty-%d dettach-%d interactive-%d ps_name-%s exec_ps_command-%s volume-%s image-name-%s\n", + opt->memory, + opt->innerport, + opt->outerport, + opt->tty, + opt->dettach, + opt->interactive, + opt->ps_name, + opt->exec_ps_command, + opt->volume, + opt->image_name); + */ +} + +PSLISTPTR +get_pslist(regex_t *list_pattern) +{ + PSLISTPTR list = NEW(PSLIST); + PSLISTPTR p = list; + p->name[0] = 0; + p->next = 0; + FILE *fp = popen(ps_command,"r"); + while(fgets(p->name,PSNAME_MAX,fp)!=NULL) { + if (regexec(list_pattern, p->name, (size_t) 0, NULL, 0)) continue; + p->next = NEW(PSLIST); + p = p->next; + } + p->name[0] = 0; + pclose(fp); + + return list; +} + +void +print_pslist(PSLISTPTR list) +{ + for(;list && list->name[0]; list = list->next) { + fprintf(stdout, " %s\n",list->name); + } +} + +int +check_pslist_name(PSLISTPTR list, char *arg) +{ + for(;list && list->name[0]; list = list->next) { + if (strstr(list->name,arg)!=0) return 1; + } + + return 0; +} + +int +check_name(const char *p) +{ + if (!p) return 1; + for(;*p;p++) { + char c = *p; + if (c<=' ') return 1; + if (('a'<=c && c<='z') || + ('0'<=c && c<='9') || + ('_'==c ) || + ('-'==c )) continue; + return 1; + printf("%c", c); + } + return 0; +} + +int +check_user_name(const char *account_name) +{ + const char *regex = "[ek]([0-9]{6})"; + + regex_t *pattern = NEW(regex_t); + int ret = 1; + + if (regcomp(pattern, regex, REG_EXTENDED|REG_NEWLINE) != 0) { + exit(0); + } + + ret = regexec(pattern, account_name, (size_t) 0, NULL, 0); + regfree(pattern); + + if (!ret) { + return STUDENTS; + } + + ret = regexec(pattern, account_name, (size_t) 0, NULL, 0); + regfree(pattern); + + const int managers_num = sizeof(managers) / sizeof(managers[0]); + int i = 0; + + for (; i< managers_num; i++) { + if (strncmp(account_name, managers[i], NAME_LENGTH) == 0) { + return MANAGERS; + } + } + + const int guests_num = sizeof(guests) / sizeof(guests[0]); + int j = 0; + + for (; j< guests_num; j++) { + if (strncmp(account_name, guests[j], NAME_LENGTH) == 0) { + return GUESTS; + } + } + + return -1; +} + +void +bind_name(char *name, const char *first, const char *second) +{ + strncat(name, first, PS_NAME_LENGTH); + strncat(name, delimiter, PS_NAME_LENGTH); + strncat(name, second, PS_NAME_LENGTH); + strncat(name, delimiter, PS_NAME_LENGTH); + return; +} + +void +make_ps_name(char *ps_name, const int account_type, const char *account_name, const char *vm_num) +{ + switch(account_type) { + case STUDENTS: + strncat(ps_name, students_sym, PS_NAME_LENGTH); + strncat(ps_name, delimiter, PS_NAME_LENGTH); + strncat(ps_name, account_name, 3); + strncat(ps_name, delimiter, PS_NAME_LENGTH); + strncat(ps_name, account_name, PS_NAME_LENGTH); + strncat(ps_name, delimiter, PS_NAME_LENGTH); + break; + case GUESTS: + bind_name(ps_name, guests_sym, account_name); + break; + case MANAGERS: + bind_name(ps_name, managers_sym, account_name); + break; + default : + fprintf(stderr, "[!] Error: no registered type name."); + return; + } + + strncat(ps_name, vm_num, PS_NAME_LENGTH); +} + +void +usage() +{ + printf("Usage: ie-docker\n"); + printf("\trun: run process\n"); + printf("\tbuild: build docker process from Dockerfile\n"); + printf("\tattach: attach process\n"); + printf("\tdettach: dettach process\n"); + printf("\timages: list images\n"); + printf("\tcommit: \n"); +} + +void +run_usage() +{ + printf("Usage:\tie-docker run\n"); + printf("\tie-docker [option] --name [ps_name] {image name}:{tag} [execute command] [argument]"); +} + +/* main(int argc, char **argv) - main process loop */ + +int main(int argc, char **argv) +{ + int gid; + int uid; + + /* Set euid and egid to actual user */ + + char *name = getlogin(); + uid = getuid(); + gid = getgid(); + printf("uid %d gid %d name %s\n", uid,gid,name); + setegid(getgid()); + seteuid(getuid()); + + int account_type = check_user_name(name); + if (account_type < 0) { + fprintf(stderr, "[!] Permission denied. :%s\n", name); + } + + /* Confirm user is in GROUP(999) group */ + + /* + if ( gid != 999 ) { + printf("User Not Authorized! Exiting...\n"); + exit(1); + } + */ + + /* Set uid, gid, euid and egid to root */ + + regex_t *pattern = NEW(regex_t); + if (regcomp(pattern, name, 0) != 0) { + exit(0); + } + + setegid(0); + seteuid(0); + setgid(0); + setuid(0); + + if (strncmp(argv[1], create_command, 6) == 0) { + char exec[512]; + sprintf(exec, "/usr/local/bin/create.py %s", argv[2]); + system(exec); + exit(1); + } + + char *ps_name = (char *)malloc(sizeof(char) * PS_NAME_LENGTH); + if (ps_name == NULL) { + printf("[!] malloc error."); + } + ps_name[0] = '\0'; + + run_command_opt *opt = (run_command_opt *)malloc(sizeof(run_command_opt)); + if (opt == NULL) { + printf("[!] malloc error."); + } + opt->tty = FALSE; + opt->dettach = FALSE; + opt->interactive = FALSE; + + if (strncmp(argv[1], "ps", 4) != 0) { + if (strncmp(argv[1], "run", 3) == 0) { + parse_run_command(argc, argv, opt); + if (check_name(opt->ps_name)) { + fprintf(stderr, bad_name); + exit(0); + } + get_port_number(name, opt->ps_name, opt->outerport); + strncpy(ps_name, opt->ps_name, 64); + opt->ps_name[0] = '\0'; + make_ps_name(opt->ps_name, account_type, name, ps_name); + } else { + make_ps_name(ps_name, account_type, name, argv[2]); + } + printf("process name : %s\n", opt->ps_name); + } + + PSLISTPTR pslist = get_pslist(pattern); + + /* + * Check argv for proper arguments and run + * the corresponding script, if invoked. + */ + + if (argv[1]==0 || strncmp(argv[1], "ps", 4) == 0 ) { + print_pslist(pslist); + } else if (strncmp(argv[1], run_command, 5) == 0) { + + char *args[16]; + int i = 0; + + args[i++] = command; + args[i++] = run_command; + if (opt->dettach) args[i++] = "-d"; + if (opt->tty) args[i++] = "-t"; + if (opt->interactive) args[i++] = "-i"; + args[i++] = "-m"; + args[i++] = "512m"; + args[i++] = "-v"; + args[i++] = opt->volume; + args[i++] = "-p"; + char port[32]; + sprintf(port, "%s:%s", opt->outerport, opt->innerport); + args[i++] = port; + args[i++] = "--name"; + args[i++] = opt->ps_name; + args[i++] = opt->image_name; + args[i++] = opt->exec_ps_command; + args[i++] = NULL; + /* + printf("run command opt ::memory-%s innerport-%s outerport-%s tty-%d dettach-%d interactive-%d ps_name-%s exec_ps_command-%s volume-%s image-name-%s\n", + opt->memory, + opt->innerport, + opt->outerport, + opt->tty, + opt->dettach, + opt->interactive, + opt->ps_name, + opt->exec_ps_command, + opt->volume, + opt->image_name); + +*/ + if (execv(args[0], args) < 0) { + perror("[!] Execv:"); + } + } else if (strncmp(argv[1], start_command, 5) == 0) { + if (execl(command, command, start_command, ps_name, NULL) < 0) { + perror("[!] Execl:"); + } + } else if (strncmp(argv[1], exec_command, 5) == 0) { + if (execl(command, command, exec_command, argv[2], argv[3], argv[4], NULL) < 0) { + perror("[!] Execl:"); + } + } else if ( strncmp(argv[1], stop_command, 4) == 0 ) { + if (execl(command, command, stop_command, ps_name, NULL) < 0) { + perror("[!] Execl:"); + } + } else if ( strncmp(argv[1], build_command, 8) == 0 ) { + if (execl(command, command, build_command, argv[2], NULL) < 0) { + perror("[!] Execl:"); + } + } else if (strncmp(argv[1], attach_command, 6) == 0 ) { + if (execl(command, command, attach_command, ps_name, NULL) < 0) { + perror("[!] Execl:"); + } + } else if ( strncmp(argv[1], rm_command, 2) == 0 ) { + if (execl(command, command, rm_command, ps_name, NULL) < 0) { + perror("[!] Execl:"); + } + } else { + usage(); + } + free(ps_name); + free(opt); + exit(0); +} + +/* end */ diff -r 000000000000 -r 61bc8410d480 ie-cloud.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ie-cloud.h Wed Feb 11 20:23:09 2015 +0900 @@ -0,0 +1,82 @@ +/* Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License */ +#ifndef IE_DOCKER + +#define command "/usr/bin/docker" +#define ps_command "/usr/bin/docker ps -a" +#define run_command "run" +#define build_command "build" +#define attach_command "attach" +// #define pull_command "pull" /* download docker image command */ +#define images_command "images" /* list images command */ +#define commit_command "commit" /* make image command */ +#define rm_command "rm" /* remove container command */ +#define rmi_command "rmi" /* remove image command */ +#define start_command "start" +#define stop_command "stop" +#define exec_command "exec" + +#define create_command "create" + +/* Define global variables */ + +static char bad_name[] = "Bad process name. Try students_e11_e115711_01 or teachers_kono_02\n"; + +const char *guests[] = {"mata"}; +const char *managers[] = {"taira"}; +const char students_sym[] = "students"; +const char managers_sym[] = "managers"; +const char guests_sym[] = "guests"; +const char delimiter[] = "_"; +const char portlist_file[] = "/etc/iecloudport.list"; + +enum { + NAME_LENGTH = 50, + PS_NAME_LENGTH = 50, + RUN_COMMAND_LENGTH = 1024, + PORT_LENGTH = 16, + BUFF_SIZE = 50 +}; + +enum { + STUDENTS, + GUESTS, + MANAGERS +}; + +#define PSNAME_MAX (512) + +typedef struct pslist { + char name[PSNAME_MAX]; + struct pslist *next; +} PSLIST, *PSLISTPTR; + +#define NEW(type) ((type*)malloc(sizeof(type))) + +/* docker run option + * -t tty + * --name [process name] + * -v volume + * -m memory + * image name + * -i skeep open tdin + */ + +enum { + FALSE = 0, + TRUE = 1 +}; + +typedef struct run_command_opt_t { + char memory[16]; + char innerport[PORT_LENGTH]; + char outerport[PORT_LENGTH]; // system decide port number + int tty; // true = 1; false = 0 + int dettach; // true = 1; false = 0 + int interactive; // true = 1; false = 0 + char ps_name[64]; // user decide name + char exec_ps_command[64]; // + char volume[128]; + char image_name[16]; +} run_command_opt; + +#endif /* IE_DOCKER */ diff -r 000000000000 -r 61bc8410d480 iecloudport.list --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/iecloudport.list Wed Feb 11 20:23:09 2015 +0900 @@ -0,0 +1,2000 @@ +10000 +10001 +10002 +10003 +10004 +10005 +10006 +10007 +10008 +10009 +10010 +10011 +10012 +10013 +10014 +10015 +10016 +10017 +10018 +10019 +10020 +10021 +10022 +10023 +10024 +10025 +10026 +10027 +10028 +10029 +10030 +10031 +10032 +10033 +10034 +10035 +10036 +10037 +10038 +10039 +10040 +10041 +10042 +10043 +10044 +10045 +10046 +10047 +10048 +10049 +10050 +10051 +10052 +10053 +10054 +10055 +10056 +10057 +10058 +10059 +10060 +10061 +10062 +10063 +10064 +10065 +10066 +10067 +10068 +10069 +10070 +10071 +10072 +10073 +10074 +10075 +10076 +10077 +10078 +10079 +10080 +10081 +10082 +10083 +10084 +10085 +10086 +10087 +10088 +10089 +10090 +10091 +10092 +10093 +10094 +10095 +10096 +10097 +10098 +10099 +10100 +10101 +10102 +10103 +10104 +10105 +10106 +10107 +10108 +10109 +10110 +10111 +10112 +10113 +10114 +10115 +10116 +10117 +10118 +10119 +10120 +10121 +10122 +10123 +10124 +10125 +10126 +10127 +10128 +10129 +10130 +10131 +10132 +10133 +10134 +10135 +10136 +10137 +10138 +10139 +10140 +10141 +10142 +10143 +10144 +10145 +10146 +10147 +10148 +10149 +10150 +10151 +10152 +10153 +10154 +10155 +10156 +10157 +10158 +10159 +10160 +10161 +10162 +10163 +10164 +10165 +10166 +10167 +10168 +10169 +10170 +10171 +10172 +10173 +10174 +10175 +10176 +10177 +10178 +10179 +10180 +10181 +10182 +10183 +10184 +10185 +10186 +10187 +10188 +10189 +10190 +10191 +10192 +10193 +10194 +10195 +10196 +10197 +10198 +10199 +10200 +10201 +10202 +10203 +10204 +10205 +10206 +10207 +10208 +10209 +10210 +10211 +10212 +10213 +10214 +10215 +10216 +10217 +10218 +10219 +10220 +10221 +10222 +10223 +10224 +10225 +10226 +10227 +10228 +10229 +10230 +10231 +10232 +10233 +10234 +10235 +10236 +10237 +10238 +10239 +10240 +10241 +10242 +10243 +10244 +10245 +10246 +10247 +10248 +10249 +10250 +10251 +10252 +10253 +10254 +10255 +10256 +10257 +10258 +10259 +10260 +10261 +10262 +10263 +10264 +10265 +10266 +10267 +10268 +10269 +10270 +10271 +10272 +10273 +10274 +10275 +10276 +10277 +10278 +10279 +10280 +10281 +10282 +10283 +10284 +10285 +10286 +10287 +10288 +10289 +10290 +10291 +10292 +10293 +10294 +10295 +10296 +10297 +10298 +10299 +10300 +10301 +10302 +10303 +10304 +10305 +10306 +10307 +10308 +10309 +10310 +10311 +10312 +10313 +10314 +10315 +10316 +10317 +10318 +10319 +10320 +10321 +10322 +10323 +10324 +10325 +10326 +10327 +10328 +10329 +10330 +10331 +10332 +10333 +10334 +10335 +10336 +10337 +10338 +10339 +10340 +10341 +10342 +10343 +10344 +10345 +10346 +10347 +10348 +10349 +10350 +10351 +10352 +10353 +10354 +10355 +10356 +10357 +10358 +10359 +10360 +10361 +10362 +10363 +10364 +10365 +10366 +10367 +10368 +10369 +10370 +10371 +10372 +10373 +10374 +10375 +10376 +10377 +10378 +10379 +10380 +10381 +10382 +10383 +10384 +10385 +10386 +10387 +10388 +10389 +10390 +10391 +10392 +10393 +10394 +10395 +10396 +10397 +10398 +10399 +10400 +10401 +10402 +10403 +10404 +10405 +10406 +10407 +10408 +10409 +10410 +10411 +10412 +10413 +10414 +10415 +10416 +10417 +10418 +10419 +10420 +10421 +10422 +10423 +10424 +10425 +10426 +10427 +10428 +10429 +10430 +10431 +10432 +10433 +10434 +10435 +10436 +10437 +10438 +10439 +10440 +10441 +10442 +10443 +10444 +10445 +10446 +10447 +10448 +10449 +10450 +10451 +10452 +10453 +10454 +10455 +10456 +10457 +10458 +10459 +10460 +10461 +10462 +10463 +10464 +10465 +10466 +10467 +10468 +10469 +10470 +10471 +10472 +10473 +10474 +10475 +10476 +10477 +10478 +10479 +10480 +10481 +10482 +10483 +10484 +10485 +10486 +10487 +10488 +10489 +10490 +10491 +10492 +10493 +10494 +10495 +10496 +10497 +10498 +10499 +10500 +10501 +10502 +10503 +10504 +10505 +10506 +10507 +10508 +10509 +10510 +10511 +10512 +10513 +10514 +10515 +10516 +10517 +10518 +10519 +10520 +10521 +10522 +10523 +10524 +10525 +10526 +10527 +10528 +10529 +10530 +10531 +10532 +10533 +10534 +10535 +10536 +10537 +10538 +10539 +10540 +10541 +10542 +10543 +10544 +10545 +10546 +10547 +10548 +10549 +10550 +10551 +10552 +10553 +10554 +10555 +10556 +10557 +10558 +10559 +10560 +10561 +10562 +10563 +10564 +10565 +10566 +10567 +10568 +10569 +10570 +10571 +10572 +10573 +10574 +10575 +10576 +10577 +10578 +10579 +10580 +10581 +10582 +10583 +10584 +10585 +10586 +10587 +10588 +10589 +10590 +10591 +10592 +10593 +10594 +10595 +10596 +10597 +10598 +10599 +10600 +10601 +10602 +10603 +10604 +10605 +10606 +10607 +10608 +10609 +10610 +10611 +10612 +10613 +10614 +10615 +10616 +10617 +10618 +10619 +10620 +10621 +10622 +10623 +10624 +10625 +10626 +10627 +10628 +10629 +10630 +10631 +10632 +10633 +10634 +10635 +10636 +10637 +10638 +10639 +10640 +10641 +10642 +10643 +10644 +10645 +10646 +10647 +10648 +10649 +10650 +10651 +10652 +10653 +10654 +10655 +10656 +10657 +10658 +10659 +10660 +10661 +10662 +10663 +10664 +10665 +10666 +10667 +10668 +10669 +10670 +10671 +10672 +10673 +10674 +10675 +10676 +10677 +10678 +10679 +10680 +10681 +10682 +10683 +10684 +10685 +10686 +10687 +10688 +10689 +10690 +10691 +10692 +10693 +10694 +10695 +10696 +10697 +10698 +10699 +10700 +10701 +10702 +10703 +10704 +10705 +10706 +10707 +10708 +10709 +10710 +10711 +10712 +10713 +10714 +10715 +10716 +10717 +10718 +10719 +10720 +10721 +10722 +10723 +10724 +10725 +10726 +10727 +10728 +10729 +10730 +10731 +10732 +10733 +10734 +10735 +10736 +10737 +10738 +10739 +10740 +10741 +10742 +10743 +10744 +10745 +10746 +10747 +10748 +10749 +10750 +10751 +10752 +10753 +10754 +10755 +10756 +10757 +10758 +10759 +10760 +10761 +10762 +10763 +10764 +10765 +10766 +10767 +10768 +10769 +10770 +10771 +10772 +10773 +10774 +10775 +10776 +10777 +10778 +10779 +10780 +10781 +10782 +10783 +10784 +10785 +10786 +10787 +10788 +10789 +10790 +10791 +10792 +10793 +10794 +10795 +10796 +10797 +10798 +10799 +10800 +10801 +10802 +10803 +10804 +10805 +10806 +10807 +10808 +10809 +10810 +10811 +10812 +10813 +10814 +10815 +10816 +10817 +10818 +10819 +10820 +10821 +10822 +10823 +10824 +10825 +10826 +10827 +10828 +10829 +10830 +10831 +10832 +10833 +10834 +10835 +10836 +10837 +10838 +10839 +10840 +10841 +10842 +10843 +10844 +10845 +10846 +10847 +10848 +10849 +10850 +10851 +10852 +10853 +10854 +10855 +10856 +10857 +10858 +10859 +10860 +10861 +10862 +10863 +10864 +10865 +10866 +10867 +10868 +10869 +10870 +10871 +10872 +10873 +10874 +10875 +10876 +10877 +10878 +10879 +10880 +10881 +10882 +10883 +10884 +10885 +10886 +10887 +10888 +10889 +10890 +10891 +10892 +10893 +10894 +10895 +10896 +10897 +10898 +10899 +10900 +10901 +10902 +10903 +10904 +10905 +10906 +10907 +10908 +10909 +10910 +10911 +10912 +10913 +10914 +10915 +10916 +10917 +10918 +10919 +10920 +10921 +10922 +10923 +10924 +10925 +10926 +10927 +10928 +10929 +10930 +10931 +10932 +10933 +10934 +10935 +10936 +10937 +10938 +10939 +10940 +10941 +10942 +10943 +10944 +10945 +10946 +10947 +10948 +10949 +10950 +10951 +10952 +10953 +10954 +10955 +10956 +10957 +10958 +10959 +10960 +10961 +10962 +10963 +10964 +10965 +10966 +10967 +10968 +10969 +10970 +10971 +10972 +10973 +10974 +10975 +10976 +10977 +10978 +10979 +10980 +10981 +10982 +10983 +10984 +10985 +10986 +10987 +10988 +10989 +10990 +10991 +10992 +10993 +10994 +10995 +10996 +10997 +10998 +10999 +11000 +11001 +11002 +11003 +11004 +11005 +11006 +11007 +11008 +11009 +11010 +11011 +11012 +11013 +11014 +11015 +11016 +11017 +11018 +11019 +11020 +11021 +11022 +11023 +11024 +11025 +11026 +11027 +11028 +11029 +11030 +11031 +11032 +11033 +11034 +11035 +11036 +11037 +11038 +11039 +11040 +11041 +11042 +11043 +11044 +11045 +11046 +11047 +11048 +11049 +11050 +11051 +11052 +11053 +11054 +11055 +11056 +11057 +11058 +11059 +11060 +11061 +11062 +11063 +11064 +11065 +11066 +11067 +11068 +11069 +11070 +11071 +11072 +11073 +11074 +11075 +11076 +11077 +11078 +11079 +11080 +11081 +11082 +11083 +11084 +11085 +11086 +11087 +11088 +11089 +11090 +11091 +11092 +11093 +11094 +11095 +11096 +11097 +11098 +11099 +11100 +11101 +11102 +11103 +11104 +11105 +11106 +11107 +11108 +11109 +11110 +11111 +11112 +11113 +11114 +11115 +11116 +11117 +11118 +11119 +11120 +11121 +11122 +11123 +11124 +11125 +11126 +11127 +11128 +11129 +11130 +11131 +11132 +11133 +11134 +11135 +11136 +11137 +11138 +11139 +11140 +11141 +11142 +11143 +11144 +11145 +11146 +11147 +11148 +11149 +11150 +11151 +11152 +11153 +11154 +11155 +11156 +11157 +11158 +11159 +11160 +11161 +11162 +11163 +11164 +11165 +11166 +11167 +11168 +11169 +11170 +11171 +11172 +11173 +11174 +11175 +11176 +11177 +11178 +11179 +11180 +11181 +11182 +11183 +11184 +11185 +11186 +11187 +11188 +11189 +11190 +11191 +11192 +11193 +11194 +11195 +11196 +11197 +11198 +11199 +11200 +11201 +11202 +11203 +11204 +11205 +11206 +11207 +11208 +11209 +11210 +11211 +11212 +11213 +11214 +11215 +11216 +11217 +11218 +11219 +11220 +11221 +11222 +11223 +11224 +11225 +11226 +11227 +11228 +11229 +11230 +11231 +11232 +11233 +11234 +11235 +11236 +11237 +11238 +11239 +11240 +11241 +11242 +11243 +11244 +11245 +11246 +11247 +11248 +11249 +11250 +11251 +11252 +11253 +11254 +11255 +11256 +11257 +11258 +11259 +11260 +11261 +11262 +11263 +11264 +11265 +11266 +11267 +11268 +11269 +11270 +11271 +11272 +11273 +11274 +11275 +11276 +11277 +11278 +11279 +11280 +11281 +11282 +11283 +11284 +11285 +11286 +11287 +11288 +11289 +11290 +11291 +11292 +11293 +11294 +11295 +11296 +11297 +11298 +11299 +11300 +11301 +11302 +11303 +11304 +11305 +11306 +11307 +11308 +11309 +11310 +11311 +11312 +11313 +11314 +11315 +11316 +11317 +11318 +11319 +11320 +11321 +11322 +11323 +11324 +11325 +11326 +11327 +11328 +11329 +11330 +11331 +11332 +11333 +11334 +11335 +11336 +11337 +11338 +11339 +11340 +11341 +11342 +11343 +11344 +11345 +11346 +11347 +11348 +11349 +11350 +11351 +11352 +11353 +11354 +11355 +11356 +11357 +11358 +11359 +11360 +11361 +11362 +11363 +11364 +11365 +11366 +11367 +11368 +11369 +11370 +11371 +11372 +11373 +11374 +11375 +11376 +11377 +11378 +11379 +11380 +11381 +11382 +11383 +11384 +11385 +11386 +11387 +11388 +11389 +11390 +11391 +11392 +11393 +11394 +11395 +11396 +11397 +11398 +11399 +11400 +11401 +11402 +11403 +11404 +11405 +11406 +11407 +11408 +11409 +11410 +11411 +11412 +11413 +11414 +11415 +11416 +11417 +11418 +11419 +11420 +11421 +11422 +11423 +11424 +11425 +11426 +11427 +11428 +11429 +11430 +11431 +11432 +11433 +11434 +11435 +11436 +11437 +11438 +11439 +11440 +11441 +11442 +11443 +11444 +11445 +11446 +11447 +11448 +11449 +11450 +11451 +11452 +11453 +11454 +11455 +11456 +11457 +11458 +11459 +11460 +11461 +11462 +11463 +11464 +11465 +11466 +11467 +11468 +11469 +11470 +11471 +11472 +11473 +11474 +11475 +11476 +11477 +11478 +11479 +11480 +11481 +11482 +11483 +11484 +11485 +11486 +11487 +11488 +11489 +11490 +11491 +11492 +11493 +11494 +11495 +11496 +11497 +11498 +11499 +11500 +11501 +11502 +11503 +11504 +11505 +11506 +11507 +11508 +11509 +11510 +11511 +11512 +11513 +11514 +11515 +11516 +11517 +11518 +11519 +11520 +11521 +11522 +11523 +11524 +11525 +11526 +11527 +11528 +11529 +11530 +11531 +11532 +11533 +11534 +11535 +11536 +11537 +11538 +11539 +11540 +11541 +11542 +11543 +11544 +11545 +11546 +11547 +11548 +11549 +11550 +11551 +11552 +11553 +11554 +11555 +11556 +11557 +11558 +11559 +11560 +11561 +11562 +11563 +11564 +11565 +11566 +11567 +11568 +11569 +11570 +11571 +11572 +11573 +11574 +11575 +11576 +11577 +11578 +11579 +11580 +11581 +11582 +11583 +11584 +11585 +11586 +11587 +11588 +11589 +11590 +11591 +11592 +11593 +11594 +11595 +11596 +11597 +11598 +11599 +11600 +11601 +11602 +11603 +11604 +11605 +11606 +11607 +11608 +11609 +11610 +11611 +11612 +11613 +11614 +11615 +11616 +11617 +11618 +11619 +11620 +11621 +11622 +11623 +11624 +11625 +11626 +11627 +11628 +11629 +11630 +11631 +11632 +11633 +11634 +11635 +11636 +11637 +11638 +11639 +11640 +11641 +11642 +11643 +11644 +11645 +11646 +11647 +11648 +11649 +11650 +11651 +11652 +11653 +11654 +11655 +11656 +11657 +11658 +11659 +11660 +11661 +11662 +11663 +11664 +11665 +11666 +11667 +11668 +11669 +11670 +11671 +11672 +11673 +11674 +11675 +11676 +11677 +11678 +11679 +11680 +11681 +11682 +11683 +11684 +11685 +11686 +11687 +11688 +11689 +11690 +11691 +11692 +11693 +11694 +11695 +11696 +11697 +11698 +11699 +11700 +11701 +11702 +11703 +11704 +11705 +11706 +11707 +11708 +11709 +11710 +11711 +11712 +11713 +11714 +11715 +11716 +11717 +11718 +11719 +11720 +11721 +11722 +11723 +11724 +11725 +11726 +11727 +11728 +11729 +11730 +11731 +11732 +11733 +11734 +11735 +11736 +11737 +11738 +11739 +11740 +11741 +11742 +11743 +11744 +11745 +11746 +11747 +11748 +11749 +11750 +11751 +11752 +11753 +11754 +11755 +11756 +11757 +11758 +11759 +11760 +11761 +11762 +11763 +11764 +11765 +11766 +11767 +11768 +11769 +11770 +11771 +11772 +11773 +11774 +11775 +11776 +11777 +11778 +11779 +11780 +11781 +11782 +11783 +11784 +11785 +11786 +11787 +11788 +11789 +11790 +11791 +11792 +11793 +11794 +11795 +11796 +11797 +11798 +11799 +11800 +11801 +11802 +11803 +11804 +11805 +11806 +11807 +11808 +11809 +11810 +11811 +11812 +11813 +11814 +11815 +11816 +11817 +11818 +11819 +11820 +11821 +11822 +11823 +11824 +11825 +11826 +11827 +11828 +11829 +11830 +11831 +11832 +11833 +11834 +11835 +11836 +11837 +11838 +11839 +11840 +11841 +11842 +11843 +11844 +11845 +11846 +11847 +11848 +11849 +11850 +11851 +11852 +11853 +11854 +11855 +11856 +11857 +11858 +11859 +11860 +11861 +11862 +11863 +11864 +11865 +11866 +11867 +11868 +11869 +11870 +11871 +11872 +11873 +11874 +11875 +11876 +11877 +11878 +11879 +11880 +11881 +11882 +11883 +11884 +11885 +11886 +11887 +11888 +11889 +11890 +11891 +11892 +11893 +11894 +11895 +11896 +11897 +11898 +11899 +11900 +11901 +11902 +11903 +11904 +11905 +11906 +11907 +11908 +11909 +11910 +11911 +11912 +11913 +11914 +11915 +11916 +11917 +11918 +11919 +11920 +11921 +11922 +11923 +11924 +11925 +11926 +11927 +11928 +11929 +11930 +11931 +11932 +11933 +11934 +11935 +11936 +11937 +11938 +11939 +11940 +11941 +11942 +11943 +11944 +11945 +11946 +11947 +11948 +11949 +11950 +11951 +11952 +11953 +11954 +11955 +11956 +11957 +11958 +11959 +11960 +11961 +11962 +11963 +11964 +11965 +11966 +11967 +11968 +11969 +11970 +11971 +11972 +11973 +11974 +11975 +11976 +11977 +11978 +11979 +11980 +11981 +11982 +11983 +11984 +11985 +11986 +11987 +11988 +11989 +11990 +11991 +11992 +11993 +11994 +11995 +11996 +11997 +11998 +11999 diff -r 000000000000 -r 61bc8410d480 numberfile.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/numberfile.py Wed Feb 11 20:23:09 2015 +0900 @@ -0,0 +1,17 @@ +#!/usr/bin/python + +filename = "iecloudport.list" + +import argparse + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description='Create new project for ie-docker.') + parser.add_argument('number', metavar='N', help='start number.') + parser.add_argument('limit', metavar='N', help='limit number.') + args = parser.parse_args() + + f = open(filename,"w") + for num in range(int(args.number), int(args.limit)): + num_str = str(num) + f.write(num_str + "\n") + f.close() diff -r 000000000000 -r 61bc8410d480 portops.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/portops.py Wed Feb 11 20:23:09 2015 +0900 @@ -0,0 +1,87 @@ +#!/usr/bin/python + +portlist_file = "/etc/iecloud/iecloudport.list" +CONTAINER_NUM_LIMIT = 4 +testuser = "testuser" +DELIMITER = "," + +def remove_port_list(user, projectname): + portlist = read_port_list() + delete_line = "" + release_port = "" + for port in portlist: + portline = port.split(DELIMITER) + if (len(portline) < 3): + continue + if (portline[1] == user and portline[2] == projectname): + delete_line = port + release_port = portline[0] + break + + if release_port == "": + print("[!] No remove port.") + return + portlist.remove(delete_line) + portlist.append(release_port) + write_port_list(portlist) + +def read_port_list(): + f = open(portlist_file, "r") + portlist = [] + for port in f: + portlist.append(port.rstrip()) + f.close() + return portlist + +def write_port_list(portlist): + portlist_tmp = [] + for port in portlist: + portlist_tmp.append(port + "\n") + f = open(portlist_file, "w") + f.writelines(portlist_tmp) + f.close() + +def is_limit(portlist, user): + count = 0 + for port in portlist: + portline = port.split(DELIMITER) + if len(portline) < 2: + continue + if portline[1] == user: + count = count + 1 + if count < CONTAINER_NUM_LIMIT: + return True + else: + return False + +def mark_use_port(user, projectname): + portlist = read_port_list() + port_num = "" + for port in portlist: + portline = port.split(DELIMITER) + if len(portline) == 1: + port_num = portline[0] + break + portlist.remove(port_num) + portlist.append(port_num + DELIMITER + user + DELIMITER + projectname) + write_port_list(portlist) + +def get_marked_port(user): + ports = read_port_list() + for port in ports: + portline = port.split(DELIMITER) + if len(portline) < 2: + continue + if portline[1] == user: + return portline[0] + +def reserve_port(user, projectname): + portlist = read_port_list() + if not is_limit(portlist, user): + return False + mark_use_port(user,projectname) + return True + +if __name__ == "__main__": + print("put test source.") + remove_port_list("taira", "sample")