1 # Copyright 2020 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.
16 from juju
.machine
import Machine
17 from juju
.application
import Application
18 from juju
.action
import Action
19 from juju
.unit
import Unit
22 class N2VCDeploymentStatus(Enum
):
25 COMPLETED
= "completed"
32 Dict class that allows to access the keys like attributes
35 def __getattribute__(self
, name
):
40 class EntityType(Enum
):
42 APPLICATION
= Application
47 def has_value(cls
, value
):
48 return value
in cls
._value
2member
_map
_ # pylint: disable=E1101
51 def get_entity(cls
, value
):
53 cls
._value
2member
_map
_[value
] # pylint: disable=E1101
54 if value
in cls
._value
2member
_map
_ # pylint: disable=E1101
55 else None # pylint: disable=E1101
59 def get_entity_from_delta(cls
, delta_entity
: str):
61 Get Value from delta entity
63 :param: delta_entity: Possible values are "machine", "application", "unit", "action"
65 for v
in cls
._value
2member
_map
_: # pylint: disable=E1101
66 if v
.__name
__.lower() == delta_entity
:
67 return cls
.get_entity(v
)
72 EntityType
.MACHINE
: Dict({"field": "agent_status", "status": ["started"]}),
73 EntityType
.APPLICATION
: Dict(
74 {"field": "status", "status": ["active", "blocked"]}
76 EntityType
.ACTION
: Dict(
77 {"field": "status", "status": ["completed", "failed", "cancelled"]}
84 "pending": N2VCDeploymentStatus
.PENDING
,
85 "started": N2VCDeploymentStatus
.COMPLETED
,
87 EntityType
.APPLICATION
: {
88 "waiting": N2VCDeploymentStatus
.RUNNING
,
89 "maintenance": N2VCDeploymentStatus
.RUNNING
,
90 "blocked": N2VCDeploymentStatus
.RUNNING
,
91 "error": N2VCDeploymentStatus
.FAILED
,
92 "active": N2VCDeploymentStatus
.COMPLETED
,
95 "pending": N2VCDeploymentStatus
.PENDING
,
96 "running": N2VCDeploymentStatus
.RUNNING
,
97 "completed": N2VCDeploymentStatus
.COMPLETED
,
100 "waiting": N2VCDeploymentStatus
.RUNNING
,
101 "maintenance": N2VCDeploymentStatus
.RUNNING
,
102 "blocked": N2VCDeploymentStatus
.RUNNING
,
103 "error": N2VCDeploymentStatus
.FAILED
,
104 "active": N2VCDeploymentStatus
.COMPLETED
,
110 "api_endpoints": Dict(
111 {"table": "admin", "filter": {"_id": "juju"}, "key": "api_endpoints"}