本文整理汇总了Python中utils.utils.log函数的典型用法代码示例。如果您正苦于以下问题:Python log函数的具体用法?Python log怎么用?Python log使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了log函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: make_sleepy
def make_sleepy(self,parameters, instance_id):
utils.log( "Making instance {0} sleepy...".format(instance_id))
credentials = parameters[self.PARAM_CREDENTIALS]
ec2 = boto.connect_cloudwatch(
str(credentials[self.PARAM_CREDS_PUBLIC]),
str(credentials[self.PARAM_CREDS_PRIVATE])
)
region = "us-east-1"
terminate_arn = 'arn:aws:automate:{0}:ec2:terminate'.format(region)
alarm_name = 'ec2_shutdown_sleepy_{0}'.format(instance_id)
# define our alarm to terminate the instance if it gets sleepy
# i.e. if CPU utilisation is less than 10% for 1 x 4 hr intervals
sleepy_alarm = MetricAlarm(
name=alarm_name,
namespace='AWS/EC2',
metric='CPUUtilization',
statistic='Average',
comparison='<',
threshold='10',
period='3600',
evaluation_periods=4,
alarm_actions=[terminate_arn],
dimensions={'InstanceId':instance_id}
)
# create the alarm.. Zzzz!
ec2.create_alarm(sleepy_alarm)
开发者ID:UCSB-CS-RACELab,项目名称:CloudRunner,代码行数:26,代码来源:ec2_worker.py
示例2: run_instances
def run_instances(self, count, parameters, security_configured):
"""
Spawns the specified number of OpenStack instances using the parameters
provided. This method is blocking in that it waits until the
requested VMs are properly booted up. However if the requested
VMs cannot be procured within 1800 seconds, this method will treat
it as an error and return. (Also see documentation for the BaseAgent
class).
This method differs from its OpenStack counterpart because OpenStack
does not support spot instances.
Args:
count: Number of VMs to spawn.
parameters: A dictionary of parameters. This must contain 'keyname',
'group', 'image_id' and 'instance_type' parameters.
security_configured: Uses this boolean value as an heuristic to
detect brand new AppScale deployments.
Returns:
A tuple of the form (instances, public_ips, private_ips).
"""
if parameters[self.PARAM_SPOT] == "True":
parameters[self.PARAM_SPOT] = 'False'
utils.log("OpenStack does not support spot instances")
super.run_instances(self, count, parameters, security_configured)
开发者ID:airamrguez,项目名称:appscale,代码行数:27,代码来源:openstack_agent.py
示例3: attach_disk
def attach_disk(self, parameters, disk_name, instance_id):
""" Attaches the Elastic Block Store volume specified in 'disk_name' to this
virtual machine.
Args:
parameters: A dict with keys for each parameter needed to connect to AWS.
disk_name: A str naming the EBS mount to attach to this machine.
instance_id: A str naming the id of the instance that the disk should be
attached to. In practice, callers add disks to their own instances.
Returns:
The location on the local filesystem where the disk has been attached.
"""
# In Amazon Web Services, if we're running on a Xen Paravirtualized machine,
# then devices get added starting at /dev/xvda. If not, they get added at
# /dev/sda. Find out which one we're on so that we know where the disk will
# get attached to.
if glob.glob("/dev/xvd*"):
mount_point = '/dev/xvdc'
else:
mount_point = '/dev/sdc'
try:
conn = self.open_connection(parameters)
utils.log('Attaching volume {0} to instance {1}, at {2}'.format(
disk_name, instance_id, mount_point))
conn.attach_volume(disk_name, instance_id, mount_point)
return mount_point
except EC2ResponseError as exception:
utils.log('An error occurred when trying to attach volume {0} to ' \
'instance {1} at /dev/sdc'.format(disk_name, instance_id))
self.handle_failure('EC2 response error while attaching volume:' +
exception.error_message)
开发者ID:UCSB-CS-RACELab,项目名称:eager-appscale,代码行数:32,代码来源:ec2_agent.py
示例4: __spawn_vms
def __spawn_vms(self, agent, num_vms, parameters, reservation_id):
"""
Private method for starting a set of VMs
Args:
agent Infrastructure agent in charge of current operation
num_vms No. of VMs to be spawned
parameters A dictionary of parameters
reservation_id Reservation ID of the current run request
"""
status_info = self.reservations.get(reservation_id)
try:
security_configured = agent.configure_instance_security(parameters)
instance_info = agent.run_instances(num_vms, parameters,
security_configured)
ids = instance_info[0]
public_ips = instance_info[1]
private_ips = instance_info[2]
status_info['state'] = self.STATE_RUNNING
status_info['vm_info'] = {
'public_ips': public_ips,
'private_ips': private_ips,
'instance_ids': ids
}
utils.log('Successfully finished request {0}.'.format(reservation_id))
except AgentRuntimeException as exception:
status_info['state'] = self.STATE_FAILED
status_info['reason'] = str(exception)
self.reservations.put(reservation_id, status_info)
开发者ID:daxiaxia,项目名称:appscale,代码行数:29,代码来源:infrastructure_manager.py
示例5: describe_instances_old
def describe_instances_old(self, parameters):
"""
Retrieves the list of running instances that have been instantiated using a
particular EC2 keyname. The target keyname is read from the input parameter
map. (Also see documentation for the BaseAgent class)
Args:
parameters A dictionary containing the 'keyname' parameter
Returns:
A tuple of the form (public_ips, private_ips, instances) where each
member is a list.
"""
instance_ids = []
public_ips = []
private_ips = []
conn = self.open_connection(parameters)
reservations = conn.get_all_instances()
instances = [i for r in reservations for i in r.instances]
utils.log("Looking for instances with key = {0}".format(parameters[self.PARAM_KEYNAME]))
for i in instances:
if i.state == 'running' and i.key_name == parameters[self.PARAM_KEYNAME]:
instance_ids.append(i.id)
public_ips.append(i.public_dns_name)
private_ips.append(i.private_dns_name)
return public_ips, private_ips, instance_ids
开发者ID:UCSB-CS-RACELab,项目名称:CloudRunner,代码行数:27,代码来源:ec2_worker.py
示例6: terminate_instances
def terminate_instances(self, parameters):
"""
Stop one or more EC2 instances. The input instance IDs are
fetched from the 'instance_ids' parameter in the input parameters
map. (Also see documentation for the BaseAgent class)
If parameters contains the 'prefix' key, instances will be terminated
based on whether or not the keypair used to start them begins with
the given prefix.
Args:
parameters A dictionary of parameters
"""
conn = self.open_connection(parameters)
instance_ids = []
if self.PARAM_KEY_PREFIX in parameters:
prefix = parameters[self.PARAM_KEY_PREFIX]
reservations = conn.get_all_instances()
instances = [i for r in reservations for i in r.instances]
for i in instances:
if i.key_name is not None and i.key_name.startswith(prefix):
instance_ids.append(i.id)
else:
instance_ids = parameters[self.PARAM_INSTANCE_IDS]
terminated_instances = conn.terminate_instances(instance_ids)
for instance in terminated_instances:
instance.update()
while instance.state != 'terminated':
time.sleep(5)
instance.update()
utils.log('Instance {0} was terminated'.format(instance.id))
return True
开发者ID:UCSB-CS-RACELab,项目名称:CloudRunner,代码行数:31,代码来源:ec2_worker.py
示例7: validate_application_for_deployment
def validate_application_for_deployment(self, secret, app):
if self.secret != secret:
return self.__generate_response(False, self.REASON_BAD_SECRET)
name = app['name']
version = app['version']
dependencies = app['dependencies']
api_list = app['api_list']
api_list_without_specs = self.__remove_specs(api_list)
owner = app['owner']
if dependencies:
dep_invalid = self.adaptor.validate_application_dependencies(name, version,
api_list_without_specs, dependencies)
if dep_invalid:
detail = { 'detail' : dep_invalid }
return self.__generate_response(False, self.REASON_BAD_DEPENDENCIES, detail)
pre_validation_errors = []
for api in api_list:
api_name = api['name']
api_spec = api['specification']
if not self.__is_api_name_valid(api_name):
pre_validation_errors.append('Invalid characters in API name: {0}'.format(api_name))
spec_valid, spec_errors = swagger.validate_swagger_description(api_spec)
if not spec_valid:
pre_validation_errors.append(spec_errors)
if pre_validation_errors:
detail = { 'detail' : '|'.join(pre_validation_errors) }
return self.__generate_response(False, self.REASON_BAD_API_METADATA, detail)
passed, message = self.policy_engine.run_policy_enforcement(name, version, dependencies,
api_list_without_specs, owner)
if not passed:
detail = { 'detail' : message }
return self.__generate_response(False, self.REASON_API_POLICY_VIOLATION, detail)
post_validation_errors = []
for api in api_list:
api_name = api['name']
api_version = api['version']
api_spec = api['specification']
if self.adaptor.is_api_available(api_name, api_version):
passed, message = self.__invoke_api_validations(api_name, api_version, api_spec)
else:
passed, message = self.__handle_new_api(api_name, api_version, api_spec)
if not passed:
post_validation_errors.append(message)
if post_validation_errors:
detail = { 'detail' : '|'.join(post_validation_errors)}
return self.__generate_response(False, self.REASON_API_VALIDATION_FAILED, detail)
if not self.adaptor.record_application_dependencies(name, version, api_list_without_specs, dependencies):
utils.log("Failed to record dependencies for {0}-v{1}".format(name, version))
return self.__generate_response(False, self.REASON_DEPENDENCY_RECORDING_FAILED)
return self.__generate_response(True, self.REASON_API_VALIDATION_SUCCESS)
开发者ID:jackguo,项目名称:eager-appscale,代码行数:59,代码来源:eager.py
示例8: stop
def stop(self):
"""
Stop the infrastructure manager service.
"""
if self.started:
utils.log('Stopping AppScale Infrastructure Manager')
self.started = False
self.server.shutdown()
else:
utils.log('Warning - Stop called on already stopped server')
开发者ID:GavinHwa,项目名称:appscale,代码行数:10,代码来源:infrastructure_manager_service.py
示例9: stop
def stop(self):
"""
Stop the EAGER service.
"""
if self.started:
utils.log('Stopping EAGER service')
self.started = False
self.server.shutdown()
else:
utils.log('Warning - Stop called on already stopped server')
开发者ID:UCSB-CS-RACELab,项目名称:eager-appscale,代码行数:10,代码来源:eager_service.py
示例10: setProperty
def setProperty(self, prop, value):
if prop == None or value == None:
if prop in self.properties:
del self.properties[prop]
utils.logTrace('Removing property ' + repr(prop) + ' value: ' + repr(value))
if prop in self.properties:
old = ''
if self.properties[prop] != None:
old = self.properties[prop]
utils.log('Token "' + self.name + '" Replacing ' + prop + ' old value: ' + repr(old) + ' new value ' + repr(value))
self.properties[prop] = value
开发者ID:pgrossma,项目名称:petri,代码行数:11,代码来源:token.py
示例11: addToken
def addToken(self, token, lock=False):
try:
if lock:
self.tlLock.acquire()
tokenName = token.getName()
if not tokenName in self.list:
self.list[tokenName] = []
self.list[tokenName].append(token)
utils.log('Adding token ' + tokenName)
finally:
if lock:
self.tlLock.release()
开发者ID:pgrossma,项目名称:petri,代码行数:12,代码来源:token.py
示例12: handle_failure
def handle_failure(self, msg):
"""
Log the specified error message and raise an AgentRuntimeException
Args:
msg An error message to be logged and included in the raised exception
Raises:
AgentRuntimeException Contains the input error message
"""
utils.log(msg)
raise AgentRuntimeException(msg)
开发者ID:JohnAbel,项目名称:stochss,代码行数:12,代码来源:ec2_agent.py
示例13: start
def start(self):
"""
Start the EAGER service. This method blocks
as long as the service is alive. The caller should handle the
threading requirements
"""
if self.started:
utils.log('Warning - Start called on already running server')
else:
utils.log('Starting EAGER service on port: ' + str(self.port))
self.started = True
while self.started:
self.server.serve_forever()
开发者ID:UCSB-CS-RACELab,项目名称:eager-appscale,代码行数:13,代码来源:eager_service.py
示例14: terminate_instances
def terminate_instances(self, parameters):
"""
Stop one of more EC2 instances using. The input instance IDs are
fetched from the 'instance_ids' parameters in the input map. (Also
see documentation for the BaseAgent class)
Args:
parameters A dictionary of parameters
"""
instance_ids = parameters[self.PARAM_INSTANCE_IDS]
conn = self.open_connection(parameters)
terminated_instances = conn.terminate_instances(instance_ids)
for instance in terminated_instances:
utils.log('Instance {0} was terminated'.format(instance.id))
开发者ID:EnbitIT,项目名称:appscale,代码行数:14,代码来源:ec2_agent.py
示例15: remove
def remove(self, token):
try:
self.tlLock.acquire()
n = 0
if not token.getName() in self.list:
utils.logTrace('token ' + token.getName() + ' not found')
return
l = self.list[token.getName()]
if not token in l:
utils.log('token ' + token.getName() + ' not found in remove')
ndx = l.index(token)
del l[ndx]
finally:
self.tlLock.release()
开发者ID:pgrossma,项目名称:petri,代码行数:14,代码来源:token.py
示例16: __init__
def __init__(self, initialTokenAssignments):
utils.log('New TokenList')
self.initialTokenAssignments = initialTokenAssignments
self.list = {}
self.requiredTokensByState = {}
if initialTokenAssignments != None:
for tokenName, attributes in self.initialTokenAssignments.iteritems():
numTokens = attributes[0]
if not tokenName in self.list:
self.list[tokenName] = []
for t in xrange(int(numTokens)):
token = Token(tokenName, copy.deepcopy(attributes[1]))
token.unlock()
self.list[tokenName].append(token)
开发者ID:pgrossma,项目名称:petri,代码行数:14,代码来源:token.py
示例17: __init__
def __init__(self):
parent_dir = os.path.dirname(os.path.realpath(sys.argv[0]))
self.policy_store_dir = os.path.join(parent_dir, self.POLICY_STORE_DIR)
self.active_policies = []
self.inactive_policies = []
self.lock = Lock()
if os.path.exists(self.policy_store_dir):
for policy_file in os.listdir(self.policy_store_dir):
if policy_file.endswith('.a.py'):
full_path = os.path.join(self.policy_store_dir, policy_file)
try:
policy = Policy(full_path)
self.active_policies.append(policy)
except Exception as ex:
utils.log("Error while loading policy '{0}': {1}".format(policy_file, str(ex)))
elif policy_file.endswith('.i.py'):
full_path = os.path.join(self.policy_store_dir, policy_file)
try:
policy = Policy(full_path)
self.inactive_policies.append(policy)
except Exception as ex:
utils.log("Error while loading policy '{0}': {1}".format(policy_file, str(ex)))
if self.active_policies:
msg_suffix = '1 policy'
if len(self.active_policies) > 1:
msg_suffix = '{0} policies'.format(len(self.active_policies))
utils.log("Initialized policy engine with {0}.".format(msg_suffix))
else:
utils.log("No active policies found.")
开发者ID:jackguo,项目名称:eager-appscale,代码行数:31,代码来源:policy_engine.py
示例18: evaluate
def evaluate(self, app, errors):
globals_map = globals().copy()
globals_map['app'] = app
globals_map['assert_app_dependency'] = assert_app_dependency
globals_map['assert_not_app_dependency'] = assert_not_app_dependency
globals_map['assert_app_dependency_in_range'] = assert_app_dependency_in_range
globals_map['assert_true'] = assert_true
globals_map['assert_false'] = assert_false
globals_map['compare_versions'] = compare_versions
try:
exec(self.source_code, globals_map, {})
except EagerPolicyAssertionException as ex:
errors.append('[{0}] {1}'.format(self.name, ex))
except Exception as ex:
utils.log('[{0}] Unexpected policy exception: {1}'.format(self.name, ex))
开发者ID:jackguo,项目名称:eager-appscale,代码行数:15,代码来源:models.py
示例19: configure_instance_security
def configure_instance_security(self, parameters):
"""
Setup EC2 security keys and groups. Required input values are read from
the parameters dictionary. More specifically, this method expects to
find a 'keyname' parameter and a 'group' parameter in the parameters
dictionary. Using these provided values, this method will create a new
EC2 key-pair and a security group. Security group will be granted permissions
to access any port on the instantiated VMs. (Also see documentation for the
BaseAgent class)
Args:
parameters A dictionary of parameters
"""
keyname = parameters[self.PARAM_KEYNAME]
#keyname = "cloudrunner-keypair"
group = parameters[self.PARAM_GROUP]
#group = "cloudrunner-security-group"
key_path = '{0}.key'.format(keyname)
ssh_key = os.path.abspath(key_path)
utils.log(
'About to spawn EC2 instances - Expecting to find a key at {0}'.format(ssh_key)
)
try:
conn = self.open_connection(parameters)
if os.path.exists(ssh_key):
utils.log('SSH keys found in the local system - Not initializing EC2 security')
else:
utils.log('Creating key pair: ' + keyname)
key_pair = conn.create_key_pair(keyname)
utils.write_key_file(ssh_key, key_pair.material)
security_groups = conn.get_all_security_groups()
group_exists = False
for security_group in security_groups:
if security_group.name == group:
group_exists = True
break
if not group_exists:
utils.log('Creating security group: ' + group)
newgroup = conn.create_security_group(group, 'CloudRunner security group')
newgroup.authorize('tcp', 22, 22, '0.0.0.0/0')
newgroup.authorize('tcp', 5672, 5672, '0.0.0.0/0')
newgroup.authorize('tcp', 6379, 6379, '0.0.0.0/0')
newgroup.authorize('tcp', 11211, 11211, '0.0.0.0/0')
newgroup.authorize('tcp', 55672, 55672, '0.0.0.0/0')
result = {
'success': True,
'absolute_key_path': ssh_key
}
return result
except EC2ResponseError as exception:
self.handle_failure(
'EC2 response error while initializing security: {0}'.format(exception.error_message)
)
except Exception as exception:
self.handle_failure(
'Error while initializing EC2 security: {0}'.format(exception.message)
)
开发者ID:UCSB-CS-RACELab,项目名称:CloudRunner,代码行数:58,代码来源:ec2_worker.py
示例20: add
def add(self, tokenName, amount, properties = {}):
try:
self.tlLock.acquire()
n = 0
if not tokenName in self.list:
self.list[tokenName] = []
for i in xrange(amount):
token = Token(tokenName)
token.unlock()
for propName, propValue in properties.items():
token.setProperty(propName, propValue)
self.list[tokenName].append(token)
utils.log('Adding token ' + tokenName)
return n
finally:
self.tlLock.release()
开发者ID:pgrossma,项目名称:petri,代码行数:16,代码来源:token.py
注:本文中的utils.utils.log函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论