2019-12-21 09:36:55 +00:00
|
|
|
import os
|
|
|
|
|
2019-12-31 10:30:02 +00:00
|
|
|
from uncloud.settings import settings
|
|
|
|
from uncloud.shared import shared
|
2019-12-21 09:36:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
def update_config(section, kwargs):
|
2019-12-30 09:35:07 +00:00
|
|
|
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
|
2019-12-30 09:35:07 +00:00
|
|
|
|
2019-12-21 09:36:55 +00:00
|
|
|
uncloud_config[section] = kwargs
|
2019-12-30 09:35:07 +00:00
|
|
|
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")
|
2019-12-30 09:35:07 +00:00
|
|
|
|
2019-12-21 09:36:55 +00:00
|
|
|
otp_parser = configure_subparsers.add_parser("otp")
|
2019-12-30 09:35:07 +00:00
|
|
|
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"
|
|
|
|
)
|
2019-12-21 09:36:55 +00:00
|
|
|
|
|
|
|
network_parser = configure_subparsers.add_parser("network")
|
2019-12-30 09:35:07 +00:00
|
|
|
network_parser.add_argument(
|
|
|
|
"--prefix-length", required=True, type=int
|
|
|
|
)
|
2019-12-21 09:36:55 +00:00
|
|
|
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")
|
2019-12-30 09:35:07 +00:00
|
|
|
ssh_parser.add_argument("--username", default="root")
|
|
|
|
ssh_parser.add_argument(
|
|
|
|
"--private-key-path",
|
|
|
|
default=os.path.expanduser("~/.ssh/id_rsa"),
|
|
|
|
)
|
2019-12-21 09:36:55 +00:00
|
|
|
|
|
|
|
storage_parser = configure_subparsers.add_parser("storage")
|
2019-12-30 09:35:07 +00:00
|
|
|
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)
|
2019-12-21 09:36:55 +00:00
|
|
|
|
|
|
|
ceph_storage_parser = storage_parser_subparsers.add_parser("ceph")
|
2019-12-30 09:35:07 +00:00
|
|
|
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 main(**kwargs):
|
2019-12-30 09:35:07 +00:00
|
|
|
subcommand = kwargs.pop("subcommand")
|
2019-12-21 09:36:55 +00:00
|
|
|
if not subcommand:
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
update_config(subcommand, kwargs)
|