Python horizon.exceptions.handle() Examples
The following are 30
code examples of horizon.exceptions.handle().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
horizon.exceptions
, or try the search function
.
Example #1
Source File: forms.py From trove-dashboard with Apache License 2.0 | 6 votes |
def handle(self, request, data): try: datastore = data['datastore'].split(',')[0] datastore_version = data['datastore'].split(',')[1] api.trove.configuration_create(request, data['name'], "{}", description=data['description'], datastore=datastore, datastore_version=datastore_version) messages.success(request, _('Created configuration group')) except Exception as e: redirect = reverse("horizon:project:database_configurations:index") exceptions.handle(request, _('Unable to create configuration ' 'group. %s') % e, redirect=redirect) return True
Example #2
Source File: forms.py From monasca-ui with Apache License 2.0 | 6 votes |
def handle(self, request, data): try: alarm_def = api.monitor.alarmdef_get(request, self.initial['id']) api.monitor.alarmdef_update( request, alarm_id=self.initial['id'], severity=data['severity'], name=data['name'], expression=data['expression'], description=data['description'], match_by=alarm_def['match_by'], actions_enabled=data['actions_enabled'], alarm_actions=data['alarm_actions'], ok_actions=data['ok_actions'], undetermined_actions=data['undetermined_actions'], ) messages.success(request, _('Alarm definition has been updated.')) except Exception as e: exceptions.handle(request, _('%s') % e) return False return True
Example #3
Source File: tabs.py From trove-dashboard with Apache License 2.0 | 6 votes |
def get_users_data(self): instance = self.tab_group.kwargs['instance'] try: data = api.trove.users_list(self.request, instance.id) for user in data: user.instance = instance try: user.access = api.trove.user_list_access(self.request, instance.id, user.name, host=user.host) except exceptions.NOT_FOUND: pass except Exception: msg = _('Unable to get user access data.') exceptions.handle(self.request, msg) except Exception: msg = _('Unable to get user data.') exceptions.handle(self.request, msg) data = [] return data
Example #4
Source File: views.py From trove-dashboard with Apache License 2.0 | 6 votes |
def get_data(self): try: LOG.info("Obtaining instance for detailed view ") instance_id = self.kwargs['instance_id'] instance = api.trove.instance_get(self.request, instance_id) instance.host = tables.get_host(instance) except Exception: msg = _('Unable to retrieve details ' 'for database instance: %s') % instance_id exceptions.handle(self.request, msg, redirect=self.get_redirect_url()) try: instance.full_flavor = api.trove.flavor_get( self.request, instance.flavor["id"]) except Exception: LOG.error('Unable to retrieve flavor details' ' for database instance: %s' % instance_id) return instance
Example #5
Source File: views.py From manila-ui with Apache License 2.0 | 6 votes |
def get_data(self): try: snapshot_id = self.kwargs['snapshot_id'] snapshot = manila.share_snapshot_get(self.request, snapshot_id) share = manila.share_get(self.request, snapshot.share_id) if share.mount_snapshot_support: snapshot.rules = manila.share_snapshot_rules_list( self.request, snapshot_id) snapshot.export_locations = ( manila.share_snap_export_location_list( self.request, snapshot)) export_locations = [ exp['path'] for exp in snapshot.export_locations ] snapshot.el_size = ui_utils.calculate_longest_str_size( export_locations) snapshot.share_name_or_id = share.name or share.id except Exception: exceptions.handle( self.request, _('Unable to retrieve snapshot details.'), redirect=self.redirect_url) return snapshot
Example #6
Source File: create_instance.py From trove-dashboard with Apache License 2.0 | 6 votes |
def populate_availability_zone_choices(self, request, context): try: zones = self.availability_zones(request) except Exception: zones = [] redirect = reverse('horizon:project:databases:index') exceptions.handle(request, _('Unable to retrieve availability zones.'), redirect=redirect) zone_list = [(zone.zoneName, zone.zoneName) for zone in zones if zone.zoneState['available']] zone_list.sort() if not zone_list: zone_list.insert(0, ("", _("No availability zones found"))) elif len(zone_list) > 1: zone_list.insert(0, ("", _("Any Availability Zone"))) return zone_list
Example #7
Source File: views.py From trove-dashboard with Apache License 2.0 | 6 votes |
def get_object(self, *args, **kwargs): instance_id = self.kwargs['instance_id'] try: instance = api.trove.instance_get(self.request, instance_id) flavor_id = instance.flavor['id'] flavors = {} for i, j in self.get_flavors(): flavors[str(i)] = j if flavor_id in flavors: instance.flavor_name = flavors[flavor_id] else: flavor = api.trove.flavor_get(self.request, flavor_id) instance.flavor_name = flavor.name return instance except Exception: redirect = reverse('horizon:project:databases:index') msg = _('Unable to retrieve instance details.') exceptions.handle(self.request, msg, redirect=redirect)
Example #8
Source File: forms.py From monasca-ui with Apache License 2.0 | 6 votes |
def handle(self, request, data): try: alarm_actions = [] if data['notifications']: alarm_actions = [notification.get('id') for notification in data['notifications']] api.monitor.alarm_update( request, alarm_id=self.initial['id'], state=self.initial['state'], severity=data['severity'], name=data['name'], expression=data['expression'], description=data['description'], actions_enabled=data['actions_enabled'], alarm_actions=alarm_actions, ok_actions=alarm_actions, undetermined_actions=alarm_actions, ) messages.success(request, _('Alarm has been edited successfully.')) except Exception as e: exceptions.handle(request, _('Unable to edit the alarm: %s') % e) return False return True
Example #9
Source File: forms.py From monasca-ui with Apache License 2.0 | 6 votes |
def handle(self, request, data): try: alarm_actions = [notification.get('id') for notification in data['notifications']] api.monitor.alarm_create( request, name=data['name'], expression=data['expression'], description=data['description'], severity=data['severity'], alarm_actions=alarm_actions, ok_actions=alarm_actions, undetermined_actions=alarm_actions, ) messages.success(request, _('Alarm has been created successfully.')) except Exception as e: exceptions.handle(request, _('Unable to create the alarm: %s') % e.message) return False return True
Example #10
Source File: forms.py From monasca-ui with Apache License 2.0 | 6 votes |
def handle(self, request, data): try: kwargs = {} kwargs['notification_id'] = self.initial['id'] kwargs['name'] = data['name'] kwargs['type'] = data['type'] kwargs['address'] = data['address'] kwargs['period'] = int(data['period']) api.monitor.notification_update( request, **kwargs ) messages.success(request, _('Notification has been edited successfully.')) except Exception as e: exceptions.handle(request, _('Unable to edit the notification: %s') % e) return False return True
Example #11
Source File: forms.py From trove-dashboard with Apache License 2.0 | 6 votes |
def handle(self, request, data): instance = data.get('instance_id') try: api.trove.user_create( request, instance, data['name'], data['password'], host=data['host'], databases=self._get_databases(data)) messages.success(request, _('Created user "%s".') % data['name']) except Exception as e: redirect = reverse("horizon:project:databases:detail", args=(instance,)) exceptions.handle(request, _('Unable to create user. %s') % e, redirect=redirect) return True
Example #12
Source File: tabs.py From trove-dashboard with Apache License 2.0 | 6 votes |
def get_instances_data(self): cluster = self.tab_group.kwargs['cluster'] data = [] try: instances = api.trove.cluster_get(self.request, cluster.id).instances for instance in instances: instance_info = api.trove.instance_get(self.request, instance['id']) flavor_id = instance_info.flavor['id'] instance_info.full_flavor = api.trove.flavor_get(self.request, flavor_id) if "type" in instance: instance_info.type = instance["type"] if "ip" in instance: instance_info.ip = instance["ip"] if "hostname" in instance: instance_info.hostname = instance["hostname"] data.append(instance_info) except Exception: msg = _('Unable to get instances data.') exceptions.handle(self.request, msg) data = [] return data
Example #13
Source File: forms.py From trove-dashboard with Apache License 2.0 | 6 votes |
def handle(self, request, data): instance = data.get('instance_id') try: api.trove.user_update_attributes( request, instance, data['user_name'], host=data['user_host'], new_name=data['new_name'], new_password=data['new_password'], new_host=data['new_host']) messages.success(request, _('Updated user "%s".') % data['user_name']) except Exception as e: redirect = reverse("horizon:project:databases:detail", args=(instance,)) exceptions.handle(request, _('Unable to update user. %s') % e, redirect=redirect) return True
Example #14
Source File: forms.py From trove-dashboard with Apache License 2.0 | 6 votes |
def get_parameters(self, request, datastore, datastore_version): try: choices = [] self.parameters = self.parameters( request, datastore, datastore_version) for parameter in self.parameters: choices.append((parameter.name, parameter.name)) return sorted(choices) except Exception: LOG.exception( "Exception while obtaining configuration parameters list") redirect = reverse('horizon:project:database_configurations:index') exceptions.handle(request, _('Unable to create list of parameters.'), redirect=redirect)
Example #15
Source File: forms.py From trove-dashboard with Apache License 2.0 | 6 votes |
def handle(self, request, data): try: (config_param_manager .get(request, self.initial["configuration_id"]) .add_param(data["name"], config_param_manager.adjust_type( config_param_manager.find_parameter( data["name"], self.parameters).type, data["value"]))) messages.success(request, _('Successfully added parameter')) except Exception as e: redirect = reverse("horizon:project:database_configurations:index") exceptions.handle(request, _('Unable to add new parameter: %s') % e, redirect=redirect) return True
Example #16
Source File: views.py From trove-dashboard with Apache License 2.0 | 6 votes |
def build_response(request, instance_id, filename, tail): data = (_('Unable to load {0} log for instance "{1}".') .format(filename, instance_id)) if request.GET.get('publish'): publish = True else: publish = False try: data = get_contents(request, instance_id, filename, publish, int(tail)) except Exception: exceptions.handle(request, ignore=True) return http.HttpResponse(data.encode('utf-8'), content_type='text/plain')
Example #17
Source File: forms.py From trove-dashboard with Apache License 2.0 | 6 votes |
def populate_network_choices(self, request): network_list = [] try: if api.base.is_service_enabled(request, 'network'): tenant_id = self.request.user.tenant_id networks = api.neutron.network_list_for_tenant(request, tenant_id) network_list = [(network.id, network.name_or_id) for network in networks] else: self.fields['network'].widget = forms.HiddenInput() except exceptions.ServiceCatalogException: network_list = [] redirect = reverse('horizon:project:database_clusters:index') exceptions.handle(request, _('Unable to retrieve networks.'), redirect=redirect) return network_list
Example #18
Source File: forms.py From trove-dashboard with Apache License 2.0 | 6 votes |
def flavors(self, request): try: datastore = None datastore_version = None datastore_dict = self.initial.get('datastore', None) if datastore_dict: datastore = datastore_dict.get('type', None) datastore_version = datastore_dict.get('version', None) return trove_api.trove.datastore_flavors( request, datastore_name=datastore, datastore_version=datastore_version) except Exception: LOG.exception("Exception while obtaining flavors list") self._flavors = [] redirect = reverse('horizon:project:database_clusters:index') exceptions.handle(request, _('Unable to obtain flavors.'), redirect=redirect)
Example #19
Source File: create.py From freezer-web-ui with Apache License 2.0 | 6 votes |
def __init__(self, request, *args, **kwargs): super(ClientsConfigurationAction, self).__init__(request, *args, **kwargs) err_msg = _('Unable to retrieve client list.') job_id = args[0].get('job_id', None) default_role_name = self.get_default_role_field_name() self.fields[default_role_name] = forms.CharField(required=False) self.fields[default_role_name].initial = 'member' all_clients = [] try: all_clients = freezer_api.Client(request).list() except Exception: exceptions.handle(request, err_msg) client_list = [(c.uuid, c.hostname) for c in all_clients] field_name = self.get_member_field_name('member') if not job_id: self.fields[field_name] = forms.MultipleChoiceField() self.fields[field_name].choices = client_list
Example #20
Source File: views.py From trove-dashboard with Apache License 2.0 | 6 votes |
def get_data(self): try: cluster_id = self.kwargs['cluster_id'] cluster = api.trove.cluster_get(self.request, cluster_id) except Exception: redirect = reverse('horizon:project:database_clusters:index') msg = _('Unable to retrieve details ' 'for database cluster: %s') % cluster_id exceptions.handle(self.request, msg, redirect=redirect) try: cluster.full_flavor = api.trove.flavor_get( self.request, cluster.instances[0]["flavor"]["id"]) except Exception: LOG.error('Unable to retrieve flavor details' ' for database cluster: %s' % cluster_id) cluster.num_instances = len(cluster.instances) # Todo(saurabhs) Set mgmt_url to dispaly Mgmt Console URL on # cluster details page # for instance in cluster.instances: # if instance['type'] == "master": # cluster.mgmt_url = "https://%s:5450/webui" % instance['ip'][0] return cluster
Example #21
Source File: create.py From freezer-web-ui with Apache License 2.0 | 6 votes |
def handle(self, request, context): try: interval_unit = context['interval_uint'] if not interval_unit or interval_unit == 'continuous': context['schedule_interval'] = interval_unit else: interval_value = context['interval_value'] schedule_interval = "{0} {1}".format(interval_value, interval_unit) context['schedule_interval'] = schedule_interval if context['job_id'] != '': freezer_api.Job(request).update(context['job_id'], context) else: freezer_api.Job(request).create(context) return shortcuts.redirect('horizon:disaster_recovery:jobs:index') except Exception: exceptions.handle(request) return False
Example #22
Source File: forms.py From monasca-ui with Apache License 2.0 | 6 votes |
def handle(self, request, data): try: api.monitor.notification_create( request, name=data['name'], type=data['type'], address=data['address'], period=int(data['period'])) messages.success(request, _('Notification method has been created ' 'successfully.')) except Exception as e: exceptions.handle(request, _('Unable to create the notification ' 'method: %s') % e) return False return True
Example #23
Source File: attach.py From freezer-web-ui with Apache License 2.0 | 5 votes |
def handle(self, request, context): try: freezer_api.Session(request).add_job(context['session_id'], context['job_id']) return reverse("horizon:disaster_recovery:jobs:index") except Exception: exceptions.handle(request) return False
Example #24
Source File: tables.py From manila-ui with Apache License 2.0 | 5 votes |
def delete(self, request, obj_id): try: manila.share_snapshot_deny( request, self.table.kwargs['snapshot_id'], obj_id) except Exception: msg = _('Unable to delete snapshot rule "%s".') % obj_id exceptions.handle(request, msg)
Example #25
Source File: create.py From freezer-web-ui with Apache License 2.0 | 5 votes |
def handle(self, request, context): try: if context['session_id'] != '': freezer_api.Session(request).update(context, context['session_id']) else: freezer_api.Session(request).create(context) return reverse("horizon:disaster_recovery:sessions:index") except Exception: exceptions.handle(request) return False
Example #26
Source File: attach.py From freezer-web-ui with Apache License 2.0 | 5 votes |
def populate_session_id_choices(self, request, context): sessions = [] try: sessions = freezer_api.Session(request).list() except Exception: exceptions.handle(request, _('Error getting session list')) sessions = [(s.session_id, s.description) for s in sessions] sessions.insert(0, ('', _('Select A Session'))) return sessions
Example #27
Source File: utils.py From freezer-web-ui with Apache License 2.0 | 5 votes |
def shield(message, redirect=''): """decorator to reduce boilerplate try except blocks for horizon functions :param message: a str error message :param redirect: a str with the redirect namespace without including horizon:disaster_recovery: eg. @shield('error', redirect='jobs:index') """ def wrap(function): @wraps(function) def wrapped_function(view, *args, **kwargs): try: return function(view, *args, **kwargs) except Exception as error: LOG.error(error.message) namespace = "horizon:disaster_recovery:" r = reverse("{0}{1}".format(namespace, redirect)) if view.request.path == r: # To avoid an endless loop, we must not redirect to the # same page on which the error happened user_home = get_user_home(view.request.user) exceptions.handle(view.request, _(error.message), redirect=user_home) else: exceptions.handle(view.request, _(error.message), redirect=r) return wrapped_function return wrap
Example #28
Source File: tables.py From manila-ui with Apache License 2.0 | 5 votes |
def delete(self, request, obj_id): obj = self.table.get_object_by_id(obj_id) name = self.table.get_object_display(obj) try: manila.share_snapshot_delete(request, obj_id) except Exception: msg = _('Unable to delete snapshot "%s". One or more shares ' 'depend on it.') exceptions.handle(self.request, msg % name) raise
Example #29
Source File: workflows.py From monasca-ui with Apache License 2.0 | 5 votes |
def __init__(self, request, context, *args, **kwargs): super(SetAlarmNotificationsAction, self).__init__( request, context, *args, **kwargs ) try: notifications = ad_forms._get_notifications(request) self.fields['notifications'].choices = notifications except Exception as e: exceptions.handle(request, _('Unable to retrieve notifications: %s') % e)
Example #30
Source File: forms.py From trove-dashboard with Apache License 2.0 | 5 votes |
def parameters(self, request, datastore, datastore_version): try: return api.trove.configuration_parameters_list( request, datastore, datastore_version) except Exception: LOG.exception( "Exception while obtaining configuration parameter list") redirect = reverse('horizon:project:database_configurations:index') exceptions.handle(request, _('Unable to obtain list of parameters.'), redirect=redirect)