This file is indexed.

/usr/lib/python2.7/dist-packages/os_xenapi/dom0/etc/xapi.d/plugins/netwrap.py is in python-os-xenapi 0.3.1-0ubuntu1.

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

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
#!/usr/bin/env python

# Copyright 2012 OpenStack Foundation
# Copyright 2012 United States Government as represented by the
# Administrator of the National Aeronautics and Space Administration.
# All Rights Reserved.
#
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.

#
# XenAPI plugin for executing network commands (ovs, iptables, etc) on dom0
#

import gettext
gettext.install('neutron', unicode=1)
try:
    import json
except ImportError:
    import simplejson as json
import subprocess

import XenAPIPlugin


ALLOWED_CMDS = [
    'ip',
    'ipset',
    'iptables-save',
    'iptables-restore',
    'ip6tables-save',
    'ip6tables-restore',
    'sysctl',
    # NOTE(yamamoto): of_interface=native doesn't use ovs-ofctl
    'ovs-ofctl',
    'ovs-vsctl',
    'ovsdb-client',
    'conntrack',
    ]


class PluginError(Exception):
    """Base Exception class for all plugin errors."""
    def __init__(self, *args):
        Exception.__init__(self, *args)


def _run_command(cmd, cmd_input):
    """Abstracts out the basics of issuing system commands.

    If the command returns anything in stderr, a PluginError is raised with
    that information. Otherwise, the output from stdout is returned
    """
    pipe = subprocess.PIPE
    proc = subprocess.Popen(cmd, shell=False, stdin=pipe, stdout=pipe,
                            stderr=pipe, close_fds=True)
    (out, err) = proc.communicate(cmd_input)
    return proc.returncode, out, err


def run_command(session, args):
    cmd = json.loads(args.get('cmd'))
    if cmd and cmd[0] not in ALLOWED_CMDS:
        msg = _("Dom0 execution of '%s' is not permitted") % cmd[0]
        raise PluginError(msg)
    returncode, out, err = _run_command(
        cmd, json.loads(args.get('cmd_input', 'null')))
    if not err:
        err = ""
    if not out:
        out = ""
    # This runs in Dom0, will return to neutron-ovs-agent in compute node
    result = {'returncode': returncode,
              'out': out,
              'err': err}
    return json.dumps(result)


if __name__ == "__main__":
    XenAPIPlugin.dispatch({"run_command": run_command})