示例#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)
示例#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
示例#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}
示例#4
0
文件: hosts.py 项目: ArikaChen/cinder
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
示例#5
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)
示例#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}
示例#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}
示例#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}
示例#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']))
示例#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}
示例#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']})
示例#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"]}
            )
示例#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}
示例#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']))
示例#15
0
文件: views.py 项目: artofwar/stack
    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
示例#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']
                })
示例#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"],
             )
         )
示例#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)
示例#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)
示例#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)
示例#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)
示例#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)
示例#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)