3
3
low-level perspective of service states and relation states.
6
from collections import namedtuple
9
class RelationEndpoint(
10
# This idiom allows for the efficient and simple construction of
11
# value types based on tuples; notably __eq__ and __hash__ are
12
# correctly defined for value types. In addition, the storage
13
# overhead is that of an ordinary tuple (although not so important
14
# for this usage). See urlib/parse.py in Python 3.x for other
18
"service_name relation_type relation_name relation_role subordinate")):
11
class RelationEndpoint(object):
12
def __init__(self, service_name,
16
relation_scope=GLOBAL):
17
self.service_name = service_name
18
self.relation_type = relation_type
19
self.relation_name = relation_name
20
self.relation_role = relation_role
21
self.relation_scope = relation_scope
24
return (self.service_name,
30
return hash(self._tuple())
32
def __cmp__(self, other):
33
if not isinstance(other, RelationEndpoint):
34
raise TypeError("Expected RelationEndpoint, got %s" %
36
return cmp(self._tuple(), other._tuple())
22
38
def may_relate_to(self, other):
23
39
"""Test whether the `other` endpoint may be used in a common relation.