This file is indexed.

/usr/lib/python3/dist-packages/provisioningserver/support_dump.py is in python3-maas-provisioningserver 2.0.0~beta3+bzr4941-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
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# Copyright 2016 Canonical Ltd.  This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).

"""MAAS rack controller support dump commands."""

__all__ = [
    'add_arguments',
    'run',
]

from functools import lru_cache
import json
import os
from pprint import pprint
import traceback

from provisioningserver.boot.tftppath import (
    get_image_metadata,
    list_boot_images,
)
from provisioningserver.config import ClusterConfiguration
from provisioningserver.networks import get_interfaces_definition
from provisioningserver.utils.ipaddr import get_ip_addr
from provisioningserver.utils.iproute import get_ip_route


all_arguments = (
    '--networking',
    '--config',
    '--images'
)


def add_arguments(parser):
    """Add this command's options to the `ArgumentParser`.

    Specified by the `ActionScript` interface.
    """
    parser.description = run.__doc__
    parser.add_argument(
        '--networking', action='store_true', required=False,
        help='Dump networking information.')
    parser.add_argument(
        '--config', action='store_true', required=False,
        help='Dump configuration information.')
    parser.add_argument(
        '--images', action='store_true', required=False,
        help='Dump boot image information.')


@lru_cache(1)
def get_cluster_configuration():
    config_dict = {}
    try:
        with ClusterConfiguration.open() as configuration:
            for var in vars(ClusterConfiguration):
                if not var.startswith('_'):
                    config_dict[var] = getattr(configuration, var)
    except:
        print("Warning: Could not load cluster configuration.")
        print("(some data may not be accurate)")
        print()
    return config_dict


# The following lists define the functions and/or commands that will be run
# during each phase of the support dump.
NETWORKING_DUMP = [
    {
        "function": get_ip_addr
    },
    {
        "function": get_ip_route
    },
    {
        "title": "get_interfaces_definition()",
        "function": lambda: get_interfaces_definition()[0]
    },
]

CONFIG_DUMP = [
    {
        "function": get_cluster_configuration
    }
]

IMAGES_DUMP = [
    {
        "function": list_boot_images
    },
    {
        "title": "get_image_metadata()",
        "function": lambda *args: json.loads(get_image_metadata(*args))
    },
    {
        "command": "/usr/sbin/tgt-admin --show"
    }
]


def _dump(item, *args, **kwargs):
    if "function" in item:
        function = item['function']
        title = item['title'] if 'title' in item else function.__name__ + "()"
        print("### %s ###" % title)
        try:
            pprint(function(*args, **kwargs))
        except Exception:
            print(traceback.format_exc())
        print()
    if "command" in item:
        print("### %s ###" % item['command'])
        os.system("%s 2>&1" % item['command'])
        print()


def run(args):
    """Dump support information. By default, dumps everything available."""
    params = vars(args).copy()
    networking = params.pop('networking', False)
    config = params.pop('config', False)
    images = params.pop('images', False)

    config_dict = get_cluster_configuration()

    complete = False
    if not networking and not images and not config:
        complete = True

    if complete or networking:
        for item in NETWORKING_DUMP:
            _dump(item)

    if complete or config:
        for item in CONFIG_DUMP:
            _dump(item)

    if complete or images:
        for item in IMAGES_DUMP:
            _dump(item, config_dict['tftp_root'])