Exemple #1
0
    def index(self, req):
        """
        Return a list of all running services. Filter by host & service name.
        """
        context = req.environ['nova.context']
        authorize(context)
        now = timeutils.utcnow()
        services = db.service_get_all(context)

        host = ''
        if 'host' in req.GET:
            host = req.GET['host']
        service = ''
        if 'service' in req.GET:
            service = req.GET['service']
        if host:
            services = [s for s in services if s['host'] == host]
        if service:
            services = [s for s in services if s['binary'] == service]

        svcs = []
        for svc in services:
            delta = now - (svc['updated_at'] or svc['created_at'])
            alive = abs(utils.total_seconds(delta)) <= CONF.service_down_time
            art = (alive and "up") or "down"
            active = 'enabled'
            if svc['disabled']:
                active = 'disabled'
            svcs.append({"binary": svc['binary'], 'host': svc['host'],
                         'zone': svc['availability_zone'],
                         'status': active, 'state': art,
                         'updated_at': svc['updated_at']})
        return {'services': svcs}
Exemple #2
0
    def index(self, req):
        """
        Return a list of all running services. Filter by host & service name.
        """
        context = req.environ['nova.context']
        authorize(context)
        now = timeutils.utcnow()
        services = db.service_get_all(context)

        host = ''
        if 'host' in req.GET:
            host = req.GET['host']
        service = ''
        if 'service' in req.GET:
            service = req.GET['service']
        if host:
            services = [s for s in services if s['host'] == host]
        if service:
            services = [s for s in services if s['binary'] == service]

        svcs = []
        for svc in services:
            delta = now - (svc['updated_at'] or svc['created_at'])
            alive = abs(utils.total_seconds(delta)) <= CONF.service_down_time
            art = (alive and "up") or "down"
            active = 'enabled'
            if svc['disabled']:
                active = 'disabled'
            svcs.append({"binary": svc['binary'], 'host': svc['host'],
                         'zone': svc['availability_zone'],
                         'status': active, 'state': art,
                         'updated_at': svc['updated_at']})
        return {'services': svcs}
Exemple #3
0
 def is_up(self, service_ref):
     """Moved from nova.utils
     Check whether a service is up based on last heartbeat.
     """
     last_heartbeat = service_ref['updated_at'] or service_ref['created_at']
     # Timestamps in DB are UTC.
     elapsed = utils.total_seconds(timeutils.utcnow() - last_heartbeat)
     LOG.debug('DB_Driver.is_up last_heartbeat = %(lhb)s elapsed = %(el)s',
               {'lhb': str(last_heartbeat), 'el': str(elapsed)})
     return abs(elapsed) <= CONF.service_down_time
Exemple #4
0
 def is_up(self, service_ref):
     """Moved from nova.utils
     Check whether a service is up based on last heartbeat.
     """
     last_heartbeat = service_ref['updated_at'] or service_ref['created_at']
     # Timestamps in DB are UTC.
     elapsed = utils.total_seconds(timeutils.utcnow() - last_heartbeat)
     LOG.debug('DB_Driver.is_up last_heartbeat = %(lhb)s elapsed = %(el)s',
               {'lhb': str(last_heartbeat), 'el': str(elapsed)})
     return abs(elapsed) <= CONF.service_down_time
Exemple #5
0
 def is_up(self, service_ref):
     """Moved from nova.utils
     Check whether a service is up based on last heartbeat.
     """
     last_heartbeat = service_ref['updated_at'] or service_ref['created_at']
     if isinstance(last_heartbeat, basestring):
         # NOTE(russellb) If this service_ref came in over rpc via
         # conductor, then the timestamp will be a string and needs to be
         # converted back to a datetime.
         last_heartbeat = timeutils.parse_strtime(last_heartbeat)
     # Timestamps in DB are UTC.
     elapsed = utils.total_seconds(timeutils.utcnow() - last_heartbeat)
     LOG.debug('DB_Driver.is_up last_heartbeat = %(lhb)s elapsed = %(el)s',
               {'lhb': str(last_heartbeat), 'el': str(elapsed)})
     return abs(elapsed) <= CONF.service_down_time
