Exemple #1
0
    def test_service_get_all(self):
        values = [{"host": "host1", "topic": "topic1"}, {"host": "host2", "topic": "topic2"}, {"disabled": True}]
        services = [self._create_service(vals) for vals in values]
        disabled_services = [services[-1]]
        non_disabled_services = services[:-1]

        compares = [
            (services, db.service_get_all(self.ctxt)),
            (disabled_services, db.service_get_all(self.ctxt, True)),
            (non_disabled_services, db.service_get_all(self.ctxt, False)),
        ]
        for comp in compares:
            self._assertEqualListsOfObjects(*comp)
Exemple #2
0
def _list_hosts(req, service=None):
    """Returns a summary list of hosts."""
    curr_time = timeutils.utcnow()
    context = req.environ['cinder.context']
    services = db.service_get_all(context, False)
    zone = ''
    if 'zone' in req.GET:
        zone = req.GET['zone']
    if zone:
        services = [s for s in services if s['availability_zone'] == zone]
    hosts = []
    for host in services:
        delta = curr_time - (host['updated_at'] or host['created_at'])
        alive = abs(utils.total_seconds(delta)) <= CONF.service_down_time
        status = (alive and "available") or "unavailable"
        active = 'enabled'
        if host['disabled']:
            active = 'disabled'
        LOG.debug('status, active and update: %s, %s, %s' %
                  (status, active, host['updated_at']))
        hosts.append({
            'host_name': host['host'],
            'service': host['topic'],
            'zone': host['availability_zone'],
            'service-status': status,
            'service-state': active,
            'last-update': host['updated_at']
        })
    if service:
        hosts = [host for host in hosts if host["service"] == service]
    return hosts
