Exemple #1
0
    def get_all_host_states(self, context):
        """
        The host_state_map in the HostManager isn't
        maintained properly during storage host registration/deregistration.
        Override get_all_host_states and add proper serialization.

        For example:
        {'192.168.1.100': HostState(), ...}
        """
        topic = CONF.volume_topic
        for host, host_state in self.host_state_map.items():
            try:
                db.service_get_by_host_and_topic(context,
                                                 host,
                                                 topic)
            except exception.ServiceNotFound:
                # The host has been deregistered
                LOG.debug(_("clean up host_state_map: %(host)s" %
                            {'host': host}))
                del self.host_state_map[host]
                continue

        s = super(PowerVCHostManager, self)
        hosts = s.get_all_host_states(context)

        return hosts
Exemple #2
0
    def show(self, req, id):
        """Shows the volume usage info given by hosts.

        :param context: security context
        :param host: hostname
        :returns: expected to use HostShowTemplate.
            ex.::

                {'host': {'resource':D},..}
                D: {'host': 'hostname','project': 'admin',
                    'volume_count': 1, 'total_volume_gb': 2048}
        """
        host = id
        context = req.environ['cinder.context']
        if not context.is_admin:
            msg = _("Describe-resource is admin only functionality")
            raise webob.exc.HTTPForbidden(explanation=msg)

        try:
            host_ref = db.service_get_by_host_and_topic(context,
                                                        host,
                                                        CONF.volume_topic)
        except exception.ServiceNotFound:
            raise webob.exc.HTTPNotFound(explanation=_("Host not found"))

        # Getting total available/used resource
        # TODO(jdg): Add summary info for Snapshots
        volume_refs = db.volume_get_all_by_host(context, host_ref['host'])
        (count, sum) = db.volume_data_get_for_host(context,
                                                   host_ref['host'])

        snap_count_total = 0
        snap_sum_total = 0
        resources = [{'resource': {'host': host, 'project': '(total)',
                      'volume_count': str(count),
                      'total_volume_gb': str(sum),
                      'snapshot_count': str(snap_count_total),
                      'total_snapshot_gb': str(snap_sum_total)}}]

        project_ids = [v['project_id'] for v in volume_refs]
        project_ids = list(set(project_ids))
        for project_id in project_ids:
            (count, sum) = db.volume_data_get_for_project(context, project_id)
            (snap_count, snap_sum) = db.snapshot_data_get_for_project(
                context,
                project_id)
            resources.append(
                {'resource':
                    {'host': host,
                     'project': project_id,
                     'volume_count': str(count),
                     'total_volume_gb': str(sum),
                     'snapshot_count': str(snap_count),
                     'total_snapshot_gb': str(snap_sum)}})
            snap_count_total += int(snap_count)
            snap_sum_total += int(snap_sum)
        resources[0]['resource']['snapshot_count'] = str(snap_count_total)
        resources[0]['resource']['total_snapshot_gb'] = str(snap_sum_total)
        return {"host": resources}
Exemple #3
0
    def show(self, req, id):
        """Shows the volume usage info given by hosts.

        :param context: security context
        :param host: hostname
        :returns: expected to use HostShowTemplate.
            ex.::

                {'host': {'resource':D},..}
                D: {'host': 'hostname','project': 'admin',
                    'volume_count': 1, 'total_volume_gb': 2048}
        """
        host = id
        context = req.environ['cinder.context']
        if not context.is_admin:
            msg = _("Describe-resource is admin only functionality")
            raise webob.exc.HTTPForbidden(explanation=msg)

        try:
            host_ref = db.service_get_by_host_and_topic(context,
                                                        host,
                                                        CONF.volume_topic)
        except exception.ServiceNotFound:
            raise webob.exc.HTTPNotFound(explanation=_("Host not found"))

        # Getting total available/used resource
        # TODO(jdg): Add summary info for Snapshots
        volume_refs = db.volume_get_all_by_host(context, host_ref['host'])
        (count, sum) = db.volume_data_get_for_host(context,
                                                   host_ref['host'])

        snap_count_total = 0
        snap_sum_total = 0
        resources = [{'resource': {'host': host, 'project': '(total)',
                                   'volume_count': str(count),
                                   'total_volume_gb': str(sum),
                                   'snapshot_count': str(snap_count_total),
                                   'total_snapshot_gb': str(snap_sum_total)}}]

        project_ids = [v['project_id'] for v in volume_refs]
        project_ids = list(set(project_ids))
        for project_id in project_ids:
            (count, sum) = db.volume_data_get_for_project(context, project_id)
            (snap_count, snap_sum) = db.snapshot_data_get_for_project(
                context,
                project_id)
            resources.append(
                {'resource':
                    {'host': host,
                     'project': project_id,
                     'volume_count': str(count),
                     'total_volume_gb': str(sum),
                     'snapshot_count': str(snap_count),
                     'total_snapshot_gb': str(snap_sum)}})
            snap_count_total += int(snap_count)
            snap_sum_total += int(snap_sum)
        resources[0]['resource']['snapshot_count'] = str(snap_count_total)
        resources[0]['resource']['total_snapshot_gb'] = str(snap_sum_total)
        return {"host": resources}
Exemple #4
0
    def test_service_get_by_host_and_topic(self):
        service1 = self._create_service({'host': 'host1', 'topic': 'topic1'})
        service2 = self._create_service({'host': 'host2', 'topic': 'topic2'})

        real_service1 = db.service_get_by_host_and_topic(self.ctxt,
                                                         host='host1',
                                                         topic='topic1')
        self._assertEqualObjects(service1, real_service1)
Exemple #5
0
    def test_service_get_by_host_and_topic(self):
        service1 = self._create_service({'host': 'host1', 'topic': 'topic1'})
        service2 = self._create_service({'host': 'host2', 'topic': 'topic2'})

        real_service1 = db.service_get_by_host_and_topic(self.ctxt,
                                                         host='host1',
                                                         topic='topic1')
        self._assertEqualObjects(service1, real_service1)
Exemple #6
0
 def get_by_host_and_topic(cls, context, host, topic):
     db_service = db.service_get_by_host_and_topic(context, host, topic)
     return cls._from_db_object(context, cls(context), db_service)
Exemple #7
0
    def test_service_get_by_host_and_topic(self):
        service1 = self._create_service({"host": "host1", "topic": "topic1"})

        real_service1 = db.service_get_by_host_and_topic(self.ctxt, host="host1", topic="topic1")
        self._assertEqualObjects(service1, real_service1)