How to use the horizon.exceptions function in horizon

To help you get started, we’ve selected a few horizon examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github openstack / horizon / openstack_dashboard / dashboards / admin / volumes / views.py View on Github external
def get_data(self):
        try:
            volume_id = self.kwargs['volume_id']
            volume = cinder.volume_get(self.request, volume_id)
        except Exception:
            exceptions.handle(self.request,
                              _('Unable to retrieve volume details.'),
                              redirect=self.success_url)
        return volume
github openstack / horizon / openstack_dashboard / dashboards / admin / volume_types / qos_specs / views.py View on Github external
def get_data(self):
        try:
            qos_spec_id = self.kwargs['qos_spec_id']
            qos_list = api.cinder.qos_spec_get_keys(self.request, qos_spec_id)
        except Exception:
            qos_list = []
            exceptions.handle(self.request,
                              _('Unable to retrieve QoS spec list.'))
        return qos_list
github openstack / horizon / openstack_dashboard / dashboards / identity / groups / forms.py View on Github external
def handle(self, request, data):
        try:
            LOG.info('Creating group with name "%s"', data['name'])
            api.keystone.group_create(
                request,
                domain_id=identity_utils.get_domain_id_for_operation(
                    self.request),
                name=data['name'],
                description=data['description'])
            messages.success(request,
                             _('Group "%s" was successfully created.')
                             % data['name'])
        except exceptions.Conflict:
            msg = _('Group "%s" already exists.') % data['name']
            messages.error(request, msg)
        except Exception:
            exceptions.handle(request, _('Unable to create group.'))
            return False
        return True
github openstack / adjutant-ui / adjutant_ui / content / tasks / views.py View on Github external
def get_object(self):
        try:
            return adjutant.task_get(self.request,
                                     self.kwargs['task_id']).json()
        except Exception:
            msg = _('Unable to retrieve user.')
            url = reverse('horizon:management:tasks:index')
            exceptions.handle(self.request, msg, redirect=url)
github openstack / searchlight-ui / searchlight_ui / api / rest / searchlight.py View on Github external
def _get_searchlight_url(request):
    """Get searchlight's URL from keystone; allow an override in settings"""
    searchlight_url = getattr(settings, 'SEARCHLIGHT_URL', None)
    try:
        searchlight_url = base.url_for(request, 'search')
    except exceptions.ServiceCatalogException:
        pass
    # Currently the keystone endpoint is http://host:port/
    # without the version.
    return "/".join(map(lambda x: x.strip('/'), (searchlight_url, "v1")))
github openstack / horizon / openstack_dashboard / dashboards / identity / projects / workflows.py View on Github external
project_id = ''
        if 'project_id' in self.initial:
            project_id = self.initial['project_id']

        # Get the default role
        try:
            default_role = keystone.get_default_role(self.request)
            # Default role is necessary to add members to a project
            if default_role is None:
                default = settings.OPENSTACK_KEYSTONE_DEFAULT_ROLE
                msg = (_('Could not find default role "%s" in Keystone') %
                       default)
                raise exceptions.NotFound(msg)
        except Exception:
            exceptions.handle(self.request,
                              err_msg,
                              redirect=reverse(INDEX_URL))
        default_role_name = self.get_default_role_field_name()
        self.fields[default_role_name] = forms.CharField(required=False)
        self.fields[default_role_name].initial = default_role.id

        # Get list of available users
        all_users = []
        try:
            all_users = api.keystone.user_list(request,
                                               domain=domain_id)
        except Exception:
            exceptions.handle(request, err_msg)
        users_list = [(user.id, user.name) for user in all_users]

        # Get list of roles
github openstack / horizon / openstack_dashboard / dashboards / admin / flavors / views.py View on Github external
def get_initial(self):
        flavor_id = self.kwargs['id']

        try:
            # Get initial flavor information
            flavor = api.nova.flavor_get(self.request, flavor_id)
        except Exception:
            exceptions.handle(self.request,
                              _('Unable to retrieve flavor details.'),
                              redirect=reverse_lazy(INDEX_URL))
        return {'flavor_id': flavor.id,
                'name': flavor.name,
                'vcpus': flavor.vcpus,
                'memory_mb': flavor.ram,
                'disk_gb': flavor.disk,
                'swap_mb': flavor.swap or 0,
                'rxtx_factor': flavor.rxtx_factor or 1,
                'eph_gb': getattr(flavor, 'OS-FLV-EXT-DATA:ephemeral', None)}
github intel / virtual-storage-manager / source / vsm-dashboard / vsm_dashboard / dashboards / vsm / clustermgmt / views.py View on Github external
def update_table(request):
    try:
        _zones = vsmapi.get_zone_list(request,)
    except Exception, e:
        exceptions.handle(request,_('Unable to retrieve sever list. '))

    #generate the zone list
    zones = {}
    for _zone in _zones:
        zones.setdefault(_zone.id, _zone.name)

    _server_list = vsmapi.get_server_list(request)
    _new_server_list = []
    for _server in _server_list:
        _zone_name = ""
        _is_monitor = "no"
        if _server.zone_id in zones:
            _zone_name = zones[_server.zone_id]
        if "monitor" in _server.type:
            _is_monitor = "yes"
        _new_server = {
github openstack / sahara-dashboard / sahara_dashboard / content / data_processing / jobs / data_sources / tabs.py View on Github external
def get_data_sources_data(self):
        try:
            data_sources = saharaclient.data_source_list(self.request)
        except Exception:
            data_sources = []
            exceptions.handle(self.request,
                              _("Unable to fetch data source list"))
        return data_sources
github openstack / networking-bgpvpn / bgpvpn_dashboard / dashboards / project / bgpvpn / network_associations / tables.py View on Github external
def delete(self, request, asso_id):
        try:
            bgpvpn_api.network_association_delete(
                request, asso_id, self.table.kwargs['bgpvpn_id'])
        except Exception:
            msg = _('Failed to delete Network Association %s') % asso_id
            LOG.info(msg)
            redirect = reverse('horizon:project:bgpvpn:detail')
            exceptions.handle(request, msg, redirect=redirect)