/usr/share/pyshared/juju/state/endpoint.py is in juju-0.7 0.7-0ubuntu2.
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 | """
This module supports a user-level view of the topology, instead of the
low-level perspective of service states and relation states.
"""
from collections import namedtuple
class RelationEndpoint(
# This idiom allows for the efficient and simple construction of
# value types based on tuples; notably __eq__ and __hash__ are
# correctly defined for value types. In addition, the storage
# overhead is that of an ordinary tuple (although not so important
# for this usage). See urlib/parse.py in Python 3.x for other
# examples.
namedtuple(
"RelationEndpoint",
("service_name", "relation_type", "relation_name", "relation_role",
"relation_scope"))):
__slots__ = ()
def __new__(cls, service_name, relation_type, relation_name, relation_role,
relation_scope="global"):
return super(cls, RelationEndpoint).__new__(
cls, service_name, relation_type, relation_name, relation_role,
relation_scope)
def may_relate_to(self, other):
"""Test whether the `other` endpoint may be used in a common relation.
RelationEndpoints may be related if they share the same relation_type
(which is called an "interface" in charms) and one is a ``provides``
and the other is a ``requires``; or if both endpoints have a
relation_role of ``peers``.
Raises a `TypeError` is `other` is not a `RelationEndpoint`.
"""
if not isinstance(other, RelationEndpoint):
raise TypeError("Not a RelationEndpoint", other)
return (self.relation_type == other.relation_type and
((self.relation_role == "server" and
other.relation_role == "client") or
(self.relation_role == "client" and
other.relation_role == "server") or
(self.relation_role == "peer" and
other.relation_role == "peer")))
|