Merge "pylint: Address no-else-return warning"
This commit is contained in:
commit
c8d92aebb1
@ -55,7 +55,6 @@ disable=
|
|||||||
duplicate-code,
|
duplicate-code,
|
||||||
inconsistent-return-statements, # TODO
|
inconsistent-return-statements, # TODO
|
||||||
interface-not-implemented,
|
interface-not-implemented,
|
||||||
no-else-return,
|
|
||||||
no-self-use,
|
no-self-use,
|
||||||
# python3 way: Let's do it once we have a consensus.
|
# python3 way: Let's do it once we have a consensus.
|
||||||
super-with-arguments, # TODO
|
super-with-arguments, # TODO
|
||||||
|
@ -768,8 +768,7 @@ class Site(Registry, HorizonComponent):
|
|||||||
key=operator.attrgetter('name'))
|
key=operator.attrgetter('name'))
|
||||||
dashboards.extend(extra)
|
dashboards.extend(extra)
|
||||||
return dashboards
|
return dashboards
|
||||||
else:
|
return sorted(self._registry.values())
|
||||||
return sorted(self._registry.values())
|
|
||||||
|
|
||||||
def get_default_dashboard(self):
|
def get_default_dashboard(self):
|
||||||
"""Returns the default :class:`~horizon.Dashboard` instance.
|
"""Returns the default :class:`~horizon.Dashboard` instance.
|
||||||
@ -780,10 +779,9 @@ class Site(Registry, HorizonComponent):
|
|||||||
"""
|
"""
|
||||||
if self.default_dashboard:
|
if self.default_dashboard:
|
||||||
return self._registered(self.default_dashboard)
|
return self._registered(self.default_dashboard)
|
||||||
elif self._registry:
|
if self._registry:
|
||||||
return self.get_dashboards()[0]
|
return self.get_dashboards()[0]
|
||||||
else:
|
raise NotRegistered("No dashboard modules have been registered.")
|
||||||
raise NotRegistered("No dashboard modules have been registered.")
|
|
||||||
|
|
||||||
def get_user_home(self, user):
|
def get_user_home(self, user):
|
||||||
"""Returns the default URL for a particular user.
|
"""Returns the default URL for a particular user.
|
||||||
@ -810,13 +808,12 @@ class Site(Registry, HorizonComponent):
|
|||||||
if user_home:
|
if user_home:
|
||||||
if callable(user_home):
|
if callable(user_home):
|
||||||
return user_home(user)
|
return user_home(user)
|
||||||
elif isinstance(user_home, str):
|
if isinstance(user_home, str):
|
||||||
# Assume we've got a URL if there's a slash in it
|
# Assume we've got a URL if there's a slash in it
|
||||||
if '/' in user_home:
|
if '/' in user_home:
|
||||||
return user_home
|
return user_home
|
||||||
else:
|
mod, func = user_home.rsplit(".", 1)
|
||||||
mod, func = user_home.rsplit(".", 1)
|
return getattr(import_module(mod), func)(user)
|
||||||
return getattr(import_module(mod), func)(user)
|
|
||||||
# If it's not callable and not a string, it's wrong.
|
# If it's not callable and not a string, it's wrong.
|
||||||
raise ValueError('The user_home setting must be either a string '
|
raise ValueError('The user_home setting must be either a string '
|
||||||
'or a callable object (e.g. a function).')
|
'or a callable object (e.g. a function).')
|
||||||
|
@ -88,8 +88,7 @@ def require_perms(view_func, required):
|
|||||||
# If we don't have any permissions, just return the original view.
|
# If we don't have any permissions, just return the original view.
|
||||||
if required:
|
if required:
|
||||||
return dec
|
return dec
|
||||||
else:
|
return view_func
|
||||||
return view_func
|
|
||||||
|
|
||||||
|
|
||||||
def require_component_access(view_func, component):
|
def require_component_access(view_func, component):
|
||||||
|
@ -365,8 +365,7 @@ class DynamicSelectWidget(SelectWidget):
|
|||||||
if self.add_item_link_args:
|
if self.add_item_link_args:
|
||||||
return urls.reverse(self.add_item_link,
|
return urls.reverse(self.add_item_link,
|
||||||
args=self.add_item_link_args)
|
args=self.add_item_link_args)
|
||||||
else:
|
return urls.reverse(self.add_item_link)
|
||||||
return urls.reverse(self.add_item_link)
|
|
||||||
except urls.NoReverseMatch:
|
except urls.NoReverseMatch:
|
||||||
return self.add_item_link
|
return self.add_item_link
|
||||||
|
|
||||||
|
@ -217,7 +217,7 @@ class ModalFormView(ModalFormMixin, views.HorizonFormView):
|
|||||||
# and implemented.
|
# and implemented.
|
||||||
response['X-Horizon-Location'] = success_url
|
response['X-Horizon-Location'] = success_url
|
||||||
return response
|
return response
|
||||||
else:
|
|
||||||
# If handled didn't return, we can assume something went
|
# If handled didn't return, we can assume something went
|
||||||
# wrong, and we should send back the form as-is.
|
# wrong, and we should send back the form as-is.
|
||||||
return self.form_invalid(form)
|
return self.form_invalid(form)
|
||||||
|
@ -401,8 +401,7 @@ class LinkAction(BaseAction):
|
|||||||
if datum:
|
if datum:
|
||||||
obj_id = self.table.get_object_id(datum)
|
obj_id = self.table.get_object_id(datum)
|
||||||
return urls.reverse(self.url, args=(obj_id,))
|
return urls.reverse(self.url, args=(obj_id,))
|
||||||
else:
|
return urls.reverse(self.url)
|
||||||
return urls.reverse(self.url)
|
|
||||||
except urls.NoReverseMatch as ex:
|
except urls.NoReverseMatch as ex:
|
||||||
LOG.info('No reverse found for "%(url)s": %(exception)s',
|
LOG.info('No reverse found for "%(url)s": %(exception)s',
|
||||||
{'url': self.url, 'exception': ex})
|
{'url': self.url, 'exception': ex})
|
||||||
|
@ -661,8 +661,7 @@ class Row(html.HTMLElement):
|
|||||||
column_names = self.table._meta.status_columns
|
column_names = self.table._meta.status_columns
|
||||||
if column_names:
|
if column_names:
|
||||||
return self.table.get_row_status_class(self.status)
|
return self.table.get_row_status_class(self.status)
|
||||||
else:
|
return ''
|
||||||
return ''
|
|
||||||
|
|
||||||
def render(self):
|
def render(self):
|
||||||
return render_to_string("horizon/common/_data_table_row.html",
|
return render_to_string("horizon/common/_data_table_row.html",
|
||||||
@ -858,10 +857,9 @@ class Cell(html.HTMLElement):
|
|||||||
"""Returns a css class name determined by the status value."""
|
"""Returns a css class name determined by the status value."""
|
||||||
if status is True:
|
if status is True:
|
||||||
return "status_up"
|
return "status_up"
|
||||||
elif status is False:
|
if status is False:
|
||||||
return "status_down"
|
return "status_down"
|
||||||
else:
|
return "warning"
|
||||||
return "warning"
|
|
||||||
|
|
||||||
def get_default_classes(self):
|
def get_default_classes(self):
|
||||||
"""Returns a flattened string of the cell's CSS classes."""
|
"""Returns a flattened string of the cell's CSS classes."""
|
||||||
@ -1643,7 +1641,7 @@ class DataTable(object, metaclass=DataTableMetaclass):
|
|||||||
obj_ids = [obj_id]
|
obj_ids = [obj_id]
|
||||||
response = action.multiple(self, self.request, obj_ids)
|
response = action.multiple(self, self.request, obj_ids)
|
||||||
return response
|
return response
|
||||||
elif action and action.requires_input and not (obj_id or obj_ids):
|
if action and action.requires_input and not (obj_id or obj_ids):
|
||||||
messages.info(self.request,
|
messages.info(self.request,
|
||||||
_("Please select a row before taking that action."))
|
_("Please select a row before taking that action."))
|
||||||
return None
|
return None
|
||||||
@ -1688,8 +1686,7 @@ class DataTable(object, metaclass=DataTableMetaclass):
|
|||||||
if request.is_ajax():
|
if request.is_ajax():
|
||||||
if not error:
|
if not error:
|
||||||
return HttpResponse(new_row.render())
|
return HttpResponse(new_row.render())
|
||||||
else:
|
return HttpResponse(status=error.status_code)
|
||||||
return HttpResponse(status=error.status_code)
|
|
||||||
elif new_row.ajax_cell_action_name == action_name:
|
elif new_row.ajax_cell_action_name == action_name:
|
||||||
# inline edit of the cell actions
|
# inline edit of the cell actions
|
||||||
return self.inline_edit_handle(request, table_name,
|
return self.inline_edit_handle(request, table_name,
|
||||||
@ -1749,8 +1746,7 @@ class DataTable(object, metaclass=DataTableMetaclass):
|
|||||||
if request.is_ajax():
|
if request.is_ajax():
|
||||||
if not error:
|
if not error:
|
||||||
return HttpResponse(cell.render())
|
return HttpResponse(cell.render())
|
||||||
else:
|
return HttpResponse(status=error.status_code)
|
||||||
return HttpResponse(status=error.status_code)
|
|
||||||
|
|
||||||
def inline_update_action(self, request, datum, cell, obj_id, cell_name):
|
def inline_update_action(self, request, datum, cell, obj_id, cell_name):
|
||||||
"""Handling update by POST of the cell."""
|
"""Handling update by POST of the cell."""
|
||||||
@ -1907,10 +1903,9 @@ class DataTable(object, metaclass=DataTableMetaclass):
|
|||||||
values = statuses.values()
|
values = statuses.values()
|
||||||
if any([status is False for status in values]):
|
if any([status is False for status in values]):
|
||||||
return False
|
return False
|
||||||
elif any([status is None for status in values]):
|
if any([status is None for status in values]):
|
||||||
return None
|
return None
|
||||||
else:
|
return True
|
||||||
return True
|
|
||||||
|
|
||||||
def get_row_status_class(self, status):
|
def get_row_status_class(self, status):
|
||||||
"""Returns a css class name determined by the status value.
|
"""Returns a css class name determined by the status value.
|
||||||
@ -1920,10 +1915,9 @@ class DataTable(object, metaclass=DataTableMetaclass):
|
|||||||
"""
|
"""
|
||||||
if status is True:
|
if status is True:
|
||||||
return "status_up"
|
return "status_up"
|
||||||
elif status is False:
|
if status is False:
|
||||||
return "status_down"
|
return "status_down"
|
||||||
else:
|
return "warning"
|
||||||
return "warning"
|
|
||||||
|
|
||||||
def get_columns(self):
|
def get_columns(self):
|
||||||
"""Returns this table's columns including auto-generated ones."""
|
"""Returns this table's columns including auto-generated ones."""
|
||||||
|
@ -383,11 +383,10 @@ class PagedTableMixin(object):
|
|||||||
prev_marker = self.request.GET.get(meta.prev_pagination_param, None)
|
prev_marker = self.request.GET.get(meta.prev_pagination_param, None)
|
||||||
if prev_marker:
|
if prev_marker:
|
||||||
return prev_marker, "asc"
|
return prev_marker, "asc"
|
||||||
else:
|
marker = self.request.GET.get(meta.pagination_param, None)
|
||||||
marker = self.request.GET.get(meta.pagination_param, None)
|
if marker:
|
||||||
if marker:
|
return marker, "desc"
|
||||||
return marker, "desc"
|
return None, "desc"
|
||||||
return None, "desc"
|
|
||||||
|
|
||||||
|
|
||||||
class PagedTableWithPageMenu(object):
|
class PagedTableWithPageMenu(object):
|
||||||
|
@ -63,8 +63,7 @@ class TabView(views.HorizonTemplateView):
|
|||||||
if self.request.is_ajax():
|
if self.request.is_ajax():
|
||||||
if tab_group.selected:
|
if tab_group.selected:
|
||||||
return http.HttpResponse(tab_group.selected.render())
|
return http.HttpResponse(tab_group.selected.render())
|
||||||
else:
|
return http.HttpResponse(tab_group.render())
|
||||||
return http.HttpResponse(tab_group.render())
|
|
||||||
return self.render_to_response(context)
|
return self.render_to_response(context)
|
||||||
|
|
||||||
def get(self, request, *args, **kwargs):
|
def get(self, request, *args, **kwargs):
|
||||||
|
@ -141,31 +141,28 @@ def horizon_dashboard_nav(context):
|
|||||||
def quota(val, units=None):
|
def quota(val, units=None):
|
||||||
if val == float("inf"):
|
if val == float("inf"):
|
||||||
return _("(No Limit)")
|
return _("(No Limit)")
|
||||||
elif units is not None:
|
if units is not None:
|
||||||
return "%s %s %s" % (val, force_text(units),
|
return "%s %s %s" % (val, force_text(units),
|
||||||
force_text(_("Available")))
|
force_text(_("Available")))
|
||||||
else:
|
return "%s %s" % (val, force_text(_("Available")))
|
||||||
return "%s %s" % (val, force_text(_("Available")))
|
|
||||||
|
|
||||||
|
|
||||||
@register.filter
|
@register.filter
|
||||||
def quotainf(val, units=None):
|
def quotainf(val, units=None):
|
||||||
if val == float("inf"):
|
if val == float("inf"):
|
||||||
return '-1'
|
return '-1'
|
||||||
elif units is not None:
|
if units is not None:
|
||||||
return "%s %s" % (val, units)
|
return "%s %s" % (val, units)
|
||||||
else:
|
return val
|
||||||
return val
|
|
||||||
|
|
||||||
|
|
||||||
@register.simple_tag
|
@register.simple_tag
|
||||||
def quotapercent(used, limit):
|
def quotapercent(used, limit):
|
||||||
if used >= limit or limit == 0:
|
if used >= limit or limit == 0:
|
||||||
return 100
|
return 100
|
||||||
elif limit == float("inf"):
|
if limit == float("inf"):
|
||||||
return '[%s, true]' % used
|
return '[%s, true]' % used
|
||||||
else:
|
return round((float(used) / float(limit)) * 100)
|
||||||
return round((float(used) / float(limit)) * 100)
|
|
||||||
|
|
||||||
|
|
||||||
class JSTemplateNode(template.Node):
|
class JSTemplateNode(template.Node):
|
||||||
|
@ -30,5 +30,4 @@ def truncate(value, size):
|
|||||||
# pylint: disable=chained-comparison
|
# pylint: disable=chained-comparison
|
||||||
if len(value) > size and size > 3:
|
if len(value) > size and size > 3:
|
||||||
return value[0:(size - 3)] + '...'
|
return value[0:(size - 3)] + '...'
|
||||||
else:
|
return value[0:size]
|
||||||
return value[0:size]
|
|
||||||
|
@ -51,8 +51,7 @@ def timesince_or_never(dt, default=None):
|
|||||||
|
|
||||||
if isinstance(dt, datetime.date):
|
if isinstance(dt, datetime.date):
|
||||||
return timesince(dt)
|
return timesince(dt)
|
||||||
else:
|
return default
|
||||||
return default
|
|
||||||
|
|
||||||
|
|
||||||
@register.filter
|
@register.filter
|
||||||
|
@ -76,8 +76,7 @@ def trace(name):
|
|||||||
if setting_utils.get_dict_config('OPENSTACK_PROFILER', 'enabled'):
|
if setting_utils.get_dict_config('OPENSTACK_PROFILER', 'enabled'):
|
||||||
return profiler.trace(name, info=None, hide_args=False,
|
return profiler.trace(name, info=None, hide_args=False,
|
||||||
allow_multiple_trace=True)(func)
|
allow_multiple_trace=True)(func)
|
||||||
else:
|
return func
|
||||||
return func
|
|
||||||
return decorator
|
return decorator
|
||||||
|
|
||||||
|
|
||||||
|
@ -517,8 +517,7 @@ class UpdateMembersStep(Step):
|
|||||||
def get_member_field_name(self, role_id):
|
def get_member_field_name(self, role_id):
|
||||||
if issubclass(self.action_class, MembershipAction):
|
if issubclass(self.action_class, MembershipAction):
|
||||||
return self.action.get_member_field_name(role_id)
|
return self.action.get_member_field_name(role_id)
|
||||||
else:
|
return self.slug + "_role_" + role_id
|
||||||
return self.slug + "_role_" + role_id
|
|
||||||
|
|
||||||
|
|
||||||
class Workflow(html.HTMLElement, metaclass=WorkflowMetaclass):
|
class Workflow(html.HTMLElement, metaclass=WorkflowMetaclass):
|
||||||
@ -794,9 +793,8 @@ class Workflow(html.HTMLElement, metaclass=WorkflowMetaclass):
|
|||||||
% cls._registerable_class.__name__)
|
% cls._registerable_class.__name__)
|
||||||
if step_class in cls._cls_registry:
|
if step_class in cls._cls_registry:
|
||||||
return False
|
return False
|
||||||
else:
|
cls._cls_registry.append(step_class)
|
||||||
cls._cls_registry.append(step_class)
|
return True
|
||||||
return True
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def unregister(cls, step_class):
|
def unregister(cls, step_class):
|
||||||
@ -893,8 +891,7 @@ class Workflow(html.HTMLElement, metaclass=WorkflowMetaclass):
|
|||||||
"""
|
"""
|
||||||
if "%s" in message:
|
if "%s" in message:
|
||||||
return message % self.name
|
return message % self.name
|
||||||
else:
|
return message
|
||||||
return message
|
|
||||||
|
|
||||||
def verify_integrity(self):
|
def verify_integrity(self):
|
||||||
provided_keys = self.contributions | set(self.context_seed.keys())
|
provided_keys = self.contributions | set(self.context_seed.keys())
|
||||||
|
@ -68,8 +68,8 @@ class KeystoneBackend(object):
|
|||||||
user = auth_user.create_user_from_token(self.request, token,
|
user = auth_user.create_user_from_token(self.request, token,
|
||||||
endpoint, services_region)
|
endpoint, services_region)
|
||||||
return user
|
return user
|
||||||
else:
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def _check_auth_expiry(self, auth_ref, margin=None):
|
def _check_auth_expiry(self, auth_ref, margin=None):
|
||||||
if not utils.is_token_valid(auth_ref, margin):
|
if not utils.is_token_valid(auth_ref, margin):
|
||||||
|
@ -83,8 +83,7 @@ class BasePlugin(object, metaclass=abc.ABCMeta):
|
|||||||
client = v3_client.Client(session=session, auth=auth_plugin)
|
client = v3_client.Client(session=session, auth=auth_plugin)
|
||||||
if auth_ref.is_federated:
|
if auth_ref.is_federated:
|
||||||
return client.federation.projects.list()
|
return client.federation.projects.list()
|
||||||
else:
|
return client.projects.list(user=auth_ref.user_id)
|
||||||
return client.projects.list(user=auth_ref.user_id)
|
|
||||||
|
|
||||||
except (keystone_exceptions.ClientException,
|
except (keystone_exceptions.ClientException,
|
||||||
keystone_exceptions.AuthorizationFailure):
|
keystone_exceptions.AuthorizationFailure):
|
||||||
|
@ -300,11 +300,10 @@ def get_token_auth_plugin(auth_url, token, project_id=None, domain_name=None):
|
|||||||
token=token,
|
token=token,
|
||||||
domain_name=domain_name,
|
domain_name=domain_name,
|
||||||
reauthenticate=False)
|
reauthenticate=False)
|
||||||
else:
|
return v3_auth.Token(auth_url=auth_url,
|
||||||
return v3_auth.Token(auth_url=auth_url,
|
token=token,
|
||||||
token=token,
|
project_id=project_id,
|
||||||
project_id=project_id,
|
reauthenticate=False)
|
||||||
reauthenticate=False)
|
|
||||||
|
|
||||||
|
|
||||||
def get_project_list(*args, **kwargs):
|
def get_project_list(*args, **kwargs):
|
||||||
|
@ -232,10 +232,10 @@ def logout(request, login_url=None, **kwargs):
|
|||||||
auth_user.unset_session_user_variables(request)
|
auth_user.unset_session_user_variables(request)
|
||||||
return django_http.HttpResponseRedirect(
|
return django_http.HttpResponseRedirect(
|
||||||
settings.WEBSSO_DEFAULT_REDIRECT_LOGOUT)
|
settings.WEBSSO_DEFAULT_REDIRECT_LOGOUT)
|
||||||
else:
|
|
||||||
return django_auth_views.logout_then_login(request,
|
return django_auth_views.logout_then_login(request,
|
||||||
login_url=login_url,
|
login_url=login_url,
|
||||||
**kwargs)
|
**kwargs)
|
||||||
|
|
||||||
|
|
||||||
# TODO(stephenfin): Migrate to CBV
|
# TODO(stephenfin): Migrate to CBV
|
||||||
|
@ -65,19 +65,18 @@ class Server(base.APIResourceWrapper):
|
|||||||
def image_name(self):
|
def image_name(self):
|
||||||
if not self.image:
|
if not self.image:
|
||||||
return None
|
return None
|
||||||
elif hasattr(self.image, 'name'):
|
if hasattr(self.image, 'name'):
|
||||||
return self.image.name
|
return self.image.name
|
||||||
elif 'name' in self.image:
|
if 'name' in self.image:
|
||||||
return self.image['name']
|
return self.image['name']
|
||||||
else:
|
try:
|
||||||
try:
|
image = glance.image_get(self.request, self.image['id'])
|
||||||
image = glance.image_get(self.request, self.image['id'])
|
self.image['name'] = image.name
|
||||||
self.image['name'] = image.name
|
return image.name
|
||||||
return image.name
|
except (glance_exceptions.ClientException,
|
||||||
except (glance_exceptions.ClientException,
|
horizon_exceptions.ServiceCatalogException):
|
||||||
horizon_exceptions.ServiceCatalogException):
|
self.image['name'] = None
|
||||||
self.image['name'] = None
|
return None
|
||||||
return None
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def availability_zone(self):
|
def availability_zone(self):
|
||||||
|
@ -104,8 +104,7 @@ class Image(base.APIResourceWrapper):
|
|||||||
def property_visible(self, prop_name, show_ext_attrs=False):
|
def property_visible(self, prop_name, show_ext_attrs=False):
|
||||||
if show_ext_attrs:
|
if show_ext_attrs:
|
||||||
return prop_name not in self._attrs
|
return prop_name not in self._attrs
|
||||||
else:
|
return prop_name not in (self._attrs | self._ext_attrs)
|
||||||
return prop_name not in (self._attrs | self._ext_attrs)
|
|
||||||
|
|
||||||
def to_dict(self, show_ext_attrs=False):
|
def to_dict(self, show_ext_attrs=False):
|
||||||
if not isinstance(self._apiresource, abc.Iterable):
|
if not isinstance(self._apiresource, abc.Iterable):
|
||||||
@ -494,7 +493,8 @@ def image_create(request, **kwargs):
|
|||||||
# The image data is meant to be uploaded externally, return a
|
# The image data is meant to be uploaded externally, return a
|
||||||
# special wrapper to bypass the web server in a subsequent upload
|
# special wrapper to bypass the web server in a subsequent upload
|
||||||
return ExternallyUploadedImage(image, request)
|
return ExternallyUploadedImage(image, request)
|
||||||
elif isinstance(data, TemporaryUploadedFile):
|
|
||||||
|
if isinstance(data, TemporaryUploadedFile):
|
||||||
# Hack to fool Django, so we can keep file open in the new thread.
|
# Hack to fool Django, so we can keep file open in the new thread.
|
||||||
data.file._closer.close_called = True
|
data.file._closer.close_called = True
|
||||||
elif isinstance(data, InMemoryUploadedFile):
|
elif isinstance(data, InMemoryUploadedFile):
|
||||||
@ -603,8 +603,7 @@ def metadefs_namespace_get(request, namespace, resource_type=None, wrap=False):
|
|||||||
# to wrap.
|
# to wrap.
|
||||||
if wrap:
|
if wrap:
|
||||||
return Namespace(namespace)
|
return Namespace(namespace)
|
||||||
else:
|
return namespace
|
||||||
return namespace
|
|
||||||
|
|
||||||
|
|
||||||
@profiler.trace
|
@profiler.trace
|
||||||
|
@ -90,8 +90,7 @@ class Service(base.APIDictWrapper):
|
|||||||
if(self.type == "identity"):
|
if(self.type == "identity"):
|
||||||
return _("%(type)s (%(backend)s backend)") \
|
return _("%(type)s (%(backend)s backend)") \
|
||||||
% {"type": self.type, "backend": keystone_backend_name()}
|
% {"type": self.type, "backend": keystone_backend_name()}
|
||||||
else:
|
return self.type
|
||||||
return self.type
|
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "<Service: %s>" % self
|
return "<Service: %s>" % self
|
||||||
|
@ -251,15 +251,15 @@ class SecurityGroupRule(NeutronAPIDictWrapper):
|
|||||||
# ethertype, direction (Neutron specific)
|
# ethertype, direction (Neutron specific)
|
||||||
|
|
||||||
def _get_secgroup_name(self, sg_id, sg_dict):
|
def _get_secgroup_name(self, sg_id, sg_dict):
|
||||||
if sg_id:
|
if not sg_id:
|
||||||
if sg_dict is None:
|
|
||||||
sg_dict = {}
|
|
||||||
# If sg name not found in sg_dict,
|
|
||||||
# first two parts of UUID is used as sg name.
|
|
||||||
return sg_dict.get(sg_id, sg_id[:13])
|
|
||||||
else:
|
|
||||||
return u''
|
return u''
|
||||||
|
|
||||||
|
if sg_dict is None:
|
||||||
|
sg_dict = {}
|
||||||
|
# If sg name not found in sg_dict,
|
||||||
|
# first two parts of UUID is used as sg name.
|
||||||
|
return sg_dict.get(sg_id, sg_id[:13])
|
||||||
|
|
||||||
def __init__(self, sgr, sg_dict=None):
|
def __init__(self, sgr, sg_dict=None):
|
||||||
# In Neutron, if both remote_ip_prefix and remote_group_id are None,
|
# In Neutron, if both remote_ip_prefix and remote_group_id are None,
|
||||||
# it means all remote IP range is allowed, i.e., 0.0.0.0/0 or ::/0.
|
# it means all remote IP range is allowed, i.e., 0.0.0.0/0 or ::/0.
|
||||||
@ -752,21 +752,21 @@ class FloatingIpManager(object):
|
|||||||
# have been done already. We skip all checks here.
|
# have been done already. We skip all checks here.
|
||||||
return [target for target in target_list
|
return [target for target in target_list
|
||||||
if target['instance_id'] == instance_id]
|
if target['instance_id'] == instance_id]
|
||||||
else:
|
|
||||||
ports = self._target_ports_by_instance(instance_id)
|
ports = self._target_ports_by_instance(instance_id)
|
||||||
reachable_subnets = self._get_reachable_subnets(
|
reachable_subnets = self._get_reachable_subnets(
|
||||||
ports, fetch_router_ports=True)
|
ports, fetch_router_ports=True)
|
||||||
name = self._get_server_name(instance_id)
|
name = self._get_server_name(instance_id)
|
||||||
targets = []
|
targets = []
|
||||||
for p in ports:
|
for p in ports:
|
||||||
for ip in p.fixed_ips:
|
for ip in p.fixed_ips:
|
||||||
if ip['subnet_id'] not in reachable_subnets:
|
if ip['subnet_id'] not in reachable_subnets:
|
||||||
continue
|
continue
|
||||||
# Floating IPs can only target IPv4 addresses.
|
# Floating IPs can only target IPv4 addresses.
|
||||||
if netaddr.IPAddress(ip['ip_address']).version != 4:
|
if netaddr.IPAddress(ip['ip_address']).version != 4:
|
||||||
continue
|
continue
|
||||||
targets.append(FloatingIpTarget(p, ip['ip_address'], name))
|
targets.append(FloatingIpTarget(p, ip['ip_address'], name))
|
||||||
return targets
|
return targets
|
||||||
|
|
||||||
def _get_server_name(self, server_id):
|
def _get_server_name(self, server_id):
|
||||||
try:
|
try:
|
||||||
@ -1343,10 +1343,9 @@ def port_list_with_trunk_types(request, **params):
|
|||||||
def _get_port_info(port):
|
def _get_port_info(port):
|
||||||
if port['id'] in parent_ports:
|
if port['id'] in parent_ports:
|
||||||
return PortTrunkParent(port)
|
return PortTrunkParent(port)
|
||||||
elif port['id'] in child_ports:
|
if port['id'] in child_ports:
|
||||||
return PortTrunkSubport(port, child_ports[port['id']])
|
return PortTrunkSubport(port, child_ports[port['id']])
|
||||||
else:
|
return Port(port)
|
||||||
return Port(port)
|
|
||||||
|
|
||||||
return [_get_port_info(p) for p in ports]
|
return [_get_port_info(p) for p in ports]
|
||||||
|
|
||||||
@ -1807,8 +1806,7 @@ def list_extensions(request):
|
|||||||
return {}
|
return {}
|
||||||
if 'extensions' in extensions_list:
|
if 'extensions' in extensions_list:
|
||||||
return tuple(extensions_list['extensions'])
|
return tuple(extensions_list['extensions'])
|
||||||
else:
|
return ()
|
||||||
return ()
|
|
||||||
|
|
||||||
|
|
||||||
@profiler.trace
|
@profiler.trace
|
||||||
|
@ -1064,8 +1064,7 @@ def service_disable(request, host, binary, reason=None):
|
|||||||
if reason:
|
if reason:
|
||||||
return _nova.novaclient(request).services.disable_log_reason(
|
return _nova.novaclient(request).services.disable_log_reason(
|
||||||
host, binary, reason)
|
host, binary, reason)
|
||||||
else:
|
return _nova.novaclient(request).services.disable(host, binary)
|
||||||
return _nova.novaclient(request).services.disable(host, binary)
|
|
||||||
|
|
||||||
|
|
||||||
@profiler.trace
|
@profiler.trace
|
||||||
|
@ -325,21 +325,21 @@ class Services(generic.View):
|
|||||||
Will return HTTP 501 status code if the service_list extension is
|
Will return HTTP 501 status code if the service_list extension is
|
||||||
not supported.
|
not supported.
|
||||||
"""
|
"""
|
||||||
if api.base.is_service_enabled(request, 'volume') and \
|
if not (api.base.is_service_enabled(request, 'volume') and
|
||||||
api.cinder.extension_supported(request, 'Services'):
|
api.cinder.extension_supported(request, 'Services')):
|
||||||
result = api.cinder.service_list(request)
|
|
||||||
return {'items': [{
|
|
||||||
'binary': u.binary,
|
|
||||||
'host': u.host,
|
|
||||||
'zone': u.zone,
|
|
||||||
'updated_at': u.updated_at,
|
|
||||||
'status': u.status,
|
|
||||||
'state': u.state,
|
|
||||||
'id': idx + 1
|
|
||||||
} for idx, u in enumerate(result)]}
|
|
||||||
else:
|
|
||||||
raise rest_utils.AjaxError(501, '')
|
raise rest_utils.AjaxError(501, '')
|
||||||
|
|
||||||
|
result = api.cinder.service_list(request)
|
||||||
|
return {'items': [{
|
||||||
|
'binary': u.binary,
|
||||||
|
'host': u.host,
|
||||||
|
'zone': u.zone,
|
||||||
|
'updated_at': u.updated_at,
|
||||||
|
'status': u.status,
|
||||||
|
'state': u.state,
|
||||||
|
'id': idx + 1
|
||||||
|
} for idx, u in enumerate(result)]}
|
||||||
|
|
||||||
|
|
||||||
@urls.register
|
@urls.register
|
||||||
class DefaultQuotaSets(generic.View):
|
class DefaultQuotaSets(generic.View):
|
||||||
@ -353,24 +353,23 @@ class DefaultQuotaSets(generic.View):
|
|||||||
Example GET:
|
Example GET:
|
||||||
http://localhost/api/cinder/quota-sets/defaults/
|
http://localhost/api/cinder/quota-sets/defaults/
|
||||||
"""
|
"""
|
||||||
if api.cinder.is_volume_service_enabled(request):
|
if not api.cinder.is_volume_service_enabled(request):
|
||||||
quota_set = api.cinder.default_quota_get(
|
|
||||||
request, request.user.tenant_id)
|
|
||||||
|
|
||||||
result = [
|
|
||||||
{
|
|
||||||
'display_name':
|
|
||||||
quotas.QUOTA_NAMES.get(
|
|
||||||
quota.name,
|
|
||||||
quota.name.replace("_", " ").title()
|
|
||||||
) + '',
|
|
||||||
'name': quota.name,
|
|
||||||
'limit': quota.limit
|
|
||||||
}
|
|
||||||
for quota in quota_set]
|
|
||||||
return {'items': result}
|
|
||||||
else:
|
|
||||||
raise rest_utils.AjaxError(501, _('Service Cinder is disabled.'))
|
raise rest_utils.AjaxError(501, _('Service Cinder is disabled.'))
|
||||||
|
quota_set = api.cinder.default_quota_get(
|
||||||
|
request, request.user.tenant_id)
|
||||||
|
|
||||||
|
result = [
|
||||||
|
{
|
||||||
|
'display_name':
|
||||||
|
quotas.QUOTA_NAMES.get(
|
||||||
|
quota.name,
|
||||||
|
quota.name.replace("_", " ").title()
|
||||||
|
) + '',
|
||||||
|
'name': quota.name,
|
||||||
|
'limit': quota.limit
|
||||||
|
}
|
||||||
|
for quota in quota_set]
|
||||||
|
return {'items': result}
|
||||||
|
|
||||||
@rest_utils.ajax(data_required=True)
|
@rest_utils.ajax(data_required=True)
|
||||||
def patch(self, request):
|
def patch(self, request):
|
||||||
|
@ -201,12 +201,11 @@ class Services(generic.View):
|
|||||||
@rest_utils.ajax()
|
@rest_utils.ajax()
|
||||||
def get(self, request):
|
def get(self, request):
|
||||||
"""Get a list of agents"""
|
"""Get a list of agents"""
|
||||||
if api.base.is_service_enabled(request, 'network') and \
|
if (api.base.is_service_enabled(request, 'network') and
|
||||||
api.neutron.is_extension_supported(request, 'agent'):
|
api.neutron.is_extension_supported(request, 'agent')):
|
||||||
result = api.neutron.agent_list(request, **request.GET.dict())
|
result = api.neutron.agent_list(request, **request.GET.dict())
|
||||||
return {'items': [n.to_dict() for n in result]}
|
return {'items': [n.to_dict() for n in result]}
|
||||||
else:
|
raise rest_utils.AjaxError(501, '')
|
||||||
raise rest_utils.AjaxError(501, '')
|
|
||||||
|
|
||||||
|
|
||||||
@urls.register
|
@urls.register
|
||||||
@ -234,23 +233,23 @@ class DefaultQuotaSets(generic.View):
|
|||||||
|
|
||||||
@rest_utils.ajax()
|
@rest_utils.ajax()
|
||||||
def get(self, request):
|
def get(self, request):
|
||||||
if api.base.is_service_enabled(request, 'network'):
|
if not api.base.is_service_enabled(request, 'network'):
|
||||||
quota_set = api.neutron.tenant_quota_get(
|
|
||||||
request, request.user.tenant_id)
|
|
||||||
|
|
||||||
result = [{
|
|
||||||
'display_name': quotas.QUOTA_NAMES.get(
|
|
||||||
quota.name,
|
|
||||||
quota.name.replace('_', ' ').title()
|
|
||||||
) + '',
|
|
||||||
'name': quota.name,
|
|
||||||
'limit': quota.limit
|
|
||||||
} for quota in quota_set]
|
|
||||||
|
|
||||||
return {'items': result}
|
|
||||||
else:
|
|
||||||
raise rest_utils.AjaxError(501, _('Service Neutron is disabled.'))
|
raise rest_utils.AjaxError(501, _('Service Neutron is disabled.'))
|
||||||
|
|
||||||
|
quota_set = api.neutron.tenant_quota_get(
|
||||||
|
request, request.user.tenant_id)
|
||||||
|
|
||||||
|
result = [{
|
||||||
|
'display_name': quotas.QUOTA_NAMES.get(
|
||||||
|
quota.name,
|
||||||
|
quota.name.replace('_', ' ').title()
|
||||||
|
) + '',
|
||||||
|
'name': quota.name,
|
||||||
|
'limit': quota.limit
|
||||||
|
} for quota in quota_set]
|
||||||
|
|
||||||
|
return {'items': result}
|
||||||
|
|
||||||
|
|
||||||
@urls.register
|
@urls.register
|
||||||
class QuotasSets(generic.View):
|
class QuotasSets(generic.View):
|
||||||
|
@ -123,12 +123,11 @@ class Services(generic.View):
|
|||||||
Will return HTTP 501 status code if the service_list extension is
|
Will return HTTP 501 status code if the service_list extension is
|
||||||
not supported.
|
not supported.
|
||||||
"""
|
"""
|
||||||
if api.base.is_service_enabled(request, 'compute') \
|
if (api.base.is_service_enabled(request, 'compute') and
|
||||||
and api.nova.extension_supported('Services', request):
|
api.nova.extension_supported('Services', request)):
|
||||||
result = api.nova.service_list(request)
|
result = api.nova.service_list(request)
|
||||||
return {'items': [u.to_dict() for u in result]}
|
return {'items': [u.to_dict() for u in result]}
|
||||||
else:
|
raise rest_utils.AjaxError(501, '')
|
||||||
raise rest_utils.AjaxError(501, '')
|
|
||||||
|
|
||||||
|
|
||||||
@urls.register
|
@urls.register
|
||||||
@ -727,28 +726,28 @@ class DefaultQuotaSets(generic.View):
|
|||||||
Example GET:
|
Example GET:
|
||||||
http://localhost/api/nova/quota-sets/defaults/
|
http://localhost/api/nova/quota-sets/defaults/
|
||||||
"""
|
"""
|
||||||
if api.base.is_service_enabled(request, 'compute'):
|
if not api.base.is_service_enabled(request, 'compute'):
|
||||||
quota_set = api.nova.default_quota_get(request,
|
|
||||||
request.user.tenant_id)
|
|
||||||
|
|
||||||
disabled_quotas = quotas.get_disabled_quotas(request)
|
|
||||||
|
|
||||||
filtered_quotas = [quota for quota in quota_set
|
|
||||||
if quota.name not in disabled_quotas]
|
|
||||||
|
|
||||||
result = [{
|
|
||||||
'display_name': quotas.QUOTA_NAMES.get(
|
|
||||||
quota.name,
|
|
||||||
quota.name.replace("_", " ").title()
|
|
||||||
) + '',
|
|
||||||
'name': quota.name,
|
|
||||||
'limit': quota.limit
|
|
||||||
} for quota in filtered_quotas]
|
|
||||||
|
|
||||||
return {'items': result}
|
|
||||||
else:
|
|
||||||
raise rest_utils.AjaxError(501, _('Service Nova is disabled.'))
|
raise rest_utils.AjaxError(501, _('Service Nova is disabled.'))
|
||||||
|
|
||||||
|
quota_set = api.nova.default_quota_get(request,
|
||||||
|
request.user.tenant_id)
|
||||||
|
|
||||||
|
disabled_quotas = quotas.get_disabled_quotas(request)
|
||||||
|
|
||||||
|
filtered_quotas = [quota for quota in quota_set
|
||||||
|
if quota.name not in disabled_quotas]
|
||||||
|
|
||||||
|
result = [{
|
||||||
|
'display_name': quotas.QUOTA_NAMES.get(
|
||||||
|
quota.name,
|
||||||
|
quota.name.replace("_", " ").title()
|
||||||
|
) + '',
|
||||||
|
'name': quota.name,
|
||||||
|
'limit': quota.limit
|
||||||
|
} for quota in filtered_quotas]
|
||||||
|
|
||||||
|
return {'items': result}
|
||||||
|
|
||||||
@rest_utils.ajax(data_required=True)
|
@rest_utils.ajax(data_required=True)
|
||||||
def patch(self, request):
|
def patch(self, request):
|
||||||
"""Update the values for Nova specific quotas
|
"""Update the values for Nova specific quotas
|
||||||
|
@ -128,7 +128,7 @@ def ajax(authenticated=True, data_required=False,
|
|||||||
data = function(self, request, *args, **kw)
|
data = function(self, request, *args, **kw)
|
||||||
if isinstance(data, http.HttpResponse):
|
if isinstance(data, http.HttpResponse):
|
||||||
return data
|
return data
|
||||||
elif data is None:
|
if data is None:
|
||||||
return JSONResponse('', status=204)
|
return JSONResponse('', status=204)
|
||||||
return JSONResponse(data, json_encoder=json_encoder)
|
return JSONResponse(data, json_encoder=json_encoder)
|
||||||
except http_errors as e:
|
except http_errors as e:
|
||||||
|
@ -171,8 +171,7 @@ def swift_get_containers(request, marker=None, prefix=None):
|
|||||||
container_objs = [Container(c) for c in containers]
|
container_objs = [Container(c) for c in containers]
|
||||||
if(len(container_objs) > limit):
|
if(len(container_objs) > limit):
|
||||||
return (container_objs[0:-1], True)
|
return (container_objs[0:-1], True)
|
||||||
else:
|
return (container_objs, False)
|
||||||
return (container_objs, False)
|
|
||||||
|
|
||||||
|
|
||||||
@profiler.trace
|
@profiler.trace
|
||||||
@ -271,8 +270,7 @@ def swift_get_objects(request, container_name, prefix=None, marker=None,
|
|||||||
|
|
||||||
if(len(object_objs) > limit):
|
if(len(object_objs) > limit):
|
||||||
return (object_objs[0:-1], True)
|
return (object_objs[0:-1], True)
|
||||||
else:
|
return (object_objs, False)
|
||||||
return (object_objs, False)
|
|
||||||
|
|
||||||
|
|
||||||
@profiler.trace
|
@profiler.trace
|
||||||
@ -302,14 +300,14 @@ def wildcard_search(string, q):
|
|||||||
q_list = q.split('*')
|
q_list = q.split('*')
|
||||||
if all(map(lambda x: x == '', q_list)):
|
if all(map(lambda x: x == '', q_list)):
|
||||||
return True
|
return True
|
||||||
elif q_list[0] not in string:
|
if q_list[0] not in string:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
if q_list[0] == '':
|
||||||
|
tail = string
|
||||||
else:
|
else:
|
||||||
if q_list[0] == '':
|
head, delimiter, tail = string.partition(q_list[0])
|
||||||
tail = string
|
return wildcard_search(tail, '*'.join(q_list[1:]))
|
||||||
else:
|
|
||||||
head, delimiter, tail = string.partition(q_list[0])
|
|
||||||
return wildcard_search(tail, '*'.join(q_list[1:]))
|
|
||||||
|
|
||||||
|
|
||||||
@profiler.trace
|
@profiler.trace
|
||||||
|
@ -30,8 +30,7 @@ class AdminDeleteImage(project_tables.DeleteImage):
|
|||||||
def allowed(self, request, image=None):
|
def allowed(self, request, image=None):
|
||||||
if image and image.protected:
|
if image and image.protected:
|
||||||
return False
|
return False
|
||||||
else:
|
return True
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
class AdminEditImage(project_tables.EditImage):
|
class AdminEditImage(project_tables.EditImage):
|
||||||
|
@ -77,13 +77,11 @@ class UpdateSubnet(proj_tables.SubnetPolicyTargetMixin, tables.LinkAction):
|
|||||||
|
|
||||||
def subnet_ip_availability(availability):
|
def subnet_ip_availability(availability):
|
||||||
subnet_availability = availability.get("free_ips")
|
subnet_availability = availability.get("free_ips")
|
||||||
if subnet_availability:
|
if not subnet_availability:
|
||||||
if subnet_availability > 10000:
|
return "Not Available"
|
||||||
return ">10000"
|
if subnet_availability > 10000:
|
||||||
else:
|
return ">10000"
|
||||||
return str(subnet_availability)
|
return str(subnet_availability)
|
||||||
else:
|
|
||||||
return str("Not Available")
|
|
||||||
|
|
||||||
|
|
||||||
class SubnetsTable(tables.DataTable):
|
class SubnetsTable(tables.DataTable):
|
||||||
|
@ -77,8 +77,7 @@ DISPLAY_CHOICES = (
|
|||||||
def get_availability_zones(network):
|
def get_availability_zones(network):
|
||||||
if 'availability_zones' in network and network.availability_zones:
|
if 'availability_zones' in network and network.availability_zones:
|
||||||
return ', '.join(network.availability_zones)
|
return ', '.join(network.availability_zones)
|
||||||
else:
|
return _("-")
|
||||||
return _("-")
|
|
||||||
|
|
||||||
|
|
||||||
class AdminNetworksFilterAction(project_tables.ProjectNetworksFilterAction):
|
class AdminNetworksFilterAction(project_tables.ProjectNetworksFilterAction):
|
||||||
|
@ -67,8 +67,7 @@ class UpdateMembersLink(tables.LinkAction):
|
|||||||
# domain admin or cloud admin = True
|
# domain admin or cloud admin = True
|
||||||
# project admin or member = False
|
# project admin or member = False
|
||||||
return api.keystone.is_domain_admin(request)
|
return api.keystone.is_domain_admin(request)
|
||||||
else:
|
return super(UpdateMembersLink, self).allowed(request, project)
|
||||||
return super(UpdateMembersLink, self).allowed(request, project)
|
|
||||||
|
|
||||||
|
|
||||||
class UpdateGroupsLink(tables.LinkAction):
|
class UpdateGroupsLink(tables.LinkAction):
|
||||||
@ -84,8 +83,7 @@ class UpdateGroupsLink(tables.LinkAction):
|
|||||||
# domain admin or cloud admin = True
|
# domain admin or cloud admin = True
|
||||||
# project admin or member = False
|
# project admin or member = False
|
||||||
return api.keystone.is_domain_admin(request)
|
return api.keystone.is_domain_admin(request)
|
||||||
else:
|
return super(UpdateGroupsLink, self).allowed(request, project)
|
||||||
return super(UpdateGroupsLink, self).allowed(request, project)
|
|
||||||
|
|
||||||
def get_link_url(self, project):
|
def get_link_url(self, project):
|
||||||
step = 'update_group_members'
|
step = 'update_group_members'
|
||||||
@ -119,8 +117,7 @@ class CreateProject(tables.LinkAction):
|
|||||||
# domain admin or cloud admin = True
|
# domain admin or cloud admin = True
|
||||||
# project admin or member = False
|
# project admin or member = False
|
||||||
return api.keystone.is_domain_admin(request)
|
return api.keystone.is_domain_admin(request)
|
||||||
else:
|
return api.keystone.keystone_can_edit_project()
|
||||||
return api.keystone.keystone_can_edit_project()
|
|
||||||
|
|
||||||
|
|
||||||
class UpdateProject(policy.PolicyTargetMixin, tables.LinkAction):
|
class UpdateProject(policy.PolicyTargetMixin, tables.LinkAction):
|
||||||
@ -137,8 +134,7 @@ class UpdateProject(policy.PolicyTargetMixin, tables.LinkAction):
|
|||||||
# domain admin or cloud admin = True
|
# domain admin or cloud admin = True
|
||||||
# project admin or member = False
|
# project admin or member = False
|
||||||
return api.keystone.is_domain_admin(request)
|
return api.keystone.is_domain_admin(request)
|
||||||
else:
|
return api.keystone.keystone_can_edit_project()
|
||||||
return api.keystone.keystone_can_edit_project()
|
|
||||||
|
|
||||||
|
|
||||||
class ModifyQuotas(tables.LinkAction):
|
class ModifyQuotas(tables.LinkAction):
|
||||||
|
@ -486,8 +486,7 @@ class CreateProject(workflows.Workflow):
|
|||||||
def format_status_message(self, message):
|
def format_status_message(self, message):
|
||||||
if "%s" in message:
|
if "%s" in message:
|
||||||
return message % self.context.get('name', 'unknown project')
|
return message % self.context.get('name', 'unknown project')
|
||||||
else:
|
return message
|
||||||
return message
|
|
||||||
|
|
||||||
def _create_project(self, request, data):
|
def _create_project(self, request, data):
|
||||||
# create the project
|
# create the project
|
||||||
@ -657,8 +656,7 @@ class UpdateProject(workflows.Workflow):
|
|||||||
def format_status_message(self, message):
|
def format_status_message(self, message):
|
||||||
if "%s" in message:
|
if "%s" in message:
|
||||||
return message % self.context.get('name', 'unknown project')
|
return message % self.context.get('name', 'unknown project')
|
||||||
else:
|
return message
|
||||||
return message
|
|
||||||
|
|
||||||
@memoized.memoized_method
|
@memoized.memoized_method
|
||||||
def _get_available_roles(self, request):
|
def _get_available_roles(self, request):
|
||||||
@ -748,8 +746,7 @@ class UpdateProject(workflows.Workflow):
|
|||||||
'administrative role manually via the CLI.')
|
'administrative role manually via the CLI.')
|
||||||
messages.warning(request, msg)
|
messages.warning(request, msg)
|
||||||
return True
|
return True
|
||||||
else:
|
return False
|
||||||
return False
|
|
||||||
|
|
||||||
def _update_project_members(self, request, data, project_id):
|
def _update_project_members(self, request, data, project_id):
|
||||||
# update project members
|
# update project members
|
||||||
|
@ -276,8 +276,8 @@ class UpdateUserForm(BaseUserForm, AddExtraColumnMixIn):
|
|||||||
|
|
||||||
if isinstance(response, http.HttpResponse):
|
if isinstance(response, http.HttpResponse):
|
||||||
return response
|
return response
|
||||||
else:
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
class ChangePasswordForm(PasswordMixin, forms.SelfHandlingForm):
|
class ChangePasswordForm(PasswordMixin, forms.SelfHandlingForm):
|
||||||
@ -341,5 +341,5 @@ class ChangePasswordForm(PasswordMixin, forms.SelfHandlingForm):
|
|||||||
|
|
||||||
if isinstance(response, http.HttpResponse):
|
if isinstance(response, http.HttpResponse):
|
||||||
return response
|
return response
|
||||||
else:
|
|
||||||
return True
|
return True
|
||||||
|
@ -143,20 +143,18 @@ def get_instance_info(fip):
|
|||||||
return (_("%(instance_name)s %(fixed_ip)s")
|
return (_("%(instance_name)s %(fixed_ip)s")
|
||||||
% {'instance_name': getattr(fip, "instance_name", ''),
|
% {'instance_name': getattr(fip, "instance_name", ''),
|
||||||
'fixed_ip': fip.fixed_ip})
|
'fixed_ip': fip.fixed_ip})
|
||||||
elif fip.instance_type == 'loadbalancer':
|
if fip.instance_type == 'loadbalancer':
|
||||||
return _("Load Balancer VIP %s") % fip.fixed_ip
|
return _("Load Balancer VIP %s") % fip.fixed_ip
|
||||||
elif fip.instance_type:
|
if fip.instance_type:
|
||||||
return fip.fixed_ip
|
return fip.fixed_ip
|
||||||
else:
|
return None
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
def get_instance_link(datum):
|
def get_instance_link(datum):
|
||||||
if getattr(datum, 'instance_id'):
|
if getattr(datum, 'instance_id'):
|
||||||
return reverse("horizon:project:instances:detail",
|
return reverse("horizon:project:instances:detail",
|
||||||
args=(datum.instance_id,))
|
args=(datum.instance_id,))
|
||||||
else:
|
return None
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
STATUS_DISPLAY_CHOICES = (
|
STATUS_DISPLAY_CHOICES = (
|
||||||
|
@ -156,8 +156,7 @@ class IPAssociationWorkflow(workflows.Workflow):
|
|||||||
if "%s" in message:
|
if "%s" in message:
|
||||||
return message % self.context.get('ip_address',
|
return message % self.context.get('ip_address',
|
||||||
_('unknown IP address'))
|
_('unknown IP address'))
|
||||||
else:
|
return message
|
||||||
return message
|
|
||||||
|
|
||||||
def handle(self, request, data):
|
def handle(self, request, data):
|
||||||
try:
|
try:
|
||||||
|
@ -137,12 +137,11 @@ class RebootInstance(policy.PolicyTargetMixin, tables.BatchAction):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def allowed(self, request, instance=None):
|
def allowed(self, request, instance=None):
|
||||||
if instance is not None:
|
if instance is None:
|
||||||
return ((instance.status in ACTIVE_STATES or
|
|
||||||
instance.status == 'SHUTOFF') and
|
|
||||||
not is_deleting(instance))
|
|
||||||
else:
|
|
||||||
return True
|
return True
|
||||||
|
return ((instance.status in ACTIVE_STATES or
|
||||||
|
instance.status == 'SHUTOFF') and
|
||||||
|
not is_deleting(instance))
|
||||||
|
|
||||||
def action(self, request, obj_id):
|
def action(self, request, obj_id):
|
||||||
api.nova.server_reboot(request, obj_id, soft_reboot=False)
|
api.nova.server_reboot(request, obj_id, soft_reboot=False)
|
||||||
@ -173,8 +172,7 @@ class SoftRebootInstance(RebootInstance):
|
|||||||
def allowed(self, request, instance=None):
|
def allowed(self, request, instance=None):
|
||||||
if instance is not None:
|
if instance is not None:
|
||||||
return instance.status in ACTIVE_STATES
|
return instance.status in ACTIVE_STATES
|
||||||
else:
|
return True
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
class RescueInstance(policy.PolicyTargetMixin, tables.LinkAction):
|
class RescueInstance(policy.PolicyTargetMixin, tables.LinkAction):
|
||||||
|
@ -319,9 +319,8 @@ class SetInstanceDetailsAction(workflows.Action):
|
|||||||
msg = _("You must select an image.")
|
msg = _("You must select an image.")
|
||||||
self._errors['image_id'] = self.error_class([msg])
|
self._errors['image_id'] = self.error_class([msg])
|
||||||
return
|
return
|
||||||
else:
|
self._check_flavor_for_image(cleaned_data)
|
||||||
self._check_flavor_for_image(cleaned_data)
|
self._check_volume_for_image(cleaned_data)
|
||||||
self._check_volume_for_image(cleaned_data)
|
|
||||||
|
|
||||||
def _check_source_instance_snapshot(self, cleaned_data):
|
def _check_source_instance_snapshot(self, cleaned_data):
|
||||||
# using the array form of get blows up with KeyError
|
# using the array form of get blows up with KeyError
|
||||||
@ -677,32 +676,31 @@ class CustomizeAction(workflows.Action):
|
|||||||
def clean_uploaded_files(self, prefix, files):
|
def clean_uploaded_files(self, prefix, files):
|
||||||
upload_str = prefix + "_upload"
|
upload_str = prefix + "_upload"
|
||||||
|
|
||||||
has_upload = upload_str in files
|
if upload_str not in files:
|
||||||
if has_upload:
|
|
||||||
upload_file = files[upload_str]
|
|
||||||
log_script_name = upload_file.name
|
|
||||||
LOG.info('got upload %s', log_script_name)
|
|
||||||
|
|
||||||
if upload_file._size > 16 * units.Ki: # 16kb
|
|
||||||
msg = _('File exceeds maximum size (16kb)')
|
|
||||||
raise forms.ValidationError(msg)
|
|
||||||
|
|
||||||
script = upload_file.read()
|
|
||||||
if script != "":
|
|
||||||
try:
|
|
||||||
if not isinstance(script, str):
|
|
||||||
script = script.decode()
|
|
||||||
normalize_newlines(script)
|
|
||||||
except Exception as e:
|
|
||||||
msg = _('There was a problem parsing the'
|
|
||||||
' %(prefix)s: %(error)s')
|
|
||||||
msg = msg % {'prefix': prefix,
|
|
||||||
'error': e}
|
|
||||||
raise forms.ValidationError(msg)
|
|
||||||
return script
|
|
||||||
else:
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
upload_file = files[upload_str]
|
||||||
|
log_script_name = upload_file.name
|
||||||
|
LOG.info('got upload %s', log_script_name)
|
||||||
|
|
||||||
|
if upload_file._size > 16 * units.Ki: # 16kb
|
||||||
|
msg = _('File exceeds maximum size (16kb)')
|
||||||
|
raise forms.ValidationError(msg)
|
||||||
|
|
||||||
|
script = upload_file.read()
|
||||||
|
if script != "":
|
||||||
|
try:
|
||||||
|
if not isinstance(script, str):
|
||||||
|
script = script.decode()
|
||||||
|
normalize_newlines(script)
|
||||||
|
except Exception as e:
|
||||||
|
msg = _('There was a problem parsing the'
|
||||||
|
' %(prefix)s: %(error)s')
|
||||||
|
msg = msg % {'prefix': prefix,
|
||||||
|
'error': e}
|
||||||
|
raise forms.ValidationError(msg)
|
||||||
|
return script
|
||||||
|
|
||||||
|
|
||||||
class PostCreationStep(workflows.Step):
|
class PostCreationStep(workflows.Step):
|
||||||
action_class = CustomizeAction
|
action_class = CustomizeAction
|
||||||
@ -877,8 +875,7 @@ class LaunchInstance(workflows.Workflow):
|
|||||||
if int(count) > 1:
|
if int(count) > 1:
|
||||||
return message % {"count": _("%s instances") % count,
|
return message % {"count": _("%s instances") % count,
|
||||||
"name": name}
|
"name": name}
|
||||||
else:
|
return message % {"count": _("instance"), "name": name}
|
||||||
return message % {"count": _("instance"), "name": name}
|
|
||||||
|
|
||||||
@sensitive_variables('context')
|
@sensitive_variables('context')
|
||||||
def handle(self, request, context):
|
def handle(self, request, context):
|
||||||
|
@ -99,8 +99,7 @@ class ResizeInstance(workflows.Workflow):
|
|||||||
def format_status_message(self, message):
|
def format_status_message(self, message):
|
||||||
if "%s" in message:
|
if "%s" in message:
|
||||||
return message % self.context.get('name', 'unknown instance')
|
return message % self.context.get('name', 'unknown instance')
|
||||||
else:
|
return message
|
||||||
return message
|
|
||||||
|
|
||||||
@sensitive_variables('context')
|
@sensitive_variables('context')
|
||||||
def handle(self, request, context):
|
def handle(self, request, context):
|
||||||
|
@ -63,10 +63,9 @@ class QuotaKeypairMixin(object):
|
|||||||
verbose_name=self.verbose_name,
|
verbose_name=self.verbose_name,
|
||||||
quota_exceeded=_("(Quota exceeded)"))
|
quota_exceeded=_("(Quota exceeded)"))
|
||||||
return False
|
return False
|
||||||
else:
|
classes = [c for c in self.classes if c != "disabled"]
|
||||||
classes = [c for c in self.classes if c != "disabled"]
|
self.classes = classes
|
||||||
self.classes = classes
|
return True
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
class ImportKeyPair(QuotaKeypairMixin, tables.LinkAction):
|
class ImportKeyPair(QuotaKeypairMixin, tables.LinkAction):
|
||||||
|
@ -50,8 +50,7 @@ class AddAllowedAddressPair(policy.PolicyTargetMixin, tables.LinkAction):
|
|||||||
def get_link_url(self, port=None):
|
def get_link_url(self, port=None):
|
||||||
if port:
|
if port:
|
||||||
return reverse(self.url, args=(port.id,))
|
return reverse(self.url, args=(port.id,))
|
||||||
else:
|
return reverse(self.url, args=(self.table.kwargs.get('port_id'),))
|
||||||
return reverse(self.url, args=(self.table.kwargs.get('port_id'),))
|
|
||||||
|
|
||||||
|
|
||||||
class DeleteAllowedAddressPair(tables.DeleteAction):
|
class DeleteAllowedAddressPair(tables.DeleteAction):
|
||||||
|
@ -39,10 +39,9 @@ def get_fixed_ips(port):
|
|||||||
def get_attached(port):
|
def get_attached(port):
|
||||||
if port['device_owner']:
|
if port['device_owner']:
|
||||||
return port['device_owner']
|
return port['device_owner']
|
||||||
elif port['device_id']:
|
if port['device_id']:
|
||||||
return _('Attached')
|
return _('Attached')
|
||||||
else:
|
return _('Detached')
|
||||||
return _('Detached')
|
|
||||||
|
|
||||||
|
|
||||||
class UpdatePort(policy.PolicyTargetMixin, tables.LinkAction):
|
class UpdatePort(policy.PolicyTargetMixin, tables.LinkAction):
|
||||||
|
@ -171,8 +171,7 @@ STATUS_DISPLAY_CHOICES = (
|
|||||||
def get_availability_zones(network):
|
def get_availability_zones(network):
|
||||||
if 'availability_zones' in network and network.availability_zones:
|
if 'availability_zones' in network and network.availability_zones:
|
||||||
return ', '.join(network.availability_zones)
|
return ', '.join(network.availability_zones)
|
||||||
else:
|
return _("-")
|
||||||
return _("-")
|
|
||||||
|
|
||||||
|
|
||||||
class ProjectNetworksFilterAction(tables.FilterAction):
|
class ProjectNetworksFilterAction(tables.FilterAction):
|
||||||
|
@ -608,6 +608,6 @@ class CreateNetwork(workflows.Workflow):
|
|||||||
tenant_id=network.tenant_id)
|
tenant_id=network.tenant_id)
|
||||||
if subnet:
|
if subnet:
|
||||||
return True
|
return True
|
||||||
else:
|
|
||||||
self._delete_network(request, network)
|
self._delete_network(request, network)
|
||||||
return False
|
return False
|
||||||
|
@ -31,10 +31,9 @@ LOG = logging.getLogger(__name__)
|
|||||||
def get_device_owner(port):
|
def get_device_owner(port):
|
||||||
if port['device_owner'] == 'network:router_gateway':
|
if port['device_owner'] == 'network:router_gateway':
|
||||||
return _('External Gateway')
|
return _('External Gateway')
|
||||||
elif port['device_owner'] == 'network:router_interface':
|
if port['device_owner'] == 'network:router_interface':
|
||||||
return _('Internal Interface')
|
return _('Internal Interface')
|
||||||
else:
|
return ' '
|
||||||
return ' '
|
|
||||||
|
|
||||||
|
|
||||||
class AddInterface(policy.PolicyTargetMixin, tables.LinkAction):
|
class AddInterface(policy.PolicyTargetMixin, tables.LinkAction):
|
||||||
|
@ -183,15 +183,13 @@ class UpdateRow(tables.Row):
|
|||||||
def get_external_network(router):
|
def get_external_network(router):
|
||||||
if router.external_gateway_info:
|
if router.external_gateway_info:
|
||||||
return router.external_gateway_info['network']
|
return router.external_gateway_info['network']
|
||||||
else:
|
return _("-")
|
||||||
return _("-")
|
|
||||||
|
|
||||||
|
|
||||||
def get_availability_zones(router):
|
def get_availability_zones(router):
|
||||||
if 'availability_zones' in router and router.availability_zones:
|
if 'availability_zones' in router and router.availability_zones:
|
||||||
return ', '.join(router.availability_zones)
|
return ', '.join(router.availability_zones)
|
||||||
else:
|
return _("-")
|
||||||
return _("-")
|
|
||||||
|
|
||||||
|
|
||||||
class RoutersFilterAction(tables.FilterAction):
|
class RoutersFilterAction(tables.FilterAction):
|
||||||
|
@ -180,8 +180,7 @@ def get_remote_ip_prefix(rule):
|
|||||||
else:
|
else:
|
||||||
range = rule.ip_range['cidr']
|
range = rule.ip_range['cidr']
|
||||||
return range
|
return range
|
||||||
else:
|
return None
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
def get_remote_security_group(rule):
|
def get_remote_security_group(rule):
|
||||||
@ -196,17 +195,15 @@ def get_port_range(rule):
|
|||||||
ip_proto = rule.ip_protocol
|
ip_proto = rule.ip_protocol
|
||||||
if rule.from_port == rule.to_port:
|
if rule.from_port == rule.to_port:
|
||||||
return check_rule_template(rule.from_port, ip_proto)
|
return check_rule_template(rule.from_port, ip_proto)
|
||||||
else:
|
return (u"%(from)s - %(to)s" %
|
||||||
return (u"%(from)s - %(to)s" %
|
{'from': check_rule_template(rule.from_port, ip_proto),
|
||||||
{'from': check_rule_template(rule.from_port, ip_proto),
|
'to': check_rule_template(rule.to_port, ip_proto)})
|
||||||
'to': check_rule_template(rule.to_port, ip_proto)})
|
|
||||||
|
|
||||||
|
|
||||||
def filter_direction(direction):
|
def filter_direction(direction):
|
||||||
if direction is None or direction.lower() == 'ingress':
|
if direction is None or direction.lower() == 'ingress':
|
||||||
return _('Ingress')
|
return _('Ingress')
|
||||||
else:
|
return _('Egress')
|
||||||
return _('Egress')
|
|
||||||
|
|
||||||
|
|
||||||
def filter_protocol(protocol):
|
def filter_protocol(protocol):
|
||||||
|
@ -69,8 +69,7 @@ class ManageVolumes(policy.PolicyTargetMixin, tables.LinkAction):
|
|||||||
def allowed(self, request, group=None):
|
def allowed(self, request, group=None):
|
||||||
if hasattr(group, 'status'):
|
if hasattr(group, 'status'):
|
||||||
return group.status != 'error'
|
return group.status != 'error'
|
||||||
else:
|
return False
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
class CreateSnapshot(policy.PolicyTargetMixin, tables.LinkAction):
|
class CreateSnapshot(policy.PolicyTargetMixin, tables.LinkAction):
|
||||||
@ -83,8 +82,7 @@ class CreateSnapshot(policy.PolicyTargetMixin, tables.LinkAction):
|
|||||||
def allowed(self, request, group=None):
|
def allowed(self, request, group=None):
|
||||||
if hasattr(group, 'status'):
|
if hasattr(group, 'status'):
|
||||||
return group.status != 'error'
|
return group.status != 'error'
|
||||||
else:
|
return False
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
class CloneGroup(policy.PolicyTargetMixin, tables.LinkAction):
|
class CloneGroup(policy.PolicyTargetMixin, tables.LinkAction):
|
||||||
@ -97,8 +95,7 @@ class CloneGroup(policy.PolicyTargetMixin, tables.LinkAction):
|
|||||||
def allowed(self, request, group=None):
|
def allowed(self, request, group=None):
|
||||||
if hasattr(group, 'status'):
|
if hasattr(group, 'status'):
|
||||||
return group.status != 'error'
|
return group.status != 'error'
|
||||||
else:
|
return False
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
class UpdateRow(tables.Row):
|
class UpdateRow(tables.Row):
|
||||||
|
@ -445,10 +445,9 @@ def get_volume_type(volume):
|
|||||||
def get_encrypted_value(volume):
|
def get_encrypted_value(volume):
|
||||||
if not hasattr(volume, 'encrypted') or volume.encrypted is None:
|
if not hasattr(volume, 'encrypted') or volume.encrypted is None:
|
||||||
return _("-")
|
return _("-")
|
||||||
elif volume.encrypted is False:
|
if volume.encrypted is False:
|
||||||
return _("No")
|
return _("No")
|
||||||
else:
|
return _("Yes")
|
||||||
return _("Yes")
|
|
||||||
|
|
||||||
|
|
||||||
def get_encrypted_link(volume):
|
def get_encrypted_link(volume):
|
||||||
|
@ -581,8 +581,7 @@ class EditAttachmentsView(tables.DataTableView, forms.ModalFormView):
|
|||||||
form = self.get_form()
|
form = self.get_form()
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
return self.form_valid(form)
|
return self.form_valid(form)
|
||||||
else:
|
return self.get(request, *args, **kwargs)
|
||||||
return self.get(request, *args, **kwargs)
|
|
||||||
|
|
||||||
|
|
||||||
class RetypeView(forms.ModalFormView):
|
class RetypeView(forms.ModalFormView):
|
||||||
|
@ -56,11 +56,8 @@ def _getattr(obj, name, default):
|
|||||||
attr does not exist, here, we return `default` even if attr evaluates to
|
attr does not exist, here, we return `default` even if attr evaluates to
|
||||||
None or False.
|
None or False.
|
||||||
"""
|
"""
|
||||||
value = getattr(obj, name, default)
|
value = getattr(obj, name, default) or default
|
||||||
if value:
|
return value
|
||||||
return value
|
|
||||||
else:
|
|
||||||
return default
|
|
||||||
|
|
||||||
|
|
||||||
context = template.Context({
|
context = template.Context({
|
||||||
|
@ -42,8 +42,7 @@ class BaseUsage(object):
|
|||||||
days_range = settings.OVERVIEW_DAYS_RANGE
|
days_range = settings.OVERVIEW_DAYS_RANGE
|
||||||
if days_range:
|
if days_range:
|
||||||
return self.today.date() - datetime.timedelta(days=days_range)
|
return self.today.date() - datetime.timedelta(days=days_range)
|
||||||
else:
|
return datetime.date(self.today.year, self.today.month, 1)
|
||||||
return datetime.date(self.today.year, self.today.month, 1)
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_start(year, month, day):
|
def get_start(year, month, day):
|
||||||
|
@ -74,8 +74,7 @@ def get_instance_link(datum):
|
|||||||
view = "horizon:project:instances:detail"
|
view = "horizon:project:instances:detail"
|
||||||
if datum.get('instance_id', False):
|
if datum.get('instance_id', False):
|
||||||
return urls.reverse(view, args=(datum.get('instance_id'),))
|
return urls.reverse(view, args=(datum.get('instance_id'),))
|
||||||
else:
|
return None
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
class ProjectUsageTable(BaseUsageTable):
|
class ProjectUsageTable(BaseUsageTable):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user