diff --git a/.gitignore b/.gitignore index 588f203..3352a56 100644 --- a/.gitignore +++ b/.gitignore @@ -30,6 +30,7 @@ nosetests.xml .venv .log *.cover +*.sample # Translations *.mo diff --git a/etc/oslo-config-generator/fuxi-k8s-config-generator.conf b/etc/oslo-config-generator/fuxi-k8s-config-generator.conf new file mode 100644 index 0000000..7bf0172 --- /dev/null +++ b/etc/oslo-config-generator/fuxi-k8s-config-generator.conf @@ -0,0 +1,4 @@ +[DEFAULT] +output_file = etc/fuxi_kubernetes.conf.sample +wrap_width = 79 +namespace = fuxi-kubernetes diff --git a/fuxi_kubernetes/__init__.py b/fuxi_kubernetes/__init__.py index 1eda11a..7b27af8 100644 --- a/fuxi_kubernetes/__init__.py +++ b/fuxi_kubernetes/__init__.py @@ -12,6 +12,8 @@ import pbr.version +from fuxi_kubernetes.common import constants + __version__ = pbr.version.VersionInfo( - 'fuxi-kubernetes').version_string() + constants.PROJECT_NAME).version_string() diff --git a/fuxi_kubernetes/common/config.py b/fuxi_kubernetes/common/config.py new file mode 100644 index 0000000..8c8d2a6 --- /dev/null +++ b/fuxi_kubernetes/common/config.py @@ -0,0 +1,34 @@ +# 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. + +from oslo_config import cfg + +from fuxi_kubernetes.i18n import _ + + +flexvolume_driver_group = cfg.OptGroup( + 'flexvolume_driver', + title='FlexVolume driver Options', + help=_('Configuration options for FlexVolume driver')) + +flexvolume_driver_opts = [ + cfg.HostAddressOpt('node_ip', + help=_('IP address of machine ' + 'on which FlexVolume driver runs.')), + cfg.IntOpt('driver_server_port', + default=7878, + help=_('Port for the server of FlexVolume driver.')), +] + + +CONF = cfg.CONF +CONF.register_opts(flexvolume_driver_opts, flexvolume_driver_group.name) diff --git a/fuxi_kubernetes/common/constants.py b/fuxi_kubernetes/common/constants.py index 0ce52a6..9c202b6 100644 --- a/fuxi_kubernetes/common/constants.py +++ b/fuxi_kubernetes/common/constants.py @@ -11,6 +11,9 @@ # under the License. +PROJECT_NAME = 'fuxi-kubernetes' + + VOLUME_DRIVER_CMD = ( CMD_INIT, CMD_GET_VOLUME_NAME, diff --git a/fuxi_kubernetes/i18n.py b/fuxi_kubernetes/i18n.py new file mode 100644 index 0000000..d604254 --- /dev/null +++ b/fuxi_kubernetes/i18n.py @@ -0,0 +1,22 @@ +# 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. + +import oslo_i18n + +from fuxi_kubernetes.common import constants + +DOMAIN = constants.PROJECT_NAME + +_translators = oslo_i18n.TranslatorFactory(domain=DOMAIN) + +# The primary translation function using the well-known name "_" +_ = _translators.primary diff --git a/fuxi_kubernetes/opts.py b/fuxi_kubernetes/opts.py new file mode 100644 index 0000000..0100362 --- /dev/null +++ b/fuxi_kubernetes/opts.py @@ -0,0 +1,27 @@ +# 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. + +__all__ = [ + 'list_fuxi_k8s_opts', +] + +import itertools + +from fuxi_kubernetes.common import config + + +def list_fuxi_k8s_opts(): + + return [ + (config.flexvolume_driver_group.name, + itertools.chain(config.flexvolume_driver_opts,)), + ] diff --git a/setup.cfg b/setup.cfg index 6f360a2..d389294 100644 --- a/setup.cfg +++ b/setup.cfg @@ -23,6 +23,9 @@ packages = fuxi_kubernetes [entry_points] +oslo.config.opts = + fuxi-kubernetes = fuxi_kubernetes.opts:list_fuxi_k8s_opts + console_scripts = fuxi-k8s-volume-driver-cinder = fuxi_kubernetes.cmd.cinder:main fuxi-k8s-volume-driver-server = fuxi_kubernetes.cmd.driver_server:main diff --git a/tools/generate_config_file_samples.sh b/tools/generate_config_file_samples.sh new file mode 100755 index 0000000..e4a8302 --- /dev/null +++ b/tools/generate_config_file_samples.sh @@ -0,0 +1,54 @@ +#!/bin/sh +# +# 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. + +set -e + +GEN_CMD=oslo-config-generator +SCRIPT_PATH=$(dirname "$(readlink -f "$0")") +DIST_PATH=$(dirname "$SCRIPT_PATH") + +prerequisites() ( + if ! command -v "$GEN_CMD" > /dev/null; then + echo "ERROR: $GEN_CMD not installed on the system." + return 1 + fi + + if ! [ -f "${DIST_PATH}/fuxi_kubernetes.egg-info/entry_points.txt" ]; then + curr_dir=$(pwd) + cd "${DIST_PATH}" + python setup.py egg_info # Generate entrypoints for config generation + cd "${curr_dir}" + fi + + return 0 +) + +generate() ( + curr_dir=$(pwd) + cd "${DIST_PATH}" + # Set PYTHONPATH so that it will use the generated egg-info + PYTHONPATH=. find "etc/oslo-config-generator" -type f -exec "$GEN_CMD" --config-file="{}" \; + cd "${curr_dir}" +) + + +prerequisites +rc=$? +if [ $rc -ne 0 ]; then + exit $rc +fi + +generate + +set -x