Last change
on this file since 1165 was
1163,
checked in by broder, 16 years ago
|
There's a race condition for if the VM gets powered off between the
listvms and the actual request. Solve the problem correctly by using a
non-conflicting error code to indicate an invalid command
|
-
Property svn:executable set to
*
|
File size:
1.3 KB
|
Rev | Line | |
---|
[625] | 1 | #!/usr/bin/python |
---|
| 2 | """ |
---|
| 3 | Sends remctl commands about a running VM to the host it's running on. |
---|
| 4 | """ |
---|
| 5 | |
---|
| 6 | from subprocess import PIPE, Popen, call |
---|
| 7 | import sys |
---|
| 8 | import yaml |
---|
| 9 | |
---|
| 10 | def main(argv): |
---|
| 11 | if len(argv) < 3: |
---|
| 12 | print >>sys.stderr, "usage: sipb-xen-remote-control <machine> <command>" |
---|
| 13 | return 2 |
---|
| 14 | machine_name = argv[1] |
---|
| 15 | command = argv[2] |
---|
| 16 | |
---|
| 17 | p = Popen(['/usr/sbin/sipb-xen-remote-proxy-web', 'listvms'], stdout=PIPE) |
---|
| 18 | output = p.communicate()[0] |
---|
| 19 | if p.returncode != 0: |
---|
| 20 | raise RuntimeError("Command '%s' returned non-zero exit status %d" |
---|
| 21 | % ('sipb-xen-remote-proxy-web', p.returncode)) |
---|
| 22 | vms = yaml.load(output, yaml.CSafeLoader) |
---|
| 23 | |
---|
| 24 | if machine_name not in vms: |
---|
| 25 | print >>sys.stderr, "machine '%s' is not on" % machine_name |
---|
[721] | 26 | return 1 |
---|
[625] | 27 | host = vms[machine_name]['host'] |
---|
| 28 | |
---|
[721] | 29 | p = Popen(['remctl', host, 'remote', 'control'] + argv[1:], |
---|
| 30 | stdout=PIPE, stderr=PIPE) |
---|
| 31 | (out, err) = p.communicate() |
---|
| 32 | if p.returncode == 1: |
---|
[1163] | 33 | print >>sys.stderr, "machine '%s' is not on" % machine_name |
---|
| 34 | return 1 |
---|
| 35 | elif p.returncode == 34: |
---|
[1159] | 36 | print >>sys.stderr, "ERROR: invalid command" |
---|
[1163] | 37 | return 34 |
---|
[721] | 38 | sys.stderr.write(err) |
---|
| 39 | sys.stdout.write(out) |
---|
| 40 | return p.returncode |
---|
[625] | 41 | |
---|
| 42 | if __name__ == '__main__': |
---|
| 43 | sys.exit(main(sys.argv)) |
---|
| 44 | |
---|
| 45 | # vim:et:sw=4:ts=4 |
---|
Note: See
TracBrowser
for help on using the repository browser.