Feature 10886 manual scaling for KNF (helm chart) deployment
[osm/N2VC.git] / n2vc / definitions.py
1 # Copyright 2021 Canonical Ltd.
2 #
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
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,
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.
14
15 from typing import NoReturn
16
17 from n2vc.utils import get_ee_id_components
18
19
20 class RelationEndpoint:
21 """Represents an endpoint of an application"""
22
23 def __init__(self, ee_id: str, vca_id: str, endpoint_name: str) -> NoReturn:
24 """
25 Args:
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
31 """
32 ee_components = get_ee_id_components(ee_id)
33 self._model_name = ee_components[0]
34 self._application_name = ee_components[1]
35 self._vca_id = vca_id
36 self._endpoint_name = endpoint_name
37
38 @property
39 def application_name(self) -> str:
40 """Returns the application name"""
41 return self._application_name
42
43 @property
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}"
47
48 @property
49 def endpoint_name(self) -> str:
50 """Returns the endpoint name"""
51 return self._endpoint_name
52
53 @property
54 def model_name(self) -> str:
55 """Returns the model name"""
56 return self._model_name
57
58 @property
59 def vca_id(self) -> str:
60 """Returns the vca id"""
61 return self._vca_id
62
63 def __str__(self) -> str:
64 app = self.application_name
65 endpoint = self.endpoint_name
66 model = self.model_name
67 vca = self.vca_id
68 return f"{app}:{endpoint} (model: {model}, vca: {vca})"
69
70
71 class Offer:
72 """Represents a juju offer"""
73
74 def __init__(self, url: str, vca_id: str = None) -> NoReturn:
75 """
76 Args:
77 url: Offer url. Format: <user>/<model>.<offer-name>.
78 """
79 self._url = url
80 self._username = url.split(".")[0].split("/")[0]
81 self._model_name = url.split(".")[0].split("/")[1]
82 self._name = url.split(".")[1]
83 self._vca_id = vca_id
84
85 @property
86 def model_name(self) -> str:
87 """Returns the model name"""
88 return self._model_name
89
90 @property
91 def name(self) -> str:
92 """Returns the offer name"""
93 return self._name
94
95 @property
96 def username(self) -> str:
97 """Returns the username"""
98 return self._username
99
100 @property
101 def url(self) -> str:
102 """Returns the offer url"""
103 return self._url
104
105 @property
106 def vca_id(self) -> str:
107 """Returns the vca id"""
108 return self._vca_id