/usr/lib/python3/dist-packages/provisioningserver/service_monitor.py is in python3-maas-provisioningserver 2.4.0~beta2-6865-gec43e47e6-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 | # Copyright 2015-2016 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
"""Services monitored on rackd."""
__all__ = [
]
from provisioningserver.rpc import getRegionClient
from provisioningserver.rpc.exceptions import NoConnectionsAvailable
from provisioningserver.rpc.region import GetControllerType
from provisioningserver.utils.service_monitor import (
Service,
SERVICE_STATE,
ServiceMonitor,
)
class DHCPService(Service):
"""Abstract monitored dhcp service."""
def __init__(self):
super(DHCPService, self).__init__()
self.expected_state = SERVICE_STATE.OFF
def getExpectedState(self):
"""Return a the expected state for the dhcp service.
The dhcp service always starts as off. Once the rackd starts dhcp
`expected_state` will be set to ON.
"""
return (self.expected_state, None)
def is_on(self):
"""Return true if the service should be on."""
return self.expected_state == SERVICE_STATE.ON
def on(self):
"""Set the expected state of the service to `ON`."""
self.expected_state = SERVICE_STATE.ON
def off(self):
"""Set the expected state of the service to `OFF`."""
self.expected_state = SERVICE_STATE.OFF
class DHCPv4Service(DHCPService):
name = "dhcpd"
service_name = "maas-dhcpd"
snap_service_name = "dhcpd"
class DHCPv6Service(DHCPService):
name = "dhcpd6"
service_name = "maas-dhcpd6"
snap_service_name = "dhcpd6"
class NTPServiceOnRack(Service):
"""Monitored NTP service on a rack controller host."""
name = "ntp_rack"
service_name = "chrony"
snap_service_name = "ntp"
def getExpectedState(self):
try:
client = getRegionClient()
except NoConnectionsAvailable:
return SERVICE_STATE.ANY, None
else:
d = client(GetControllerType, system_id=client.localIdent)
d.addCallback(self._getExpectedStateForControllerType)
return d
def _getExpectedStateForControllerType(self, controller_type):
if controller_type["is_rack"]:
if controller_type["is_region"]:
return SERVICE_STATE.ANY, "managed by the region."
else:
return SERVICE_STATE.ON, None
else:
return SERVICE_STATE.ANY, None
# Global service monitor for rackd. NOTE that changes to this need to be
# mirrored in maasserver.model.services.
service_monitor = ServiceMonitor(
DHCPv4Service(),
DHCPv6Service(),
NTPServiceOnRack(),
)
|