How to use the horizon.exceptions.handle 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 / project / instances / tabs.py View on Github external
def get_context_data(self, request):
        instance = self.tab_group.kwargs['instance']
        console_type = settings.CONSOLE_TYPE
        console_url = None
        try:
            console_type, console_url = console.get_console(
                request, console_type, instance)
            # For serial console, the url is different from VNC, etc.
            # because it does not include params for title and token
            if console_type == "SERIAL":
                console_url = reverse('horizon:project:instances:serial',
                                      args=[instance.id])
        except exceptions.NotAvailable:
            exceptions.handle(request, ignore=True, force_log=True)

        return {'console_url': console_url, 'instance_id': instance.id,
                'console_type': console_type}
github openstack / horizon / openstack_dashboard / contrib / trove / content / database_clusters / forms.py View on Github external
def datastores(self, request):
        try:
            return trove_api.trove.datastore_list(request)
        except Exception:
            LOG.exception("Exception while obtaining datastores list")
            self._datastores = []
            redirect = reverse('horizon:project:database_clusters:index')
            exceptions.handle(request,
                              _('Unable to obtain datastores.'),
                              redirect=redirect)
github openstack / horizon / horizon / dashboards / project / networks / views.py View on Github external
def _get_object(self, *args, **kwargs):
        if not hasattr(self, "_object"):
            network_id = self.kwargs['network_id']
            try:
                self._object = api.quantum.network_get(self.request,
                                                       network_id)
            except:
                redirect = self.success_url
                msg = _('Unable to retrieve network details.')
                exceptions.handle(self.request, msg, redirect=redirect)
        return self._object
github openstack / python-muranoclient / tabula / tabula / windc / views.py View on Github external
def get_data(self):
        try:
            dc_id = self.kwargs['data_center_id']
            self.datacenter_id = dc_id
            datacenter = api.datacenters_get(self.request, dc_id)
            self.dc_name = datacenter.name
            services = api.services_list(self.request, dc_id)
        except:
            services = []
            exceptions.handle(self.request,
                              _('Unable to retrieve list of services for '
                                'data center "%s".') % self.dc_name)
        return services
github openstack / manila-ui / manila_ui / dashboards / admin / share_group_snapshots / views.py View on Github external
def get_object(self):
        if not hasattr(self, "_object"):
            s_id = self.kwargs["share_group_snapshot_id"]
            try:
                self._object = manila.share_group_snapshot_get(
                    self.request, s_id)
            except Exception:
                msg = _("Unable to retrieve share group snapshot '%s'.") % s_id
                url = reverse('horizon:admin:share_group_snapshots:index')
                exceptions.handle(self.request, msg, redirect=url)
        return self._object
github openstack / horizon / openstack_dashboard / dashboards / project / instances / workflows / create_instance.py View on Github external
base.is_service_enabled(self.request, 'volume')
            flavors = json.dumps([f._info for f in
                                  instance_utils.flavor_list(self.request)])
            extra['flavors'] = flavors
            images = image_utils.get_available_images(
                self.request, self.initial['project_id'], self._images_cache)
            if images is not None:
                attrs = [{'id': i.id,
                          'min_disk': getattr(i, 'min_disk', 0),
                          'min_ram': getattr(i, 'min_ram', 0),
                          'size': functions.bytes_to_gigabytes(i.size)}
                         for i in images]
                extra['images'] = json.dumps(attrs)

        except Exception:
            exceptions.handle(self.request,
                              _("Unable to retrieve quota information."))
        return super(SetInstanceDetailsAction, self).get_help_text(extra)
github cmusatyalab / elijah-openstack / dashboard / images / views.py View on Github external
def get_object(self):
        if not hasattr(self, "_object"):
            try:
                self._object = api.glance.image_get(self.request,
                                                    self.kwargs['image_id'])
            except:
                msg = _('Unable to retrieve image.')
                url = reverse('horizon:project:images_and_snapshots:index')
                exceptions.handle(self.request, msg, redirect=url)
        return self._object
github openstack / sahara-dashboard / sahara_dashboard / content / data_processing / clusters / clusters / workflows / create.py View on Github external
def populate_keypair_choices(self, request, context):
        try:
            keypairs = nova.keypair_list(request)
        except Exception:
            keypairs = []
            exceptions.handle(request,
                              _("Unable to fetch keypair choices."))
        keypair_list = [(kp.name, kp.name) for kp in keypairs]
        keypair_list.insert(0, ("", _("No keypair")))

        return keypair_list
github cmusatyalab / elijah-openstack / dashboard / instances / views.py View on Github external
def get_data(self):
        # Gather our instances
        try:
            instances = api.nova.server_list(self.request)
        except:
            instances = []
            exceptions.handle(self.request,
                              _('Unable to retrieve instances.'))
        # Gather our flavors and correlate our instances to them
        if instances:
            try:
                flavors = api.nova.flavor_list(self.request)
            except:
                flavors = []
                exceptions.handle(self.request, ignore=True)

            full_flavors = SortedDict([(str(flavor.id), flavor)
                                        for flavor in flavors])
            # Loop through instances to get flavor info.
            for instance in instances:
                try:
                    flavor_id = instance.flavor["id"]
                    if flavor_id in full_flavors:
                        instance.full_flavor = full_flavors[flavor_id]
                    else:
                        # If the flavor_id is not in full_flavors list,
                        # get it via nova api.
                        instance.full_flavor = api.nova.flavor_get(
                            self.request, flavor_id)
                except:
                    msg = _('Unable to retrieve instance size information.')
github openstack / senlin-dashboard / senlin_dashboard / cluster / nodes / tabs.py View on Github external
event_tables.EventsTable._meta.pagination_param, None)
        reversed_order = prev_marker is not None

        node_id = self.tab_group.kwargs['node_id']
        try:
            filters = {"obj_id": node_id}
            events, self._more, self._prev = senlin.event_list(
                self.request,
                marker=marker,
                paginate=True,
                reversed_order=reversed_order,
                filters=filters)
        except Exception:
            self._prev = self._more = False
            events = []
            exceptions.handle(self.request,
                              _('Unable to retrieve node event list.'))
        return events