This file is indexed.

/usr/lib/python3/dist-packages/provisioningserver/drivers/power/moonshot.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
# Copyright 2015 Canonical Ltd.  This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).

"""Moonshot IPMI Power Driver."""

__all__ = []


from provisioningserver.drivers.power import (
    PowerActionError,
    PowerDriver,
)
from provisioningserver.utils import shell
from provisioningserver.utils.shell import (
    call_and_check,
    ExternalProcessError,
    select_c_utf8_locale,
)


class MoonshotIPMIPowerDriver(PowerDriver):

    name = 'moonshot'
    description = "Moonshot IPMI Power Driver."
    settings = []

    def detect_missing_packages(self):
        if not shell.has_command_available('ipmipower'):
            return ['freeipmi-tools']
        return []

    def _issue_ipmitool_command(
            self, power_change, power_hwaddress=None, power_address=None,
            power_user=None, power_pass=None, ipmitool=None, **extra):
        command = (
            ipmitool, '-I', 'lanplus', '-H', power_address, '-U', power_user,
            '-P', power_pass, power_hwaddress, 'power', power_change
        )
        try:
            output = call_and_check(command, env=select_c_utf8_locale())
            output = output.decode('utf-8')
        except ExternalProcessError as e:
            raise PowerActionError(
                "Failed to power %s %s: %s" % (
                    power_change, power_hwaddress, e.output_as_unicode))
        else:
            if 'on' in output:
                return 'on'
            elif 'off' in output:
                return 'off'
            else:
                raise PowerActionError(
                    "Got unknown power state from ipmipower: %s" % output)

    def power_on(self, system_id, context):
        self._issue_ipmitool_command('on', **context)

    def power_off(self, system_id, context):
        self._issue_ipmitool_command('off', **context)

    def power_query(self, system_id, context):
        return self._issue_ipmitool_command('status', **context)