Mercurial > hg > Applications > virsh-wrapper
comparison ie-virsh.c @ 9:ea51e779b381
error message
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 13 Nov 2012 16:35:34 +0900 |
parents | bff4054ed58f |
children | 422041acef4c |
comparison
equal
deleted
inserted
replaced
8:b2e2eec87764 | 9:ea51e779b381 |
---|---|
27 #define command "/usr/bin/virsh" | 27 #define command "/usr/bin/virsh" |
28 #define list_command "/usr/bin/virsh list --all" | 28 #define list_command "/usr/bin/virsh list --all" |
29 #define start_command "start" | 29 #define start_command "start" |
30 #define stop_command "destroy" | 30 #define stop_command "destroy" |
31 #define define_command "define" | 31 #define define_command "define" |
32 #define undefine_command "undefine" | |
32 #define dumpxml_command "dumpxml" | 33 #define dumpxml_command "dumpxml" |
34 | |
35 static char bad_name[] = "Bad vmname. Try students/e11/e115711/01 or teachers/kono/02\n"; | |
33 | 36 |
34 #define VMNAME_MAX (512) | 37 #define VMNAME_MAX (512) |
35 | 38 |
36 typedef struct vmlist { | 39 typedef struct vmlist { |
37 char name[VMNAME_MAX]; | 40 char name[VMNAME_MAX]; |
94 } | 97 } |
95 | 98 |
96 void | 99 void |
97 usage() | 100 usage() |
98 { | 101 { |
99 printf("Usage: COMMAND [list|start|destroy|xmldump] [vm-name]\n"); | 102 printf("Usage: COMMAND [define|list|start|destroy|xmldump|undefine] [vm-name]\n"); |
103 printf(" vm-name should be students/e11/e115711/01 or teachers/kono/02\n"); | |
100 } | 104 } |
101 | 105 |
102 /* main(int argc, char **argv) - main process loop */ | 106 /* main(int argc, char **argv) - main process loop */ |
103 | 107 |
104 int main(int argc, char **argv) | 108 int main(int argc, char **argv) |
138 | 142 |
139 | 143 |
140 if (argc>=3) { | 144 if (argc>=3) { |
141 if ( strncmp(argv[1], "define", 6) == 0 ) { | 145 if ( strncmp(argv[1], "define", 6) == 0 ) { |
142 if (regexec(pattern, argv[2], (size_t) 0, NULL, 0)) { | 146 if (regexec(pattern, argv[2], (size_t) 0, NULL, 0)) { |
143 fprintf(stderr, "bad vmname for define\n"); | 147 fprintf(stderr, bad_name); |
144 exit(0); | 148 exit(0); |
145 } | 149 } |
146 if (check_name(argv[2])) { | 150 if (check_name(argv[2])) { |
147 fprintf(stderr, "bad vmname for define\n"); | 151 fprintf(stderr, bad_name); |
148 exit(0); | 152 exit(0); |
149 } | 153 } |
150 char exec[1024]; | 154 char exec[1024]; |
151 strncpy(exec, "/usr/local/bin/newvm.py -c /etc/libvirt/qemu/fedora16.xml -n ",900); | 155 strncpy(exec, "/usr/local/bin/newvm.py -c /etc/libvirt/qemu/fedora16.xml -n ",900); |
152 strncat(exec, argv[2],1000); | 156 strncat(exec, argv[2],1000); |
163 if (argc>=3) { | 167 if (argc>=3) { |
164 if ( strncmp(argv[1], "define", 6) == 0 ) { | 168 if ( strncmp(argv[1], "define", 6) == 0 ) { |
165 strncpy(name_xml,argv[2],900); | 169 strncpy(name_xml,argv[2],900); |
166 strncat(name_xml,".xml",1000); | 170 strncat(name_xml,".xml",1000); |
167 } else if (check_vmlist_name(vmlist, argv[2])==0) { | 171 } else if (check_vmlist_name(vmlist, argv[2])==0) { |
168 fprintf(stderr, "bad vmname\n"); | 172 fprintf(stderr, bad_name); |
169 print_vmlist(vmlist); | 173 print_vmlist(vmlist); |
170 exit(0); | 174 exit(0); |
171 } | 175 } |
172 } else if (argc<2) { | 176 } else if (argc<2) { |
173 print_vmlist(vmlist); | 177 print_vmlist(vmlist); |
196 } else if ( strncmp(argv[1], "define", 6) == 0 ) { | 200 } else if ( strncmp(argv[1], "define", 6) == 0 ) { |
197 chdir("/etc/libvirt/qemu"); | 201 chdir("/etc/libvirt/qemu"); |
198 if (execl(command, command, define_command, name_xml, NULL) < 0) { | 202 if (execl(command, command, define_command, name_xml, NULL) < 0) { |
199 perror("Execl:"); | 203 perror("Execl:"); |
200 } | 204 } |
205 } else if ( strncmp(argv[1], "undefine", 8) == 0 ) { | |
206 chdir("/etc/libvirt/qemu"); | |
207 if (execl(command, command, undefine_command, argv[2], NULL) < 0) { | |
208 perror("Execl:"); | |
209 } | |
201 } else { | 210 } else { |
202 usage(); | 211 usage(); |
203 exit(1); | 212 exit(1); |
204 } | 213 } |
205 exit(0); | 214 exit(0); |