This file is indexed.

/usr/bin/lxc-device is in lxc 1.0.3-0ubuntu3.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/python3
#
# lxc-device: Add devices to a running container
#
# This python implementation is based on the work done in the original
# shell implementation done by Serge Hallyn in Ubuntu (and other contributors)
#
# (C) Copyright Canonical Ltd. 2012
#
# Authors:
# Stéphane Graber <stgraber@ubuntu.com>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#

import argparse
import gettext
import lxc
import os

_ = gettext.gettext
gettext.textdomain("lxc-device")

# Begin parsing the command line
parser = argparse.ArgumentParser(description=_("LXC: Manage devices"),
                                 formatter_class=argparse.RawTextHelpFormatter)

# Global arguments
parser.add_argument("-n", dest="container", metavar="CONTAINER",
                    help=_("Name of the container to add the device to"),
                    required=True)

parser.add_argument("-P", "--lxcpath", dest="lxcpath", metavar="PATH",
                    help=_("Use specified container path"), default=None)

# Commands
subparsers = parser.add_subparsers()
subparser_add = subparsers.add_parser('add', help=_('Add a device'))
subparser_add.set_defaults(action="add")

subparser_add.add_argument(dest="device", metavar="DEVICE",
                           help=_("Add a device "
                                  "(path to a node or interface name)"))

subparser_add.add_argument(dest="name", metavar="NAME", nargs="?",
                           help=_("Use an alternative path or name "
                                  "in the container"))

args = parser.parse_args()

# Some basic checks
## Check for valid action
if not hasattr(args, "action"):
    parser.error(_("You must specify an action."))

## Don't rename if no alternative name
if not args.name:
    args.name = args.device

## Check that the container is ready
container = lxc.Container(args.container, args.lxcpath)

## Check that we have control over the container
if not container.controllable:
    parser.error("Insufficent privileges to control: %s" % container.name)

## Check that the container is running
if not container.running:
    parser.error("The container must be running.")

# Do the work
if args.action == "add":
    if os.path.exists("/sys/class/net/%s/" % args.device):
        ret = container.add_device_net(args.device, args.name)
    else:
        ret = container.add_device_node(args.device, args.name)

    if ret:
        print("Added '%s' to '%s' as '%s'." %
              (args.device, container.name, args.name))
    else:
        print("Failed to add '%s' to '%s' as '%s'." %
              (args.device, container.name, args.name))