Exemple #6
0
 def is_up(self, service_ref):
     """Moved from nova.utils
     Check whether a service is up based on last heartbeat.
     """
     last_heartbeat = service_ref['updated_at'] or service_ref['created_at']
     if isinstance(last_heartbeat, basestring):
         # NOTE(russellb) If this service_ref came in over rpc via
         # conductor, then the timestamp will be a string and needs to be
         # converted back to a datetime.
         last_heartbeat = timeutils.parse_strtime(last_heartbeat)
     # Timestamps in DB are UTC.
     elapsed = utils.total_seconds(timeutils.utcnow() - last_heartbeat)
     LOG.debug('DB_Driver.is_up last_heartbeat = %(lhb)s elapsed = %(el)s',
               {'lhb': str(last_heartbeat), 'el': str(elapsed)})
     return abs(elapsed) <= CONF.service_down_time
 def _get_dead_hosts(self, context):
     '''
     get the node status by nova-recover service
     and return all failed node
     :param context:
     :return:
     '''
     now = timeutils.utcnow()
     services = db.service_get_all_by_topic(context, topic)
     dead_hosts = []
     alive_hosts = []
     for service in services:
         delta = now - (service['updated_at'] or service['created_at'])
         alive = abs(utils.total_seconds(delta)) <= FLAGS.service_down_time
         service_host = service['host']
         if  alive:
             alive_hosts.append(service_host)
         else:
             dead_hosts.append(service_host)
     return dead_hosts, alive_hosts
Exemple #8
0
 def is_up(self, service_ref):
     """Moved from nova.utils
     Check whether a service is up based on last heartbeat.
     """
     last_heartbeat = service_ref["updated_at"] or service_ref["created_at"]
     if isinstance(last_heartbeat, basestring):
         # NOTE(russellb) If this service_ref came in over rpc via
         # conductor, then the timestamp will be a string and needs to be
         # converted back to a datetime.
         last_heartbeat = timeutils.parse_strtime(last_heartbeat)
     else:
         # Objects have proper UTC timezones, but the timeutils comparison
         # below does not (and will fail)
         last_heartbeat = last_heartbeat.replace(tzinfo=None)
     # Timestamps in DB are UTC.
     elapsed = utils.total_seconds(timeutils.utcnow() - last_heartbeat)
     LOG.debug(
         "DB_Driver.is_up last_heartbeat = %(lhb)s elapsed = %(el)s",
         {"lhb": str(last_heartbeat), "el": str(elapsed)},
     )
     return abs(elapsed) <= CONF.service_down_time
Exemple #9
0
    def index(self, req):
        """
        Return a list of all running services. Filter by host & service name.
        """
        context = req.environ["nova.context"]
        authorize(context)
        now = timeutils.utcnow()
        services = self.host_api.service_get_all(context, set_zones=True)

        host = ""
        if "host" in req.GET:
            host = req.GET["host"]
        service = ""
        if "service" in req.GET:
            service = req.GET["service"]
        if host:
            services = [s for s in services if s["host"] == host]
        if service:
            services = [s for s in services if s["binary"] == service]

        svcs = []
        for svc in services:
            delta = now - (svc["updated_at"] or svc["created_at"])
            alive = abs(utils.total_seconds(delta)) <= CONF.service_down_time
            art = (alive and "up") or "down"
            active = "enabled"
            if svc["disabled"]:
                active = "disabled"
            svcs.append(
                {
                    "binary": svc["binary"],
                    "host": svc["host"],
                    "zone": svc["availability_zone"],
                    "status": active,
                    "state": art,
                    "updated_at": svc["updated_at"],
                }
            )
        return {"services": svcs}
Exemple #10
0
def is_service_alive(updated_at, created_at):
    delta = timeutils.utcnow() - (updated_at or created_at)
    return abs(utils.total_seconds(delta)) <= CONF.service_down_time
Exemple #11
0
 def service_is_up(service):
     """Check whether a service is up based on last heartbeat."""
     last_heartbeat = service['updated_at'] or service['created_at']
     # Timestamps in DB are UTC.
     elapsed = utils.total_seconds(utils.utcnow() - last_heartbeat)
     return abs(elapsed) <= FLAGS.service_down_time
Exemple #12
0
 def service_is_up(service):
     """Check whether a service is up based on last heartbeat."""
     last_heartbeat = service['updated_at'] or service['created_at']
     # Timestamps in DB are UTC.
     elapsed = utils.total_seconds(utils.utcnow() - last_heartbeat)
     return abs(elapsed) <= FLAGS.service_down_time
Exemple #13
0
def is_service_alive(updated_at, created_at):
    delta = timeutils.utcnow() - (updated_at or created_at)
    return abs(utils.total_seconds(delta)) <= CONF.service_down_time