0

我有一个 Openstack 驱动的 Django 修改应用程序,它显示了可供用户启动的磁盘映像和快照。用户当前可以看到他们创建的快照和未创建的快照。我想根据用户是否拥有当前表将它们分成两个。

我的两个表定义如下(注意我做了row_actions相应的修改):

class UserSnapshotsTable(OldSnapshotsTable):
  cloud = tables.Column(get_cloud, verbose_name=_("Cloud"))

    class Meta:
      name = "usersnapshots"
      verbose_name = _("User Snapshots")
      table_actions = (DeleteSnapshot,)
      row_actions = (LaunchSnapshot, LaunchCluster, EditImage, DeleteSnapshot)
      pagination_param = "snapshot_marker"
      row_class = UpdateRow
      status_columns = ["status"]

class OtherSnapshotsTable(OldSnapshotsTable):
  cloud = tables.Column(get_cloud, verbose_name=_("Cloud"))

    class Meta:
      name = "othersnapshots"
      verbose_name = _("Other Snapshots")
      table_actions = (DeleteSnapshot,)
      row_actions = (LaunchSnapshot, LaunchCluster)
      pagination_param = "snapshot_marker"
      row_class = UpdateRow
      status_columns = ["status"]

我已经更改了 HTML 模板以提取“UserSnapshotsTable”和“OtherSnapshotsTable”表(我复制了原始表并重命名了两者),但两个完整的表仍然在各自的标题下生成。生成数据的函数有两个:

def get_usersnapshots_data(self):
    req = self.request
    marker = req.GET.get(UserSnapshotsTable._meta.pagination_param, None)
    try:
        usersnaps, self._more_snapshots = api.snapshot_list_detailed(req,
                                                           marker=marker)
    except:
        usersnaps = []
        exceptions.handle(req, _("Unable to retrieve user-owned snapshots."))
    return usersnaps

def get_othersnapshots_data(self):
    req = self.request
    marker = req.GET.get(OtherSnapshotsTable._meta.pagination_param, None)
    try:
        othersnaps, self._more_snapshots = api.snapshot_list_detailed(req,
                                                            marker=marker)
    except:
        othersnaps = []
        exceptions.handle(req, _("Unable to retrieve non-user-owned snapshots."))
    return othersnaps

还有为图像定义的编辑/删除选项,并为快照导入,这似乎有一个关键的比较。这是“删除”之一(第 7 行):

class DeleteImage(tables.DeleteAction):
    data_type_singular = _("Image")
    data_type_plural = _("Images")

    def allowed(self, request, image=None):
      if image:
        return image.owner == request.user.tenant_id
        # Return True to allow table-level bulk delete action to appear.
      return True

    def delete(self, request, obj_id):
      api.image_delete(request, obj_id)

我怎样才能把这些表分开?这是我第一次在这里提问,所以如果我能提供更多信息,请告诉我。为它的长度道歉。

4

1 回答 1

0

据我所知,您正在使用glanceclient. 如果是这样,您可以使用extra_filters参数 ofsnapshot_list_detailed()仅过滤用户图像,如下所示:

usersnaps, self._more_snapshots = api.snapshot_list_detailed(
    req,
    marker = marker,
    extra_filters = {"owner": "user_name"}
)

snapshot_list_detailedUndercover使用Openstack Image Service API 的GET 图像

于 2013-11-08T22:02:51.997 回答