2015-02-23 17:36:55 -08:00
|
|
|
# Copyright 2015 IBM Corp.
|
2015-04-02 23:49:29 -06:00
|
|
|
# Copyright 2015, Hewlett-Packard Development Company, L.P.
|
2015-02-23 17:36:55 -08:00
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
|
2019-08-23 16:01:05 +08:00
|
|
|
from datetime import datetime
|
|
|
|
|
2015-04-02 23:49:29 -06:00
|
|
|
from django.conf import settings
|
2019-08-23 16:01:05 +08:00
|
|
|
from django.http import JsonResponse
|
2015-02-23 17:36:55 -08:00
|
|
|
from django.views import generic
|
2019-08-23 16:01:05 +08:00
|
|
|
import pytz
|
2015-02-23 17:36:55 -08:00
|
|
|
|
[NG] Support local file upload in Create Image workflow
First, now there are 2 '/api/glance/images/ API wrapper endpoints for
creating a new image - POST and PUT. The POST endpoint which existed
before now resides at PUT. This was done to support legacy
(i.e. proxied by web-server) file uploads in Angular Create Image,
because Django (which we need to use in that case) doesn't correctly
process PUT request. So, if local file binary payload is added to the
form contents, we send it using POST request.
Second, speaking of '/api/glance/images' PUT request previously known
as POST... Where before the POST call to Horizon REST API wrappers
returned the final image object that Glance just created, now there
are two possibilities for what happens after PUT is sent.
* When Create Image form Source Type is set to URL, then everything is
going as before.
* When Source Type is set to File, then just a file name instead of an
actual Blob is sent to '/api/glance/images', then the Glance Image
is queued for creation and Horizon web-server responds with an Image
object which dict() representation has 2 additional keys:
'upload_url' and 'token_id'. The 'upload_url' tells the location for
the subsequent CORS request, while 'token_id' is passed as a header
in that request, so Keystone would let it in. CORS upload is started
immediately as Image is queued for creation (first promise is
resolved) and returns the second promise, which is resolved once the
upload finishes. The modal form hangs until second promise resolves
to indicate that upload is in progress. Upload progress notification
is added in a follow-up patch.
DEPLOY NOTES
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).
Related-Bug: #1467890
Implements blueprint: horizon-glance-large-image-upload
Change-Id: I5d842d614c16d3250380ea1dc1c6e0289d206fb5
2016-05-24 14:54:54 +03:00
|
|
|
from openstack_dashboard import api
|
2015-02-23 17:36:55 -08:00
|
|
|
from openstack_dashboard.api.rest import urls
|
|
|
|
from openstack_dashboard.api.rest import utils as rest_utils
|
|
|
|
|
|
|
|
|
2015-04-02 23:49:29 -06:00
|
|
|
# settings that we allow to be retrieved via REST API
|
|
|
|
# these settings are available to the client and are not secured.
|
|
|
|
# *** THEY SHOULD BE TREATED WITH EXTREME CAUTION ***
|
2019-04-11 06:26:54 +09:00
|
|
|
settings_required = settings.REST_API_REQUIRED_SETTINGS
|
|
|
|
settings_additional = settings.REST_API_ADDITIONAL_SETTINGS
|
2015-04-02 23:49:29 -06:00
|
|
|
|
|
|
|
settings_allowed = settings_required + settings_additional
|
|
|
|
|
|
|
|
|
|
|
|
@urls.register
|
|
|
|
class Settings(generic.View):
|
|
|
|
"""API for retrieving settings.
|
|
|
|
|
|
|
|
This API returns read-only settings values.
|
|
|
|
This configuration object can be fetched as needed.
|
|
|
|
Examples of settings: OPENSTACK_HYPERVISOR_FEATURES
|
|
|
|
"""
|
|
|
|
url_regex = r'settings/$'
|
[NG] Support local file upload in Create Image workflow
First, now there are 2 '/api/glance/images/ API wrapper endpoints for
creating a new image - POST and PUT. The POST endpoint which existed
before now resides at PUT. This was done to support legacy
(i.e. proxied by web-server) file uploads in Angular Create Image,
because Django (which we need to use in that case) doesn't correctly
process PUT request. So, if local file binary payload is added to the
form contents, we send it using POST request.
Second, speaking of '/api/glance/images' PUT request previously known
as POST... Where before the POST call to Horizon REST API wrappers
returned the final image object that Glance just created, now there
are two possibilities for what happens after PUT is sent.
* When Create Image form Source Type is set to URL, then everything is
going as before.
* When Source Type is set to File, then just a file name instead of an
actual Blob is sent to '/api/glance/images', then the Glance Image
is queued for creation and Horizon web-server responds with an Image
object which dict() representation has 2 additional keys:
'upload_url' and 'token_id'. The 'upload_url' tells the location for
the subsequent CORS request, while 'token_id' is passed as a header
in that request, so Keystone would let it in. CORS upload is started
immediately as Image is queued for creation (first promise is
resolved) and returns the second promise, which is resolved once the
upload finishes. The modal form hangs until second promise resolves
to indicate that upload is in progress. Upload progress notification
is added in a follow-up patch.
DEPLOY NOTES
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).
Related-Bug: #1467890
Implements blueprint: horizon-glance-large-image-upload
Change-Id: I5d842d614c16d3250380ea1dc1c6e0289d206fb5
2016-05-24 14:54:54 +03:00
|
|
|
SPECIALS = {
|
2015-01-26 15:12:27 +00:00
|
|
|
'HORIZON_IMAGES_UPLOAD_MODE': api.glance.get_image_upload_mode(),
|
2016-12-14 11:53:57 +01:00
|
|
|
'HORIZON_ACTIVE_IMAGE_VERSION': str(api.glance.VERSIONS.active),
|
2019-04-11 06:26:54 +09:00
|
|
|
'IMAGES_ALLOW_LOCATION': settings.IMAGES_ALLOW_LOCATION,
|
2018-10-16 16:34:18 +03:00
|
|
|
'AJAX_POLL_INTERVAL': settings.HORIZON_CONFIG.get(
|
|
|
|
'ajax_poll_interval', 2500)
|
[NG] Support local file upload in Create Image workflow
First, now there are 2 '/api/glance/images/ API wrapper endpoints for
creating a new image - POST and PUT. The POST endpoint which existed
before now resides at PUT. This was done to support legacy
(i.e. proxied by web-server) file uploads in Angular Create Image,
because Django (which we need to use in that case) doesn't correctly
process PUT request. So, if local file binary payload is added to the
form contents, we send it using POST request.
Second, speaking of '/api/glance/images' PUT request previously known
as POST... Where before the POST call to Horizon REST API wrappers
returned the final image object that Glance just created, now there
are two possibilities for what happens after PUT is sent.
* When Create Image form Source Type is set to URL, then everything is
going as before.
* When Source Type is set to File, then just a file name instead of an
actual Blob is sent to '/api/glance/images', then the Glance Image
is queued for creation and Horizon web-server responds with an Image
object which dict() representation has 2 additional keys:
'upload_url' and 'token_id'. The 'upload_url' tells the location for
the subsequent CORS request, while 'token_id' is passed as a header
in that request, so Keystone would let it in. CORS upload is started
immediately as Image is queued for creation (first promise is
resolved) and returns the second promise, which is resolved once the
upload finishes. The modal form hangs until second promise resolves
to indicate that upload is in progress. Upload progress notification
is added in a follow-up patch.
DEPLOY NOTES
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).
Related-Bug: #1467890
Implements blueprint: horizon-glance-large-image-upload
Change-Id: I5d842d614c16d3250380ea1dc1c6e0289d206fb5
2016-05-24 14:54:54 +03:00
|
|
|
}
|
2015-04-02 23:49:29 -06:00
|
|
|
|
|
|
|
@rest_utils.ajax()
|
|
|
|
def get(self, request):
|
2019-04-11 06:26:54 +09:00
|
|
|
# TODO(amotoki): Drop the default value of getattr.
|
|
|
|
# It will be unnecessary once all default settings are defined.
|
[NG] Support local file upload in Create Image workflow
First, now there are 2 '/api/glance/images/ API wrapper endpoints for
creating a new image - POST and PUT. The POST endpoint which existed
before now resides at PUT. This was done to support legacy
(i.e. proxied by web-server) file uploads in Angular Create Image,
because Django (which we need to use in that case) doesn't correctly
process PUT request. So, if local file binary payload is added to the
form contents, we send it using POST request.
Second, speaking of '/api/glance/images' PUT request previously known
as POST... Where before the POST call to Horizon REST API wrappers
returned the final image object that Glance just created, now there
are two possibilities for what happens after PUT is sent.
* When Create Image form Source Type is set to URL, then everything is
going as before.
* When Source Type is set to File, then just a file name instead of an
actual Blob is sent to '/api/glance/images', then the Glance Image
is queued for creation and Horizon web-server responds with an Image
object which dict() representation has 2 additional keys:
'upload_url' and 'token_id'. The 'upload_url' tells the location for
the subsequent CORS request, while 'token_id' is passed as a header
in that request, so Keystone would let it in. CORS upload is started
immediately as Image is queued for creation (first promise is
resolved) and returns the second promise, which is resolved once the
upload finishes. The modal form hangs until second promise resolves
to indicate that upload is in progress. Upload progress notification
is added in a follow-up patch.
DEPLOY NOTES
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).
Related-Bug: #1467890
Implements blueprint: horizon-glance-large-image-upload
Change-Id: I5d842d614c16d3250380ea1dc1c6e0289d206fb5
2016-05-24 14:54:54 +03:00
|
|
|
plain_settings = {k: getattr(settings, k, None) for k
|
|
|
|
in settings_allowed if k not in self.SPECIALS}
|
|
|
|
plain_settings.update(self.SPECIALS)
|
2019-11-25 12:34:30 +02:00
|
|
|
plain_settings.update(self.disk_formats(request))
|
[NG] Support local file upload in Create Image workflow
First, now there are 2 '/api/glance/images/ API wrapper endpoints for
creating a new image - POST and PUT. The POST endpoint which existed
before now resides at PUT. This was done to support legacy
(i.e. proxied by web-server) file uploads in Angular Create Image,
because Django (which we need to use in that case) doesn't correctly
process PUT request. So, if local file binary payload is added to the
form contents, we send it using POST request.
Second, speaking of '/api/glance/images' PUT request previously known
as POST... Where before the POST call to Horizon REST API wrappers
returned the final image object that Glance just created, now there
are two possibilities for what happens after PUT is sent.
* When Create Image form Source Type is set to URL, then everything is
going as before.
* When Source Type is set to File, then just a file name instead of an
actual Blob is sent to '/api/glance/images', then the Glance Image
is queued for creation and Horizon web-server responds with an Image
object which dict() representation has 2 additional keys:
'upload_url' and 'token_id'. The 'upload_url' tells the location for
the subsequent CORS request, while 'token_id' is passed as a header
in that request, so Keystone would let it in. CORS upload is started
immediately as Image is queued for creation (first promise is
resolved) and returns the second promise, which is resolved once the
upload finishes. The modal form hangs until second promise resolves
to indicate that upload is in progress. Upload progress notification
is added in a follow-up patch.
DEPLOY NOTES
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).
Related-Bug: #1467890
Implements blueprint: horizon-glance-large-image-upload
Change-Id: I5d842d614c16d3250380ea1dc1c6e0289d206fb5
2016-05-24 14:54:54 +03:00
|
|
|
return plain_settings
|
2019-08-23 16:01:05 +08:00
|
|
|
|
2019-11-25 12:34:30 +02:00
|
|
|
def disk_formats(self, request):
|
|
|
|
# The purpose of OPENSTACK_IMAGE_FORMATS is to provide a simple object
|
|
|
|
# that does not contain the lazy-loaded translations, so the list can
|
|
|
|
# be sent as JSON to the client-side (Angular).
|
|
|
|
return {'OPENSTACK_IMAGE_FORMATS': [
|
|
|
|
value
|
|
|
|
for (value, name) in api.glance.get_image_formats(request)
|
|
|
|
]}
|
|
|
|
|
2019-08-23 16:01:05 +08:00
|
|
|
|
|
|
|
@urls.register
|
|
|
|
class Timezones(generic.View):
|
|
|
|
"""API for timezone service."""
|
|
|
|
url_regex = r'timezones/$'
|
|
|
|
|
|
|
|
@rest_utils.ajax()
|
|
|
|
def get(self, request):
|
|
|
|
zones = {tz: datetime.now(pytz.timezone(tz)).strftime('%z')
|
|
|
|
for tz in pytz.common_timezones}
|
|
|
|
return JsonResponse({'timezone_dict': zones})
|