Add lxcid
This commit is contained in:
parent
41156fe424
commit
7c25d22d41
23
usr/bin/lxcid
Executable file
23
usr/bin/lxcid
Executable file
@ -0,0 +1,23 @@
|
||||
#!/usr/bin/python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import argparse
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
parser = argparse.ArgumentParser(description='Print shifted UID / GID of an LXC user')
|
||||
parser.add_argument('--group', '-g', action='store_true', help='Get primary GID')
|
||||
parser.add_argument('container', help='LXC container in which to lookup')
|
||||
parser.add_argument('user', help='User to lookup')
|
||||
|
||||
if len(sys.argv) < 2:
|
||||
parser.print_usage()
|
||||
sys.exit(1)
|
||||
args = parser.parse_args()
|
||||
|
||||
# Check if lxc-ls prints back the container name
|
||||
is_running = subprocess.run(['lxc-ls', '--running', args.container], stdout=subprocess.PIPE, check=True)
|
||||
lxc_command = 'lxc-attach' if is_running else 'lxc-execute'
|
||||
# Run id command inside container
|
||||
id = subprocess.run([lxc_command, args.container, '--', 'id', '-g' if args.group else '-u', args.user], stdout=subprocess.PIPE, check=True)
|
||||
print(int(id.stdout) + 100000)
|
@ -58,7 +58,7 @@ def create_container(container, image):
|
||||
uid = image['uid'] if 'uid' in image else '0'
|
||||
gid = image['gid'] if 'gid' in image else '0'
|
||||
cmd = image['cmd'] if 'cmd' in image else '/bin/sh'
|
||||
cwd = image['cwd'] if 'cwd' in image else '/'
|
||||
cwd = image['cwd'] if 'cwd' in image else '/root'
|
||||
halt = image['halt'] if 'halt' in image else 'SIGINT'
|
||||
# Lease the first unused IP to the container
|
||||
ipv4 = update_hosts_lease(container, True)
|
||||
|
Loading…
Reference in New Issue
Block a user