Example #1
0
    def get_data(self):
        needs_gs = False
        if cinder.is_volume_service_enabled(self.request):
            try:
                marker, sort_dir = self._get_marker()
                snapshots, self._has_more_data, self._has_prev_data = \
                    cinder.volume_snapshot_list_paged(
                        self.request, paginate=True, marker=marker,
                        sort_dir=sort_dir, search_opts={'all_tenants': True})
                volumes = cinder.volume_list(self.request,
                                             search_opts={'all_tenants': True})
                volumes = dict((v.id, v) for v in volumes)
            except Exception:
                snapshots = []
                volumes = {}
                exceptions.handle(self.request,
                                  _("Unable to retrieve "
                                    "volume snapshots."))

            needs_gs = any(
                getattr(snapshot, 'group_snapshot_id', None)
                for snapshot in snapshots)
            if needs_gs:
                try:
                    group_snapshots = cinder.group_snapshot_list(
                        self.request, search_opts={'all_tenants': True})
                    group_snapshots = dict(
                        (gs.id, gs) for gs in group_snapshots)
                except Exception:
                    group_snapshots = {}
                    exceptions.handle(self.request,
                                      _("Unable to retrieve group snapshots."))
            # Gather our tenants to correlate against volume IDs
            try:
                tenants, has_more = keystone.tenant_list(self.request)
            except Exception:
                tenants = []
                msg = _('Unable to retrieve project '
                        'information of volume snapshots.')
                exceptions.handle(self.request, msg)

            tenant_dict = dict((t.id, t) for t in tenants)
            for snapshot in snapshots:
                volume = volumes.get(snapshot.volume_id)
                if needs_gs:
                    group_snapshot = group_snapshots.get(
                        snapshot.group_snapshot_id)
                    snapshot.group_snapshot = group_snapshot
                else:
                    snapshot.group_snapshot = None
                tenant_id = snapshot.project_id
                tenant = tenant_dict.get(tenant_id, None)
                snapshot._volume = volume
                snapshot.tenant_name = getattr(tenant, "name", None)
                snapshot.host_name = getattr(volume, 'os-vol-host-attr:host',
                                             None)

        else:
            snapshots = []
        return snapshots
Example #2
0
    def get_data(self):
        needs_gs = False
        if cinder.is_volume_service_enabled(self.request):
            try:
                marker, sort_dir = self._get_marker()
                snapshots, self._has_more_data, self._has_prev_data = \
                    cinder.volume_snapshot_list_paged(
                        self.request, paginate=True, marker=marker,
                        sort_dir=sort_dir, search_opts={'all_tenants': True})
                volumes = cinder.volume_list(
                    self.request,
                    search_opts={'all_tenants': True})
                volumes = dict((v.id, v) for v in volumes)
            except Exception:
                snapshots = []
                volumes = {}
                exceptions.handle(self.request, _("Unable to retrieve "
                                                  "volume snapshots."))

            needs_gs = any(getattr(snapshot, 'group_snapshot_id', None)
                           for snapshot in snapshots)
            if needs_gs:
                try:
                    group_snapshots = cinder.group_snapshot_list(
                        self.request, search_opts={'all_tenants': True})
                    group_snapshots = dict((gs.id, gs) for gs
                                           in group_snapshots)
                except Exception:
                    group_snapshots = {}
                    exceptions.handle(self.request,
                                      _("Unable to retrieve group snapshots."))
            # Gather our tenants to correlate against volume IDs
            try:
                tenants, has_more = keystone.tenant_list(self.request)
            except Exception:
                tenants = []
                msg = _('Unable to retrieve project '
                        'information of volume snapshots.')
                exceptions.handle(self.request, msg)

            tenant_dict = dict((t.id, t) for t in tenants)
            for snapshot in snapshots:
                volume = volumes.get(snapshot.volume_id)
                if needs_gs:
                    group_snapshot = group_snapshots.get(
                        snapshot.group_snapshot_id)
                    snapshot.group_snapshot = group_snapshot
                else:
                    snapshot.group_snapshot = None
                tenant_id = snapshot.project_id
                tenant = tenant_dict.get(tenant_id, None)
                snapshot._volume = volume
                snapshot.tenant_name = getattr(tenant, "name", None)
                snapshot.host_name = getattr(
                    volume, 'os-vol-host-attr:host', None)

        else:
            snapshots = []
        return snapshots
