n2vc/config.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 |
1 |
MODEL_CONFIG_KEYS = [ |
16 |
|
"agent-metadata-url", |
17 |
|
"agent-stream", |
18 |
|
"apt-ftp-proxy", |
19 |
|
"apt-http-proxy", |
20 |
|
"apt-https-proxy", |
21 |
|
"apt-mirror", |
22 |
|
"apt-no-proxy", |
23 |
|
"automatically-retry-hooks", |
24 |
|
"backup-dir", |
25 |
|
"cloudinit-userdata", |
26 |
|
"container-image-metadata-url", |
27 |
|
"container-image-stream", |
28 |
|
"container-inherit-properties", |
29 |
|
"container-networking-method", |
30 |
|
"default-series", |
31 |
|
"default-space", |
32 |
|
"development", |
33 |
|
"disable-network-management", |
34 |
|
"egress-subnets", |
35 |
|
"enable-os-refresh-update", |
36 |
|
"enable-os-upgrade", |
37 |
|
"fan-config", |
38 |
|
"firewall-mode", |
39 |
|
"ftp-proxy", |
40 |
|
"http-proxy", |
41 |
|
"https-proxy", |
42 |
|
"ignore-machine-addresses", |
43 |
|
"image-metadata-url", |
44 |
|
"image-stream", |
45 |
|
"juju-ftp-proxy", |
46 |
|
"juju-http-proxy", |
47 |
|
"juju-https-proxy", |
48 |
|
"juju-no-proxy", |
49 |
|
"logforward-enabled", |
50 |
|
"logging-config", |
51 |
|
"lxd-snap-channel", |
52 |
|
"max-action-results-age", |
53 |
|
"max-action-results-size", |
54 |
|
"max-status-history-age", |
55 |
|
"max-status-history-size", |
56 |
|
"net-bond-reconfigure-delay", |
57 |
|
"no-proxy", |
58 |
|
"provisioner-harvest-mode", |
59 |
|
"proxy-ssh", |
60 |
|
"snap-http-proxy", |
61 |
|
"snap-https-proxy", |
62 |
|
"snap-store-assertions", |
63 |
|
"snap-store-proxy", |
64 |
|
"snap-store-proxy-url", |
65 |
|
"ssl-hostname-verification", |
66 |
|
"test-mode", |
67 |
|
"transmit-vendor-metrics", |
68 |
|
"update-status-hook-interval", |
69 |
|
] |
70 |
|
|
71 |
|
|
72 |
1 |
class ModelConfig(dict): |
73 |
1 |
prefix = "model_config_" |
74 |
|
|
75 |
1 |
def __init__(self, config: dict): |
76 |
1 |
for key, value in config.items(): |
77 |
1 |
if ( |
78 |
|
key.startswith(self.prefix) |
79 |
|
and self._get_renamed_key(key) in MODEL_CONFIG_KEYS |
80 |
|
): |
81 |
0 |
self.__setitem__(self._get_renamed_key(key), value) |
82 |
|
|
83 |
1 |
def _get_renamed_key(self, key): |
84 |
0 |
return key.replace(self.prefix, "").replace("_", "-") |