本文整理汇总了Python中threepio.logger.info函数的典型用法代码示例。如果您正苦于以下问题:Python info函数的具体用法?Python info怎么用?Python info使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了info函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
开发者ID:Angelfirenze,项目名称:atmosphere,代码行数:33,代码来源:instance.py
示例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)
开发者ID:MMontgomeryII,项目名称:atmosphere,代码行数:30,代码来源:application.py
示例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.")
开发者ID:bollig,项目名称:atmosphere,代码行数:34,代码来源:instance.py
示例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
开发者ID:kmeiern,项目名称:atmosphere,代码行数:25,代码来源:quota.py
示例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}
开发者ID:karbon62,项目名称:atmosphere,代码行数:25,代码来源:emails.py
示例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)
开发者ID:Spencerx,项目名称:atmosphere,代码行数:31,代码来源:allocation.py
示例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)
开发者ID:Angelfirenze,项目名称:atmosphere,代码行数:30,代码来源:task.py
示例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
开发者ID:iPlantCollaborativeOpenSource,项目名称:atmosphere,代码行数:33,代码来源:allocation.py
示例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
开发者ID:Cyberlusion,项目名称:Restoring-the-ecosystem,代码行数:35,代码来源:snapshot.py
示例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)
开发者ID:davianlou,项目名称:atmosphere,代码行数:34,代码来源:openstack_manager.py
示例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
开发者ID:xingningdu,项目名称:atmosphere,代码行数:31,代码来源:instance.py
示例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
开发者ID:420reich,项目名称:atmosphere,代码行数:25,代码来源:user.py
示例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)
开发者ID:chromabinary,项目名称:atmosphere,代码行数:35,代码来源:driver.py
示例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
开发者ID:transformersprimeabcxyz,项目名称:atmosphere-science,代码行数:25,代码来源:task.py
示例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)
开发者ID:LatinQueen4Life,项目名称:atmosphere,代码行数:25,代码来源:allocation.py
示例16: create_volume_from_image
def create_volume_from_image(identity_uuid, image_id, size_id, name,
description, metadata):
"""
Create a new volume from an image
"""
try:
identity = Identity.objects.get(uuid=identity_uuid)
user = identity.created_by
driver = get_cached_driver(identity=identity)
image = driver._connection.ex_get_image(image_id)
size = driver._connection.ex_get_size(size_id)
if not image:
raise Exception("No image found for id=%s." % image_id)
if not size:
raise Exception("No size found for id=%s." % size_id)
success, esh_volume = driver._connection.create_volume(
size.id, name, description=description, metadata=metadata,
image=image)
if not success:
raise Exception("Could not create volume from image")
# Save the new volume to the database
convert_esh_volume(
esh_volume, identity.provider.uuid, identity_uuid, user)
except SoftTimeLimitExceeded as e:
create_volume_from_image.retry(exc=e)
except Identity.DoesNotExist:
logger.info("An Identity for uuid=%s does not exist.", identity_uuid)
raise
开发者ID:Cyberlusion,项目名称:Restoring-the-ecosystem,代码行数:33,代码来源:snapshot.py
示例17: total_usage
def total_usage(username, start_date, allocation_source_name=None,end_date=None, burn_rate=False, email=None):
"""
This function outputs the total allocation usage in hours
"""
from service.allocation_logic import create_report
if not end_date:
end_date = timezone.now()
user_allocation = create_report(start_date,end_date,user_id=username,allocation_source_name=allocation_source_name)
if email:
return user_allocation
total_allocation = 0.0
for data in user_allocation:
#print data['instance_id'], data['allocation_source'], data['instance_status_start_date'], data['instance_status_end_date'], data['applicable_duration']
if not data['allocation_source']=='N/A':
total_allocation += data['applicable_duration']
compute_used_total = round(total_allocation/3600.0,2)
if compute_used_total > 0:
logger.info("Total usage for User %s with AllocationSource %s from %s-%s = %s"
% (username, allocation_source_name, start_date, end_date, compute_used_total))
if burn_rate:
burn_rate_total = 0 if len(user_allocation)<1 else user_allocation[-1]['burn_rate']
if burn_rate_total != 0:
logger.info("User %s with AllocationSource %s Burn Rate: %s"
% (username, allocation_source_name, burn_rate_total))
return [compute_used_total, burn_rate_total]
return compute_used_total
开发者ID:xuhang57,项目名称:atmosphere,代码行数:26,代码来源:allocation_source.py
示例18: default_quota
def default_quota(cls, user, provider):
"""
Load each Default Quota Plugin and call `plugin.get_default_quota(user, provider)`
"""
_default_quota = None
for DefaultQuotaPlugin in cls.load_plugins(cls.list_of_classes):
plugin = DefaultQuotaPlugin()
try:
inspect.getcallargs(
getattr(plugin, 'get_default_quota'),
user=user,
provider=provider
)
except AttributeError:
logger.info(
"Validation plugin %s missing method 'get_default_quota'" %
DefaultQuotaPlugin
)
except TypeError:
logger.info(
"Validation plugin %s does not accept kwargs `user` & `provider`"
% DefaultQuotaPlugin
)
_default_quota = plugin.get_default_quota(
user=user, provider=provider
)
if _default_quota:
return _default_quota
return _default_quota
开发者ID:iPlantCollaborativeOpenSource,项目名称:atmosphere,代码行数:29,代码来源:plugins.py
示例19: update_instances
def update_instances(driver, identity, esh_list, core_list):
"""
End-date core instances that don't show up in esh_list
&& Update the values of instances that do
"""
esh_ids = [instance.id for instance in esh_list]
#logger.info('%s Instances for Identity %s: %s' % (len(esh_ids), identity, esh_ids))
for core_instance in core_list:
try:
index = esh_ids.index(core_instance.provider_alias)
except ValueError:
logger.info("Did not find instance %s in ID List: %s" %
(core_instance.provider_alias, esh_ids))
core_instance.end_date_all()
continue
esh_instance = esh_list[index]
esh_size = driver.get_size(esh_instance.size.id)
core_size = convert_esh_size(esh_size, provider_id)
core_instance.update_history(
esh_instance.extra['status'],
core_size,
esh_instance.extra.get('task') or
esh_instance.extra.get(
'metadata', {}).get('tmp_status'))
return
开发者ID:Spencerx,项目名称:atmosphere,代码行数:25,代码来源:allocation.py
示例20: _build_first_history
def _build_first_history(
self,
status_name,
size,
start_date,
end_date=None,
first_update=False,
activity=None
):
# FIXME: Move this call so that it happens inside InstanceStatusHistory to avoid circ.dep.
from core.models import InstanceStatusHistory
if not first_update and status_name not in [
'build', 'pending', 'running'
]:
logger.info(
"First Update Unknown - Status name on instance %s: %s",
self.provider_alias, status_name
)
# Instance state is 'unknown' from start of instance until now
# NOTE: This is needed to prevent over-charging accounts
status_name = 'unknown'
activity = None
first_history = InstanceStatusHistory.create_history(
status_name,
self,
size,
start_date=start_date,
end_date=end_date,
activity=activity
)
first_history.save()
return first_history
开发者ID:iPlantCollaborativeOpenSource,项目名称:atmosphere,代码行数:32,代码来源:instance.py
注:本文中的threepio.logger.info函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论