Example #3
0
    def test_snapshots_tab(self):
        cinder.volume_snapshot_list_paged(
            IsA(http.HttpRequest), paginate=True, marker=None, sort_dir='desc',
            search_opts={'all_tenants': True},).AndReturn(
            [self.cinder_volume_snapshots.list(), False, False])
        cinder.volume_list(IsA(http.HttpRequest), search_opts={
            'all_tenants': True}).\
            AndReturn(self.cinder_volumes.list())
        keystone.tenant_list(IsA(http.HttpRequest)). \
            AndReturn([self.tenants.list(), False])

        self.mox.ReplayAll()
        res = self.client.get(reverse('horizon:admin:volumes:snapshots_tab'))

        self.assertEqual(res.status_code, 200)
        self.assertTemplateUsed(res, 'horizon/common/_detail_table.html')
        snapshots = res.context['volume_snapshots_table'].data
        self.assertItemsEqual(snapshots, self.cinder_volume_snapshots.list())
Example #4
0
    def test_snapshots_tab(self):
        cinder.volume_snapshot_list_paged(
            IsA(http.HttpRequest), paginate=True, marker=None, sort_dir='desc',
            search_opts={'all_tenants': True},).AndReturn(
            [self.cinder_volume_snapshots.list(), False, False])
        cinder.volume_list(IsA(http.HttpRequest), search_opts={
            'all_tenants': True}).\
            AndReturn(self.cinder_volumes.list())
        keystone.tenant_list(IsA(http.HttpRequest)). \
            AndReturn([self.tenants.list(), False])

        self.mox.ReplayAll()
        url = reverse('horizon:admin:volumes:snapshots_tab')
        res = self.client.get(urlunquote(url))

        self.assertEqual(res.status_code, 200)
        self.assertTemplateUsed(res, 'admin/volumes/index.html')
        snapshots = res.context['volume_snapshots_table'].data
        self.assertItemsEqual(snapshots, self.cinder_volume_snapshots.list())
Example #5
0
    def _test_snapshots_index_paginated(self, marker, sort_dir, snapshots, url,
                                        has_more, has_prev):
        cinder.volume_snapshot_list_paged(
            IsA(http.HttpRequest), paginate=True, marker=marker,
            sort_dir=sort_dir, search_opts={'all_tenants': True}) \
            .AndReturn([snapshots, has_more, has_prev])
        cinder.volume_list(IsA(http.HttpRequest), search_opts={
            'all_tenants': True}).\
            AndReturn(self.cinder_volumes.list())
        keystone.tenant_list(IsA(http.HttpRequest)) \
            .AndReturn([self.tenants.list(), False])

        self.mox.ReplayAll()

        res = self.client.get(url)

        self.assertTemplateUsed(res, 'admin/volumes/index.html')
        self.assertEqual(res.status_code, 200)

        self.mox.UnsetStubs()
        return res
Example #6
0
    def _test_snapshots_index_paginated(self, marker, sort_dir, snapshots, url,
                                        has_more, has_prev):
        cinder.volume_snapshot_list_paged(
            IsA(http.HttpRequest), paginate=True, marker=marker,
            sort_dir=sort_dir, search_opts={'all_tenants': True}) \
            .AndReturn([snapshots, has_more, has_prev])
        cinder.volume_list(IsA(http.HttpRequest), search_opts={
            'all_tenants': True}).\
            AndReturn(self.cinder_volumes.list())
        keystone.tenant_list(IsA(http.HttpRequest)) \
            .AndReturn([self.tenants.list(), False])

        self.mox.ReplayAll()

        res = self.client.get(url)

        self.assertTemplateUsed(res, 'admin/volumes/index.html')
        self.assertEqual(res.status_code, 200)

        self.mox.UnsetStubs()
        return res
