Commit b1eafd4a by Stéphane Graber

lxc-device: Show an error message when non-root

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: 's avatarStéphane Graber <stgraber@ubuntu.com> Acked-by: 's avatarSerge E. Hallyn <serge.hallyn@ubuntu.com>
parent daf04e4c
......@@ -32,6 +32,7 @@ warnings.filterwarnings("ignore", "The python-lxc API isn't yet stable")
import argparse
import gettext
import lxc
import os
import sys
_ = gettext.gettext
......@@ -49,6 +50,11 @@ parser.add_argument("--add", action="append", default=[], metavar="DEVICE",
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.")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment