本文整理汇总了Python中threepio.logger.info函数的典型用法代码示例。如果您正苦于以下问题:Python info函数的具体用法?Python info怎么用?Python info使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了info函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _launch_machine
def _launch_machine(driver, identity, machine, size,
name, userdata_content=None, network=None,
password=None, token=None, **kwargs):
if isinstance(driver.provider, EucaProvider):
#Create/deploy the instance -- NOTE: Name is passed in extras
logger.info("EUCA -- driver.create_instance EXTRAS:%s" % kwargs)
esh_instance = driver\
.create_instance(name=name, image=machine, size=size,
ex_userdata=userdata_contents, **kwargs)
elif isinstance(driver.provider, OSProvider):
deploy = True
#ex_metadata, ex_keyname
extra_args = _extra_openstack_args(identity)
kwargs.update(extra_args)
logger.debug("OS driver.create_instance kwargs: %s" % kwargs)
esh_instance = driver.create_instance(
name=name, image=machine, size=size,
token=token,
networks=[network], ex_admin_pass=password,
**kwargs)
#Used for testing.. Eager ignores countdown
if app.conf.CELERY_ALWAYS_EAGER:
logger.debug("Eager Task, wait 1 minute")
time.sleep(1*60)
elif isinstance(driver.provider, AWSProvider):
#TODO:Extra stuff needed for AWS provider here
esh_instance = driver.deploy_instance(
name=name, image=machine,
size=size, deploy=True,
token=token, **kwargs)
else:
raise Exception("Unable to launch with this provider.")
return (esh_instance, token, password)
示例2: _update_application
def _update_application(self, request, app, **kwargs):
data = request.DATA
user = request.user
data = request.DATA
app_owner = app.created_by
app_members = app.get_members()
if user != app_owner and not Group.check_membership(user, app_members):
return failure_response(status.HTTP_403_FORBIDDEN,
"You are not the Application owner. "
"This incident will be reported")
#Or it wont.. Up to operations..
partial_update = True if request.method == 'PATCH' else False
serializer = ApplicationSerializer(app, data=data,
context={'request': request},
partial=partial_update)
if serializer.is_valid():
logger.info('metadata = %s' % data)
#TODO: Update application metadata on each machine?
#update_machine_metadata(esh_driver, esh_machine, data)
serializer.save()
if 'created_by_identity' in data:
identity = serializer.object.created_by_identity
update_application_owner(serializer.object, identity)
if 'boot_scripts' in data:
_save_scripts_to_application(serializer.object,
data.get('boot_scripts',[]))
return Response(serializer.data)
return failure_response(
status.HTTP_400_BAD_REQUEST,
serializer.errors)
示例3: transaction
def transaction(cls, status_name, instance, size,
start_time=None, last_history=None):
try:
with transaction.atomic():
if not last_history:
# Required to prevent race conditions.
last_history = instance.get_last_history()\
.select_for_update(nowait=True)
if not last_history:
raise ValueError(
"A previous history is required "
"to perform a transaction. Instance:%s" %
(instance,))
elif last_history.end_date:
raise ValueError("Old history already has end date: %s"
% last_history)
last_history.end_date = start_time
last_history.save()
new_history = InstanceStatusHistory.create_history(
status_name, instance, size, start_time)
logger.info(
"Status Update - User:%s Instance:%s "
"Old:%s New:%s Time:%s" %
(instance.created_by,
instance.provider_alias,
last_history.status.name,
new_history.status.name,
new_history.start_date))
new_history.save()
return new_history
except DatabaseError:
logger.exception(
"instance_status_history: Lock is already acquired by"
"another transaction.")
示例4: set_provider_quota
def set_provider_quota(identity_id):
"""
"""
identity = Identity.objects.get(id=identity_id)
if not identity.credential_set.all():
#Can't update quota if credentials arent set
return
if identity.provider.get_type_name().lower() == 'openstack':
driver = get_esh_driver(identity)
username = identity.created_by.username
user_id = driver._connection._get_user_id()
tenant_id = driver._connection._get_tenant_id()
membership = IdentityMembership.objects.get(identity__id=identity_id,
member__name=username)
user_quota = membership.quota
if user_quota:
values = {'cores': user_quota.cpu,
'ram': user_quota.memory * 1024}
logger.info("Updating quota for %s to %s" % (username, values))
ad = AccountDriver(identity.provider)
admin_driver = ad.admin_driver
admin_driver._connection.ex_update_quota_for_user(tenant_id,
user_id,
values)
return True
示例5: quota_request_email
def quota_request_email(request, username, new_quota, reason):
"""
Processes Increase Quota request. Sends email to [email protected]
Returns a response.
"""
user = User.objects.get(username=username)
membership = IdentityMembership.objects.get(
identity=user.select_identity(),
member__in=user.group_set.all())
admin_url = reverse('admin:core_identitymembership_change',
args=(membership.id,))
subject = "Atmosphere Quota Request - %s" % username
context = {
"user": user,
"quota": new_quota,
"reason": reason,
"url": request.build_absolute_uri(admin_url)
}
body = render_to_string("core/email/quota_request.html",
context=Context(context))
logger.info(body)
email_success = email_admin(request, subject, body, cc_user=False)
return {"email_sent": email_success}
示例6: over_allocation_test
def over_allocation_test(identity, esh_instances):
from api import get_esh_driver
from core.models.instance import convert_esh_instance
from atmosphere import settings
over_allocated, time_diff = check_over_allocation(
identity.created_by.username, identity.id,
time_period=relativedelta(day=1, months=1))
logger.info("Overallocation Test: %s - %s - %s\tInstances:%s"
% (identity.created_by.username, over_allocated, time_diff, esh_instances))
if not over_allocated:
# Nothing changed, bail.
return False
if settings.DEBUG:
logger.info('Do not enforce allocations in DEBUG mode')
return False
driver = get_esh_driver(identity)
running_instances = []
for instance in esh_instances:
#Suspend active instances, update the task in the DB
try:
if driver._is_active_instance(instance):
driver.suspend_instance(instance)
except Exception, e:
if 'in vm_state suspended' not in e.message:
raise
updated_esh = driver.get_instance(instance.id)
updated_core = convert_esh_instance(driver, updated_esh,
identity.provider.id,
identity.id,
identity.created_by)
running_instances.append(updated_core)
示例7: mount_volume_task
def mount_volume_task(driver, instance_id, volume_id, device=None,
mount_location=None, *args, **kwargs):
"""
Mount, if possible, the volume to instance
Device and mount_location assumed if empty
"""
logger.info("Mount ONLY: %s --> %s" % (volume_id,instance_id))
logger.info("device_location:%s --> mount_location: %s"
% (device, mount_location))
try:
if not hasattr(driver, 'deploy_to'):
#Do not attempt to mount if we don't have sh access
return None
vol = driver.get_volume(volume_id)
existing_mount = vol.extra.get('metadata',{}).get('mount_location')
if existing_mount:
raise VolumeMountConflict(instance_id, volume_id,
"Volume already mounted at %s. Run 'unmount_volume' first!" %
existing_mount)
if not driver._connection.ex_volume_attached_to_instance(vol, instance_id):
raise VolumeMountConflict(instance_id, volume_id, "Cannot mount volume %s "
"-- Not attached to instance %s" % (volume_id, instance_id))
mount_chain = _get_mount_chain(driver, instance_id, volume_id,
device, mount_location)
mount_chain.apply_async()
except VolumeMountConflict:
raise
except Exception, e:
logger.exception("Exc occurred")
raise VolumeMountConflict(instance_id, volume_id)
示例8: fill_user_allocation_source_for
def fill_user_allocation_source_for(driver, user):
from core.models import AtmosphereUser
assert isinstance(user, AtmosphereUser)
allocation_list = find_user_allocation_source_for(driver, user)
if allocation_list is None:
logger.info(
"find_user_allocation_source_for %s is None, so stop and don't delete allocations"
% user.username
)
return
allocation_resources = []
user_allocation_sources = []
old_user_allocation_sources = list(
UserAllocationSource.objects.filter(
user=user
).order_by('allocation_source__name').all()
)
for api_allocation in allocation_list:
allocation_source = get_or_create_allocation_source(api_allocation)
allocation_resources.append(allocation_source)
user_allocation_source = get_or_create_user_allocation_source(
user, allocation_source
)
user_allocation_sources.append(user_allocation_source)
canonical_source_names = [source.name for source in allocation_resources]
for user_allocation_source in old_user_allocation_sources:
if user_allocation_source.allocation_source.name not in canonical_source_names:
delete_user_allocation_source(
user, user_allocation_source.allocation_source
)
return allocation_resources
示例9: create_volume_from_snapshot
def create_volume_from_snapshot(identity_uuid, snapshot_id, size_id, name,
description, metadata):
"""
Create a new volume for the snapshot
NOTE: The size must be at least the same size as the original volume.
"""
try:
identity = Identity.objects.get(uuid=identity_uuid)
driver = get_cached_driver(identity=identity)
snapshot = driver._connection.ex_get_snapshot(snapshot_id)
size = driver._connection.ex_get_size(size_id)
if not snapshot:
raise Exception("No snapshot found for id=%s." % snapshot_id)
if not size:
raise Exception("No size found for id=%s." % size_id)
success, esh_volume = driver._connection.create_volume(
snapshot.size, name, description=description, metadata=metadata,
snapshot=snapshot)
if not success:
raise Exception("Could not create volume from snapshot")
# Save the new volume to the database
convert_esh_volume(
esh_volume, identity.provider.uuid, identity_uuid,
identity.created_by)
except SoftTimeLimitExceeded as e:
create_volume_from_snapshot.retry(exc=e)
except Identity.DoesNotExist:
logger.info("An Identity for uuid=%s does not exist.", identity_uuid)
raise
示例10: __init__
def __init__(self, provider=None, *args, **kwargs):
super(AccountDriver, self).__init__()
if provider:
all_creds = self._init_by_provider(provider, *args, **kwargs)
else:
all_creds = kwargs
if 'location' in all_creds:
self.namespace = "Atmosphere_OpenStack:%s" % all_creds['location']
else:
logger.info("Using default namespace.. Could cause conflicts if "
"switching between providers. To avoid ambiguity, "
"provide the kwarg: location='provider_prefix'")
# Build credentials for each manager
self.credentials = all_creds
ex_auth_version = all_creds.get("ex_force_auth_version", '2.0_password')
if ex_auth_version.startswith('2'):
self.identity_version = 2
elif ex_auth_version.startswith('3'):
self.identity_version = 3
else:
raise Exception("Could not determine identity_version of %s"
% ex_auth_version)
user_creds = self._build_user_creds(all_creds)
image_creds = self._build_image_creds(all_creds)
net_creds = self._build_network_creds(all_creds)
sdk_creds = self._build_sdk_creds(all_creds)
# Initialize managers with respective credentials
self.user_manager = UserManager(**user_creds)
self.image_manager = ImageManager(**image_creds)
self.network_manager = NetworkManager(**net_creds)
self.openstack_sdk = _connect_to_openstack_sdk(**sdk_creds)
示例11: restore_ip_chain
def restore_ip_chain(esh_driver, esh_instance, redeploy=False):
"""
Returns: a task, chained together
task chain: wait_for("active") --> AddFixed --> AddFloating
--> reDeploy
start with: task.apply_async()
"""
from service.tasks.driver import \
wait_for, add_fixed_ip, add_floating_ip, deploy_init_to
init_task = wait_for.s(
esh_driver.__class__, esh_driver.provider,
esh_driver.identity, esh_instance.id, ["active",],
no_tasks=True)
#Step 1: Add fixed
fixed_ip_task = add_fixed_ip.si(
esh_driver.__class__, esh_driver.provider,
esh_driver.identity, esh_instance.id)
init_task.link(fixed_ip_task)
#Add float and re-deploy OR just add floating IP...
if redeploy:
deploy_task = deploy_init_to.si(esh_driver.__class__, esh_driver.provider,
esh_driver.identity, esh_instance.id,
redeploy=True)
fixed_ip_task.link(deploy_task)
else:
logger.info("Skip deployment, Add floating IP only")
floating_ip_task = add_floating_ip.si(esh_driver.__class__, esh_driver.provider,
esh_driver.identity,
esh_instance.id)
fixed_ip_task.link(floating_ip_task)
return init_task
示例12: get_default_provider
def get_default_provider(username):
"""
Return default provider given
"""
try:
from core.models.group import get_user_group
group = get_user_group(username)
provider = group.providers.filter(
Q(end_date=None) | Q(end_date__gt=timezone.now()),
active=True, type__name="OpenStack")
if provider:
provider = provider[0]
else:
logger.error("get_default_provider could not find "
"a valid Provider")
return None
logger.debug(
"default provider is %s " % provider)
return provider
except IndexError:
logger.info("No provider found for %s" % username)
return None
except Exception, e:
logger.exception(e)
return None
示例13: _deploy_init_to
def _deploy_init_to(driverCls, provider, identity, instance_id,
username=None, password=None, redeploy=False,
**celery_task_args):
try:
logger.debug("_deploy_init_to 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
#NOTE: This is unrelated to the password argument
logger.info(instance.extra)
instance._node.extra['password'] = None
msd = init(instance, identity.user.username, password, redeploy)
kwargs = _generate_ssh_kwargs()
kwargs.update({'deploy': msd})
driver.deploy_to(instance, **kwargs)
_update_status_log(instance, "Deploy Finished")
logger.debug("_deploy_init_to 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_init_to.retry(exc=exc)
except Exception as exc:
logger.exception(exc)
_deploy_init_to.retry(exc=exc)
示例14: attach_volume_task
def attach_volume_task(driver, instance_id, volume_id, device=None,
mount_location=None, *args, **kwargs):
"""
Attach (And mount, if possible) volume to instance
Device and mount_location assumed if empty
"""
logger.info("Attach: %s --> %s" % (volume_id, instance_id))
logger.info("device_location:%s, mount_location: %s"
% (device, mount_location))
try:
attach_volume = attach_task.si(
driver.__class__, driver.provider, driver.identity,
instance_id, volume_id, device)
if not hasattr(driver, 'deploy_to'):
# Do not attempt to mount if we don't have sh access
attach_volume.apply_async()
# No mount location, return None
return None
mount_chain = _get_mount_chain(driver, instance_id, volume_id,
device, mount_location)
attach_volume.link(mount_chain)
attach_volume.apply_async()
except Exception as e:
raise VolumeMountConflict(instance_id, volume_id)
return mount_location
示例15: monitor_instances_for
def monitor_instances_for(provider, users=None, print_logs=False):
"""
Update instances for provider.
"""
#For now, lets just ignore everything that isn't openstack.
if 'openstack' not in provider.type.name.lower():
return
instance_map = get_instance_owner_map(provider, users=users)
if print_logs:
import logging
import sys
consolehandler = logging.StreamHandler(sys.stdout)
consolehandler.setLevel(logging.DEBUG)
logger.addHandler(consolehandler)
if print_logs:
print_table_header()
for username in sorted(instance_map.keys()):
instances = instance_map[username]
monitor_instances_for_user(provider, username, instances, print_logs)
logger.info("Monitoring completed")
if print_logs:
logger.removeHandler(consolehandler)