1 # Copyright 2021 Canonical Ltd.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 from typing
import NoReturn
17 from n2vc
.utils
import get_ee_id_components
20 class RelationEndpoint
:
21 """Represents an endpoint of an application"""
23 def __init__(self
, ee_id
: str, vca_id
: str, endpoint_name
: str) -> NoReturn
:
26 ee_id: Execution environment id.
27 Format: "<model>.<application_name>.<machine_id>".
28 vca_id: Id of the VCA. Identifies the Juju Controller
29 where the application is deployed
30 endpoint_name: Name of the endpoint for the relation
32 ee_components
= get_ee_id_components(ee_id
)
33 self
._model
_name
= ee_components
[0]
34 self
._application
_name
= ee_components
[1]
36 self
._endpoint
_name
= endpoint_name
39 def application_name(self
) -> str:
40 """Returns the application name"""
41 return self
._application
_name
44 def endpoint(self
) -> str:
45 """Returns the application name and the endpoint. Format: <application>:<endpoint>"""
46 return f
"{self.application_name}:{self._endpoint_name}"
49 def endpoint_name(self
) -> str:
50 """Returns the endpoint name"""
51 return self
._endpoint
_name
54 def model_name(self
) -> str:
55 """Returns the model name"""
56 return self
._model
_name
59 def vca_id(self
) -> str:
60 """Returns the vca id"""
63 def __str__(self
) -> str:
64 app
= self
.application_name
65 endpoint
= self
.endpoint_name
66 model
= self
.model_name
68 return f
"{app}:{endpoint} (model: {model}, vca: {vca})"
72 """Represents a juju offer"""
74 def __init__(self
, url
: str, vca_id
: str = None) -> NoReturn
:
77 url: Offer url. Format: <user>/<model>.<offer-name>.
80 self
._username
= url
.split(".")[0].split("/")[0]
81 self
._model
_name
= url
.split(".")[0].split("/")[1]
82 self
._name
= url
.split(".")[1]
86 def model_name(self
) -> str:
87 """Returns the model name"""
88 return self
._model
_name
91 def name(self
) -> str:
92 """Returns the offer name"""
96 def username(self
) -> str:
97 """Returns the username"""
101 def url(self
) -> str:
102 """Returns the offer url"""
106 def vca_id(self
) -> str:
107 """Returns the vca id"""