2012-02-04 17:40:31 -06:00
|
|
|
# Copyright 2012 United States Government as represented by the
|
2011-10-31 11:31:05 -07:00
|
|
|
# Administrator of the National Aeronautics and Space Administration.
|
|
|
|
# All Rights Reserved.
|
|
|
|
#
|
2012-02-04 17:40:31 -06:00
|
|
|
# Copyright 2012 Nebula, Inc.
|
2011-10-31 11:31:05 -07: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.
|
|
|
|
|
|
|
|
from __future__ import absolute_import
|
|
|
|
|
2014-09-11 19:10:41 +02:00
|
|
|
import collections
|
2013-02-19 18:38:45 +11:00
|
|
|
import itertools
|
2014-09-11 19:10:41 +02:00
|
|
|
import json
|
2011-10-31 11:31:05 -07:00
|
|
|
import logging
|
2014-12-08 15:13:51 +02:00
|
|
|
import os
|
2011-10-31 11:31:05 -07:00
|
|
|
|
2014-01-03 17:31:49 +01:00
|
|
|
from django.conf import settings
|
2015-05-22 10:54:42 +08:00
|
|
|
from django.core.files.uploadedfile import InMemoryUploadedFile
|
|
|
|
from django.core.files.uploadedfile import SimpleUploadedFile
|
|
|
|
from django.core.files.uploadedfile import TemporaryUploadedFile
|
|
|
|
|
2012-07-31 13:28:48 -07:00
|
|
|
import glanceclient as glance_client
|
2016-05-19 18:15:24 +03:00
|
|
|
import six
|
2014-07-29 16:57:39 +02:00
|
|
|
from six.moves import _thread as thread
|
2012-03-11 18:37:18 -07:00
|
|
|
|
2013-11-14 15:01:24 -07:00
|
|
|
from horizon.utils import functions as utils
|
2017-03-17 19:15:23 +00:00
|
|
|
from horizon.utils.memoized import memoized
|
2013-08-02 13:23:46 +04:00
|
|
|
from openstack_dashboard.api import base
|
2016-07-08 19:04:42 +03:00
|
|
|
from openstack_dashboard.contrib.developer.profiler import api as profiler
|
2011-10-31 11:31:05 -07:00
|
|
|
|
|
|
|
|
|
|
|
LOG = logging.getLogger(__name__)
|
Base Glance Metadata Definitions Admin UI
Provide a base admin UI for viewing, importing, and associating the
metadata definitions that can be used with various resource types
such as flavors, images, and host aggregates.
In Juno, Glance provided a metadata definitions catalog[1][2] where
users can register the available metadata definitions that can be used
on different types of resources (images, artifacts, volumes, flavors,
aggregates, etc). This includes key / value pairs such as
properties, extra specs, etc. Horizon landed several patches that
read these properties. You can view the functionality in the
"update metadata" action on Flavors, Images, and Host Aggregates.
This specific patch is to bring in the Admin UI for the basic coarse
grained actions on the definitions in the catalog. This includes creating
(importing) a namespace, viewing the overview details about
it, deleting the namespace, and associating the namespace for use with
specific resource types.
Future blueprints will be registered for:
- CRUD on individual metadata definitions within the namespace
For example, editing the default value of an individual property.
[1] Approved Glance Juno Spec:
https://github.com/openstack/glance-specs/blob/master/specs/juno/metadata-schema-catalog.rst
[2] Glance PTL Juno Feature Overview:
https://www.youtube.com/watch?v=3ptriiw1wK8&t=14m27s
Co-Authored-By: Travis Tripp <travis.tripp@hp.com>
Co-Authored-By: Santiago Baldassin<santiago.b.baldassin@intel.com>
Co-Authored-By: Bartosz Fic <bartosz.fic@intel.com>
Co-Authored-By: Pawel Koniszewski <pawel.koniszewski@intel.com>
Co-Authored-By: Michal Dulko <michal.dulko@intel.com>
DocImpact: Concept awareness
Change-Id: Ie34007f73af7e0941631a52f03841068e509a72c
Implements: blueprint glance-metadata-definitions-base-admin-ui
2014-09-12 13:54:01 +02:00
|
|
|
VERSIONS = base.APIVersionManager("image", preferred_version=2)
|
2011-10-31 11:31:05 -07:00
|
|
|
|
2015-11-17 10:19:59 -06:00
|
|
|
try:
|
|
|
|
from glanceclient.v2 import client as glance_client_v2
|
|
|
|
VERSIONS.load_supported_version(2, {"client": glance_client_v2,
|
|
|
|
"version": 2})
|
|
|
|
except ImportError:
|
|
|
|
pass
|
|
|
|
|
|
|
|
try:
|
|
|
|
from glanceclient.v1 import client as glance_client_v1
|
|
|
|
VERSIONS.load_supported_version(1, {"client": glance_client_v1,
|
|
|
|
"version": 1})
|
|
|
|
except ImportError:
|
|
|
|
pass
|
|
|
|
|
2011-10-31 11:31:05 -07:00
|
|
|
|
2015-01-26 15:12:27 +00:00
|
|
|
class Image(base.APIResourceWrapper):
|
|
|
|
_attrs = {"architecture", "container_format", "disk_format", "created_at",
|
|
|
|
"owner", "size", "id", "status", "updated_at", "checksum",
|
|
|
|
"visibility", "name", "is_public", "protected", "min_disk",
|
|
|
|
"min_ram"}
|
|
|
|
_ext_attrs = {"file", "locations", "schema", "tags", "virtual_size",
|
|
|
|
"kernel_id", "ramdisk_id", "image_url"}
|
|
|
|
|
|
|
|
def __init__(self, apiresource):
|
|
|
|
super(Image, self).__init__(apiresource)
|
|
|
|
|
|
|
|
def __getattribute__(self, attr):
|
|
|
|
# Because Glance v2 treats custom properties as normal
|
|
|
|
# attributes, we need to be more flexible than the resource
|
|
|
|
# wrappers usually allow. In v1 they were defined under a
|
|
|
|
# "properties" attribute.
|
|
|
|
if VERSIONS.active >= 2 and attr == "properties":
|
|
|
|
return {k: v for (k, v) in self._apiresource.items()
|
|
|
|
if self.property_visible(k)}
|
|
|
|
try:
|
|
|
|
return object.__getattribute__(self, attr)
|
|
|
|
except AttributeError:
|
|
|
|
return getattr(self._apiresource, attr)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def name(self):
|
|
|
|
return getattr(self._apiresource, 'name', None)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def size(self):
|
|
|
|
image_size = getattr(self._apiresource, 'size', 0)
|
|
|
|
if image_size is None:
|
|
|
|
return 0
|
|
|
|
return image_size
|
|
|
|
|
|
|
|
@size.setter
|
|
|
|
def size(self, value):
|
|
|
|
self._apiresource.size = value
|
|
|
|
|
|
|
|
@property
|
|
|
|
def is_public(self):
|
|
|
|
# Glance v2 no longer has a 'is_public' attribute, but uses a
|
|
|
|
# 'visibility' attribute instead.
|
|
|
|
return (getattr(self._apiresource, 'is_public', None) or
|
|
|
|
getattr(self._apiresource, 'visibility', None) == "public")
|
|
|
|
|
|
|
|
def property_visible(self, prop_name, show_ext_attrs=False):
|
|
|
|
if show_ext_attrs:
|
|
|
|
return prop_name not in self._attrs
|
|
|
|
else:
|
|
|
|
return prop_name not in (self._attrs | self._ext_attrs)
|
|
|
|
|
|
|
|
def to_dict(self, show_ext_attrs=False):
|
|
|
|
# When using v1 Image objects (including when running unit tests
|
|
|
|
# for v2), self._apiresource is not iterable. In that case,
|
|
|
|
# the properties are included in the apiresource dict, so
|
|
|
|
# just return that dict.
|
|
|
|
if not isinstance(self._apiresource, collections.Iterable):
|
|
|
|
return self._apiresource.to_dict()
|
|
|
|
image_dict = super(Image, self).to_dict()
|
|
|
|
image_dict['is_public'] = self.is_public
|
|
|
|
image_dict['properties'] = {
|
|
|
|
k: self._apiresource[k] for k in self._apiresource
|
|
|
|
if self.property_visible(k, show_ext_attrs=show_ext_attrs)}
|
|
|
|
return image_dict
|
|
|
|
|
|
|
|
def __eq__(self, other_image):
|
|
|
|
return self._apiresource == other_image._apiresource
|
|
|
|
|
|
|
|
def __ne__(self, other_image):
|
|
|
|
return not self.__eq__(other_image)
|
|
|
|
|
|
|
|
|
2014-08-04 15:07:04 +09:00
|
|
|
@memoized
|
2015-01-26 15:12:27 +00:00
|
|
|
def glanceclient(request, version=None):
|
|
|
|
api_version = VERSIONS.get_active_version()
|
|
|
|
|
2014-03-14 08:20:19 -06:00
|
|
|
url = base.url_for(request, 'image')
|
2012-07-17 12:35:49 +02:00
|
|
|
insecure = getattr(settings, 'OPENSTACK_SSL_NO_VERIFY', False)
|
2013-08-28 13:21:19 +02:00
|
|
|
cacert = getattr(settings, 'OPENSTACK_SSL_CACERT', None)
|
2015-01-26 15:12:27 +00:00
|
|
|
|
|
|
|
# TODO(jpichon): Temporarily keep both till we update the API calls
|
|
|
|
# to stop hardcoding a version in this file. Once that's done we
|
|
|
|
# can get rid of the deprecated 'version' parameter.
|
|
|
|
if version is None:
|
|
|
|
return api_version['client'].Client(url, token=request.user.token.id,
|
|
|
|
insecure=insecure, cacert=cacert)
|
|
|
|
else:
|
|
|
|
return glance_client.Client(version, url, token=request.user.token.id,
|
|
|
|
insecure=insecure, cacert=cacert)
|
|
|
|
|
|
|
|
|
|
|
|
# Note: Glance is adding more than just public and private in Newton or later
|
|
|
|
PUBLIC_TO_VISIBILITY_MAP = {
|
|
|
|
None: None,
|
|
|
|
True: 'public',
|
|
|
|
False: 'private'
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
def _normalize_is_public_filter(filters):
|
|
|
|
if not filters:
|
|
|
|
return
|
|
|
|
|
2017-03-09 23:16:51 -05:00
|
|
|
# Glance v1 uses filter 'is_public' (True, False).
|
|
|
|
# Glance v2 uses filter 'visibility' ('public', 'private', ...).
|
2015-01-26 15:12:27 +00:00
|
|
|
if VERSIONS.active >= 2:
|
|
|
|
if 'is_public' in filters:
|
2017-03-09 23:16:51 -05:00
|
|
|
# Glance v2: Replace 'is_public' with 'visibility'.
|
2015-01-26 15:12:27 +00:00
|
|
|
visibility = PUBLIC_TO_VISIBILITY_MAP[filters['is_public']]
|
|
|
|
del filters['is_public']
|
|
|
|
if visibility is not None:
|
|
|
|
filters['visibility'] = visibility
|
|
|
|
elif 'visibility' in filters:
|
2017-03-09 23:16:51 -05:00
|
|
|
# Glance v1: Replace 'visibility' with 'is_public'.
|
2015-01-26 15:12:27 +00:00
|
|
|
filters['is_public'] = (
|
|
|
|
getattr(filters, 'visibility', None) == "public")
|
2017-03-09 23:16:51 -05:00
|
|
|
del filters['visibility']
|
|
|
|
|
|
|
|
|
|
|
|
def _normalize_owner_id_filter(filters):
|
|
|
|
if not filters:
|
|
|
|
return
|
|
|
|
|
|
|
|
# Glance v1 uses filter 'property-owner_id' (Project ID).
|
|
|
|
# Glance v2 uses filter 'owner' (Project ID).
|
|
|
|
if VERSIONS.active >= 2:
|
|
|
|
if 'property-owner_id' in filters:
|
|
|
|
# Glance v2: Replace 'property-owner_id' with 'owner'.
|
|
|
|
filters['owner'] = filters['property-owner_id']
|
|
|
|
del filters['property-owner_id']
|
|
|
|
elif 'owner' in filters:
|
|
|
|
# Glance v1: Replace 'owner' with 'property-owner_id'.
|
|
|
|
filters['property-owner_id'] = filters['owner']
|
|
|
|
del filters['owner']
|
2015-01-26 15:12:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
def _normalize_list_input(filters, **kwargs):
|
|
|
|
_normalize_is_public_filter(filters)
|
2017-03-09 23:16:51 -05:00
|
|
|
_normalize_owner_id_filter(filters)
|
2015-01-26 15:12:27 +00:00
|
|
|
|
|
|
|
if VERSIONS.active < 2:
|
|
|
|
# Glance v1 client processes some keywords specifically.
|
|
|
|
# Others, it just takes as a nested dict called filters.
|
|
|
|
# This results in the following being passed into the glance client:
|
|
|
|
# {
|
|
|
|
# 'is_public': u'true',
|
|
|
|
# 'sort_key': u'name',
|
|
|
|
# 'sort_dir': u'asc',
|
|
|
|
# 'filters': {
|
|
|
|
# u'min_disk': u'0',
|
|
|
|
# u'name': u'mysql',
|
|
|
|
# 'properties': {
|
|
|
|
# u'os_shutdown_timeout': u'1'
|
|
|
|
# }
|
|
|
|
# }
|
|
|
|
# }
|
|
|
|
v1_keywords = ['page_size', 'limit', 'sort_dir', 'sort_key', 'marker',
|
|
|
|
'is_public', 'return_req_id', 'paginate']
|
|
|
|
|
|
|
|
filters = {}
|
|
|
|
properties = {}
|
|
|
|
for key, value in iter(kwargs.items()):
|
|
|
|
if key in v1_keywords:
|
|
|
|
continue
|
|
|
|
else:
|
|
|
|
filters[key] = value
|
|
|
|
del kwargs[key]
|
|
|
|
|
|
|
|
if properties:
|
|
|
|
filters['properties'] = properties
|
|
|
|
if filters:
|
|
|
|
kwargs['filters'] = filters
|
2011-10-31 11:31:05 -07:00
|
|
|
|
|
|
|
|
2016-07-08 19:04:42 +03:00
|
|
|
@profiler.trace
|
2011-10-31 11:31:05 -07:00
|
|
|
def image_delete(request, image_id):
|
2012-04-12 17:13:56 -07:00
|
|
|
return glanceclient(request).images.delete(image_id)
|
2011-10-31 11:31:05 -07:00
|
|
|
|
|
|
|
|
2016-07-08 19:04:42 +03:00
|
|
|
@profiler.trace
|
2011-10-31 11:31:05 -07:00
|
|
|
def image_get(request, image_id):
|
2017-06-09 10:47:12 +00:00
|
|
|
"""Returns an Image object populated with metadata for a given image."""
|
2013-12-16 13:05:37 -05:00
|
|
|
image = glanceclient(request).images.get(image_id)
|
2015-01-26 15:12:27 +00:00
|
|
|
return Image(image)
|
2014-10-24 20:14:46 +04:00
|
|
|
|
|
|
|
|
2016-07-08 19:04:42 +03:00
|
|
|
@profiler.trace
|
2014-04-28 16:42:43 -07:00
|
|
|
def image_list_detailed(request, marker=None, sort_dir='desc',
|
2014-10-24 20:14:46 +04:00
|
|
|
sort_key='created_at', filters=None, paginate=False,
|
2015-01-26 15:12:27 +00:00
|
|
|
reversed_order=False, **kwargs):
|
2014-10-24 20:14:46 +04:00
|
|
|
"""Thin layer above glanceclient, for handling pagination issues.
|
|
|
|
|
|
|
|
It provides iterating both forward and backward on top of ascetic
|
|
|
|
OpenStack pagination API - which natively supports only iterating forward
|
|
|
|
through the entries. Thus in order to retrieve list of objects at previous
|
|
|
|
page, a request with the reverse entries order had to be made to Glance,
|
|
|
|
using the first object id on current page as the marker - restoring
|
|
|
|
the original items ordering before sending them back to the UI.
|
|
|
|
|
2016-09-21 09:04:53 +09:00
|
|
|
:param request:
|
2014-10-24 20:14:46 +04:00
|
|
|
|
|
|
|
The request object coming from browser to be passed further into
|
|
|
|
Glance service.
|
|
|
|
|
2016-09-21 09:04:53 +09:00
|
|
|
:param marker:
|
2014-10-24 20:14:46 +04:00
|
|
|
|
|
|
|
The id of an object which defines a starting point of a query sent to
|
|
|
|
Glance service.
|
|
|
|
|
2016-09-21 09:04:53 +09:00
|
|
|
:param sort_dir:
|
2014-10-24 20:14:46 +04:00
|
|
|
|
|
|
|
The direction by which the resulting image list throughout all pages
|
|
|
|
(if pagination is enabled) will be sorted. Could be either 'asc'
|
|
|
|
(ascending) or 'desc' (descending), defaults to 'desc'.
|
|
|
|
|
2016-09-21 09:04:53 +09:00
|
|
|
:param sort_key:
|
2014-10-24 20:14:46 +04:00
|
|
|
|
|
|
|
The name of key by by which the resulting image list throughout all
|
|
|
|
pages (if pagination is enabled) will be sorted. Defaults to
|
|
|
|
'created_at'.
|
|
|
|
|
2016-09-21 09:04:53 +09:00
|
|
|
:param filters:
|
2014-10-24 20:14:46 +04:00
|
|
|
|
|
|
|
A dictionary of filters passed as is to Glance service.
|
|
|
|
|
2016-09-21 09:04:53 +09:00
|
|
|
:param paginate:
|
2014-10-24 20:14:46 +04:00
|
|
|
|
|
|
|
Whether the pagination is enabled. If it is, then the number of
|
|
|
|
entries on a single page of images table is limited to the specific
|
|
|
|
number stored in browser cookies.
|
|
|
|
|
2016-09-21 09:04:53 +09:00
|
|
|
:param reversed_order:
|
2014-10-24 20:14:46 +04:00
|
|
|
|
|
|
|
Set this flag to True when it's necessary to get a reversed list of
|
|
|
|
images from Glance (used for navigating the images list back in UI).
|
|
|
|
"""
|
2012-05-22 20:00:43 -07:00
|
|
|
limit = getattr(settings, 'API_RESULT_LIMIT', 1000)
|
2013-11-14 15:01:24 -07:00
|
|
|
page_size = utils.get_page_size(request)
|
2013-02-19 18:38:45 +11:00
|
|
|
|
|
|
|
if paginate:
|
|
|
|
request_size = page_size + 1
|
|
|
|
else:
|
|
|
|
request_size = limit
|
|
|
|
|
2015-01-26 15:12:27 +00:00
|
|
|
_normalize_list_input(filters, **kwargs)
|
2012-07-23 13:24:55 +03:00
|
|
|
kwargs = {'filters': filters or {}}
|
2015-01-26 15:12:27 +00:00
|
|
|
|
2012-07-23 13:24:55 +03:00
|
|
|
if marker:
|
|
|
|
kwargs['marker'] = marker
|
2014-04-28 16:42:43 -07:00
|
|
|
kwargs['sort_key'] = sort_key
|
2013-02-19 18:38:45 +11:00
|
|
|
|
2014-10-24 20:14:46 +04:00
|
|
|
if not reversed_order:
|
|
|
|
kwargs['sort_dir'] = sort_dir
|
|
|
|
else:
|
|
|
|
kwargs['sort_dir'] = 'desc' if sort_dir == 'asc' else 'asc'
|
|
|
|
|
2013-02-19 18:38:45 +11:00
|
|
|
images_iter = glanceclient(request).images.list(page_size=request_size,
|
2012-07-23 13:24:55 +03:00
|
|
|
limit=limit,
|
2013-02-19 18:38:45 +11:00
|
|
|
**kwargs)
|
2014-04-28 16:42:43 -07:00
|
|
|
has_prev_data = False
|
2013-02-19 18:38:45 +11:00
|
|
|
has_more_data = False
|
|
|
|
if paginate:
|
|
|
|
images = list(itertools.islice(images_iter, request_size))
|
2014-04-28 16:42:43 -07:00
|
|
|
# first and middle page condition
|
2013-02-19 18:38:45 +11:00
|
|
|
if len(images) > page_size:
|
|
|
|
images.pop(-1)
|
|
|
|
has_more_data = True
|
2014-04-28 16:42:43 -07:00
|
|
|
# middle page condition
|
|
|
|
if marker is not None:
|
|
|
|
has_prev_data = True
|
|
|
|
# first page condition when reached via prev back
|
2014-10-24 20:14:46 +04:00
|
|
|
elif reversed_order and marker is not None:
|
2014-04-28 16:42:43 -07:00
|
|
|
has_more_data = True
|
|
|
|
# last page condition
|
|
|
|
elif marker is not None:
|
|
|
|
has_prev_data = True
|
2014-10-24 20:14:46 +04:00
|
|
|
|
|
|
|
# restore the original ordering here
|
|
|
|
if reversed_order:
|
|
|
|
images = sorted(images, key=lambda image:
|
|
|
|
(getattr(image, sort_key) or '').lower(),
|
|
|
|
reverse=(sort_dir == 'desc'))
|
2012-05-22 20:00:43 -07:00
|
|
|
else:
|
2013-02-19 18:38:45 +11:00
|
|
|
images = list(images_iter)
|
2014-10-24 20:14:46 +04:00
|
|
|
|
2015-01-26 15:12:27 +00:00
|
|
|
# TODO(jpichon): Do it better
|
|
|
|
wrapped_images = []
|
|
|
|
for image in images:
|
|
|
|
wrapped_images.append(Image(image))
|
|
|
|
|
|
|
|
return wrapped_images, has_more_data, has_prev_data
|
2011-10-31 11:31:05 -07:00
|
|
|
|
|
|
|
|
2016-07-08 19:04:42 +03:00
|
|
|
@profiler.trace
|
2012-04-12 17:13:56 -07:00
|
|
|
def image_update(request, image_id, **kwargs):
|
2014-12-08 15:13:51 +02:00
|
|
|
image_data = kwargs.get('data', None)
|
|
|
|
try:
|
2015-01-26 15:12:27 +00:00
|
|
|
# Horizon doesn't support purging image properties. Make sure we don't
|
|
|
|
# unintentionally remove properties when using v1. We don't need a
|
|
|
|
# similar setting for v2 because you have to specify which properties
|
|
|
|
# to remove, and the default is nothing gets removed.
|
|
|
|
if VERSIONS.active < 2:
|
|
|
|
kwargs['purge_props'] = False
|
|
|
|
return Image(glanceclient(request).images.update(
|
|
|
|
image_id, **kwargs))
|
2014-12-08 15:13:51 +02:00
|
|
|
finally:
|
|
|
|
if image_data:
|
|
|
|
try:
|
|
|
|
os.remove(image_data.file.name)
|
|
|
|
except Exception as e:
|
2015-05-22 10:54:42 +08:00
|
|
|
filename = str(image_data.file)
|
|
|
|
if hasattr(image_data.file, 'name'):
|
|
|
|
filename = image_data.file.name
|
2017-03-28 16:47:28 +02:00
|
|
|
LOG.warning('Failed to remove temporary image file '
|
|
|
|
'%(file)s (%(e)s)',
|
|
|
|
{'file': filename, 'e': e})
|
2011-10-31 11:31:05 -07:00
|
|
|
|
|
|
|
|
2016-05-19 18:15:24 +03:00
|
|
|
def get_image_upload_mode():
|
|
|
|
if getattr(settings, 'HORIZON_IMAGES_ALLOW_UPLOAD', None) is False:
|
|
|
|
return 'off'
|
|
|
|
mode = getattr(settings, 'HORIZON_IMAGES_UPLOAD_MODE', 'legacy')
|
|
|
|
if mode not in ('off', 'legacy', 'direct'):
|
|
|
|
LOG.warning('HORIZON_IMAGES_UPLOAD_MODE has an unrecognized value of '
|
2017-03-28 16:47:28 +02:00
|
|
|
'"%s", reverting to default "legacy" value', mode)
|
2016-05-19 18:15:24 +03:00
|
|
|
mode = 'legacy'
|
|
|
|
return mode
|
|
|
|
|
|
|
|
|
2015-01-26 15:12:27 +00:00
|
|
|
class ExternallyUploadedImage(Image):
|
2016-05-19 18:15:24 +03:00
|
|
|
def __init__(self, apiresource, request):
|
2015-01-26 15:12:27 +00:00
|
|
|
super(ExternallyUploadedImage, self).__init__(apiresource)
|
2017-01-05 17:26:05 -02:00
|
|
|
image_endpoint = base.url_for(request, 'image', 'publicURL')
|
2015-01-26 15:12:27 +00:00
|
|
|
if VERSIONS.active >= 2:
|
|
|
|
upload_template = "%s/v2/images/%s/file"
|
|
|
|
else:
|
|
|
|
upload_template = "%s/v1/images/%s"
|
|
|
|
self._url = upload_template % (image_endpoint, self.id)
|
2016-05-19 18:15:24 +03:00
|
|
|
self._token_id = request.user.token.id
|
|
|
|
|
|
|
|
def to_dict(self):
|
|
|
|
base_dict = super(ExternallyUploadedImage, self).to_dict()
|
|
|
|
base_dict.update({
|
|
|
|
'upload_url': self._url,
|
|
|
|
'token_id': self._token_id
|
|
|
|
})
|
|
|
|
return base_dict
|
|
|
|
|
2015-01-26 15:12:27 +00:00
|
|
|
@property
|
|
|
|
def upload_url(self):
|
|
|
|
return self._url
|
|
|
|
|
|
|
|
@property
|
|
|
|
def token_id(self):
|
|
|
|
return self._token_id
|
|
|
|
|
2016-05-19 18:15:24 +03:00
|
|
|
|
2016-07-08 19:04:42 +03:00
|
|
|
@profiler.trace
|
2012-06-04 20:54:19 -07:00
|
|
|
def image_create(request, **kwargs):
|
2015-04-02 10:37:28 +02:00
|
|
|
"""Create image.
|
|
|
|
|
2015-08-18 17:13:29 -06:00
|
|
|
:param kwargs:
|
|
|
|
* copy_from: URL from which Glance server should immediately copy
|
|
|
|
the data and store it in its configured image store.
|
|
|
|
* data: Form data posted from client.
|
|
|
|
* location: URL where the data for this image already resides.
|
2015-04-02 10:37:28 +02:00
|
|
|
|
2015-08-18 17:13:29 -06:00
|
|
|
In the case of 'copy_from' and 'location', the Glance server
|
2015-04-02 10:37:28 +02:00
|
|
|
will give us a immediate response from create and handle the data
|
|
|
|
asynchronously.
|
|
|
|
|
|
|
|
In the case of 'data' the process of uploading the data may take
|
2015-12-23 17:07:38 +08:00
|
|
|
some time and is handed off to a separate thread.
|
2015-04-02 10:37:28 +02:00
|
|
|
"""
|
2014-05-22 18:27:42 -07:00
|
|
|
data = kwargs.pop('data', None)
|
2015-01-26 15:12:27 +00:00
|
|
|
location = None
|
|
|
|
if VERSIONS.active >= 2:
|
|
|
|
location = kwargs.pop('location', None)
|
2012-06-04 20:54:19 -07:00
|
|
|
|
|
|
|
image = glanceclient(request).images.create(**kwargs)
|
2015-01-26 15:12:27 +00:00
|
|
|
if location is not None:
|
|
|
|
glanceclient(request).images.add_location(image.id, location, {})
|
2012-06-04 20:54:19 -07:00
|
|
|
|
2014-05-22 18:27:42 -07:00
|
|
|
if data:
|
2016-05-19 18:15:24 +03:00
|
|
|
if isinstance(data, six.string_types):
|
|
|
|
# The image data is meant to be uploaded externally, return a
|
|
|
|
# special wrapper to bypass the web server in a subsequent upload
|
|
|
|
return ExternallyUploadedImage(image, request)
|
|
|
|
elif isinstance(data, TemporaryUploadedFile):
|
2015-05-22 10:54:42 +08:00
|
|
|
# Hack to fool Django, so we can keep file open in the new thread.
|
|
|
|
data.file.close_called = True
|
2016-05-19 18:15:24 +03:00
|
|
|
elif isinstance(data, InMemoryUploadedFile):
|
2015-05-22 10:54:42 +08:00
|
|
|
# Clone a new file for InMemeoryUploadedFile.
|
|
|
|
# Because the old one will be closed by Django.
|
|
|
|
data = SimpleUploadedFile(data.name,
|
|
|
|
data.read(),
|
|
|
|
data.content_type)
|
2015-01-26 15:12:27 +00:00
|
|
|
if VERSIONS.active < 2:
|
|
|
|
thread.start_new_thread(image_update,
|
|
|
|
(request, image.id),
|
|
|
|
{'data': data})
|
|
|
|
else:
|
|
|
|
def upload():
|
|
|
|
return glanceclient(request).images.upload(image.id, data)
|
|
|
|
thread.start_new_thread(upload, ())
|
|
|
|
|
|
|
|
return Image(image)
|
2014-01-29 08:30:19 -06:00
|
|
|
|
|
|
|
|
2016-07-08 19:04:42 +03:00
|
|
|
@profiler.trace
|
2014-09-11 19:10:41 +02:00
|
|
|
def image_update_properties(request, image_id, remove_props=None, **kwargs):
|
2014-01-29 08:30:19 -06:00
|
|
|
"""Add or update a custom property of an image."""
|
2014-09-11 19:10:41 +02:00
|
|
|
return glanceclient(request, '2').images.update(image_id,
|
|
|
|
remove_props,
|
|
|
|
**kwargs)
|
2014-01-29 08:30:19 -06:00
|
|
|
|
|
|
|
|
2016-07-08 19:04:42 +03:00
|
|
|
@profiler.trace
|
2014-01-29 08:30:19 -06:00
|
|
|
def image_delete_properties(request, image_id, keys):
|
|
|
|
"""Delete custom properties for an image."""
|
|
|
|
return glanceclient(request, '2').images.update(image_id, keys)
|
2014-09-11 19:10:41 +02:00
|
|
|
|
|
|
|
|
|
|
|
class BaseGlanceMetadefAPIResourceWrapper(base.APIResourceWrapper):
|
|
|
|
|
|
|
|
@property
|
|
|
|
def description(self):
|
|
|
|
return (getattr(self._apiresource, 'description', None) or
|
|
|
|
getattr(self._apiresource, 'display_name', None))
|
|
|
|
|
|
|
|
def as_json(self, indent=4):
|
|
|
|
result = collections.OrderedDict()
|
|
|
|
for attr in self._attrs:
|
|
|
|
if hasattr(self, attr):
|
|
|
|
result[attr] = getattr(self, attr)
|
|
|
|
return json.dumps(result, indent=indent)
|
|
|
|
|
2015-01-29 13:28:48 -07:00
|
|
|
def to_dict(self):
|
|
|
|
return self._apiresource
|
|
|
|
|
2014-09-11 19:10:41 +02:00
|
|
|
|
|
|
|
class Namespace(BaseGlanceMetadefAPIResourceWrapper):
|
|
|
|
|
|
|
|
_attrs = ['namespace', 'display_name', 'description',
|
|
|
|
'resource_type_associations', 'visibility', 'protected',
|
|
|
|
'created_at', 'updated_at', 'properties', 'objects']
|
|
|
|
|
|
|
|
@property
|
Base Glance Metadata Definitions Admin UI
Provide a base admin UI for viewing, importing, and associating the
metadata definitions that can be used with various resource types
such as flavors, images, and host aggregates.
In Juno, Glance provided a metadata definitions catalog[1][2] where
users can register the available metadata definitions that can be used
on different types of resources (images, artifacts, volumes, flavors,
aggregates, etc). This includes key / value pairs such as
properties, extra specs, etc. Horizon landed several patches that
read these properties. You can view the functionality in the
"update metadata" action on Flavors, Images, and Host Aggregates.
This specific patch is to bring in the Admin UI for the basic coarse
grained actions on the definitions in the catalog. This includes creating
(importing) a namespace, viewing the overview details about
it, deleting the namespace, and associating the namespace for use with
specific resource types.
Future blueprints will be registered for:
- CRUD on individual metadata definitions within the namespace
For example, editing the default value of an individual property.
[1] Approved Glance Juno Spec:
https://github.com/openstack/glance-specs/blob/master/specs/juno/metadata-schema-catalog.rst
[2] Glance PTL Juno Feature Overview:
https://www.youtube.com/watch?v=3ptriiw1wK8&t=14m27s
Co-Authored-By: Travis Tripp <travis.tripp@hp.com>
Co-Authored-By: Santiago Baldassin<santiago.b.baldassin@intel.com>
Co-Authored-By: Bartosz Fic <bartosz.fic@intel.com>
Co-Authored-By: Pawel Koniszewski <pawel.koniszewski@intel.com>
Co-Authored-By: Michal Dulko <michal.dulko@intel.com>
DocImpact: Concept awareness
Change-Id: Ie34007f73af7e0941631a52f03841068e509a72c
Implements: blueprint glance-metadata-definitions-base-admin-ui
2014-09-12 13:54:01 +02:00
|
|
|
def resource_type_names(self):
|
2014-09-11 19:10:41 +02:00
|
|
|
result = [resource_type['name'] for resource_type in
|
2014-09-30 22:41:11 +09:00
|
|
|
getattr(self._apiresource, 'resource_type_associations')]
|
Base Glance Metadata Definitions Admin UI
Provide a base admin UI for viewing, importing, and associating the
metadata definitions that can be used with various resource types
such as flavors, images, and host aggregates.
In Juno, Glance provided a metadata definitions catalog[1][2] where
users can register the available metadata definitions that can be used
on different types of resources (images, artifacts, volumes, flavors,
aggregates, etc). This includes key / value pairs such as
properties, extra specs, etc. Horizon landed several patches that
read these properties. You can view the functionality in the
"update metadata" action on Flavors, Images, and Host Aggregates.
This specific patch is to bring in the Admin UI for the basic coarse
grained actions on the definitions in the catalog. This includes creating
(importing) a namespace, viewing the overview details about
it, deleting the namespace, and associating the namespace for use with
specific resource types.
Future blueprints will be registered for:
- CRUD on individual metadata definitions within the namespace
For example, editing the default value of an individual property.
[1] Approved Glance Juno Spec:
https://github.com/openstack/glance-specs/blob/master/specs/juno/metadata-schema-catalog.rst
[2] Glance PTL Juno Feature Overview:
https://www.youtube.com/watch?v=3ptriiw1wK8&t=14m27s
Co-Authored-By: Travis Tripp <travis.tripp@hp.com>
Co-Authored-By: Santiago Baldassin<santiago.b.baldassin@intel.com>
Co-Authored-By: Bartosz Fic <bartosz.fic@intel.com>
Co-Authored-By: Pawel Koniszewski <pawel.koniszewski@intel.com>
Co-Authored-By: Michal Dulko <michal.dulko@intel.com>
DocImpact: Concept awareness
Change-Id: Ie34007f73af7e0941631a52f03841068e509a72c
Implements: blueprint glance-metadata-definitions-base-admin-ui
2014-09-12 13:54:01 +02:00
|
|
|
|
|
|
|
return sorted(result)
|
2014-09-11 19:10:41 +02:00
|
|
|
|
|
|
|
@property
|
|
|
|
def public(self):
|
|
|
|
if getattr(self._apiresource, 'visibility') == 'public':
|
|
|
|
return True
|
|
|
|
else:
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
2016-01-25 16:20:07 -06:00
|
|
|
def filter_properties_target(namespaces_iter,
|
|
|
|
resource_types,
|
|
|
|
properties_target):
|
2017-06-09 10:47:12 +00:00
|
|
|
"""Filter metadata namespaces.
|
|
|
|
|
|
|
|
Filtering is done based ongiven resource types and a properties target.
|
2016-01-25 16:20:07 -06:00
|
|
|
|
|
|
|
:param namespaces_iter: Metadata namespaces iterable.
|
|
|
|
:param resource_types: List of resource type names.
|
|
|
|
:param properties_target: Name of the properties target.
|
|
|
|
"""
|
|
|
|
def filter_namespace(namespace):
|
|
|
|
for asn in namespace.get('resource_type_associations'):
|
|
|
|
if (asn.get('name') in resource_types and
|
|
|
|
asn.get('properties_target') == properties_target):
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
return filter(filter_namespace, namespaces_iter)
|
|
|
|
|
|
|
|
|
2015-04-01 19:33:22 +02:00
|
|
|
@memoized
|
2014-09-11 19:10:41 +02:00
|
|
|
def metadefs_namespace_get(request, namespace, resource_type=None, wrap=False):
|
|
|
|
namespace = glanceclient(request, '2').\
|
|
|
|
metadefs_namespace.get(namespace, resource_type=resource_type)
|
|
|
|
# There were problems with using the wrapper class in
|
2015-03-18 11:37:49 -07:00
|
|
|
# nested json serialization. So sometimes, it is not desirable
|
2014-09-11 19:10:41 +02:00
|
|
|
# to wrap.
|
|
|
|
if wrap:
|
|
|
|
return Namespace(namespace)
|
|
|
|
else:
|
|
|
|
return namespace
|
|
|
|
|
|
|
|
|
2016-07-08 19:04:42 +03:00
|
|
|
@profiler.trace
|
2014-09-11 19:10:41 +02:00
|
|
|
def metadefs_namespace_list(request,
|
2015-09-21 13:22:59 +03:00
|
|
|
filters=None,
|
Base Glance Metadata Definitions Admin UI
Provide a base admin UI for viewing, importing, and associating the
metadata definitions that can be used with various resource types
such as flavors, images, and host aggregates.
In Juno, Glance provided a metadata definitions catalog[1][2] where
users can register the available metadata definitions that can be used
on different types of resources (images, artifacts, volumes, flavors,
aggregates, etc). This includes key / value pairs such as
properties, extra specs, etc. Horizon landed several patches that
read these properties. You can view the functionality in the
"update metadata" action on Flavors, Images, and Host Aggregates.
This specific patch is to bring in the Admin UI for the basic coarse
grained actions on the definitions in the catalog. This includes creating
(importing) a namespace, viewing the overview details about
it, deleting the namespace, and associating the namespace for use with
specific resource types.
Future blueprints will be registered for:
- CRUD on individual metadata definitions within the namespace
For example, editing the default value of an individual property.
[1] Approved Glance Juno Spec:
https://github.com/openstack/glance-specs/blob/master/specs/juno/metadata-schema-catalog.rst
[2] Glance PTL Juno Feature Overview:
https://www.youtube.com/watch?v=3ptriiw1wK8&t=14m27s
Co-Authored-By: Travis Tripp <travis.tripp@hp.com>
Co-Authored-By: Santiago Baldassin<santiago.b.baldassin@intel.com>
Co-Authored-By: Bartosz Fic <bartosz.fic@intel.com>
Co-Authored-By: Pawel Koniszewski <pawel.koniszewski@intel.com>
Co-Authored-By: Michal Dulko <michal.dulko@intel.com>
DocImpact: Concept awareness
Change-Id: Ie34007f73af7e0941631a52f03841068e509a72c
Implements: blueprint glance-metadata-definitions-base-admin-ui
2014-09-12 13:54:01 +02:00
|
|
|
sort_dir='asc',
|
|
|
|
sort_key='namespace',
|
2014-09-11 19:10:41 +02:00
|
|
|
marker=None,
|
|
|
|
paginate=False):
|
Base Glance Metadata Definitions Admin UI
Provide a base admin UI for viewing, importing, and associating the
metadata definitions that can be used with various resource types
such as flavors, images, and host aggregates.
In Juno, Glance provided a metadata definitions catalog[1][2] where
users can register the available metadata definitions that can be used
on different types of resources (images, artifacts, volumes, flavors,
aggregates, etc). This includes key / value pairs such as
properties, extra specs, etc. Horizon landed several patches that
read these properties. You can view the functionality in the
"update metadata" action on Flavors, Images, and Host Aggregates.
This specific patch is to bring in the Admin UI for the basic coarse
grained actions on the definitions in the catalog. This includes creating
(importing) a namespace, viewing the overview details about
it, deleting the namespace, and associating the namespace for use with
specific resource types.
Future blueprints will be registered for:
- CRUD on individual metadata definitions within the namespace
For example, editing the default value of an individual property.
[1] Approved Glance Juno Spec:
https://github.com/openstack/glance-specs/blob/master/specs/juno/metadata-schema-catalog.rst
[2] Glance PTL Juno Feature Overview:
https://www.youtube.com/watch?v=3ptriiw1wK8&t=14m27s
Co-Authored-By: Travis Tripp <travis.tripp@hp.com>
Co-Authored-By: Santiago Baldassin<santiago.b.baldassin@intel.com>
Co-Authored-By: Bartosz Fic <bartosz.fic@intel.com>
Co-Authored-By: Pawel Koniszewski <pawel.koniszewski@intel.com>
Co-Authored-By: Michal Dulko <michal.dulko@intel.com>
DocImpact: Concept awareness
Change-Id: Ie34007f73af7e0941631a52f03841068e509a72c
Implements: blueprint glance-metadata-definitions-base-admin-ui
2014-09-12 13:54:01 +02:00
|
|
|
"""Retrieve a listing of Namespaces
|
2015-08-18 17:13:29 -06:00
|
|
|
|
Base Glance Metadata Definitions Admin UI
Provide a base admin UI for viewing, importing, and associating the
metadata definitions that can be used with various resource types
such as flavors, images, and host aggregates.
In Juno, Glance provided a metadata definitions catalog[1][2] where
users can register the available metadata definitions that can be used
on different types of resources (images, artifacts, volumes, flavors,
aggregates, etc). This includes key / value pairs such as
properties, extra specs, etc. Horizon landed several patches that
read these properties. You can view the functionality in the
"update metadata" action on Flavors, Images, and Host Aggregates.
This specific patch is to bring in the Admin UI for the basic coarse
grained actions on the definitions in the catalog. This includes creating
(importing) a namespace, viewing the overview details about
it, deleting the namespace, and associating the namespace for use with
specific resource types.
Future blueprints will be registered for:
- CRUD on individual metadata definitions within the namespace
For example, editing the default value of an individual property.
[1] Approved Glance Juno Spec:
https://github.com/openstack/glance-specs/blob/master/specs/juno/metadata-schema-catalog.rst
[2] Glance PTL Juno Feature Overview:
https://www.youtube.com/watch?v=3ptriiw1wK8&t=14m27s
Co-Authored-By: Travis Tripp <travis.tripp@hp.com>
Co-Authored-By: Santiago Baldassin<santiago.b.baldassin@intel.com>
Co-Authored-By: Bartosz Fic <bartosz.fic@intel.com>
Co-Authored-By: Pawel Koniszewski <pawel.koniszewski@intel.com>
Co-Authored-By: Michal Dulko <michal.dulko@intel.com>
DocImpact: Concept awareness
Change-Id: Ie34007f73af7e0941631a52f03841068e509a72c
Implements: blueprint glance-metadata-definitions-base-admin-ui
2014-09-12 13:54:01 +02:00
|
|
|
:param paginate: If true will perform pagination based on settings.
|
|
|
|
:param marker: Specifies the namespace of the last-seen namespace.
|
|
|
|
The typical pattern of limit and marker is to make an
|
|
|
|
initial limited request and then to use the last
|
|
|
|
namespace from the response as the marker parameter
|
|
|
|
in a subsequent limited request. With paginate, limit
|
|
|
|
is automatically set.
|
|
|
|
:param sort_dir: The sort direction ('asc' or 'desc').
|
|
|
|
:param sort_key: The field to sort on (for example, 'created_at'). Default
|
|
|
|
is namespace. The way base namespaces are loaded into glance
|
|
|
|
typically at first deployment is done in a single transaction
|
|
|
|
giving them a potentially unpredictable sort result when using
|
|
|
|
create_at.
|
2015-01-29 13:28:48 -07:00
|
|
|
:param filters: specifies addition fields to filter on such as
|
|
|
|
resource_types.
|
Base Glance Metadata Definitions Admin UI
Provide a base admin UI for viewing, importing, and associating the
metadata definitions that can be used with various resource types
such as flavors, images, and host aggregates.
In Juno, Glance provided a metadata definitions catalog[1][2] where
users can register the available metadata definitions that can be used
on different types of resources (images, artifacts, volumes, flavors,
aggregates, etc). This includes key / value pairs such as
properties, extra specs, etc. Horizon landed several patches that
read these properties. You can view the functionality in the
"update metadata" action on Flavors, Images, and Host Aggregates.
This specific patch is to bring in the Admin UI for the basic coarse
grained actions on the definitions in the catalog. This includes creating
(importing) a namespace, viewing the overview details about
it, deleting the namespace, and associating the namespace for use with
specific resource types.
Future blueprints will be registered for:
- CRUD on individual metadata definitions within the namespace
For example, editing the default value of an individual property.
[1] Approved Glance Juno Spec:
https://github.com/openstack/glance-specs/blob/master/specs/juno/metadata-schema-catalog.rst
[2] Glance PTL Juno Feature Overview:
https://www.youtube.com/watch?v=3ptriiw1wK8&t=14m27s
Co-Authored-By: Travis Tripp <travis.tripp@hp.com>
Co-Authored-By: Santiago Baldassin<santiago.b.baldassin@intel.com>
Co-Authored-By: Bartosz Fic <bartosz.fic@intel.com>
Co-Authored-By: Pawel Koniszewski <pawel.koniszewski@intel.com>
Co-Authored-By: Michal Dulko <michal.dulko@intel.com>
DocImpact: Concept awareness
Change-Id: Ie34007f73af7e0941631a52f03841068e509a72c
Implements: blueprint glance-metadata-definitions-base-admin-ui
2014-09-12 13:54:01 +02:00
|
|
|
:returns A tuple of three values:
|
2015-08-18 17:13:29 -06:00
|
|
|
1) Current page results
|
|
|
|
2) A boolean of whether or not there are previous page(s).
|
|
|
|
3) A boolean of whether or not there are more page(s).
|
|
|
|
|
Base Glance Metadata Definitions Admin UI
Provide a base admin UI for viewing, importing, and associating the
metadata definitions that can be used with various resource types
such as flavors, images, and host aggregates.
In Juno, Glance provided a metadata definitions catalog[1][2] where
users can register the available metadata definitions that can be used
on different types of resources (images, artifacts, volumes, flavors,
aggregates, etc). This includes key / value pairs such as
properties, extra specs, etc. Horizon landed several patches that
read these properties. You can view the functionality in the
"update metadata" action on Flavors, Images, and Host Aggregates.
This specific patch is to bring in the Admin UI for the basic coarse
grained actions on the definitions in the catalog. This includes creating
(importing) a namespace, viewing the overview details about
it, deleting the namespace, and associating the namespace for use with
specific resource types.
Future blueprints will be registered for:
- CRUD on individual metadata definitions within the namespace
For example, editing the default value of an individual property.
[1] Approved Glance Juno Spec:
https://github.com/openstack/glance-specs/blob/master/specs/juno/metadata-schema-catalog.rst
[2] Glance PTL Juno Feature Overview:
https://www.youtube.com/watch?v=3ptriiw1wK8&t=14m27s
Co-Authored-By: Travis Tripp <travis.tripp@hp.com>
Co-Authored-By: Santiago Baldassin<santiago.b.baldassin@intel.com>
Co-Authored-By: Bartosz Fic <bartosz.fic@intel.com>
Co-Authored-By: Pawel Koniszewski <pawel.koniszewski@intel.com>
Co-Authored-By: Michal Dulko <michal.dulko@intel.com>
DocImpact: Concept awareness
Change-Id: Ie34007f73af7e0941631a52f03841068e509a72c
Implements: blueprint glance-metadata-definitions-base-admin-ui
2014-09-12 13:54:01 +02:00
|
|
|
"""
|
2015-11-17 10:19:59 -06:00
|
|
|
# Listing namespaces requires the v2 API. If not supported we return an
|
|
|
|
# empty array so callers don't need to worry about version checking.
|
|
|
|
if get_version() < 2:
|
|
|
|
return [], False, False
|
|
|
|
|
2015-09-21 13:22:59 +03:00
|
|
|
if filters is None:
|
|
|
|
filters = {}
|
2014-09-11 19:10:41 +02:00
|
|
|
limit = getattr(settings, 'API_RESULT_LIMIT', 1000)
|
|
|
|
page_size = utils.get_page_size(request)
|
|
|
|
|
|
|
|
if paginate:
|
|
|
|
request_size = page_size + 1
|
|
|
|
else:
|
|
|
|
request_size = limit
|
|
|
|
|
|
|
|
kwargs = {'filters': filters}
|
|
|
|
if marker:
|
|
|
|
kwargs['marker'] = marker
|
|
|
|
kwargs['sort_dir'] = sort_dir
|
|
|
|
kwargs['sort_key'] = sort_key
|
|
|
|
|
|
|
|
namespaces_iter = glanceclient(request, '2').metadefs_namespace.list(
|
|
|
|
page_size=request_size, limit=limit, **kwargs)
|
|
|
|
|
2016-01-25 16:20:07 -06:00
|
|
|
# Filter the namespaces based on the provided properties_target since this
|
|
|
|
# is not supported by the metadata namespaces API.
|
|
|
|
resource_types = filters.get('resource_types')
|
|
|
|
properties_target = filters.get('properties_target')
|
|
|
|
if resource_types and properties_target:
|
|
|
|
namespaces_iter = filter_properties_target(namespaces_iter,
|
|
|
|
resource_types,
|
|
|
|
properties_target)
|
|
|
|
|
2014-09-11 19:10:41 +02:00
|
|
|
has_prev_data = False
|
|
|
|
has_more_data = False
|
|
|
|
if paginate:
|
|
|
|
namespaces = list(itertools.islice(namespaces_iter, request_size))
|
|
|
|
# first and middle page condition
|
|
|
|
if len(namespaces) > page_size:
|
|
|
|
namespaces.pop(-1)
|
|
|
|
has_more_data = True
|
|
|
|
# middle page condition
|
|
|
|
if marker is not None:
|
|
|
|
has_prev_data = True
|
|
|
|
# first page condition when reached via prev back
|
Base Glance Metadata Definitions Admin UI
Provide a base admin UI for viewing, importing, and associating the
metadata definitions that can be used with various resource types
such as flavors, images, and host aggregates.
In Juno, Glance provided a metadata definitions catalog[1][2] where
users can register the available metadata definitions that can be used
on different types of resources (images, artifacts, volumes, flavors,
aggregates, etc). This includes key / value pairs such as
properties, extra specs, etc. Horizon landed several patches that
read these properties. You can view the functionality in the
"update metadata" action on Flavors, Images, and Host Aggregates.
This specific patch is to bring in the Admin UI for the basic coarse
grained actions on the definitions in the catalog. This includes creating
(importing) a namespace, viewing the overview details about
it, deleting the namespace, and associating the namespace for use with
specific resource types.
Future blueprints will be registered for:
- CRUD on individual metadata definitions within the namespace
For example, editing the default value of an individual property.
[1] Approved Glance Juno Spec:
https://github.com/openstack/glance-specs/blob/master/specs/juno/metadata-schema-catalog.rst
[2] Glance PTL Juno Feature Overview:
https://www.youtube.com/watch?v=3ptriiw1wK8&t=14m27s
Co-Authored-By: Travis Tripp <travis.tripp@hp.com>
Co-Authored-By: Santiago Baldassin<santiago.b.baldassin@intel.com>
Co-Authored-By: Bartosz Fic <bartosz.fic@intel.com>
Co-Authored-By: Pawel Koniszewski <pawel.koniszewski@intel.com>
Co-Authored-By: Michal Dulko <michal.dulko@intel.com>
DocImpact: Concept awareness
Change-Id: Ie34007f73af7e0941631a52f03841068e509a72c
Implements: blueprint glance-metadata-definitions-base-admin-ui
2014-09-12 13:54:01 +02:00
|
|
|
elif sort_dir == 'desc' and marker is not None:
|
2014-09-11 19:10:41 +02:00
|
|
|
has_more_data = True
|
|
|
|
# last page condition
|
|
|
|
elif marker is not None:
|
|
|
|
has_prev_data = True
|
|
|
|
else:
|
|
|
|
namespaces = list(namespaces_iter)
|
|
|
|
|
|
|
|
namespaces = [Namespace(namespace) for namespace in namespaces]
|
|
|
|
return namespaces, has_more_data, has_prev_data
|
Base Glance Metadata Definitions Admin UI
Provide a base admin UI for viewing, importing, and associating the
metadata definitions that can be used with various resource types
such as flavors, images, and host aggregates.
In Juno, Glance provided a metadata definitions catalog[1][2] where
users can register the available metadata definitions that can be used
on different types of resources (images, artifacts, volumes, flavors,
aggregates, etc). This includes key / value pairs such as
properties, extra specs, etc. Horizon landed several patches that
read these properties. You can view the functionality in the
"update metadata" action on Flavors, Images, and Host Aggregates.
This specific patch is to bring in the Admin UI for the basic coarse
grained actions on the definitions in the catalog. This includes creating
(importing) a namespace, viewing the overview details about
it, deleting the namespace, and associating the namespace for use with
specific resource types.
Future blueprints will be registered for:
- CRUD on individual metadata definitions within the namespace
For example, editing the default value of an individual property.
[1] Approved Glance Juno Spec:
https://github.com/openstack/glance-specs/blob/master/specs/juno/metadata-schema-catalog.rst
[2] Glance PTL Juno Feature Overview:
https://www.youtube.com/watch?v=3ptriiw1wK8&t=14m27s
Co-Authored-By: Travis Tripp <travis.tripp@hp.com>
Co-Authored-By: Santiago Baldassin<santiago.b.baldassin@intel.com>
Co-Authored-By: Bartosz Fic <bartosz.fic@intel.com>
Co-Authored-By: Pawel Koniszewski <pawel.koniszewski@intel.com>
Co-Authored-By: Michal Dulko <michal.dulko@intel.com>
DocImpact: Concept awareness
Change-Id: Ie34007f73af7e0941631a52f03841068e509a72c
Implements: blueprint glance-metadata-definitions-base-admin-ui
2014-09-12 13:54:01 +02:00
|
|
|
|
|
|
|
|
2016-07-08 19:04:42 +03:00
|
|
|
@profiler.trace
|
2015-12-15 12:13:17 +08:00
|
|
|
def metadefs_namespace_full_list(request, resource_type, filters=None,
|
2015-04-01 19:33:22 +02:00
|
|
|
*args, **kwargs):
|
2015-12-15 12:13:17 +08:00
|
|
|
filters = filters or {}
|
2015-04-01 19:33:22 +02:00
|
|
|
filters['resource_types'] = [resource_type]
|
|
|
|
namespaces, has_more_data, has_prev_data = metadefs_namespace_list(
|
|
|
|
request, filters, *args, **kwargs
|
|
|
|
)
|
|
|
|
return [
|
|
|
|
metadefs_namespace_get(request, x.namespace, resource_type)
|
|
|
|
for x in namespaces
|
|
|
|
], has_more_data, has_prev_data
|
|
|
|
|
|
|
|
|
2016-07-08 19:04:42 +03:00
|
|
|
@profiler.trace
|
Base Glance Metadata Definitions Admin UI
Provide a base admin UI for viewing, importing, and associating the
metadata definitions that can be used with various resource types
such as flavors, images, and host aggregates.
In Juno, Glance provided a metadata definitions catalog[1][2] where
users can register the available metadata definitions that can be used
on different types of resources (images, artifacts, volumes, flavors,
aggregates, etc). This includes key / value pairs such as
properties, extra specs, etc. Horizon landed several patches that
read these properties. You can view the functionality in the
"update metadata" action on Flavors, Images, and Host Aggregates.
This specific patch is to bring in the Admin UI for the basic coarse
grained actions on the definitions in the catalog. This includes creating
(importing) a namespace, viewing the overview details about
it, deleting the namespace, and associating the namespace for use with
specific resource types.
Future blueprints will be registered for:
- CRUD on individual metadata definitions within the namespace
For example, editing the default value of an individual property.
[1] Approved Glance Juno Spec:
https://github.com/openstack/glance-specs/blob/master/specs/juno/metadata-schema-catalog.rst
[2] Glance PTL Juno Feature Overview:
https://www.youtube.com/watch?v=3ptriiw1wK8&t=14m27s
Co-Authored-By: Travis Tripp <travis.tripp@hp.com>
Co-Authored-By: Santiago Baldassin<santiago.b.baldassin@intel.com>
Co-Authored-By: Bartosz Fic <bartosz.fic@intel.com>
Co-Authored-By: Pawel Koniszewski <pawel.koniszewski@intel.com>
Co-Authored-By: Michal Dulko <michal.dulko@intel.com>
DocImpact: Concept awareness
Change-Id: Ie34007f73af7e0941631a52f03841068e509a72c
Implements: blueprint glance-metadata-definitions-base-admin-ui
2014-09-12 13:54:01 +02:00
|
|
|
def metadefs_namespace_create(request, namespace):
|
|
|
|
return glanceclient(request, '2').metadefs_namespace.create(**namespace)
|
|
|
|
|
|
|
|
|
2016-07-08 19:04:42 +03:00
|
|
|
@profiler.trace
|
Base Glance Metadata Definitions Admin UI
Provide a base admin UI for viewing, importing, and associating the
metadata definitions that can be used with various resource types
such as flavors, images, and host aggregates.
In Juno, Glance provided a metadata definitions catalog[1][2] where
users can register the available metadata definitions that can be used
on different types of resources (images, artifacts, volumes, flavors,
aggregates, etc). This includes key / value pairs such as
properties, extra specs, etc. Horizon landed several patches that
read these properties. You can view the functionality in the
"update metadata" action on Flavors, Images, and Host Aggregates.
This specific patch is to bring in the Admin UI for the basic coarse
grained actions on the definitions in the catalog. This includes creating
(importing) a namespace, viewing the overview details about
it, deleting the namespace, and associating the namespace for use with
specific resource types.
Future blueprints will be registered for:
- CRUD on individual metadata definitions within the namespace
For example, editing the default value of an individual property.
[1] Approved Glance Juno Spec:
https://github.com/openstack/glance-specs/blob/master/specs/juno/metadata-schema-catalog.rst
[2] Glance PTL Juno Feature Overview:
https://www.youtube.com/watch?v=3ptriiw1wK8&t=14m27s
Co-Authored-By: Travis Tripp <travis.tripp@hp.com>
Co-Authored-By: Santiago Baldassin<santiago.b.baldassin@intel.com>
Co-Authored-By: Bartosz Fic <bartosz.fic@intel.com>
Co-Authored-By: Pawel Koniszewski <pawel.koniszewski@intel.com>
Co-Authored-By: Michal Dulko <michal.dulko@intel.com>
DocImpact: Concept awareness
Change-Id: Ie34007f73af7e0941631a52f03841068e509a72c
Implements: blueprint glance-metadata-definitions-base-admin-ui
2014-09-12 13:54:01 +02:00
|
|
|
def metadefs_namespace_update(request, namespace_name, **properties):
|
|
|
|
return glanceclient(request, '2').metadefs_namespace.update(
|
|
|
|
namespace_name,
|
|
|
|
**properties)
|
|
|
|
|
|
|
|
|
2016-07-08 19:04:42 +03:00
|
|
|
@profiler.trace
|
Base Glance Metadata Definitions Admin UI
Provide a base admin UI for viewing, importing, and associating the
metadata definitions that can be used with various resource types
such as flavors, images, and host aggregates.
In Juno, Glance provided a metadata definitions catalog[1][2] where
users can register the available metadata definitions that can be used
on different types of resources (images, artifacts, volumes, flavors,
aggregates, etc). This includes key / value pairs such as
properties, extra specs, etc. Horizon landed several patches that
read these properties. You can view the functionality in the
"update metadata" action on Flavors, Images, and Host Aggregates.
This specific patch is to bring in the Admin UI for the basic coarse
grained actions on the definitions in the catalog. This includes creating
(importing) a namespace, viewing the overview details about
it, deleting the namespace, and associating the namespace for use with
specific resource types.
Future blueprints will be registered for:
- CRUD on individual metadata definitions within the namespace
For example, editing the default value of an individual property.
[1] Approved Glance Juno Spec:
https://github.com/openstack/glance-specs/blob/master/specs/juno/metadata-schema-catalog.rst
[2] Glance PTL Juno Feature Overview:
https://www.youtube.com/watch?v=3ptriiw1wK8&t=14m27s
Co-Authored-By: Travis Tripp <travis.tripp@hp.com>
Co-Authored-By: Santiago Baldassin<santiago.b.baldassin@intel.com>
Co-Authored-By: Bartosz Fic <bartosz.fic@intel.com>
Co-Authored-By: Pawel Koniszewski <pawel.koniszewski@intel.com>
Co-Authored-By: Michal Dulko <michal.dulko@intel.com>
DocImpact: Concept awareness
Change-Id: Ie34007f73af7e0941631a52f03841068e509a72c
Implements: blueprint glance-metadata-definitions-base-admin-ui
2014-09-12 13:54:01 +02:00
|
|
|
def metadefs_namespace_delete(request, namespace_name):
|
|
|
|
return glanceclient(request, '2').metadefs_namespace.delete(namespace_name)
|
|
|
|
|
|
|
|
|
2016-07-08 19:04:42 +03:00
|
|
|
@profiler.trace
|
Base Glance Metadata Definitions Admin UI
Provide a base admin UI for viewing, importing, and associating the
metadata definitions that can be used with various resource types
such as flavors, images, and host aggregates.
In Juno, Glance provided a metadata definitions catalog[1][2] where
users can register the available metadata definitions that can be used
on different types of resources (images, artifacts, volumes, flavors,
aggregates, etc). This includes key / value pairs such as
properties, extra specs, etc. Horizon landed several patches that
read these properties. You can view the functionality in the
"update metadata" action on Flavors, Images, and Host Aggregates.
This specific patch is to bring in the Admin UI for the basic coarse
grained actions on the definitions in the catalog. This includes creating
(importing) a namespace, viewing the overview details about
it, deleting the namespace, and associating the namespace for use with
specific resource types.
Future blueprints will be registered for:
- CRUD on individual metadata definitions within the namespace
For example, editing the default value of an individual property.
[1] Approved Glance Juno Spec:
https://github.com/openstack/glance-specs/blob/master/specs/juno/metadata-schema-catalog.rst
[2] Glance PTL Juno Feature Overview:
https://www.youtube.com/watch?v=3ptriiw1wK8&t=14m27s
Co-Authored-By: Travis Tripp <travis.tripp@hp.com>
Co-Authored-By: Santiago Baldassin<santiago.b.baldassin@intel.com>
Co-Authored-By: Bartosz Fic <bartosz.fic@intel.com>
Co-Authored-By: Pawel Koniszewski <pawel.koniszewski@intel.com>
Co-Authored-By: Michal Dulko <michal.dulko@intel.com>
DocImpact: Concept awareness
Change-Id: Ie34007f73af7e0941631a52f03841068e509a72c
Implements: blueprint glance-metadata-definitions-base-admin-ui
2014-09-12 13:54:01 +02:00
|
|
|
def metadefs_resource_types_list(request):
|
2015-08-21 10:16:03 -07:00
|
|
|
# Listing Resource Types requires the v2 API. If not supported we return
|
|
|
|
# an empty array so callers don't need to worry about version checking.
|
|
|
|
if get_version() < 2:
|
|
|
|
return []
|
|
|
|
else:
|
|
|
|
return glanceclient(request, '2').metadefs_resource_type.list()
|
Base Glance Metadata Definitions Admin UI
Provide a base admin UI for viewing, importing, and associating the
metadata definitions that can be used with various resource types
such as flavors, images, and host aggregates.
In Juno, Glance provided a metadata definitions catalog[1][2] where
users can register the available metadata definitions that can be used
on different types of resources (images, artifacts, volumes, flavors,
aggregates, etc). This includes key / value pairs such as
properties, extra specs, etc. Horizon landed several patches that
read these properties. You can view the functionality in the
"update metadata" action on Flavors, Images, and Host Aggregates.
This specific patch is to bring in the Admin UI for the basic coarse
grained actions on the definitions in the catalog. This includes creating
(importing) a namespace, viewing the overview details about
it, deleting the namespace, and associating the namespace for use with
specific resource types.
Future blueprints will be registered for:
- CRUD on individual metadata definitions within the namespace
For example, editing the default value of an individual property.
[1] Approved Glance Juno Spec:
https://github.com/openstack/glance-specs/blob/master/specs/juno/metadata-schema-catalog.rst
[2] Glance PTL Juno Feature Overview:
https://www.youtube.com/watch?v=3ptriiw1wK8&t=14m27s
Co-Authored-By: Travis Tripp <travis.tripp@hp.com>
Co-Authored-By: Santiago Baldassin<santiago.b.baldassin@intel.com>
Co-Authored-By: Bartosz Fic <bartosz.fic@intel.com>
Co-Authored-By: Pawel Koniszewski <pawel.koniszewski@intel.com>
Co-Authored-By: Michal Dulko <michal.dulko@intel.com>
DocImpact: Concept awareness
Change-Id: Ie34007f73af7e0941631a52f03841068e509a72c
Implements: blueprint glance-metadata-definitions-base-admin-ui
2014-09-12 13:54:01 +02:00
|
|
|
|
|
|
|
|
2016-07-08 19:04:42 +03:00
|
|
|
@profiler.trace
|
Base Glance Metadata Definitions Admin UI
Provide a base admin UI for viewing, importing, and associating the
metadata definitions that can be used with various resource types
such as flavors, images, and host aggregates.
In Juno, Glance provided a metadata definitions catalog[1][2] where
users can register the available metadata definitions that can be used
on different types of resources (images, artifacts, volumes, flavors,
aggregates, etc). This includes key / value pairs such as
properties, extra specs, etc. Horizon landed several patches that
read these properties. You can view the functionality in the
"update metadata" action on Flavors, Images, and Host Aggregates.
This specific patch is to bring in the Admin UI for the basic coarse
grained actions on the definitions in the catalog. This includes creating
(importing) a namespace, viewing the overview details about
it, deleting the namespace, and associating the namespace for use with
specific resource types.
Future blueprints will be registered for:
- CRUD on individual metadata definitions within the namespace
For example, editing the default value of an individual property.
[1] Approved Glance Juno Spec:
https://github.com/openstack/glance-specs/blob/master/specs/juno/metadata-schema-catalog.rst
[2] Glance PTL Juno Feature Overview:
https://www.youtube.com/watch?v=3ptriiw1wK8&t=14m27s
Co-Authored-By: Travis Tripp <travis.tripp@hp.com>
Co-Authored-By: Santiago Baldassin<santiago.b.baldassin@intel.com>
Co-Authored-By: Bartosz Fic <bartosz.fic@intel.com>
Co-Authored-By: Pawel Koniszewski <pawel.koniszewski@intel.com>
Co-Authored-By: Michal Dulko <michal.dulko@intel.com>
DocImpact: Concept awareness
Change-Id: Ie34007f73af7e0941631a52f03841068e509a72c
Implements: blueprint glance-metadata-definitions-base-admin-ui
2014-09-12 13:54:01 +02:00
|
|
|
def metadefs_namespace_resource_types(request, namespace_name):
|
|
|
|
resource_types = glanceclient(request, '2').metadefs_resource_type.get(
|
|
|
|
namespace_name)
|
|
|
|
|
|
|
|
# metadefs_resource_type.get() returns generator, converting it to list
|
|
|
|
return list(resource_types)
|
|
|
|
|
|
|
|
|
2016-07-08 19:04:42 +03:00
|
|
|
@profiler.trace
|
Base Glance Metadata Definitions Admin UI
Provide a base admin UI for viewing, importing, and associating the
metadata definitions that can be used with various resource types
such as flavors, images, and host aggregates.
In Juno, Glance provided a metadata definitions catalog[1][2] where
users can register the available metadata definitions that can be used
on different types of resources (images, artifacts, volumes, flavors,
aggregates, etc). This includes key / value pairs such as
properties, extra specs, etc. Horizon landed several patches that
read these properties. You can view the functionality in the
"update metadata" action on Flavors, Images, and Host Aggregates.
This specific patch is to bring in the Admin UI for the basic coarse
grained actions on the definitions in the catalog. This includes creating
(importing) a namespace, viewing the overview details about
it, deleting the namespace, and associating the namespace for use with
specific resource types.
Future blueprints will be registered for:
- CRUD on individual metadata definitions within the namespace
For example, editing the default value of an individual property.
[1] Approved Glance Juno Spec:
https://github.com/openstack/glance-specs/blob/master/specs/juno/metadata-schema-catalog.rst
[2] Glance PTL Juno Feature Overview:
https://www.youtube.com/watch?v=3ptriiw1wK8&t=14m27s
Co-Authored-By: Travis Tripp <travis.tripp@hp.com>
Co-Authored-By: Santiago Baldassin<santiago.b.baldassin@intel.com>
Co-Authored-By: Bartosz Fic <bartosz.fic@intel.com>
Co-Authored-By: Pawel Koniszewski <pawel.koniszewski@intel.com>
Co-Authored-By: Michal Dulko <michal.dulko@intel.com>
DocImpact: Concept awareness
Change-Id: Ie34007f73af7e0941631a52f03841068e509a72c
Implements: blueprint glance-metadata-definitions-base-admin-ui
2014-09-12 13:54:01 +02:00
|
|
|
def metadefs_namespace_add_resource_type(request,
|
|
|
|
namespace_name,
|
|
|
|
resource_type):
|
|
|
|
return glanceclient(request, '2').metadefs_resource_type.associate(
|
|
|
|
namespace_name, **resource_type)
|
|
|
|
|
|
|
|
|
2016-07-08 19:04:42 +03:00
|
|
|
@profiler.trace
|
Base Glance Metadata Definitions Admin UI
Provide a base admin UI for viewing, importing, and associating the
metadata definitions that can be used with various resource types
such as flavors, images, and host aggregates.
In Juno, Glance provided a metadata definitions catalog[1][2] where
users can register the available metadata definitions that can be used
on different types of resources (images, artifacts, volumes, flavors,
aggregates, etc). This includes key / value pairs such as
properties, extra specs, etc. Horizon landed several patches that
read these properties. You can view the functionality in the
"update metadata" action on Flavors, Images, and Host Aggregates.
This specific patch is to bring in the Admin UI for the basic coarse
grained actions on the definitions in the catalog. This includes creating
(importing) a namespace, viewing the overview details about
it, deleting the namespace, and associating the namespace for use with
specific resource types.
Future blueprints will be registered for:
- CRUD on individual metadata definitions within the namespace
For example, editing the default value of an individual property.
[1] Approved Glance Juno Spec:
https://github.com/openstack/glance-specs/blob/master/specs/juno/metadata-schema-catalog.rst
[2] Glance PTL Juno Feature Overview:
https://www.youtube.com/watch?v=3ptriiw1wK8&t=14m27s
Co-Authored-By: Travis Tripp <travis.tripp@hp.com>
Co-Authored-By: Santiago Baldassin<santiago.b.baldassin@intel.com>
Co-Authored-By: Bartosz Fic <bartosz.fic@intel.com>
Co-Authored-By: Pawel Koniszewski <pawel.koniszewski@intel.com>
Co-Authored-By: Michal Dulko <michal.dulko@intel.com>
DocImpact: Concept awareness
Change-Id: Ie34007f73af7e0941631a52f03841068e509a72c
Implements: blueprint glance-metadata-definitions-base-admin-ui
2014-09-12 13:54:01 +02:00
|
|
|
def metadefs_namespace_remove_resource_type(request,
|
|
|
|
namespace_name,
|
|
|
|
resource_type_name):
|
|
|
|
glanceclient(request, '2').metadefs_resource_type.deassociate(
|
|
|
|
namespace_name, resource_type_name)
|
2015-10-29 11:42:03 -07:00
|
|
|
|
|
|
|
|
|
|
|
def get_version():
|
|
|
|
return VERSIONS.active
|