本文整理汇总了Python中threepio.logger.exception函数的典型用法代码示例。如果您正苦于以下问题:Python exception函数的具体用法?Python exception怎么用?Python exception使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了exception函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: get_user_allocations
def get_user_allocations(
self, username, include_expired=False, raise_exception=True
):
path = '/v1/projects/username/%s' % username
url_match = self.tacc_api + path
resp, data = tacc_api_get(
url_match, self.tacc_username, self.tacc_password
)
user_allocations = []
try:
_validate_tas_data(data)
projects = data['result']
for project in projects:
api_allocations = project[
'allocations'
] if include_expired else select_valid_allocations(
project['allocations']
)
for allocation in api_allocations:
if allocation['resource'] == self.resource_name:
user_allocations.append((project, allocation))
return user_allocations
except ValueError as exc:
logger.exception('JSON Decode error')
if raise_exception:
raise TASAPIException("JSON Decode error -- %s" % exc)
except Exception:
logger.exception(
'Something went wrong while getting user allocations'
)
if raise_exception:
raise
return None
开发者ID:iPlantCollaborativeOpenSource,项目名称:atmosphere,代码行数:33,代码来源:allocation.py
示例2: get
def get(self, request, provider_uuid, identity_uuid):
"""
Using provider and identity, getlist of machines
TODO: Cache this request
"""
try:
request_user = request.user
logger.debug("filtered_machine_list")
filtered_machine_list = provider_filtered_machines(request,
provider_uuid,
identity_uuid,
request_user)
#logger.debug(filtered_machine_list)
except InvalidCredsError:
return invalid_creds(provider_uuid, identity_uuid)
except MalformedResponseError:
return malformed_response(provider_uuid, identity_uuid)
except (socket_error, ConnectionFailure):
return connection_failure(provider_uuid, identity_uuid)
except Exception as e:
logger.exception("Unexpected exception for user:%s"
% request_user)
return failure_response(status.HTTP_500_INTERNAL_SERVER_ERROR,
e.message)
#logger.debug(filtered_machine_list)
serialized_data = ProviderMachineSerializer(filtered_machine_list,
request_user=request.user,
many=True).data
response = Response(serialized_data)
return response
开发者ID:Angelfirenze,项目名称:atmosphere,代码行数:30,代码来源:machine.py
示例3: set_instance_from_metadata
def set_instance_from_metadata(esh_driver, core_instance):
"""
NOT BEING USED ANYMORE.. DEPRECATED..
"""
# Fixes Dep. loop - Do not remove
from api.serializers import InstanceSerializer
# Breakout for drivers (Eucalyptus) that don't support metadata
if not hasattr(esh_driver._connection, 'ex_get_metadata'):
# logger.debug("EshDriver %s does not have function 'ex_get_metadata'"
# % esh_driver._connection.__class__)
return core_instance
try:
esh_instance = esh_driver.get_instance(core_instance.provider_alias)
if not esh_instance:
return core_instance
metadata = esh_driver._connection.ex_get_metadata(esh_instance)
except Exception:
logger.exception("Exception retrieving instance metadata for %s" %
core_instance.provider_alias)
return core_instance
# TODO: Match with actual instance launch metadata in service/instance.py
# TODO: Probably best to redefine serializer as InstanceMetadataSerializer
# TODO: Define a creator and their identity by the METADATA instead of
# assuming its the person who 'found' the instance
serializer = InstanceSerializer(core_instance, data=metadata,
partial=True)
if not serializer.is_valid():
logger.warn("Encountered errors serializing metadata:%s"
% serializer.errors)
return core_instance
core_instance = serializer.save()
core_instance.esh = esh_instance
return core_instance
开发者ID:bollig,项目名称:atmosphere,代码行数:35,代码来源:instance.py
示例4: create
def create(self, request):
request_user = request.user
request_data = request.data
if not request_data.items():
return failure_response(
status.HTTP_400_BAD_REQUEST, "Reuquest Data is missing"
)
try:
self._validate_data(request_user, request_data)
except Exception as exc:
return failure_response(status.HTTP_400_BAD_REQUEST, exc.message)
try:
instance_allocation_source = self._create_instance_allocation_source(
request_data, request_user
)
serialized_instance_allocation_source = InstanceAllocationSourceSerializer(
instance_allocation_source, context={'request': self.request}
)
return Response(
serialized_instance_allocation_source.data,
status=status.HTTP_201_CREATED
)
except Exception as exc:
logger.exception(
"Encountered exception while assigning Allocation source %s to Instance %s"
% (
request_data['allocation_source_name'],
request_data['instance_id']
)
)
return failure_response(status.HTTP_409_CONFLICT, str(exc.message))
开发者ID:iPlantCollaborativeOpenSource,项目名称:atmosphere,代码行数:35,代码来源:instance_allocation_source.py
示例5: delete_project_member
def delete_project_member(self, groupname, username, adminRole=False):
"""
Retrieves the project and user object
Removes user of the admin/member role
Returns True on success
Invalid username, groupname, rolename:
raise keystoneclient.exceptions.NotFound
"""
project = self.get_project(groupname)
user = self.get_user(username)
#FIXME: Hardcoded values
if adminRole:
role = self.get_role('admin')
else:
role = self.get_role('defaultMemberRole')
if not project or not user:
return True
try:
project.remove_user(user, role)
return True
except NotFound as no_role_for_user:
logger.debug('Error - %s: User-role combination does not exist' %
no_role_for_user)
return True
except Exception, e:
logger.exception(e)
raise
开发者ID:iPlantCollaborativeOpenSource,项目名称:rtwo,代码行数:27,代码来源:openstack_user.py
示例6: _update_volume_metadata
def _update_volume_metadata(esh_driver, esh_volume,
metadata={}):
"""
NOTE: This will NOT WORK for TAGS until openstack
allows JSONArrays as values for metadata!
NOTE: This will NOT replace missing metadata tags..
ex:
Start: ('a':'value','c':'value')
passed: c=5
End: ('a':'value', 'c':5)
"""
if not esh_volume:
return {}
if not hasattr(esh_driver._connection, 'ex_update_volume_metadata'):
logger.warn(
"EshDriver %s does not have function 'ex_update_volume_metadata'" %
esh_driver._connection.__class__)
return {}
data = esh_volume.extra.get('metadata', {})
data.update(metadata)
try:
return esh_driver._connection.ex_update_volume_metadata(
esh_volume,
data)
except Exception as e:
logger.exception("Error updating the metadata")
if 'incapable of performing the request' in e.message:
return {}
else:
raise
开发者ID:George-wu509,项目名称:atmosphere,代码行数:31,代码来源:volume.py
示例7: get
def get(self, request, provider_uuid, identity_uuid, volume_id):
"""
"""
user = request.user
esh_driver = prepare_driver(request, provider_uuid, identity_uuid)
if not esh_driver:
return invalid_creds(provider_uuid, identity_uuid)
try:
esh_volume = esh_driver.get_volume(volume_id)
except ConnectionFailure:
return connection_failure(provider_uuid, identity_uuid)
except InvalidCredsError:
return invalid_creds(provider_uuid, identity_uuid)
except Exception as exc:
logger.exception("Encountered a generic exception. "
"Returning 409-CONFLICT")
return failure_response(status.HTTP_409_CONFLICT,
str(exc.message))
if not esh_volume:
try:
source = InstanceSource.objects.get(
identifier=volume_id,
provider__uuid=provider_uuid)
source.end_date = datetime.now()
source.save()
except (InstanceSource.DoesNotExist, CoreVolume.DoesNotExist):
pass
return volume_not_found(volume_id)
core_volume = convert_esh_volume(esh_volume, provider_uuid,
identity_uuid, user)
serialized_data = VolumeSerializer(core_volume,
context={'request': request}).data
response = Response(serialized_data)
return response
开发者ID:transformersprimeabcxyz,项目名称:atmosphere-science,代码行数:34,代码来源:volume.py
示例8: get_default_identity
def get_default_identity(username, provider=None):
"""
Return the default identity given to the user-group for provider.
"""
try:
from core.models.group import get_user_group
group = get_user_group(username)
identities = group.identities.all()
if provider:
if provider.is_active():
identities = identities.filter(provider=provider)
return identities[0]
else:
logger.error("Provider provided for "
"get_default_identity is inactive.")
raise("Provider provided for get_default_identity "
"is inactive.")
else:
default_provider = get_default_provider(username)
default_identity = group.identities.filter(
provider=default_provider)[0]
logger.debug(
"default_identity set to %s " %
default_identity)
return default_identity
except Exception, e:
logger.exception(e)
return None
开发者ID:Angelfirenze,项目名称:atmosphere,代码行数:28,代码来源:user.py
示例9: get_esh_instance
def get_esh_instance(request, provider_uuid, identity_uuid, instance_id):
esh_driver = prepare_driver(request, provider_uuid, identity_uuid)
if not esh_driver:
raise InvalidCredsError(
"Provider_uuid && identity_uuid "
"did not produce a valid combination")
esh_instance = None
try:
esh_instance = esh_driver.get_instance(instance_id)
except (socket_error, ConnectionFailure):
return connection_failure(provider_uuid, identity_uuid)
except InvalidCredsError:
return invalid_creds(provider_uuid, identity_uuid)
except Exception as exc:
logger.exception("Encountered a generic exception. "
"Returning 409-CONFLICT")
return failure_response(status.HTTP_409_CONFLICT,
str(exc.message))
if not esh_instance:
# End date everything
try:
core_inst = CoreInstance.objects.get(
provider_alias=instance_id,
source__provider__uuid=provider_uuid,
created_by_identity__uuid=identity_uuid)
core_inst.end_date_all()
except CoreInstance.DoesNotExist:
pass
return esh_instance
开发者ID:catdewey,项目名称:atmosphere,代码行数:30,代码来源:instance.py
示例10: update_machine_metadata
def update_machine_metadata(esh_driver, esh_machine, data={}):
"""
NOTE: This will NOT WORK for TAGS until openstack
allows JSONArrays as values for metadata!
"""
if not hasattr(esh_driver._connection, 'ex_set_image_metadata'):
logger.info("EshDriver %s does not have function 'ex_set_image_metadata'"
% esh_driver._connection.__class__)
return {}
try:
# Possible metadata that could be in 'data'
# * application uuid
# * application name
# * specific machine version
#TAGS must be converted from list --> String
logger.info("New metadata:%s" % data)
meta_response = esh_driver._connection.ex_set_image_metadata(esh_machine, data)
esh_machine.invalidate_machine_cache(esh_driver.provider, esh_machine)
return meta_response
except Exception, e:
logger.exception("Error updating machine metadata")
if 'incapable of performing the request' in e.message:
return {}
else:
raise
开发者ID:420reich,项目名称:atmosphere,代码行数:25,代码来源:metadata.py
示例11: perform_destroy
def perform_destroy(self, instance):
user = self.request.user
identity_uuid = instance.created_by_identity.uuid
identity = Identity.objects.get(id=identity_uuid)
try:
# Test that there is not an attached volume BEFORE we destroy
#NOTE: Although this is a task we are calling and waiting for response..
core_instance = destroy_instance(
user,
identity_uuid,
instance.provider_alias)
serialized_instance = InstanceSerializer(
core_instance, context={
'request': self.request},
data={}, partial=True)
if not serialized_instance.is_valid():
return Response(serialized_instance.data,
status=status.HTTP_400_BAD_REQUEST)
return Response(status=status.HTTP_204_NO_CONTENT)
except VolumeAttachConflict as exc:
message = exc.message
return failure_response(status.HTTP_409_CONFLICT, message)
except (socket_error, ConnectionFailure):
return connection_failure(identity)
except InvalidCredsError:
return invalid_creds(identity)
except Exception as exc:
logger.exception("Encountered a generic exception. "
"Returning 409-CONFLICT")
return failure_response(status.HTTP_409_CONFLICT,
str(exc.message))
开发者ID:hwijung,项目名称:atmosphere,代码行数:31,代码来源:instance.py
示例12: get_account_driver
def get_account_driver(provider, raise_exception=False):
"""
Create an account driver for a given provider.
"""
try:
if type(provider) == uuid.UUID:
provider = CoreProvider.objects.get(uuid=provider)
type_name = provider.get_type_name().lower()
if 'openstack' in type_name:
from service.accounts.openstack_manager import AccountDriver as\
OSAccountDriver
return OSAccountDriver(provider)
elif 'eucalyptus' in type_name:
from service.accounts.eucalyptus import AccountDriver as\
EucaAccountDriver
return EucaAccountDriver(provider)
except:
if type(provider) == uuid.UUID:
provider_str = "Provider with UUID %s" % provider
else:
provider_str = "Provider %s" % provider.location
logger.exception("Account driver for provider %s not found." %
(provider_str))
if raise_exception:
raise
return None
开发者ID:xuhang57,项目名称:atmosphere,代码行数:26,代码来源:driver.py
示例13: remove_empty_networks_for
def remove_empty_networks_for(provider_id):
provider = Provider.objects.get(id=provider_id)
os_driver = get_account_driver(provider)
all_instances = os_driver.admin_driver.list_all_instances()
project_map = os_driver.network_manager.project_network_map()
projects_with_networks = project_map.keys()
for project in projects_with_networks:
networks = project_map[project]['network']
if type(networks) != list:
networks = [networks]
for network in networks:
network_name = network['name']
logger.debug("Checking if network %s is in use" % network_name)
if running_instances(network_name, all_instances):
continue
#TODO: MUST change when not using 'usergroups' explicitly.
user = project
try:
logger.debug("Removing project network for User:%s, Project:%s"
% (user, project))
os_driver.network_manager.delete_project_network(user, project)
except NeutronClientException:
logger.exception("Neutron unable to remove project"
"network for %s-%s" % (user,project))
except NeutronException:
logger.exception("Neutron unable to remove project"
"network for %s-%s" % (user,project))
开发者ID:Angelfirenze,项目名称:atmosphere,代码行数:27,代码来源:accounts.py
示例14: get_default_provider
def get_default_provider(username):
"""
Return default provider given
"""
try:
from core.models.group import get_user_group
from core.models.provider import Provider
group = get_user_group(username)
provider_ids = group.current_identities.values_list(
'provider',
flat=True)
provider = Provider.objects.filter(
id__in=provider_ids,
type__name="OpenStack")
if provider:
logger.debug("get_default_provider selected a new "
"Provider for %s: %s" % (username, provider))
provider = provider[0]
else:
logger.error("get_default_provider could not find a new "
"Provider for %s" % (username,))
return None
return provider
except Exception as e:
logger.exception("get_default_provider encountered an error "
"for %s" % (username,))
return None
开发者ID:catdewey,项目名称:atmosphere,代码行数:27,代码来源:user.py
示例15: deploy_script
def deploy_script(driverCls, provider, identity, instance_id,
script, **celery_task_args):
try:
logger.debug("deploy_script task started at %s." % datetime.now())
#Check if instance still exists
driver = get_driver(driverCls, provider, identity)
instance = driver.get_instance(instance_id)
if not instance:
logger.debug("Instance has been teminated: %s." % instance_id)
return
instance._node.extra['password'] = None
kwargs = _generate_ssh_kwargs()
kwargs.update({'deploy': script})
driver.deploy_to(instance, **kwargs)
logger.debug("deploy_script task finished at %s." % datetime.now())
except DeploymentError as exc:
logger.exception(exc)
if isinstance(exc.value, NonZeroDeploymentException):
#The deployment was successful, but the return code on one or more
# steps is bad. Log the exception and do NOT try again!
raise exc.value
#TODO: Check if all exceptions thrown at this time
#fall in this category, and possibly don't retry if
#you hit the Exception block below this.
deploy_script.retry(exc=exc)
except Exception as exc:
logger.exception(exc)
deploy_script.retry(exc=exc)
开发者ID:prodigeni,项目名称:atmosphere,代码行数:29,代码来源:driver.py
示例16: time_remaining
def time_remaining(self, user=None):
"""
Returns the remaining compute_allowed,
user: If passed in *and* allocation source is 'special', calculate remaining time based on user snapshots.
Will return a negative number if 'over allocation', when `compute_used` is larger than `compute_allowed`.
Will return Infinity if `compute_allowed` is `-1` (or any negative number)
:return: decimal.Decimal
:rtype: decimal.Decimal
"""
# Handling the 'SPECIAL_ALLOCATION_SOURCES'
time_shared_allocations = getattr(settings, 'SPECIAL_ALLOCATION_SOURCES', {})
if user and self.name in time_shared_allocations.keys():
try:
compute_allowed = time_shared_allocations[self.name]['compute_allowed']
except:
raise Exception(
"The structure of settings.SPECIAL_ALLOCATION_SOURCES "
"has changed! Verify your settings are correct and/or "
"change the lines of code above.")
try:
last_snapshot = self.user_allocation_snapshots.get(user=user)
except ObjectDoesNotExist:
logger.exception('User allocation snapshot does not exist anymore (or yet), so returning -1')
return -1
else:
compute_allowed = self.compute_allowed
last_snapshot = self.snapshot
if compute_allowed < 0:
return decimal.Decimal('Infinity')
compute_used = last_snapshot.compute_used if last_snapshot else 0
remaining_compute = compute_allowed - compute_used
return remaining_compute
开发者ID:xuhang57,项目名称:atmosphere,代码行数:34,代码来源:allocation_source.py
示例17: getDefaultIdentity
def getDefaultIdentity(username, provider=None):
"""
return the Default identity given to the user-group for provider
"""
profile = UserProfile.objects.get(user__username=username)
if profile.selected_identity:
return profile.selected_identity
else:
try:
group = getUsergroup(username)
identities = group.identities.all()
if provider:
identities = identities.filter(provider=provider)
return identities[0]
else:
default_identity = group.identities.filter(
provider__location="EUCALYPTUS")[0]
profile.selected_identity = default_identity
profile.save()
logger.debug(
"profile.selected_identity set to %s " %
profile.selected_identity)
return profile.selected_identity
except Exception, e:
logger.exception(e)
return None
开发者ID:nickeddy,项目名称:atmosphere,代码行数:26,代码来源:profile.py
示例18: monitor_instances_for_user
def monitor_instances_for_user(provider, username, instances):
from core.models.instance import convert_esh_instance
from api import get_esh_driver
try:
user = AtmosphereUser.objects.get(username=username)
#TODO: When user->group is no longer true,
# we will need to modify this..
group = Group.objects.get(name=user.username)
ident = user.identity_set.get(provider=provider)
im = ident.identitymembership_set.get(member=group)
#NOTE: Couples with API, probably want this in
# service/driver
driver = get_esh_driver(ident)
core_instances = []
#NOTE: We are converting them so they will
# be picked up as core models for the 'over_allocation_test'
for instance in instances:
c_inst = convert_esh_instance(
driver, instance,
ident.provider.id, ident.id, ident.created_by)
core_instances.append(c_inst)
over_allocation = over_allocation_test(im.identity,
instances)
core_instances = user.instance_set.filter(
provider_machine__provider=provider,
end_date=None)
core_instances_ident = ident.instance_set.filter(end_date=None)
update_instances(driver, im.identity, instances, core_instances)
except:
logger.exception("Unable to monitor User:%s on Provider:%s"
% (username,provider))
开发者ID:Spencerx,项目名称:atmosphere,代码行数:31,代码来源:allocation.py
示例19: provider_filtered_machines
def provider_filtered_machines(request, provider_uuid,
identity_uuid, request_user=None):
"""
Return all filtered machines. Uses the most common,
default filtering method.
"""
identity = Identity.objects.filter(uuid=identity_uuid)
if not identity:
raise ObjectDoesNotExist()
try:
esh_driver = prepare_driver(request, provider_uuid, identity_uuid)
except Exception:
# TODO: Observe the change of 'Fail loudly' here
# and clean up the noise, rather than hide it.
logger.exception(
"Driver could not be prepared - Provider: %s , Identity: %s"
% (provider_uuid, identity_uuid))
esh_driver = None
if not esh_driver:
raise LibcloudInvalidCredsError()
logger.debug(esh_driver)
return list_filtered_machines(esh_driver, provider_uuid, request_user)
开发者ID:xuhang57,项目名称:atmosphere,代码行数:26,代码来源:machine.py
示例20: delete
def delete(self, request, provider_uuid, identity_uuid, volume_id):
"""
Destroys the volume and updates the DB
"""
user = request.user
# Ensure volume exists
esh_driver = prepare_driver(request, provider_uuid, identity_uuid)
if not esh_driver:
return invalid_creds(provider_uuid, identity_uuid)
try:
esh_volume = esh_driver.get_volume(volume_id)
except ConnectionFailure:
return connection_failure(provider_uuid, identity_uuid)
except InvalidCredsError:
return invalid_creds(provider_uuid, identity_uuid)
except Exception as exc:
logger.exception("Encountered a generic exception. "
"Returning 409-CONFLICT")
return failure_response(status.HTTP_409_CONFLICT,
str(exc.message))
if not esh_volume:
return volume_not_found(volume_id)
core_volume = convert_esh_volume(esh_volume, provider_uuid,
identity_uuid, user)
# Delete the object, update the DB
esh_driver.destroy_volume(esh_volume)
core_volume.end_date = now()
core_volume.save()
# Return the object
serialized_data = VolumeSerializer(core_volume,
context={'request': request}).data
response = Response(serialized_data)
return response
开发者ID:transformersprimeabcxyz,项目名称:atmosphere-science,代码行数:33,代码来源:volume.py
注:本文中的threepio.logger.exception函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论