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.
19 from juju
.machine
import Machine
20 from juju
.application
import Application
21 from juju
.action
import Action
22 from juju
.unit
import Unit
23 from n2vc
.exceptions
import N2VCInvalidCertificate
26 def base64_to_cacert(b64string
):
27 """Convert the base64-encoded string containing the VCA CACERT.
33 cacert
= base64
.b64decode(b64string
).decode("utf-8")
35 cacert
= re
.sub(r
"\\n", r
"\n", cacert
,)
36 except binascii
.Error
as e
:
37 raise N2VCInvalidCertificate(message
="Invalid CA Certificate: {}".format(e
))
42 class N2VCDeploymentStatus(Enum
):
45 COMPLETED
= "completed"
52 Dict class that allows to access the keys like attributes
55 def __getattribute__(self
, name
):
60 class EntityType(Enum
):
62 APPLICATION
= Application
67 def has_value(cls
, value
):
68 return value
in cls
._value
2member
_map
_ # pylint: disable=E1101
71 def get_entity(cls
, value
):
73 cls
._value
2member
_map
_[value
] # pylint: disable=E1101
74 if value
in cls
._value
2member
_map
_ # pylint: disable=E1101
75 else None # pylint: disable=E1101
79 def get_entity_from_delta(cls
, delta_entity
: str):
81 Get Value from delta entity
83 :param: delta_entity: Possible values are "machine", "application", "unit", "action"
85 for v
in cls
._value
2member
_map
_: # pylint: disable=E1101
86 if v
.__name
__.lower() == delta_entity
:
87 return cls
.get_entity(v
)
92 "pending": N2VCDeploymentStatus
.PENDING
,
93 "started": N2VCDeploymentStatus
.COMPLETED
,
96 "waiting": N2VCDeploymentStatus
.RUNNING
,
97 "maintenance": N2VCDeploymentStatus
.RUNNING
,
98 "blocked": N2VCDeploymentStatus
.RUNNING
,
99 "error": N2VCDeploymentStatus
.FAILED
,
100 "active": N2VCDeploymentStatus
.COMPLETED
,
103 "pending": N2VCDeploymentStatus
.PENDING
,
104 "running": N2VCDeploymentStatus
.RUNNING
,
105 "completed": N2VCDeploymentStatus
.COMPLETED
,
108 "waiting": N2VCDeploymentStatus
.RUNNING
,
109 "maintenance": N2VCDeploymentStatus
.RUNNING
,
110 "blocked": N2VCDeploymentStatus
.RUNNING
,
111 "error": N2VCDeploymentStatus
.FAILED
,
112 "active": N2VCDeploymentStatus
.COMPLETED
,
118 "api_endpoints": Dict(
119 {"table": "admin", "filter": {"_id": "juju"}, "key": "api_endpoints"}