uncloud/ucloud/configure/main.py

66 lines
2.5 KiB
Python
Raw Normal View History

2019-12-21 09:36:55 +00:00
import argparse
import sys
import os
from ucloud.settings import settings
from ucloud.shared import shared
2019-12-21 09:36:55 +00:00
def update_config(section, kwargs):
uncloud_config = shared.etcd_client.get(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
uncloud_config[section] = kwargs
shared.etcd_client.put(settings.config_key, uncloud_config, value_in_json=True)
2019-12-21 09:36:55 +00:00
def configure_parser(parser):
configure_subparsers = 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)
def main(**kwargs):
subcommand = kwargs.pop('subcommand')
if not subcommand:
pass
else:
update_config(subcommand, kwargs)