Mercurial > hg > Applications > docker-wrapper
changeset 1:3e0e4fd65313
set may use command.
author | taiki |
---|---|
date | Mon, 14 Jul 2014 16:25:26 -1000 |
parents | ca114837b2f4 |
children | dcca39030bd8 |
files | ie-docker.c |
diffstat | 1 files changed, 35 insertions(+), 30 deletions(-) [+] |
line wrap: on
line diff
--- a/ie-docker.c Sun Jul 13 10:45:54 2014 -1000 +++ b/ie-docker.c Mon Jul 14 16:25:26 2014 -1000 @@ -14,21 +14,25 @@ /* Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License */ -#define command "/usr/bin/docker" -/* #define list_command "/usr/bin/virsh list --all" */ -#define process_command "/usr/bin/docker ps" +#define command "/usr/bin/docker" +#define ps_command "/usr/bin/docker ps -a" #define run_command "run" -#define stop_command "destroy" -#define define_command "define" -#define undefine_command "undefine" -#define dumpxml_command "dumpxml" -#define console_command "console" +#define build_command "build" +#define attach_command "attach" +#define dettach_command "dettach" +#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" static char bad_name[] = "Bad process name. Try students/e11/e115711/01 or teachers/kono/02\n"; #define PSNAME_MAX (512) -typedef struct processlist { +typedef struct pslist { char name[PSNAME_MAX]; struct pslist *next; } PSLIST, *PSLISTPTR; @@ -41,10 +45,10 @@ get_pslist(regex_t *list_pattern) { PSLISTPTR list = NEW(PSLIST); - PSLISTPTR p = list ; + PSLISTPTR p = list; p->name[0] = 0; p->next = 0; - FILE *fp = popen(list_command,"r"); + 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); @@ -58,7 +62,7 @@ void print_pslist(PSLISTPTR list) { - for(;list && list->name[0]; list=list->next) { + for(;list && list->name[0]; list = list->next) { fprintf(stdout, " %s\n",list->name); } } @@ -66,7 +70,7 @@ int check_pslist_name(PSLISTPTR list, char *arg) { - for(;list && list->name[0]; list=list->next) { + for(;list && list->name[0]; list = list->next) { if (strstr(list->name,arg)!=0) return 1; } return 0; @@ -92,7 +96,7 @@ void usage() { - printf("Usage: COMMAND [define|list|start|destroy|xmldump|undefine|console] [ps-name]\n"); + printf("Usage:\n\trun: run process\n\tbuild: build docker process from Dockerfile\n\tattach: atach process\n\tdettach: \n\tpull: \n\timages: \n\tcommit:\n"); printf(" ps-name should be students/e11/e115711/01 or teachers/kono/02\n"); } @@ -133,19 +137,22 @@ setgid(0); setuid(0); - if (argc>=3) { - if ( strncmp(argv[1], "define", 6) == 0 ) { + if (argc >= 3) { + if ( strncmp(argv[1], pull_command, 6) == 0 ) { if (regexec(pattern, argv[2], (size_t) 0, NULL, 0)) { fprintf(stderr, bad_name); exit(0); } + if (check_name(argv[2])) { fprintf(stderr, bad_name); exit(0); } + char exec[1024]; - // strncpy(exec, "/usr/local/bin/newps.py -c /etc/libvirt/qemu/fedora16.xml -n ",900); - strncpy(exec, "/usr/local/bin/newps.py -c /etc/libvirt/qemu/fedora19.xml -n ",900); + + strncpy(exec,"/usr/local/bin/newps.py -c /etc/libvirt/qemu/fedora19.xml -n ", 900); + strncat(exec, argv[2],1000); fprintf(stdout, "excuting %s\n",exec ); system(exec); @@ -178,6 +185,10 @@ if (argv[1]==0 || strncmp(argv[1], "list", 4) == 0 ) { print_pslist(pslist); + } else if (strncmp(argv[1], run_command, 5) == 0) { + if (execl(command, command, run_command, argv[2], NULL) < 0) { + perror("Execl:"); + } } else if (strncmp(argv[1], start_command, 5) == 0) { if (execl(command, command, start_command, argv[2], NULL) < 0) { perror("Execl:"); @@ -186,22 +197,16 @@ if (execl(command, command, stop_command, argv[2], NULL) < 0) { perror("Execl:"); } - } else if ( strncmp(argv[1], dumpxml_command, 7) == 0 ) { - if (execl(command, command, dumpxml_command, argv[2], NULL) < 0) { - perror("Execl:"); - } - } else if ( strncmp(argv[1], console_command, 8) == 0 ) { - if (execl(command, command, console_command, argv[2], NULL) < 0) { + } 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], define_command, 6) == 0 ) { - chdir("/usr/local/etc/libvirt/qemu"); - if (execl(command, command, define_command, name_xml, NULL) < 0) { + } else if (strncmp(argv[1], attach_command, 6) == 0 ) { + if (execl(command, command, attach_command, name_xml, NULL) < 0) { perror("Execl:"); } - } else if ( strncmp(argv[1], undefine_command, 8) == 0 ) { - chdir("/usr/local/etc/libvirt/qemu"); - if (execl(command, command, undefine_command, argv[2], NULL) < 0) { + } else if ( strncmp(argv[1], dettach_command, 8) == 0 ) { + if (execl(command, command, dettach_command, argv[2], NULL) < 0) { perror("Execl:"); } } else {