def clean(self): cleaned_data = super(AddGroupInfoAction, self).clean() name = cleaned_data.get('name') try: groups = cinder.group_list(self.request) except Exception: msg = _('Unable to get group list') exceptions.check_message(["Connection", "refused"], msg) raise if groups is not None and name is not None: for group in groups: if group.name.lower() == name.lower(): # ensure new name has reasonable length formatted_name = name if len(name) > 20: formatted_name = name[:14] + "..." + name[-3:] raise forms.ValidationError( _('The name "%s" is already used by ' 'another group.') % formatted_name ) return cleaned_data
def clean(self): cleaned_data = super(AddGroupInfoAction, self).clean() name = cleaned_data.get('name') try: groups = cinder.group_list(self.request) except Exception: msg = _('Unable to get group list') exceptions.check_message(["Connection", "refused"], msg) raise if groups is not None and name is not None: for group in groups: if group.name.lower() == name.lower(): # ensure new name has reasonable length formatted_name = name if len(name) > 20: formatted_name = name[:14] + "..." + name[-3:] raise forms.ValidationError( _('The name "%s" is already used by ' 'another group.') % formatted_name ) return cleaned_data
def _populate_group_choices(self, request): try: groups = cinder.group_list(request) except cinder_exc.VersionNotFoundForAPIMethod: del self.fields['group'] return except Exception: redirect = reverse("horizon:project:volumes:index") exceptions.handle(request, _('Unable to retrieve the volume group list.'), redirect=redirect) group_choices = [(g.id, g.name or g.id) for g in groups] group_choices.insert(0, ("", _("No group"))) self.fields['group'].choices = group_choices
def _populate_group_choices(self, request): try: groups = cinder.group_list(request) except cinder_exc.VersionNotFoundForAPIMethod: del self.fields['group'] return except Exception: redirect = reverse("horizon:project:volumes:index") exceptions.handle(request, _('Unable to retrieve the volume group list.'), redirect=redirect) group_choices = [(g.id, g.name or g.id) for g in groups] group_choices.insert(0, ("", _("No group"))) self.fields['group'].choices = group_choices
def _get_groups(self, volumes): needs_group = False if volumes and hasattr(volumes[0], 'group_id'): needs_group = True if needs_group: try: groups_list = cinder.group_list(self.request) groups = dict((g.id, g) for g in groups_list) except Exception: groups = {} exceptions.handle(self.request, _("Unable to retrieve volume groups")) for volume in volumes: if needs_group: volume.group = groups.get(volume.group_id) else: volume.group = None