本文整理汇总了Python中threepio.logger.warn函数的典型用法代码示例。如果您正苦于以下问题:Python warn函数的具体用法?Python warn怎么用?Python warn使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了warn函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: validate_new_image
def validate_new_image(image_id, machine_request_id):
machine_request = MachineRequest.objects.get(id=machine_request_id)
machine_request.status = 'validating'
machine_request.save()
from service.instance import launch_esh_instance
admin_driver = machine_request.new_admin_driver()
admin_ident = machine_request.new_admin_identity()
if not admin_driver:
logger.warn("Need admin_driver functionality to auto-validate instance")
return False
if not admin_ident:
logger.warn("Need to know the AccountProvider to auto-validate instance")
return False
# Attempt to launch using the admin_driver
admin_driver.identity.user = admin_ident.created_by
machine = admin_driver.get_machine(image_id)
small_size = admin_driver.list_sizes()[0]
(instance, token, password) = launch_esh_instance(
admin_driver,
machine.id,
small_size.id,
admin_ident,
'Automated Image Verification - %s' % image_id,
'atmoadmin',
using_admin=True)
return instance.id
示例2: get_cached_machine
def get_cached_machine(provider_alias, provider_id):
if not ProviderMachine.cached_machines:
build_cached_machines()
cached_mach = ProviderMachine.cached_machines.get((int(provider_id), provider_alias))
if not cached_mach:
logger.warn("Cache does not have machine %s on provider %s" % (provider_alias, provider_id))
return cached_mach
示例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
示例4: invalid_provider
def invalid_provider(provider_id):
log_message = 'Provider %s is inactive, disabled, or does not exist.'\
% (provider_id, )
logger.warn(log_message)
return failure_response(
status.HTTP_401_UNAUTHORIZED,
log_message)
示例5: run
def run(self, node, client):
"""
Server-side logging
Optional Param: attempts - # of times to retry
in the event of a Non-Zero exit status(code)
"""
attempt = 0
retry_time = 0
while attempt < self.attempts:
node = super(LoggedScriptDeployment, self).run(node, client)
if self.exit_status == 0:
break
attempt += 1
retry_time = 2 * 2**attempt # 4,8,16..
logger.debug(
"WARN: Script %s on Node %s is non-zero."
" Will re-try in %s seconds. Attempt: %s/%s"
% (node.id, self.name, retry_time, attempt, self.attempts))
time.sleep(retry_time)
if self.stdout:
logger.debug('%s (%s)STDOUT: %s' % (node.id, self.name,
self.stdout))
if self.stderr:
logger.warn('%s (%s)STDERR: %s' % (node.id, self.name,
self.stderr))
return node
示例6: deploy_init_to
def deploy_init_to(driverCls, provider, identity, instance_id,
username=None, password=None, redeploy=False, *args, **kwargs):
try:
logger.debug("deploy_init_to task started at %s." % datetime.now())
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
image_metadata = driver._connection\
.ex_get_image_metadata(instance.machine)
deploy_chain = get_deploy_chain(driverCls, provider, identity,
instance, username, password, redeploy)
deploy_chain.apply_async()
#Can be really useful when testing.
#if kwargs.get('delay'):
# async.get()
logger.debug("deploy_init_to task finished at %s." % datetime.now())
except SystemExit:
logger.exception("System Exits are BAD! Find this and get rid of it!")
raise Exception("System Exit called")
except NonZeroDeploymentException:
raise
except Exception as exc:
logger.warn(exc)
deploy_init_to.retry(exc=exc)
示例7: _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
示例8: patch
def patch(self, request, provider_id, identity_id, machine_id):
"""
TODO: Determine who is allowed to edit machines besides
core_machine.owner
"""
user = request.user
data = request.DATA
esh_driver = prepare_driver(request, provider_id, identity_id)
if not esh_driver:
return invalid_creds(provider_id, identity_id)
esh_machine = esh_driver.get_machine(machine_id)
core_machine = convert_esh_machine(esh_driver, esh_machine, provider_id)
if not user.is_staff\
and user is not core_machine.application.created_by:
logger.warn('%s is Non-staff/non-owner trying to update a machine'
% (user.username))
return failure_response(
status.HTTP_401_UNAUTHORIZED,
"Only Staff and the machine Owner "
+ "are allowed to change machine info.")
core_machine.application.update(request.DATA)
serializer = ProviderMachineSerializer(core_machine,
data=data, partial=True)
if serializer.is_valid():
logger.info('metadata = %s' % data)
update_machine_metadata(esh_driver, esh_machine, data)
serializer.save()
logger.info(serializer.data)
return Response(serializer.data)
return failure_response(
status.HTTP_400_BAD_REQUEST,
serializer.errors)
示例9: get_allocation_result_for
def get_allocation_result_for(
provider, username, print_logs=False, start_date=None, end_date=None):
"""
Given provider and username:
* Find the correct identity for the user
* Create 'Allocation' using core representation
* Calculate the 'AllocationResult' and return both
"""
identity = _get_identity_from_tenant_name(provider, username)
# Attempt to run through the allocation engine
try:
allocation_result = _get_allocation_result(
identity, start_date, end_date,
print_logs=print_logs)
logger.debug("Result for Username %s: %s"
% (username, allocation_result))
return allocation_result
except IdentityMembership.DoesNotExist:
logger.warn(
"WARNING: User %s does not"
"have IdentityMembership on this database" % (username, ))
return _empty_allocation_result()
except:
logger.exception("Unable to monitor Identity:%s"
% (identity,))
raise
示例10: get
def get(self, request, provider_id=None, identity_id=None, action=None):
"""
"""
if not action:
errorObj = failureJSON([{
'code': 400,
'message': 'Action is not supported.'}])
return Response(errorObj, status=status.HTTP_400_BAD_REQUEST)
esh_driver = prepare_driver(request, identity_id)
esh_meta = esh_driver.meta()
try:
if 'test_links' in action:
test_links = esh_meta.test_links()
return Response(test_links, status=status.HTTP_200_OK)
except InvalidCredsError:
logger.warn('Authentication Failed. Provider-id:%s Identity-id:%s'
% (provider_id, identity_id))
errorObj = failureJSON([{
'code': 401,
'message': 'Identity/Provider Authentication Failed'}])
return Response(errorObj, status=status.HTTP_401_UNAUTHORIZED)
except NotImplemented, ne:
logger.exception(ne)
errorObj = failureJSON([{
'code': 404,
'message':
'The requested resource %s is not available on this provider'
% action}])
return Response(errorObj, status=status.HTTP_404_NOT_FOUND)
示例11: validate_new_image
def validate_new_image(image_id, machine_request_id):
machine_request = MachineRequest.objects.get(id=machine_request_id)
machine_request.status = "validating"
machine_request.save()
from service.instance import launch_esh_instance
admin_driver = machine_request.new_admin_driver()
admin_ident = machine_request.new_admin_identity()
if not admin_driver:
logger.warn("Need admin_driver functionality to auto-validate instance")
return False
if not admin_ident:
logger.warn("Need to know the AccountProvider to auto-validate instance")
return False
# Update the admin driver's User (Cannot be initialized via. Chromogenic)
admin_driver.identity.user = admin_ident.created_by
# Update metadata on rtwo/libcloud machine -- NOT a glance machine
machine = admin_driver.get_machine(image_id)
small_size = admin_driver.list_sizes()[0]
(instance_id, token, password) = launch_esh_instance(
admin_driver,
machine.id,
small_size.id,
admin_ident,
"Automated Image Verification - %s" % image_id,
"atmoadmin",
using_admin=True,
)
return instance_id
示例12: validate_new_image
def validate_new_image(image_id, machine_request_id):
machine_request = MachineRequest.objects.get(id=machine_request_id)
new_status, _ = StatusType.objects.get_or_create(name="validating")
machine_request.status = new_status
machine_request.old_status = 'validating'
machine_request.save()
accounts = get_account_driver(machine_request.new_machine.provider)
accounts.clear_cache()
from service.instance import launch_machine_instance
admin_driver = accounts.admin_driver
admin_ident = machine_request.new_admin_identity()
if not admin_driver:
logger.warn(
"Need admin_driver functionality to auto-validate instance")
return False
if not admin_ident:
logger.warn(
"Need to know the AccountProvider to auto-validate instance")
return False
# Attempt to launch using the admin_driver
admin_driver.identity.user = admin_ident.created_by
machine = admin_driver.get_machine(image_id)
small_size = admin_driver.list_sizes()[0]
instance = launch_machine_instance(
admin_driver, admin_ident,
machine, small_size,
'Automated Image Verification - %s' % image_id,
username='atmoadmin',
using_admin=True)
return instance.id
示例13: _update_machine
def _update_machine(self, request, provider_uuid, identity_uuid, machine_id):
# TODO: Determine who is allowed to edit machines besides
# core_machine.owner
user = request.user
data = request.DATA
esh_driver = prepare_driver(request, provider_uuid, identity_uuid)
if not esh_driver:
return invalid_creds(provider_uuid, identity_uuid)
esh_machine = esh_driver.get_machine(machine_id)
core_machine = convert_esh_machine(esh_driver, esh_machine, provider_uuid, user)
if not user.is_staff and user is not core_machine.application_version.application.created_by:
logger.warn("%s is Non-staff/non-owner trying to update a machine" % (user.username))
return failure_response(
status.HTTP_401_UNAUTHORIZED, "Only Staff and the machine Owner " "are allowed to change machine info."
)
partial_update = True if request.method == "PATCH" else False
serializer = ProviderMachineSerializer(
core_machine, request_user=request.user, data=data, partial=partial_update
)
if serializer.is_valid():
logger.info("metadata = %s" % data)
update_machine_metadata(esh_driver, esh_machine, data)
machine = serializer.save()
if "created_by_identity" in request.DATA:
identity = machine.created_by_identity
update_application_owner(core_machine.application_version.application, identity)
logger.info(serializer.data)
return Response(serializer.data)
return failure_response(status.HTTP_400_BAD_REQUEST, serializer.errors)
示例14: lookupEmail
def lookupEmail(userid):
"""
Grabs email for the user based on LDAP attrs
"""
try:
logger.debug(type(userid))
if isinstance(userid, WSGIRequest):
raise Exception("WSGIRequest invalid.")
attr = _search_ldap(userid)
emailaddr = attr[0][1]["mail"][0]
return emailaddr
except Exception as e:
logger.warn("Error occurred looking up email for user: %s" % userid)
logger.exception(e)
import traceback
import sys
import inspect
s = inspect.stack()
for i in range(0, 4):
logger.debug(s[i])
etype, value, tb = sys.exc_info()
logger.error("TB = %s" % traceback.format_tb(tb))
return None
示例15: has_permission
def has_permission(self, request, view):
auth_user = request.user
project_uuid = view.kwargs.get("project_uuid")
if not project_uuid:
logger.warn("Could not find kwarg:'project_uuid'")
return False
return any(group for group in auth_user.group_set.all() if group.projects.filter(uuid=project_uuid))