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.
19 class EnvironConfig(dict):
20 prefixes
= ["OSMLCM_VCA_", "OSMMON_VCA_"]
22 def __init__(self
, prefixes
: typing
.List
[str] = None):
24 self
.prefixes
= prefixes
25 for key
, value
in os
.environ
.items():
26 if any(key
.startswith(prefix
) for prefix
in self
.prefixes
):
27 self
.__setitem
__(self
._get
_renamed
_key
(key
), value
)
29 def _get_renamed_key(self
, key
: str) -> str:
30 for prefix
in self
.prefixes
:
31 key
= key
.replace(prefix
, "")
43 "automatically-retry-hooks",
46 "container-image-metadata-url",
47 "container-image-stream",
48 "container-inherit-properties",
49 "container-networking-method",
53 "disable-network-management",
55 "enable-os-refresh-update",
62 "ignore-machine-addresses",
72 "max-action-results-age",
73 "max-action-results-size",
74 "max-status-history-age",
75 "max-status-history-size",
76 "net-bond-reconfigure-delay",
78 "provisioner-harvest-mode",
82 "snap-store-assertions",
84 "snap-store-proxy-url",
85 "ssl-hostname-verification",
87 "transmit-vendor-metrics",
88 "update-status-hook-interval",
92 class ModelConfig(dict):
93 prefix
= "model_config_"
95 def __init__(self
, config
: dict):
96 for key
, value
in config
.items():
98 key
.startswith(self
.prefix
)
99 and self
._get
_renamed
_key
(key
) in MODEL_CONFIG_KEYS
101 self
.__setitem
__(self
._get
_renamed
_key
(key
), value
)
103 def _get_renamed_key(self
, key
):
104 return key
.replace(self
.prefix
, "").replace("_", "-")