uncloud-mravi/archive/uncloud_etcd_based/uncloud/configure/main.py

58 lines
2.3 KiB
Python
Raw Normal View History

2019-12-21 09:36:55 +00:00
import os
2020-01-03 13:38:59 +00:00
import argparse
2019-12-21 09:36:55 +00:00
from uncloud.common.shared import shared
2019-12-21 09:36:55 +00:00
2020-01-03 13:38:59 +00:00
arg_parser = argparse.ArgumentParser('configure', add_help=False)
configure_subparsers = arg_parser.add_subparsers(dest='subcommand')
otp_parser = configure_subparsers.add_parser('otp')
otp_parser.add_argument('--verification-controller-url', required=True, metavar='URL')
otp_parser.add_argument('--auth-name', required=True, metavar='OTP-NAME')
otp_parser.add_argument('--auth-realm', required=True, metavar='OTP-REALM')
otp_parser.add_argument('--auth-seed', required=True, metavar='OTP-SEED')
network_parser = configure_subparsers.add_parser('network')
network_parser.add_argument('--prefix-length', required=True, type=int)
network_parser.add_argument('--prefix', required=True)
network_parser.add_argument('--vxlan-phy-dev', required=True)
netbox_parser = configure_subparsers.add_parser('netbox')
netbox_parser.add_argument('--url', required=True)
netbox_parser.add_argument('--token', required=True)
ssh_parser = configure_subparsers.add_parser('ssh')
ssh_parser.add_argument('--username', default='root')
ssh_parser.add_argument('--private-key-path', default=os.path.expanduser('~/.ssh/id_rsa'),)
storage_parser = configure_subparsers.add_parser('storage')
storage_parser.add_argument('--file-dir', required=True)
storage_parser_subparsers = storage_parser.add_subparsers(dest='storage_backend')
filesystem_storage_parser = storage_parser_subparsers.add_parser('filesystem')
filesystem_storage_parser.add_argument('--vm-dir', required=True)
filesystem_storage_parser.add_argument('--image-dir', required=True)
ceph_storage_parser = storage_parser_subparsers.add_parser('ceph')
ceph_storage_parser.add_argument('--ceph-vm-pool', required=True)
ceph_storage_parser.add_argument('--ceph-image-pool', required=True)
2019-12-21 09:36:55 +00:00
def update_config(section, kwargs):
uncloud_config = shared.etcd_client.get(shared.settings.config_key, value_in_json=True)
2019-12-21 09:36:55 +00:00
if not uncloud_config:
uncloud_config = {}
else:
uncloud_config = uncloud_config.value
2019-12-21 09:36:55 +00:00
uncloud_config[section] = kwargs
shared.etcd_client.put(shared.settings.config_key, uncloud_config, value_in_json=True)
2019-12-21 09:36:55 +00:00
def main(arguments):
subcommand = arguments['subcommand']
2019-12-21 09:36:55 +00:00
if not subcommand:
2020-01-03 13:38:59 +00:00
arg_parser.print_help()
2019-12-21 09:36:55 +00:00
else:
update_config(subcommand, arguments)