Example #7
0
    def get_data(self):
        snapshots = []
        volumes = {}
        needs_gs = False
        if cinder.is_volume_service_enabled(self.request):
            try:
                marker, sort_dir = self._get_marker()
                snapshots, self._has_more_data, self._has_prev_data = \
                    cinder.volume_snapshot_list_paged(
                        self.request, paginate=True, marker=marker,
                        sort_dir=sort_dir)
            except Exception:
                exceptions.handle(self.request,
                                  _("Unable to retrieve volume snapshots."))
            try:
                volumes = cinder.volume_list(self.request)
                volumes = dict((v.id, v) for v in volumes)
            except Exception:
                exceptions.handle(self.request,
                                  _("Unable to retrieve volumes."))
            needs_gs = any(
                getattr(snapshot, 'group_snapshot_id', None)
                for snapshot in snapshots)
            if needs_gs:
                try:
                    group_snapshots = cinder.group_snapshot_list(self.request)
                    group_snapshots = dict(
                        (gs.id, gs) for gs in group_snapshots)
                except Exception:
                    group_snapshots = {}
                    exceptions.handle(self.request,
                                      _("Unable to retrieve group snapshots."))

        for snapshot in snapshots:
            volume = volumes.get(snapshot.volume_id)
            setattr(snapshot, '_volume', volume)
            if needs_gs:
                group_snapshot = group_snapshots.get(
                    snapshot.group_snapshot_id)
                snapshot.group_snapshot = group_snapshot
            else:
                snapshot.group_snapshot = None

        return snapshots
Example #8
0
    def get_data(self):
        snapshots = []
        volumes = {}
        needs_gs = False
        if cinder.is_volume_service_enabled(self.request):
            try:
                marker, sort_dir = self._get_marker()
                snapshots, self._has_more_data, self._has_prev_data = \
                    cinder.volume_snapshot_list_paged(
                        self.request, paginate=True, marker=marker,
                        sort_dir=sort_dir)
            except Exception:
                exceptions.handle(self.request,
                                  _("Unable to retrieve volume snapshots."))
            try:
                volumes = cinder.volume_list(self.request)
                volumes = dict((v.id, v) for v in volumes)
            except Exception:
                exceptions.handle(self.request,
                                  _("Unable to retrieve volumes."))
            needs_gs = any(getattr(snapshot, 'group_snapshot_id', None)
                           for snapshot in snapshots)
            if needs_gs:
                try:
                    group_snapshots = cinder.group_snapshot_list(self.request)
                    group_snapshots = dict((gs.id, gs) for gs
                                           in group_snapshots)
                except Exception:
                    group_snapshots = {}
                    exceptions.handle(self.request,
                                      _("Unable to retrieve group snapshots."))

        for snapshot in snapshots:
            volume = volumes.get(snapshot.volume_id)
            setattr(snapshot, '_volume', volume)
            if needs_gs:
                group_snapshot = group_snapshots.get(
                    snapshot.group_snapshot_id)
                snapshot.group_snapshot = group_snapshot
            else:
                snapshot.group_snapshot = None

        return snapshots
Example #9
0
    def get_data(self):
        if cinder.is_volume_service_enabled(self.request):
            try:
                marker, sort_dir = self._get_marker()
                snapshots, self._has_more_data, self._has_prev_data = \
                    cinder.volume_snapshot_list_paged(
                        self.request, paginate=True, marker=marker,
                        sort_dir=sort_dir, search_opts={'all_tenants': True})
                volumes = cinder.volume_list(
                    self.request,
                    search_opts={'all_tenants': True})
                volumes = dict((v.id, v) for v in volumes)
            except Exception:
                snapshots = []
                volumes = {}
                exceptions.handle(self.request, _("Unable to retrieve "
                                                  "volume snapshots."))

            # Gather our tenants to correlate against volume IDs
            try:
                tenants, has_more = keystone.tenant_list(self.request)
            except Exception:
                tenants = []
                msg = _('Unable to retrieve volume project information.')
                exceptions.handle(self.request, msg)

            tenant_dict = dict([(t.id, t) for t in tenants])
            for snapshot in snapshots:
                volume = volumes.get(snapshot.volume_id)
                tenant_id = getattr(volume,
                                    'os-vol-tenant-attr:tenant_id', None)
                tenant = tenant_dict.get(tenant_id, None)
                snapshot._volume = volume
                snapshot.tenant_name = getattr(tenant, "name", None)
                snapshot.host_name = getattr(
                    volume, 'os-vol-host-attr:host', None)

        else:
            snapshots = []
        return sorted(snapshots,
                      key=lambda snapshot: snapshot.tenant_name or '')
