blob: 402528f084e97aaaca598b00e30947a47076f38b [file] [log] [blame]
Joshua Hesketh352264b2015-08-11 23:42:08 +10001# Copyright 2014 Rackspace Australia
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may
4# not use this file except in compliance with the License. You may obtain
5# a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations
13# under the License.
14
15import abc
16
17import six
18
19
20@six.add_metaclass(abc.ABCMeta)
21class BaseConnection(object):
22 """Base class for connections.
23
24 A connection is a shared object that sources, triggers and reporters can
25 use to speak with a remote API without needing to establish a new
26 connection each time or without having to authenticate each time.
27
28 Multiple instances of the same connection may exist with different
29 credentials, for example, thus allowing for different pipelines to operate
30 on different Gerrit installations or post back as a different user etc.
31
32 Connections can implement their own public methods. Required connection
33 methods are validated by the {trigger, source, reporter} they are loaded
34 into. For example, a trigger will likely require some kind of query method
35 while a reporter may need a review method."""
36
37 def __init__(self, connection_name, connection_config):
38 # connection_name is the name given to this connection in zuul.ini
39 # connection_config is a dictionary of config_section from zuul.ini for
40 # this connection.
41 # __init__ shouldn't make the actual connection in case this connection
42 # isn't used in the layout.
43 self.connection_name = connection_name
44 self.connection_config = connection_config
45
Joshua Hesketh811e2e92015-12-08 09:55:05 +110046 # Keep track of the sources, triggers and reporters using this
47 # connection
48 self.attached_to = {
49 'source': [],
50 'trigger': [],
51 'reporter': [],
52 }
53
Joshua Hesketh352264b2015-08-11 23:42:08 +100054 def onLoad(self):
55 pass
56
57 def onStop(self):
58 pass
59
60 def registerScheduler(self, sched):
61 self.sched = sched
Joshua Hesketh811e2e92015-12-08 09:55:05 +110062
63 def registerUse(self, what, instance):
64 self.attached_to[what].append(instance)