Skip to content

Commit

Permalink
Small fixes for virsh integration
Browse files Browse the repository at this point in the history
  • Loading branch information
xlevus committed Dec 27, 2017
1 parent 07ec844 commit c91bf5e
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions virshpatcher/main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env python
from __future__ import print_function

import os
import sys
Expand Down Expand Up @@ -33,7 +34,6 @@
dest='patch',
const='virshpatcher.patcher.PatchHostPassthrough')


parser.add_argument(
'--patch', '-p',
help='`XMLPatcher` class path',
Expand All @@ -46,6 +46,11 @@
action='store_true',
default=False)


def err(*args, **kwargs):
print(*args, file=sys.stderr, **kwargs)


def load(module):
modname, klass = module.rsplit('.', 1)
x = importlib.__import__(modname, fromlist=[klass])
Expand All @@ -67,13 +72,13 @@ def main():
nargs='?',
metavar='FILE')

args = parser.parse_args(sys.argv[1:])
args, remainder = parser.parse_known_args(sys.argv[1:])
if args.help:
parser.print_help()
exit(1)

if not args.file:
print("No filename or libvirtd domain specified.")
err("No filename or libvirtd domain specified.")
exit(1)

if os.path.exists(args.file):
Expand All @@ -83,11 +88,14 @@ def main():
tree.write(args.file)

else:
os.environ['EDITOR'] = " ".join(sys.argv)
if args.file != sys.argv[-1]:
err("Libvirt domain must be the last argument provided.")

os.environ['EDITOR'] = " ".join(sys.argv[:-1])
cmd = ['virsh', 'edit', args.file]
try:
ret = subprocess.run(cmd, check=True)
except Exception as e:
print("Unable to edit domain {!r}".format(args.file))
print(e)
err("Unable to edit domain {!r}".format(args.file))
err(e)
exit(1)

0 comments on commit c91bf5e

Please sign in to comment.