X-Git-Url: https://osm.etsi.org/gitweb/?p=osm%2FN2VC.git;a=blobdiff_plain;f=n2vc%2Fconfig.py;fp=n2vc%2Fconfig.py;h=59a74be4e1f66e99eeff60bd8741c87a3c6cde39;hp=0000000000000000000000000000000000000000;hb=30701e3fbbbd545dabbd69c5145f44c0a5909558;hpb=5d7d622b026f6f4c6994fc5fbb1789d7827bf641 diff --git a/n2vc/config.py b/n2vc/config.py new file mode 100644 index 0000000..59a74be --- /dev/null +++ b/n2vc/config.py @@ -0,0 +1,84 @@ +# Copyright 2021 Canonical Ltd. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +MODEL_CONFIG_KEYS = [ + "agent-metadata-url", + "agent-stream", + "apt-ftp-proxy", + "apt-http-proxy", + "apt-https-proxy", + "apt-mirror", + "apt-no-proxy", + "automatically-retry-hooks", + "backup-dir", + "cloudinit-userdata", + "container-image-metadata-url", + "container-image-stream", + "container-inherit-properties", + "container-networking-method", + "default-series", + "default-space", + "development", + "disable-network-management", + "egress-subnets", + "enable-os-refresh-update", + "enable-os-upgrade", + "fan-config", + "firewall-mode", + "ftp-proxy", + "http-proxy", + "https-proxy", + "ignore-machine-addresses", + "image-metadata-url", + "image-stream", + "juju-ftp-proxy", + "juju-http-proxy", + "juju-https-proxy", + "juju-no-proxy", + "logforward-enabled", + "logging-config", + "lxd-snap-channel", + "max-action-results-age", + "max-action-results-size", + "max-status-history-age", + "max-status-history-size", + "net-bond-reconfigure-delay", + "no-proxy", + "provisioner-harvest-mode", + "proxy-ssh", + "snap-http-proxy", + "snap-https-proxy", + "snap-store-assertions", + "snap-store-proxy", + "snap-store-proxy-url", + "ssl-hostname-verification", + "test-mode", + "transmit-vendor-metrics", + "update-status-hook-interval", +] + + +class ModelConfig(dict): + prefix = "model_config_" + + def __init__(self, config: dict): + for key, value in config.items(): + if ( + key.startswith(self.prefix) + and self._get_renamed_key(key) in MODEL_CONFIG_KEYS + ): + self.__setitem__(self._get_renamed_key(key), value) + + def _get_renamed_key(self, key): + return key.replace(self.prefix, "").replace("_", "-")