本文整理汇总了Python中horizon.exceptions.handle方法的典型用法代码示例。如果您正苦于以下问题:Python exceptions.handle方法的具体用法?Python exceptions.handle怎么用?Python exceptions.handle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类horizon.exceptions
的用法示例。
在下文中一共展示了exceptions.handle方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: build_response
# 需要导入模块: from horizon import exceptions [as 别名]
# 或者: from horizon.exceptions import handle [as 别名]
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')
示例2: populate_availability_zone_choices
# 需要导入模块: from horizon import exceptions [as 别名]
# 或者: from horizon.exceptions import handle [as 别名]
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
示例3: get_users_data
# 需要导入模块: from horizon import exceptions [as 别名]
# 或者: from horizon.exceptions import handle [as 别名]
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
示例4: get_data
# 需要导入模块: from horizon import exceptions [as 别名]
# 或者: from horizon.exceptions import handle [as 别名]
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
示例5: get_object
# 需要导入模块: from horizon import exceptions [as 别名]
# 或者: from horizon.exceptions import handle [as 别名]
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)
示例6: handle
# 需要导入模块: from horizon import exceptions [as 别名]
# 或者: from horizon.exceptions import handle [as 别名]
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
示例7: get_instances_data
# 需要导入模块: from horizon import exceptions [as 别名]
# 或者: from horizon.exceptions import handle [as 别名]
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
示例8: get_data
# 需要导入模块: from horizon import exceptions [as 别名]
# 或者: from horizon.exceptions import handle [as 别名]
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
示例9: flavors
# 需要导入模块: from horizon import exceptions [as 别名]
# 或者: from horizon.exceptions import handle [as 别名]
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)
示例10: populate_network_choices
# 需要导入模块: from horizon import exceptions [as 别名]
# 或者: from horizon.exceptions import handle [as 别名]
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
示例11: handle
# 需要导入模块: from horizon import exceptions [as 别名]
# 或者: from horizon.exceptions import handle [as 别名]
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
示例12: get_parameters
# 需要导入模块: from horizon import exceptions [as 别名]
# 或者: from horizon.exceptions import handle [as 别名]
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)
示例13: __init__
# 需要导入模块: from horizon import exceptions [as 别名]
# 或者: from horizon.exceptions import handle [as 别名]
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
示例14: handle
# 需要导入模块: from horizon import exceptions [as 别名]
# 或者: from horizon.exceptions import handle [as 别名]
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
示例15: handle
# 需要导入模块: from horizon import exceptions [as 别名]
# 或者: from horizon.exceptions import handle [as 别名]
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