Mercurial > hg > Applications > virsh-wrapper
changeset 15:f194adc597b6
add source to edit vagrantfile.
author | taiki |
---|---|
date | Tue, 12 Nov 2013 01:50:50 -1000 |
parents | 7003cdf42392 |
children | d8ea207162ca |
files | Makefile change_vagrantfile.py ie-vagrant.c |
diffstat | 3 files changed, 53 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/Makefile Mon Nov 11 20:44:34 2013 -1000 +++ b/Makefile Tue Nov 12 01:50:50 2013 -1000 @@ -19,9 +19,11 @@ install ie-virsh /usr/local/bin/ install ie-vagrant /usr/local/bin/ install newvm.py /usr/local/bin/ + install change_vagrantfile.py /usr/local/bin/ chmod 4711 /usr/local/bin/ie-virsh chmod 4711 /usr/local/bin/ie-vagrant chmod 755 /usr/local/bin/newvm.py + chmod 755 /usr/local/bin/change_vagrantfile.py clean: rm -f $(TARGET) $(TARGET2) *.o
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/change_vagrantfile.py Tue Nov 12 01:50:50 2013 -1000 @@ -0,0 +1,20 @@ +#!/usr/bin/python +# -*- encoding: utf-8 -*- + +import sys,os + +FILE = "Vagrantfile" + +if not os.path.exists(FILE): + print(FILE + ":file not found.") + sys.exit(1) + +f = open(FILE) + +file_tmp = [] +for line in f: + file_tmp.append(line) + +for l in file_tmp: + if 'config.vm.network :private_network' in l: +
--- a/ie-vagrant.c Mon Nov 11 20:44:34 2013 -1000 +++ b/ie-vagrant.c Tue Nov 12 01:50:50 2013 -1000 @@ -12,6 +12,8 @@ #include <sys/types.h> #include <regex.h> +#include <time.h> + /******************************************** * Vagrant Wrapper - Secure Yourself * * * @@ -33,6 +35,8 @@ #define NEW(type) ((type*)malloc(sizeof(type))) +#define VAGRANT_FILE "Vagrantfile" + /* Define global variables */ void @@ -41,6 +45,30 @@ printf("Usage: COMMAND [init|up|destroy|ssh]\n"); } +void +exec_init(int uid, int gid) +{ + pid_t pid = fork(); + if (pid < 0) { + perror("fork"); + exit(-1); + } else if (pid == 0) { + if (execl(command, command, init_command, NULL) < 0) { + perror("Execl:"); + } + } else { + sleep(2); + if (chown(VAGRANT_FILE, uid, gid) != 0) { + printf("chown error.\n"); + exit(1); + } + char exec[1024]; + strncpy(exec, "/usr/local/bin/change_vagrantfile.py", 1024); + fprintf(stdout, "executing %s\n", exec); + system(exec); + } +} + /* main(int argc, char **argv) - main process loop */ int main(int argc, char **argv) @@ -70,6 +98,8 @@ exit(1); } */ + + /* Set env valiable */ putenv("VAGRANT_HOME=/root/.vagrant.d/"); putenv("VAGRANT_DEFAULT_PROVIDER=kvm"); @@ -86,9 +116,7 @@ */ if ( strncmp(argv[1], "init", 4) == 0 ) { - if (execl(command, command, init_command, NULL) < 0) { - perror("Execl:"); - } + exec_init(uid, gid); } else if ( strncmp(argv[1], "destroy", 4) == 0 ) { if (execl(command, command, destroy_command, NULL) < 0) { perror("Execl:");