|
2 | 2 | from __future__ import absolute_import
|
3 | 3 |
|
4 | 4 | import subprocess
|
5 |
| -from typing import List, Text |
| 5 | +from typing import List, Text, Tuple |
6 | 6 |
|
7 | 7 |
|
8 |
| -def docker_vm_uid(): # type: () -> int |
| 8 | +def docker_vm_id(): # type: () -> Tuple[int, int] |
9 | 9 | """
|
10 |
| - Returns the UID of the default docker user inside the VM |
| 10 | + Returns the User ID and Group ID of the default docker user inside the VM |
11 | 11 |
|
12 | 12 | When a host is using boot2docker or docker-machine to run docker with
|
13 | 13 | boot2docker.iso (As on Mac OS X), the UID that mounts the shared filesystem
|
14 | 14 | inside the VirtualBox VM is likely different than the user's UID on the host.
|
15 |
| - :return: The numeric UID (as a string) of the docker account inside |
| 15 | + :return: A tuple containing numeric User ID and Group ID of the docker account inside |
16 | 16 | the boot2docker VM
|
17 | 17 | """
|
18 | 18 | if boot2docker_running():
|
19 |
| - return boot2docker_uid() |
| 19 | + return boot2docker_id() |
20 | 20 | elif docker_machine_running():
|
21 |
| - return docker_machine_uid() |
| 21 | + return docker_machine_id() |
22 | 22 | else:
|
23 |
| - return None |
| 23 | + return (None, None) |
24 | 24 |
|
25 | 25 |
|
26 | 26 | def check_output_and_strip(cmd): # type: (List[Text]) -> Text
|
@@ -95,23 +95,26 @@ def cmd_output_to_int(cmd): # type: (List[Text]) -> int
|
95 | 95 | return None
|
96 | 96 |
|
97 | 97 |
|
98 |
| -def boot2docker_uid(): # type: () -> int |
| 98 | +def boot2docker_id(): # type: () -> Tuple[int, int] |
99 | 99 | """
|
100 |
| - Gets the UID of the docker user inside a running boot2docker vm |
101 |
| - :return: the UID, or None if error (e.g. boot2docker not present or stopped) |
| 100 | + Gets the UID and GID of the docker user inside a running boot2docker vm |
| 101 | + :return: Tuple (UID, GID), or (None, None) if error (e.g. boot2docker not present or stopped) |
102 | 102 | """
|
103 |
| - return cmd_output_to_int(['boot2docker', 'ssh', 'id', '-u']) |
104 |
| - |
| 103 | + uid = cmd_output_to_int(['boot2docker', 'ssh', 'id', '-u']) |
| 104 | + gid = cmd_output_to_int(['boot2docker', 'ssh', 'id', '-g']) |
| 105 | + return (uid, gid) |
105 | 106 |
|
106 |
| -def docker_machine_uid(): # type: () -> int |
| 107 | +def docker_machine_id(): # type: () -> Tuple[int, int] |
107 | 108 | """
|
108 | 109 | Asks docker-machine for active machine and gets the UID of the docker user
|
109 | 110 | inside the vm
|
110 |
| - :return: the UID, or None if error (e.g. docker-machine not present or stopped) |
| 111 | + :return: tuple (UID, GID), or (None, None) if error (e.g. docker-machine not present or stopped) |
111 | 112 | """
|
112 | 113 | machine_name = docker_machine_name()
|
113 |
| - return cmd_output_to_int(['docker-machine', 'ssh', machine_name, "id -u"]) |
| 114 | + uid = cmd_output_to_int(['docker-machine', 'ssh', machine_name, "id -u"]) |
| 115 | + gid = cmd_output_to_int(['docker-machine', 'ssh', machine_name, "id -g"]) |
| 116 | + return (uid, gid) |
114 | 117 |
|
115 | 118 |
|
116 | 119 | if __name__ == '__main__':
|
117 |
| - print(docker_vm_uid()) |
| 120 | + print(docker_vm_id()) |
0 commit comments