diff options
author | Zuul <zuul@review.opendev.org> | 2021-02-18 23:22:59 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2021-02-18 23:22:59 +0000 |
commit | 90d99939fbb325eff3406a15f7913980326944c6 (patch) | |
tree | fffe96c60daaff7fdb64f8b504565ea2a099d37f /trove/common | |
parent | 4069c667ce995967b36f999a0b68ff31e4cc816d (diff) | |
parent | 6fdf11ea7f5c77e83dd746fa33b7a354417aec08 (diff) | |
download | trove-90d99939fbb325eff3406a15f7913980326944c6.tar.gz |
Merge "Support to restore backup from remote location"
Diffstat (limited to 'trove/common')
-rw-r--r-- | trove/common/apischema.py | 17 | ||||
-rw-r--r-- | trove/common/constants.py | 16 | ||||
-rw-r--r-- | trove/common/swift.py | 42 |
3 files changed, 73 insertions, 2 deletions
diff --git a/trove/common/apischema.py b/trove/common/apischema.py index 4c799992..bc815fad 100644 --- a/trove/common/apischema.py +++ b/trove/common/apischema.py @@ -652,14 +652,27 @@ backup = { "properties": { "backup": { "type": "object", - "required": ["instance", "name"], + "required": ["name"], "properties": { "description": non_empty_string, "instance": uuid, "name": non_empty_string, "parent_id": uuid, "incremental": boolean_string, - "swift_container": non_empty_string + "swift_container": non_empty_string, + "restore_from": { + "type": "object", + "required": [ + "remote_location", + "local_datastore_version_id", + "size" + ], + "properties": { + "remote_location": non_empty_string, + "local_datastore_version_id": uuid, + "size": {"type": "number"} + } + } } } } diff --git a/trove/common/constants.py b/trove/common/constants.py new file mode 100644 index 00000000..0f53477b --- /dev/null +++ b/trove/common/constants.py @@ -0,0 +1,16 @@ +# Copyright 2021 Catalyst Cloud Ltd. +# +# 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. + +BACKUP_TYPE_FULL = 'full' +BACKUP_TYPE_INC = 'incremental' diff --git a/trove/common/swift.py b/trove/common/swift.py new file mode 100644 index 00000000..43910af1 --- /dev/null +++ b/trove/common/swift.py @@ -0,0 +1,42 @@ +# Copyright 2021 Catalyst Cloud Ltd. +# +# 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. + + +def parse_location(location): + storage_url = "/".join(location.split('/')[:-2]) + container_name = location.split('/')[-2] + object_name = location.split('/')[-1] + return storage_url, container_name, object_name + + +def _get_attr(original): + """Get a friendly name from an object header key.""" + key = original.replace('-', '_') + key = key.replace('x_object_meta_', '') + return key + + +def get_metadata(client, location, extra_attrs=[]): + _, container_name, object_name = parse_location(location) + headers = client.head_object(container_name, object_name) + + meta = {} + for key, value in headers.items(): + if key.startswith('x-object-meta'): + meta[_get_attr(key)] = value + + for key in extra_attrs: + meta[key] = headers.get(key) + + return meta |