Repository URL to install this package:
|
Version:
4.0.116 ▾
|
python3-workloadmgrclient
/
usr
/
lib
/
python3
/
dist-packages
/
workloadmgrclient
/
v1
/
config_backup.py
|
|---|
# Copyright (c) 2014 TrilioData, Inc.
# All Rights Reserved.
"""
OpenStack config backup Interface (1.1 extension).
"""
import copy
from workloadmgrclient import base
default_services = {
"ceilometer": {
"config_dir": ["/etc/ceilometer"],
"log_dir": ["/var/log/ceilometer/"],
},
"compute": {
"config_dir": ["/etc/nova", "/var/lib/nova"],
"log_dir": ["/var/log/nova"],
},
"keystone": {
"config_dir": ["/etc/keystone", "/var/lib/keystone"],
"log_dir": ["/var/log/keystone"],
},
"Orchestration": {"config_dir": ["/etc/heat/"], "log_dir": ["/var/log/heat/"]},
"cinder": {
"config_dir": ["/etc/cinder", "/var/lib/cinder"],
"log_dir": ["/var/log/cinder"],
},
"glance": {
"config_dir": ["/etc/glance", "/var/lib/glance"],
"log_dir": ["/var/log/glance"],
},
"swift": {"config_dir": ["/etc/swift"], "log_dir": ["/var/log/swift/"]},
"neutron": {
"config_dir": ["/etc/neutron", "/var/lib/neutron"],
"log_dir": ["/var/log/neutron/"],
},
}
class ConfigBackup(base.Resource):
"""ConfigBackup describes backup for OpenSatck configuration."""
def __repr__(self):
return "<ConfigBackup: %s>" % self.id
class ConfigBackupManager(base.Manager):
"""Manage :class:`ConfigBackup` resources."""
resource_class = ConfigBackup
def __init__(self, api):
self.default_services = copy.deepcopy(default_services)
super(ConfigBackupManager, self).__init__(api)
def config_workload(self, jobschedule, config_data):
"""create/update Config backup workload.
:param jobschedule: scheduler settings.
:param config_data list of services to backup and their config directory path,
database creds and trusted user
:rtype: :class:`ConfigWorkload`
"""
if "databases" in config_data:
databases = config_data.pop("databases")
for database, database_config in list(databases.items()):
# Check configuration values. If all parameters of configuration
# are None than removing that configuration
config_all_values = list(set(database_config.values()))
if (
len(config_all_values) == 1
and config_all_values[0].lower() == "none"
):
del databases[database]
continue
if str(database_config.get("port", None)).lower() == "none":
databases[database]["port"] = None
if "trusted_user" in config_data:
trusted_user = config_data.pop("trusted_user")
if str(trusted_user.get("username", None)).lower() == "none":
message = "Please provide username in trusted_user."
raise Exception(message)
if "authorized_key" in config_data:
authorized_key = config_data.pop("authorized_key")
services_to_backup = {}
if len(list(config_data.keys())) > 0:
services_to_backup = copy.deepcopy(default_services)
for service, config in config_data.items():
if service in services_to_backup:
if "config_dir" in config and type(config["config_dir"]) is list:
for path in config["config_dir"]:
if path not in services_to_backup[service]["config_dir"]:
services_to_backup[service]["config_dir"].append(path)
if "log_dir" in config and type(config["log_dir"]) is list:
for path in config["log_dir"]:
if path not in services_to_backup[service]["log_dir"]:
services_to_backup[service]["log_dir"].append(path)
else:
services_to_backup[service] = config
config_data = {}
for key in [
"databases",
"trusted_user",
"authorized_key",
"services_to_backup",
]:
if key in locals():
config_data[key] = locals()[key]
body = {"jobschedule": jobschedule, "config_data": config_data}
return self._post("/config_workload", body)
def get_config_workload(self):
"""
Show details of a config workload.
"""
return self._get("/config_workload")
def config_backup(self, name, description):
"""
Take backup of OpenStack config.
"""
body = {"backup": {"name": name, "description": description}}
return self._post("/config_backup", body)
def config_backup_list(self):
"""
Get a list of all config backups.
"""
return self._list("/config_backups", "backups")
def get_config_backup(self, backup_id):
"""
show details of a backup.
:param backup_id: Id of the backup to view.
"""
return self._get("/config_backup/%s" % backup_id, "config_backup")
def config_backup_delete(self, backup_id):
"""
Delete a config backup.
:param backup_id: Id of the backup to delete.
"""
return self._delete("/config_backup/%s" % backup_id)