当前位置: 首页>>代码示例>>Python>>正文


Python utils.log函数代码示例

本文整理汇总了Python中utils.utils.log函数的典型用法代码示例。如果您正苦于以下问题:Python log函数的具体用法?Python log怎么用?Python log使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了log函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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


注:本文中的utils.utils.log函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。