blob: e8cf64dac123207f6023ca18ac035ebe9f1840e0 [file] [log] [blame]
David Garcia4fee80e2020-05-13 12:18:38 +02001# Copyright 2020 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
15from enum import Enum
16from juju.machine import Machine
17from juju.application import Application
18from juju.action import Action
19from juju.unit import Unit
20
21
22class N2VCDeploymentStatus(Enum):
23 PENDING = "pending"
24 RUNNING = "running"
25 COMPLETED = "completed"
26 FAILED = "failed"
27 UNKNOWN = "unknown"
28
29
30class Dict(dict):
31 """
32 Dict class that allows to access the keys like attributes
33 """
34
35 def __getattribute__(self, name):
36 if name in self:
37 return self[name]
38
39
40class EntityType(Enum):
41 MACHINE = Machine
42 APPLICATION = Application
43 ACTION = Action
44 UNIT = Unit
45
46 @classmethod
47 def has_value(cls, value):
48 return value in cls._value2member_map_ # pylint: disable=E1101
49
50 @classmethod
51 def get_entity(cls, value):
52 return (
53 cls._value2member_map_[value] # pylint: disable=E1101
54 if value in cls._value2member_map_ # pylint: disable=E1101
55 else None # pylint: disable=E1101
56 )
57
58 @classmethod
59 def get_entity_from_delta(cls, delta_entity: str):
60 """
61 Get Value from delta entity
62
63 :param: delta_entity: Possible values are "machine", "application", "unit", "action"
64 """
65 for v in cls._value2member_map_: # pylint: disable=E1101
66 if v.__name__.lower() == delta_entity:
67 return cls.get_entity(v)
68
69
David Garcia4fee80e2020-05-13 12:18:38 +020070JujuStatusToOSM = {
David Garciac38a6962020-09-16 13:31:33 +020071 "machine": {
David Garcia4fee80e2020-05-13 12:18:38 +020072 "pending": N2VCDeploymentStatus.PENDING,
73 "started": N2VCDeploymentStatus.COMPLETED,
74 },
David Garciac38a6962020-09-16 13:31:33 +020075 "application": {
David Garcia4fee80e2020-05-13 12:18:38 +020076 "waiting": N2VCDeploymentStatus.RUNNING,
77 "maintenance": N2VCDeploymentStatus.RUNNING,
78 "blocked": N2VCDeploymentStatus.RUNNING,
79 "error": N2VCDeploymentStatus.FAILED,
80 "active": N2VCDeploymentStatus.COMPLETED,
81 },
David Garciac38a6962020-09-16 13:31:33 +020082 "action": {
David Garcia2f66c4d2020-06-19 11:40:18 +020083 "pending": N2VCDeploymentStatus.PENDING,
David Garcia4fee80e2020-05-13 12:18:38 +020084 "running": N2VCDeploymentStatus.RUNNING,
85 "completed": N2VCDeploymentStatus.COMPLETED,
86 },
David Garciac38a6962020-09-16 13:31:33 +020087 "unit": {
David Garcia4fee80e2020-05-13 12:18:38 +020088 "waiting": N2VCDeploymentStatus.RUNNING,
89 "maintenance": N2VCDeploymentStatus.RUNNING,
90 "blocked": N2VCDeploymentStatus.RUNNING,
91 "error": N2VCDeploymentStatus.FAILED,
92 "active": N2VCDeploymentStatus.COMPLETED,
93 },
94}
David Garcia2f66c4d2020-06-19 11:40:18 +020095
96DB_DATA = Dict(
97 {
98 "api_endpoints": Dict(
99 {"table": "admin", "filter": {"_id": "juju"}, "key": "api_endpoints"}
100 )
101 }
102)