config.py 6.09 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
# Copyright (c) 2015, Daniele Venzano
#
# 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.

16 17
"""Configuration parsing."""

18 19
import logging

20 21
from zoe_lib.configargparse import ArgumentParser, Namespace

22 23 24 25 26
logging.getLogger('kazoo').setLevel(logging.WARNING)
logging.getLogger('requests').setLevel(logging.WARNING)
logging.getLogger('urllib3').setLevel(logging.WARNING)
logging.getLogger('docker').setLevel(logging.INFO)

27
_CONFIG_PATHS = [
28 29
    'zoe.conf',
    '/etc/zoe/zoe.conf'
30 31
]

32 33
_CONF = None

34

35 36 37
def get_conf() -> Namespace:
    """Returns the conf singleton."""
    return _CONF
38 39 40


def load_configuration(test_conf=None):
41 42
    """Parses command line arguments."""
    global _CONF
43
    if test_conf is None:
44
        argparser = ArgumentParser(description="Zoe - Container Analytics as a Service",
45
                                   default_config_files=_CONFIG_PATHS,
46
                                   auto_env_var_prefix="ZOE_",
47 48
                                   args_for_setting_config_path=["--config"],
                                   args_for_writing_out_config_file=["--write-config"])
49 50

        # Common options
51
        argparser.add_argument('--debug', action='store_true', help='Enable debug output')
52
        argparser.add_argument('--deployment-name', help='name of this Zoe deployment', default='prod')
53 54 55

        argparser.add_argument('--dbname', help='DB name', default='zoe')
        argparser.add_argument('--dbuser', help='DB user', default='zoe')
56
        argparser.add_argument('--dbpass', help='DB password', default='')
57 58 59 60 61
        argparser.add_argument('--dbhost', help='DB hostname', default='localhost')
        argparser.add_argument('--dbport', type=int, help='DB port', default=5432)

        # Master options
        argparser.add_argument('--api-listen-uri', help='ZMQ API listen address', default='tcp://*:4850')
62 63
        argparser.add_argument('--influxdb-dbname', help='Name of the InfluxDB database to use for storing metrics', default='zoe')
        argparser.add_argument('--influxdb-url', help='URL of the InfluxDB service (ex. http://localhost:8086)', default='http://localhost:8086')
64
        argparser.add_argument('--influxdb-enable', action="store_true", help='Enable metric output toward influxDB')
65
        argparser.add_argument('--gelf-address', help='Enable Docker GELF log output to this destination (ex. udp://1.2.3.4:1234)', default='')
66
        argparser.add_argument('--workspace-base-path', help='Path where user workspaces will be created by Zoe. Must be visible at this path on all Swarm hosts.', default='/mnt/zoe-workspaces')
67
        argparser.add_argument('--workspace-deployment-path', help='Path appended to the workspace path to distinguish this deployment. If unspecified is equal to the deployment name.', default='--default--')
68
        argparser.add_argument('--overlay-network-name', help='Name of the Swarm overlay network Zoe should use', default='zoe')
69

70 71 72 73 74
        # API options
        argparser.add_argument('--listen-address', type=str, help='Address to listen to for incoming connections', default="0.0.0.0")
        argparser.add_argument('--listen-port', type=int, help='Port to listen to for incoming connections', default=5001)
        argparser.add_argument('--master-url', help='URL of the Zoe master process', default='tcp://127.0.0.1:4850')

75 76 77 78 79
        # API auth options
        argparser.add_argument('--auth-type', help='Authentication type (text or ldap)', default='text')

        argparser.add_argument('--auth-file', help='Path to the CSV file containing user,pass,role lines for text authentication', default='zoepass.csv')

80 81 82 83 84
        argparser.add_argument('--ldap-server-uri', help='LDAP server to use for authentication', default='ldap://localhost')
        argparser.add_argument('--ldap-base-dn', help='LDAP base DN for users', default='ou=something,dc=any,dc=local')
        argparser.add_argument('--ldap-admin-gid', type=int, help='LDAP group ID for admins', default=5000)
        argparser.add_argument('--ldap-user-gid', type=int, help='LDAP group ID for users', default=5001)
        argparser.add_argument('--ldap-guest-gid', type=int, help='LDAP group ID for guests', default=5002)
85

86 87
        argparser.add_argument('--service-log-path', help='Save service logs in this directory, EXPERIMENTAL', default='')

88
        argparser.add_argument('--scheduler-class', help='Scheduler class to use for scheduling ZApps', default='ZoeSimpleScheduler')
89
        argparser.add_argument('--scheduler-policy', help='Scheduler policy to use for scheduling ZApps', choices=['FIFO', 'SIZE'], default='FIFO')
90

Daniele Venzano's avatar
Daniele Venzano committed
91 92 93 94
        argparser.add_argument('--docker-tls-cert', help='Docker TLS certificate file', default='cert.pem')
        argparser.add_argument('--docker-tls-key', help='Docker TLS private key file', default='key.pem')
        argparser.add_argument('--docker-tls-ca', help='Docker TLS CA certificate file', default='ca.pem')

95 96 97 98 99 100 101
        # Docker Swarm backend options
        argparser.add_argument('--backend', choices=['OldSwarm', 'OldSwarmNewAPI'], default='OldSwarmNewAPI')
        argparser.add_argument('--backend-swarm-url', help='Swarm/Docker API endpoint (ex.: zk://zk1:2181,zk2:2181 or http://swarm:2380)', default='http://localhost:2375')
        argparser.add_argument('--backend-swarm-zk-path', help='Swarm/Docker optional ZooKeeper path for Swarm Znodes', default='/docker')

        argparser.add_argument('--cookie-secret', help='secret used to encrypt cookies', default='changeme')

102 103 104
        opts = argparser.parse_args()
        if opts.debug:
            argparser.print_values()
105

106 107 108
        if opts.workspace_deployment_path == '--default--':
            opts.workspace_deployment_path = opts.deployment_name

109
        _CONF = opts
110
    else:
111
        _CONF = test_conf