1# This file is part of Buildbot.  Buildbot is free software: you can
2# redistribute it and/or modify it under the terms of the GNU General Public
3# License as published by the Free Software Foundation, version 2.
4#
5# This program is distributed in the hope that it will be useful, but WITHOUT
6# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
7# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
8# details.
9#
10# You should have received a copy of the GNU General Public License along with
11# this program; if not, write to the Free Software Foundation, Inc., 51
12# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
13#
14# Portions Copyright Buildbot Team Members
15
16from twisted.internet import defer
17from zope.interface import implementer
18
19from buildbot import interfaces
20from buildbot.util import service
21
22
23@implementer(interfaces.IMachine)
24class Machine(service.BuildbotService):
25
26    def checkConfig(self, name, **kwargs):
27        super().checkConfig(**kwargs)
28        self.name = name
29        self.workers = []
30
31    @defer.inlineCallbacks
32    def reconfigService(self, name, **kwargs):
33        yield super().reconfigService(**kwargs)
34        assert self.name == name
35
36    def registerWorker(self, worker):
37        assert worker.machine_name == self.name
38        self.workers.append(worker)
39
40    def unregisterWorker(self, worker):
41        assert worker in self.workers
42        self.workers.remove(worker)
43
44    def __repr__(self):
45        return "<Machine '{}' at {}>".format(self.name, id(self))
46