Example #10
0
    def get_data(self):
        if cinder.is_volume_service_enabled(self.request):
            try:
                marker, sort_dir = self._get_marker()
                snapshots, self._has_more_data, self._has_prev_data = \
                    cinder.volume_snapshot_list_paged(
                        self.request, paginate=True, marker=marker,
                        sort_dir=sort_dir, search_opts={'all_tenants': True})
                volumes = cinder.volume_list(
                    self.request,
                    search_opts={'all_tenants': True})
                volumes = dict((v.id, v) for v in volumes)
            except Exception:
                snapshots = []
                volumes = {}
                exceptions.handle(self.request, _("Unable to retrieve "
                                                  "volume snapshots."))

            # Gather our tenants to correlate against volume IDs
            try:
                tenants, has_more = keystone.tenant_list(self.request)
            except Exception:
                tenants = []
                msg = _('Unable to retrieve volume project information.')
                exceptions.handle(self.request, msg)

            tenant_dict = dict([(t.id, t) for t in tenants])
            for snapshot in snapshots:
                volume = volumes.get(snapshot.volume_id)
                tenant_id = getattr(volume,
                                    'os-vol-tenant-attr:tenant_id', None)
                tenant = tenant_dict.get(tenant_id, None)
                snapshot._volume = volume
                snapshot.tenant_name = getattr(tenant, "name", None)
                snapshot.host_name = getattr(
                    volume, 'os-vol-host-attr:host', None)

        else:
            snapshots = []
        return sorted(snapshots,
                      key=lambda snapshot: snapshot.tenant_name or '')
Example #11
0
    def get_data(self):
        snapshots = []
        volumes = {}
        if cinder.is_volume_service_enabled(self.request):
            try:
                marker, sort_dir = self._get_marker()
                snapshots, self._has_more_data, self._has_prev_data = \
                    cinder.volume_snapshot_list_paged(
                        self.request, paginate=True, marker=marker,
                        sort_dir=sort_dir)
                volumes = cinder.volume_list(self.request)
                volumes = dict((v.id, v) for v in volumes)
            except Exception:
                exceptions.handle(self.request, _("Unable to retrieve "
                                                  "volume snapshots."))

        for snapshot in snapshots:
            volume = volumes.get(snapshot.volume_id)
            setattr(snapshot, '_volume', volume)

        return snapshots
Example #12
0
    def get_data(self):
        snapshots = []
        volumes = {}
        if cinder.is_volume_service_enabled(self.request):
            try:
                marker, sort_dir = self._get_marker()
                snapshots, self._has_more_data, self._has_prev_data = \
                    cinder.volume_snapshot_list_paged(
                        self.request, paginate=True, marker=marker,
                        sort_dir=sort_dir)
                volumes = cinder.volume_list(self.request)
                volumes = dict((v.id, v) for v in volumes)
            except Exception:
                exceptions.handle(self.request,
                                  _("Unable to retrieve "
                                    "volume snapshots."))

        for snapshot in snapshots:
            volume = volumes.get(snapshot.volume_id)
            setattr(snapshot, '_volume', volume)

        return snapshots
Example #13
0
 def get_volume_snapshots_data(self):
     try:
         instance = self.tab_group.kwargs['instance']
         search_opts = {'status': 'in-use'}
         marker, sort_dir = self._get_marker()
         volume = cinder.volume_list(self.request, search_opts)
         volume = getfileteredvolume(instance.id, volume)
         snapshot = []
         sp, self._more, self._prev = cinder.volume_snapshot_list_paged(
             self.request, paginate=True, marker=marker, sort_dir=sort_dir)
         for vol in volume:
             snapshot = getfileteredsnapshots(instance, vol, sp, snapshot)
         if sort_dir == "asc":
             snapshot.reverse()
         self.tab_group.kwargs['snapshots'] = snapshot
     except Exception:
         self._more = False
         self._prev = False
         redirect = self.get_redirect_url()
         exceptions.handle(self.request,
                           _('Unable to retrieve snapshot details.'),
                           redirect=redirect)
     return snapshot