Exemple #3
0
    def index(self, req):
        """
        Return a list of all running services. Filter by host & service name.
        """
        context = req.environ['cinder.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))
            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 #4
0
def _list_hosts(req, service=None):
    """Returns a summary list of hosts."""
    curr_time = timeutils.utcnow()
    context = req.environ['cinder.context']
    services = db.service_get_all(context, False)
    zone = ''
    if 'zone' in req.GET:
        zone = req.GET['zone']
    if zone:
        services = [s for s in services if s['availability_zone'] == zone]
    hosts = []
    for host in services:
        delta = curr_time - (host['updated_at'] or host['created_at'])
        alive = abs(utils.total_seconds(delta)) <= CONF.service_down_time
        status = (alive and "available") or "unavailable"
        active = 'enabled'
        if host['disabled']:
            active = 'disabled'
        LOG.debug('status, active and update: %s, %s, %s' %
                  (status, active, host['updated_at']))
        hosts.append({'host_name': host['host'],
                      'service': host['topic'],
                      'zone': host['availability_zone'],
                      'service-status': status,
                      'service-state': active,
                      'last-update': host['updated_at']})
    if service:
        hosts = [host for host in hosts
                 if host["service"] == service]
    return hosts
    def test_service_get_all(self):
        values = [
            {'host': 'host1', 'topic': 'topic1'},
            {'host': 'host2', 'topic': 'topic2'},
            {'disabled': True}
        ]
        services = [self._create_service(vals) for vals in values]
        disabled_services = [services[-1]]
        non_disabled_services = services[:-1]

        compares = [
            (services, db.service_get_all(self.ctxt)),
            (disabled_services, db.service_get_all(self.ctxt, True)),
            (non_disabled_services, db.service_get_all(self.ctxt, False))
        ]
        for comp in compares:
            self._assertEqualListsOfObjects(*comp)
Exemple #6
0
    def index(self, req):
        """Return a list of all running services.

        Filter by host & service name.
        """
        context = req.environ['cinder.context']
        authorize(context)
        detailed = self.ext_mgr.is_loaded('os-extended-services')
        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']
            versionutils.report_deprecated_feature(
                LOG,
                _("Query by service parameter is deprecated. "
                  "Please use binary parameter instead."))
        binary = ''
        if 'binary' in req.GET:
            binary = req.GET['binary']

        if host:
            services = [s for s in services if s['host'] == host]
        # NOTE(uni): deprecating service request key, binary takes precedence
        binary_key = binary or service
        if binary_key:
            services = [s for s in services if s['binary'] == binary_key]

        svcs = []
        for svc in services:
            updated_at = svc['updated_at']
            delta = now - (svc['updated_at'] or svc['created_at'])
            delta_sec = delta.total_seconds()
            if svc['modified_at']:
                delta_mod = now - svc['modified_at']
                if abs(delta_sec) >= abs(delta_mod.total_seconds()):
                    updated_at = svc['modified_at']
            alive = abs(delta_sec) <= CONF.service_down_time
            art = (alive and "up") or "down"
            active = 'enabled'
            if svc['disabled']:
                active = 'disabled'
            ret_fields = {
                'binary': svc['binary'],
                'host': svc['host'],
                'zone': svc['availability_zone'],
                'status': active,
                'state': art,
                'updated_at': updated_at
            }
            if detailed:
                ret_fields['disabled_reason'] = svc['disabled_reason']
            svcs.append(ret_fields)
        return {'services': svcs}
Exemple #7
0
    def index(self, req):
        """Return a list of all running services.

        Filter by host & service name.
        """
        context = req.environ["cinder.context"]
        authorize(context)
        detailed = self.ext_mgr.is_loaded("os-extended-services")
        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"]
            versionutils.report_deprecated_feature(
                LOG, _("Query by service parameter is deprecated. " "Please use binary parameter instead.")
            )
        binary = ""
        if "binary" in req.GET:
            binary = req.GET["binary"]

        if host:
            services = [s for s in services if s["host"] == host]
        # NOTE(uni): deprecating service request key, binary takes precedence
        binary_key = binary or service
        if binary_key:
            services = [s for s in services if s["binary"] == binary_key]

        svcs = []
        for svc in services:
            updated_at = svc["updated_at"]
            delta = now - (svc["updated_at"] or svc["created_at"])
            delta_sec = delta.total_seconds()
            if svc["modified_at"]:
                delta_mod = now - svc["modified_at"]
                if abs(delta_sec) >= abs(delta_mod.total_seconds()):
                    updated_at = svc["modified_at"]
            alive = abs(delta_sec) <= CONF.service_down_time
            art = (alive and "up") or "down"
            active = "enabled"
            if svc["disabled"]:
                active = "disabled"
            ret_fields = {
                "binary": svc["binary"],
                "host": svc["host"],
                "zone": svc["availability_zone"],
                "status": active,
                "state": art,
                "updated_at": updated_at,
            }
            if detailed:
                ret_fields["disabled_reason"] = svc["disabled_reason"]
            svcs.append(ret_fields)
        return {"services": svcs}
Exemple #8
0
    def index(self, req):
        """Return a list of all running services.

        Filter by host & service name.
        """
        context = req.environ['cinder.context']
        authorize(context)
        detailed = self.ext_mgr.is_loaded('os-extended-services')
        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']
            versionutils.report_deprecated_feature(LOG, _(
                "Query by service parameter is deprecated. "
                "Please use binary parameter instead."))
        binary = ''
        if 'binary' in req.GET:
            binary = req.GET['binary']

        if host:
            services = [s for s in services if s['host'] == host]
        # NOTE(uni): deprecating service request key, binary takes precedence
        binary_key = binary or service
        if binary_key:
            services = [s for s in services if s['binary'] == binary_key]

        svcs = []
        for svc in services:
            updated_at = svc['updated_at']
            delta = now - (svc['updated_at'] or svc['created_at'])
            delta_sec = delta.total_seconds()
            if svc['modified_at']:
                delta_mod = now - svc['modified_at']
                if abs(delta_sec) >= abs(delta_mod.total_seconds()):
                    updated_at = svc['modified_at']
            alive = abs(delta_sec) <= CONF.service_down_time
            art = (alive and "up") or "down"
            active = 'enabled'
            if svc['disabled']:
                active = 'disabled'
            ret_fields = {'binary': svc['binary'], 'host': svc['host'],
                          'zone': svc['availability_zone'],
                          'status': active, 'state': art,
                          'updated_at': updated_at}
            if detailed:
                ret_fields['disabled_reason'] = svc['disabled_reason']
            svcs.append(ret_fields)
        return {'services': svcs}
Exemple #9
0
 def list(self):
     """Show a list of all cinder services."""
     ctxt = context.get_admin_context()
     services = db.service_get_all(ctxt)
     print_format = "%-16s %-36s %-16s %-10s %-5s %-10s"
     print(print_format % (_('Binary'), _('Host'), _('Zone'), _('Status'),
                           _('State'), _('Updated At')))
     for svc in services:
         alive = utils.service_is_up(svc)
         art = ":-)" if alive else "XXX"
         status = 'enabled'
         if svc['disabled']:
             status = 'disabled'
         print(print_format %
               (svc['binary'], svc['host'].partition('.')[0],
                svc['availability_zone'], status, art, svc['updated_at']))
Exemple #10
0
    def index(self, req):
        """Return a list of all running services.

        Filter by host & service name.
        """
        context = req.environ['cinder.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']
            LOG.deprecated(
                _("Query by service parameter is deprecated. "
                  "Please use binary parameter instead."))
        binary = ''
        if 'binary' in req.GET:
            binary = req.GET['binary']

        if host:
            services = [s for s in services if s['host'] == host]
        # NOTE(uni): deprecating service request key, binary takes precedence
        binary_key = binary or service
        if binary_key:
            services = [s for s in services if s['binary'] == binary_key]

        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 #11
0
    def list(self, zone=None):
        """Show a list of all physical hosts. Filter by zone.
        args: [zone]
        """
        print(_("%(host)-25s\t%(zone)-15s") % {'host': 'host', 'zone': 'zone'})
        ctxt = context.get_admin_context()
        services = db.service_get_all(ctxt)
        if zone:
            services = [s for s in services if s['availability_zone'] == zone]
        hosts = []
        for srv in services:
            if not [h for h in hosts if h['host'] == srv['host']]:
                hosts.append(srv)

        for h in hosts:
            print(_("%(host)-25s\t%(availability_zone)-15s")
                  % {'host': h['host'],
                     'availability_zone': h['availability_zone']})
Exemple #12
0
    def list(self, zone=None):
        """Show a list of all physical hosts. Filter by zone.
        args: [zone]
        """
        print(_("%(host)-25s\t%(zone)-15s") % {"host": "host", "zone": "zone"})
        ctxt = context.get_admin_context()
        services = db.service_get_all(ctxt)
        if zone:
            services = [s for s in services if s["availability_zone"] == zone]
        hosts = []
        for srv in services:
            if not [h for h in hosts if h["host"] == srv["host"]]:
                hosts.append(srv)

        for h in hosts:
            print(
                _("%(host)-25s\t%(availability_zone)-15s")
                % {"host": h["host"], "availability_zone": h["availability_zone"]}
            )
Exemple #13
0
    def index(self, req):
        """Return a list of all running services.

        Filter by host & service name.
        """
        context = req.environ['cinder.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']
            LOG.deprecated(_("Query by service parameter is deprecated. "
                             "Please use binary parameter instead."))
        binary = ''
        if 'binary' in req.GET:
            binary = req.GET['binary']

        if host:
            services = [s for s in services if s['host'] == host]
        # NOTE(uni): deprecating service request key, binary takes precedence
        binary_key = binary or service
        if binary_key:
            services = [s for s in services if s['binary'] == binary_key]

        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 #14
0
 def list(self):
     """Show a list of all cinder services."""
     ctxt = context.get_admin_context()
     services = db.service_get_all(ctxt)
     print_format = "%-16s %-36s %-16s %-10s %-5s %-10s"
     print(print_format % (_('Binary'),
                           _('Host'),
                           _('Zone'),
                           _('Status'),
                           _('State'),
                           _('Updated At')))
     for svc in services:
         alive = utils.service_is_up(svc)
         art = ":-)" if alive else "XXX"
         status = 'enabled'
         if svc['disabled']:
             status = 'disabled'
         print(print_format % (svc['binary'], svc['host'].partition('.')[0],
                               svc['availability_zone'], status, art,
                               svc['updated_at']))
Exemple #15
0
    def get_services_data(self):
        services = []

        ctxt = nova_context.get_admin_context()
        FLAGS = nova_flags.FLAGS
        nova_flags.parse_args([])
        db_nova_services=nova_db.service_get_all(ctxt)

        ctxt = cinder_context.get_admin_context()
        FLAGS=cinder_flags.FLAGS
        cinder_flags.parse_args([])
        db_cinder_services=cinder_db.service_get_all(ctxt)
        db_cinder_services.extend(db_nova_services)
        for i, service in enumerate(db_cinder_services):
            service['id'] = i
            services.append(service)

        services = sorted(services, key=lambda svc: (svc.host))#sort the list

        return services
Exemple #16
0
    def list(self, zone=None):
        """Show a list of all physical hosts. Filter by zone.
        args: [zone]
        """
        print(_("%(host)-25s\t%(zone)-15s") % {'host': 'host', 'zone': 'zone'})
        ctxt = context.get_admin_context()
        services = db.service_get_all(ctxt)
        if zone:
            services = [s for s in services if s['availability_zone'] == zone]
        hosts = []
        for srv in services:
            if not [h for h in hosts if h['host'] == srv['host']]:
                hosts.append(srv)

        for h in hosts:
            print(
                _("%(host)-25s\t%(availability_zone)-15s") % {
                    'host': h['host'],
                    'availability_zone': h['availability_zone']
                })
Exemple #17
0
 def list(self):
     """Show a list of all cinder services."""
     ctxt = context.get_admin_context()
     services = db.service_get_all(ctxt)
     print_format = "%-16s %-36s %-16s %-10s %-5s %-10s"
     print(print_format % (_("Binary"), _("Host"), _("Zone"), _("Status"), _("State"), _("Updated At")))
     for svc in services:
         alive = utils.service_is_up(svc)
         art = ":-)" if alive else "XXX"
         status = "enabled"
         if svc["disabled"]:
             status = "disabled"
         print(
             print_format
             % (
                 svc["binary"],
                 svc["host"].partition(".")[0],
                 svc["availability_zone"],
                 status,
                 art,
                 svc["updated_at"],
             )
         )
Exemple #18
0
 def get_all_by_topic(cls, context, topic, disabled=None):
     services = db.service_get_all(context, topic=topic, disabled=disabled)
     return base.obj_make_list(context, cls(context), objects.Service,
                               services)
Exemple #19
0
 def get_all_by_binary(cls, context, binary, disabled=None):
     services = db.service_get_all(context, binary=binary, disabled=disabled)
     return base.obj_make_list(context, cls(context), objects.Service, services)
Exemple #20
0
 def get_all_by_topic(cls, context, topic, disabled=None):
     services = db.service_get_all(context, topic=topic, disabled=disabled)
     return base.obj_make_list(context, cls(context), objects.Service, services)
Exemple #21
0
 def get_all(cls, context, filters=None):
     services = db.service_get_all(context, **(filters or {}))
     return base.obj_make_list(context, cls(context), objects.Service, services)
Exemple #22
0
 def get_all(cls, context, filters=None):
     services = db.service_get_all(context, filters)
     return base.obj_make_list(context, cls(context), objects.Service,
                               services)
Exemple #23
0
 def get_all_by_binary(cls, context, binary, disabled=None):
     services = db.service_get_all(context, binary=binary,
                                   disabled=disabled)
     return base.obj_make_list(context, cls(context), objects.Service,
                               services)