tripleo-common/tripleo_common/actions/swifthelper.py
Christian Schwede 067049594a Use Mistral to create Swift temporary URLs
This patch consists of two parts.

A new Mistral action has been added to create signed temporary URLs.
The method to generate temporary URLs isnt' exposed by
python-swiftclient, therefore adding that method using it's own action.
It also sets the required metadata with a random key if not yet
existing.

The deployment workbook has been updated to create two temporary URLs
(one PUT, one GET) that can be used during the deployment for up- and
downloading Swift rings to the undercloud node.

Related-Bug: 1609421
Change-Id: Ic3da38cffdd993c768bdb137c17d625dff1aa372
2017-01-26 10:35:37 +01:00

50 lines
1.8 KiB
Python

# Copyright 2016 Red Hat, Inc.
# All Rights Reserved.
#
# 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.
import uuid
from six.moves import urllib
from swiftclient import exceptions as swiftexceptions
from swiftclient.utils import generate_temp_url
from tripleo_common.actions import base
class SwiftTempUrlAction(base.TripleOAction):
def __init__(self, container, obj, method='GET', valid='86400'):
super(SwiftTempUrlAction, self).__init__()
self.container = container
self.obj = obj
self.method = method
self.valid = valid
def run(self):
swift_client = self.get_object_client()
try:
cont_stat = swift_client.head_container(self.container)
except swiftexceptions.ClientException:
cont_stat = {}
key = cont_stat.get('x-container-meta-temp-url-key')
if not key:
key = str(uuid.uuid4())
cont_stat = swift_client.put_container(
self.container, {'X-Container-Meta-Temp-Url-Key': key})
parsed = urllib.parse.urlparse(swift_client.url)
path = "%s/%s/%s" % (parsed.path, self.container, self.obj)
temp_path = generate_temp_url(path, self.valid, key, self.method)
return "%s://%s%s" % (parsed.scheme, parsed.netloc, temp_path)