Instead of returning a python stacktrace, check what the current euid is
and show an argparse error message similar to that used in lxc-start-ephemeral.
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
import argparse
import gettext
import lxc
+import os
import sys
_ = gettext.gettext
args = parser.parse_args()
+# The user needs to be uid 0
+if not os.geteuid() == 0:
+ parser.error(_("You must be root to run this script. Try running: sudo %s"
+ % (sys.argv[0])))
+
container = lxc.Container(args.container)
if not container.running:
print("The container must be running.")