93af461e40
Since large Glance images even temporarily stored on dashboard side tend to fill up Web Server filesystem, it is desirable to route image payload directly to Glance service (which usually streams it to storage backend, which in turn has plenty of space). To make it possible we need to trick Django into thinking that a file was selected inside FileInput, while its contents are not actually transferred to Django server. Then, once image is created client-side code needs to know the exact url the image payload needs to be transferred to. Both tasks are solved via using ExternalFileField / ExternalUploadMeta classes which allow to work around the usual Django form processing workflow with minimal changes to CreateImage form business logic. The client-side code relies on CORS being enabled for Glance service (otherwise browser would forbid the PUT request to a location different from the one form content came from). In a Devstack setup you'll need to edit [cors] section of glance-api.conf file, setting `allowed_origin` setting to the full hostname of the web server (say, http://<HOST_IP>/dashboard) and restart glance-api process. A progress bar is implemented to track the progress of a file upload, in case a really huge image is transferred. The new machinery could be easily switched on/off with a single setting `HORIZON_IMAGES_UPLOAD_MODE` set to 'direct' / 'legacy'. Related-Bug: #1467890 Closes-Bug: #1403129 Implements blueprint: horizon-glance-large-image-upload Change-Id: I01d02f75268186b43066df6fd966aa01c08e01d7
59 lines
2.0 KiB
Python
59 lines
2.0 KiB
Python
# Copyright 2015 Hewlett Packard Enterprise Software, LLC
|
|
# 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.
|
|
|
|
from __future__ import absolute_import
|
|
|
|
from django import template
|
|
|
|
|
|
register = template.Library()
|
|
|
|
|
|
@register.inclusion_tag('bootstrap/progress_bar.html')
|
|
def bs_progress_bar(*args, **kwargs):
|
|
"""A Standard Bootstrap Progress Bar.
|
|
http://getbootstrap.com/components/#progress
|
|
|
|
param args (Array of Numbers: 0-100): Percent of Progress Bars
|
|
param context (String): Adds 'progress-bar-{context} to the class attribute
|
|
param contexts (Array of Strings): Cycles through contexts for stacked bars
|
|
param text (String): True: shows value within the bar, False: uses sr span
|
|
param striped (Boolean): Adds 'progress-bar-striped' to the class attribute
|
|
param animated (Boolean): Adds 'active' to the class attribute if striped
|
|
param min_val (0): Used for the aria-min value
|
|
param max_val (0): Used for the aria-max value
|
|
"""
|
|
|
|
bars = []
|
|
contexts = kwargs.get(
|
|
'contexts',
|
|
['', 'success', 'info', 'warning', 'danger']
|
|
)
|
|
|
|
for ndx, arg in enumerate(args):
|
|
bars.append(
|
|
dict(percent=arg,
|
|
context=kwargs.get('context', contexts[ndx % len(contexts)]))
|
|
)
|
|
|
|
return {
|
|
'bars': bars,
|
|
'text': kwargs.pop('text', False),
|
|
'striped': kwargs.pop('striped', False),
|
|
'animated': kwargs.pop('animated', False),
|
|
'min_val': kwargs.pop('min_val', 0),
|
|
'max_val': kwargs.pop('max_val', 100),
|
|
}
|