5 log
= logging
.getLogger(__name__
)
9 def __init__(self
, model
, data
):
14 return '<Endpoint {}:{}>'.format(self
.application
.name
, self
.name
)
17 def application(self
):
18 return self
.model
.applications
[self
.data
['application-name']]
22 return self
.data
['relation']['name']
26 return self
.data
['relation']['interface']
30 return self
.data
['relation']['role']
34 return self
.data
['relation']['scope']
37 class Relation(model
.ModelEntity
):
39 return '<Relation id={} {}>'.format(self
.entity_id
, self
.key
)
43 return [Endpoint(self
.model
, data
)
44 for data
in self
.safe_data
['endpoints']]
49 The endpoint on the provides side of this relation, or None.
51 for endpoint
in self
.endpoints
:
52 if endpoint
.role
== 'provider':
59 The endpoint on the requires side of this relation, or None.
61 for endpoint
in self
.endpoints
:
62 if endpoint
.role
== 'requirer':
69 The peers endpoint of this relation, or None.
71 for endpoint
in self
.endpoints
:
72 if endpoint
.role
== 'peer':
77 def is_subordinate(self
):
78 return any(ep
.scope
== 'container' for ep
in self
.endpoints
)
82 return any(ep
.role
== 'peer' for ep
in self
.endpoints
)
84 def matches(self
, *specs
):
86 Check if this relation matches relationship specs.
88 Relation specs are strings that would be given to Juju to establish a
89 relation, and should be in the form ``<application>[:<endpoint_name>]``
90 where the ``:<endpoint_name>`` suffix is optional. If the suffix is
91 omitted, this relation will match on any endpoint as long as the given
92 application is involved.
94 In other words, this relation will match a spec if that spec could have
95 created this relation.
97 :return: True if all specs match.
101 app_name
, endpoint_name
= spec
.split(':')
103 app_name
, endpoint_name
= spec
, None
104 for endpoint
in self
.endpoints
:
105 if app_name
== endpoint
.application
.name
and \
106 endpoint_name
in (endpoint
.name
, None):
107 # found a match for this spec, so move to next one
110 # no match for this spec
115 def applications(self
):
117 All applications involved in this relation.
119 return [ep
.application
for ep
in self
.endpoints
]
121 async def destroy(self
):
122 raise NotImplementedError()
123 # TODO: destroy a relation