コード例 #1
0
ファイル: forms.py プロジェクト: radez/horizon
    def handle(self, request, data):
        instance_choices = dict(self.fields['instance'].choices)
        instance_name = instance_choices.get(data['instance'],
                                             _("Unknown instance (None)"))
        # The name of the instance in the choices list has the ID appended to
        # it, so let's slice that off...
        instance_name = instance_name.rsplit(" (")[0]
        try:
            vol = api.volume_attach(request, data['volume_id'],
                                    data['instance'], data.get('device', ''))
            vol_name = api.volume_get(request, data['volume_id']).display_name

            message = _('Attaching volume %(vol)s to instance '
                        '%(inst)s on %(dev)s.') % {
                            "vol": vol_name,
                            "inst": instance_name,
                            "dev": vol.device
                        }
            messages.info(request, message)
            return True
        except:
            redirect = reverse("horizon:project:volumes:index")
            exceptions.handle(request,
                              _('Unable to attach volume.'),
                              redirect=redirect)
コード例 #2
0
ファイル: forms.py プロジェクト: jiangy/horizon
    def handle(self, request, data):
        instance_choices = dict(self.fields['instance'].choices)
        instance_name = instance_choices.get(data['instance'],
                                             _("Unknown instance (None)"))
        # The name of the instance in the choices list has the ID appended to
        # it, so let's slice that off...
        instance_name = instance_name.rsplit(" (")[0]
        try:
            vol = api.volume_attach(request,
                                    data['volume_id'],
                                    data['instance'],
                                    data.get('device', ''))
            vol_name = api.volume_get(request, data['volume_id']).display_name

            message = _('Attaching volume %(vol)s to instance '
                         '%(inst)s on %(dev)s.') % {"vol": vol_name,
                                                    "inst": instance_name,
                                                    "dev": vol.device}
            messages.info(request, message)
            return True
        except:
            redirect = reverse("horizon:project:volumes:index")
            exceptions.handle(request,
                              _('Unable to attach volume.'),
                              redirect=redirect)
コード例 #3
0
ファイル: tests.py プロジェクト: radez/horizon
    def test_edit_attachments_cannot_set_mount_point(self):
        PREV = settings.OPENSTACK_HYPERVISOR_FEATURES['can_set_mount_point']
        settings.OPENSTACK_HYPERVISOR_FEATURES['can_set_mount_point'] = False

        volume = self.volumes.first()
        servers = self.servers.list()

        api.volume_get(IsA(http.HttpRequest), volume.id).AndReturn(volume)
        api.nova.server_list(IsA(http.HttpRequest)).AndReturn(servers)
        self.mox.ReplayAll()

        url = reverse('horizon:project:volumes:attach', args=[volume.id])
        res = self.client.get(url)
        # Assert the device field is hidden.
        form = res.context['form']
        self.assertTrue(isinstance(form.fields['device'].widget,
                                   widgets.HiddenInput))
        settings.OPENSTACK_HYPERVISOR_FEATURES['can_set_mount_point'] = PREV
コード例 #4
0
ファイル: tests.py プロジェクト: radez/horizon
    def test_edit_attachments(self):
        volume = self.volumes.first()
        servers = self.servers.list()

        api.volume_get(IsA(http.HttpRequest), volume.id).AndReturn(volume)
        api.nova.server_list(IsA(http.HttpRequest)).AndReturn(servers)
        self.mox.ReplayAll()

        url = reverse('horizon:project:volumes:attach', args=[volume.id])
        res = self.client.get(url)
        # Asserting length of 2 accounts for the one instance option,
        # and the one 'Choose Instance' option.
        form = res.context['form']
        self.assertEqual(len(form.fields['instance']._choices),
                         2)
        self.assertEqual(res.status_code, 200)
        self.assertTrue(isinstance(form.fields['device'].widget,
                                   widgets.TextInput))
コード例 #5
0
ファイル: views.py プロジェクト: jiangy/horizon
 def get_object(self):
     if not hasattr(self, "_object"):
         volume_id = self.kwargs['volume_id']
         try:
             self._object = api.volume_get(self.request, volume_id)
         except:
             self._object = None
             exceptions.handle(self.request,
                               _('Unable to retrieve volume information.'))
     return self._object
コード例 #6
0
 def get_object(self):
     if not hasattr(self, "_object"):
         volume_id = self.kwargs['volume_id']
         try:
             self._object = api.volume_get(self.request, volume_id)
         except:
             self._object = None
             exceptions.handle(self.request,
                               _('Unable to retrieve volume information.'))
     return self._object
コード例 #7
0
    def test_index(self):
        images = self.images.list()
        snapshots = self.snapshots.list()
        volumes = self.volumes.list()

        for volume in volumes:
            volume.volume_id = volume.id
        for volume in volumes:
            api.volume_get(IsA(http.HttpRequest), volume.volume_id) \
                          .AndReturn(volume)
        for volume in volumes:
            api.volume_get(IsA(http.HttpRequest), volume.volume_id) \
                          .AndReturn(volume)
            api.volume_get(IsA(http.HttpRequest), volume.volume_id)

        api.volume_snapshot_list(IsA(http.HttpRequest)) \
                                .AndReturn(volumes)
        api.image_list_detailed(IsA(http.HttpRequest),
                                marker=None).AndReturn([images, False])
        api.snapshot_list_detailed(IsA(http.HttpRequest),
                                   marker=None).AndReturn([snapshots, False])
        self.mox.ReplayAll()

        res = self.client.get(INDEX_URL)
        self.assertTemplateUsed(res, 'project/images_and_snapshots/index.html')
        self.assertIn('images_table', res.context)
        images = res.context['images_table'].data
        filter_func = lambda im: im.container_format not in ['aki', 'ari']
        filtered_images = filter(filter_func, images)
        self.assertItemsEqual(images, filtered_images)
コード例 #8
0
ファイル: tests.py プロジェクト: BenJaziaSadok/horizon
    def test_index(self):
        images = self.images.list()
        snapshots = self.snapshots.list()
        volumes = self.volumes.list()

        for volume in volumes:
            volume.volume_id = volume.id
        for volume in volumes:
            api.volume_get(IsA(http.HttpRequest), volume.volume_id) \
                          .AndReturn(volume)
        for volume in volumes:
            api.volume_get(IsA(http.HttpRequest), volume.volume_id) \
                          .AndReturn(volume)
            api.volume_get(IsA(http.HttpRequest), volume.volume_id)

        api.volume_snapshot_list(IsA(http.HttpRequest)) \
                                .AndReturn(volumes)
        api.image_list_detailed(IsA(http.HttpRequest),
                                marker=None).AndReturn([images, False])
        api.snapshot_list_detailed(IsA(http.HttpRequest),
                                marker=None).AndReturn([snapshots, False])
        self.mox.ReplayAll()

        res = self.client.get(INDEX_URL)
        self.assertTemplateUsed(res, 'project/images_and_snapshots/index.html')
        self.assertIn('images_table', res.context)
        images = res.context['images_table'].data
        filter_func = lambda im: im.container_format not in ['aki', 'ari']
        filtered_images = filter(filter_func, images)
        self.assertItemsEqual(images, filtered_images)
コード例 #9
0
ファイル: tests.py プロジェクト: radez/horizon
    def test_edit_attachments_attached_volume(self):
        server = self.servers.first()
        volume = self.volumes.list()[0]

        api.volume_get(IsA(http.HttpRequest), volume.id) \
                       .AndReturn(volume)
        api.nova.server_list(IsA(http.HttpRequest)) \
                             .AndReturn(self.servers.list())

        self.mox.ReplayAll()

        url = reverse('horizon:project:volumes:attach',
                      args=[volume.id])
        res = self.client.get(url)

        self.assertEqual(res.context['form'].fields['instance']._choices[0][1],
                         "Select an instance")
        self.assertEqual(len(res.context['form'].fields['instance'].choices),
                         2)
        self.assertEqual(res.context['form'].fields['instance']._choices[1][0],
                         server.id)
        self.assertEqual(res.status_code, 200)
コード例 #10
0
ファイル: tests.py プロジェクト: BenJaziaSadok/horizon
    def test_queued_snapshot_actions(self):
        images = self.images.list()
        snapshots = self.snapshots.list()
        volumes = self.volumes.list()

        for volume in volumes:
            volume.volume_id = volume.id
        for volume in volumes:
            api.volume_get(IsA(http.HttpRequest), volume.volume_id) \
                          .AndReturn(volume)
        for volume in volumes:
            api.volume_get(IsA(http.HttpRequest), volume.volume_id) \
                          .AndReturn(volume)
            api.volume_get(IsA(http.HttpRequest), volume.volume_id)

        api.volume_snapshot_list(IsA(http.HttpRequest)) \
                                .AndReturn(volumes)
        api.image_list_detailed(IsA(http.HttpRequest),
                                marker=None).AndReturn([images, False])
        api.snapshot_list_detailed(IsA(http.HttpRequest), marker=None) \
                                .AndReturn([snapshots, False])
        self.mox.ReplayAll()

        res = self.client.get(INDEX_URL)
        self.assertTemplateUsed(res, 'project/images_and_snapshots/index.html')
        self.assertIn('snapshots_table', res.context)
        snaps = res.context['snapshots_table']
        self.assertEqual(len(snaps.get_rows()), 3)

        row_actions = snaps.get_row_actions(snaps.data[0])

        # first instance - status active, owned
        self.assertEqual(len(row_actions), 3)
        self.assertEqual(row_actions[0].verbose_name, u"Launch")
        self.assertEqual(row_actions[1].verbose_name, u"Edit")
        self.assertEqual(row_actions[2].verbose_name, u"Delete Snapshot")

        row_actions = snaps.get_row_actions(snaps.data[1])

        # second instance - status active, not owned
        self.assertEqual(len(row_actions), 1)
        self.assertEqual(row_actions[0].verbose_name, u"Launch")

        row_actions = snaps.get_row_actions(snaps.data[2])
        # third instance - status queued, only delete is available
        self.assertEqual(len(row_actions), 1)
        self.assertEqual(unicode(row_actions[0].verbose_name),
                         u"Delete Snapshot")
        self.assertEqual(str(row_actions[0]), "<DeleteSnapshot: delete>")
コード例 #11
0
    def test_queued_snapshot_actions(self):
        images = self.images.list()
        snapshots = self.snapshots.list()
        volumes = self.volumes.list()

        for volume in volumes:
            volume.volume_id = volume.id
        for volume in volumes:
            api.volume_get(IsA(http.HttpRequest), volume.volume_id) \
                          .AndReturn(volume)
        for volume in volumes:
            api.volume_get(IsA(http.HttpRequest), volume.volume_id) \
                          .AndReturn(volume)
            api.volume_get(IsA(http.HttpRequest), volume.volume_id)

        api.volume_snapshot_list(IsA(http.HttpRequest)) \
                                .AndReturn(volumes)
        api.image_list_detailed(IsA(http.HttpRequest),
                                marker=None).AndReturn([images, False])
        api.snapshot_list_detailed(IsA(http.HttpRequest), marker=None) \
                                .AndReturn([snapshots, False])
        self.mox.ReplayAll()

        res = self.client.get(INDEX_URL)
        self.assertTemplateUsed(res, 'project/images_and_snapshots/index.html')
        self.assertIn('snapshots_table', res.context)
        snaps = res.context['snapshots_table']
        self.assertEqual(len(snaps.get_rows()), 3)

        row_actions = snaps.get_row_actions(snaps.data[0])

        # first instance - status active, owned
        self.assertEqual(len(row_actions), 3)
        self.assertEqual(row_actions[0].verbose_name, u"Launch")
        self.assertEqual(row_actions[1].verbose_name, u"Edit")
        self.assertEqual(row_actions[2].verbose_name, u"Delete Snapshot")

        row_actions = snaps.get_row_actions(snaps.data[1])

        # second instance - status active, not owned
        self.assertEqual(len(row_actions), 1)
        self.assertEqual(row_actions[0].verbose_name, u"Launch")

        row_actions = snaps.get_row_actions(snaps.data[2])
        # third instance - status queued, only delete is available
        self.assertEqual(len(row_actions), 1)
        self.assertEqual(unicode(row_actions[0].verbose_name),
                         u"Delete Snapshot")
        self.assertEqual(str(row_actions[0]), "<DeleteSnapshot: delete>")
コード例 #12
0
    def test_index_no_images(self):
        volumes = self.volumes.list()

        for volume in volumes:
            volume.volume_id = volume.id
        for volume in volumes:
            api.volume_get(IsA(http.HttpRequest), volume.volume_id) \
                          .AndReturn(volume)
        for volume in volumes:
            api.volume_get(IsA(http.HttpRequest), volume.volume_id) \
                          .AndReturn(volume)
            api.volume_get(IsA(http.HttpRequest), volume.volume_id)

        api.volume_snapshot_list(IsA(http.HttpRequest)) \
                                .AndReturn(volumes)
        api.image_list_detailed(IsA(http.HttpRequest),
                                marker=None).AndReturn([(), False])
        api.snapshot_list_detailed(IsA(http.HttpRequest), marker=None) \
                                .AndReturn([self.snapshots.list(), False])
        self.mox.ReplayAll()

        res = self.client.get(INDEX_URL)
        self.assertTemplateUsed(res, 'project/images_and_snapshots/index.html')
コード例 #13
0
ファイル: tests.py プロジェクト: BenJaziaSadok/horizon
    def test_index_error(self):
        volumes = self.volumes.list()

        for volume in volumes:
            volume.volume_id = volume.id
        for volume in volumes:
            api.volume_get(IsA(http.HttpRequest), volume.volume_id) \
                          .AndReturn(volume)
        for volume in volumes:
            api.volume_get(IsA(http.HttpRequest), volume.volume_id) \
                          .AndReturn(volume)
            api.volume_get(IsA(http.HttpRequest), volume.volume_id)

        api.volume_snapshot_list(IsA(http.HttpRequest)) \
                                .AndReturn(volumes)
        api.image_list_detailed(IsA(http.HttpRequest),
                                marker=None).AndRaise(self.exceptions.glance)
        api.snapshot_list_detailed(IsA(http.HttpRequest), marker=None) \
                                .AndReturn([self.snapshots.list(), False])
        self.mox.ReplayAll()

        res = self.client.get(INDEX_URL)
        self.assertTemplateUsed(res, 'project/images_and_snapshots/index.html')
コード例 #14
0
ファイル: tables.py プロジェクト: dkuebric/horizon
 def get_link_url(self, snapshot):
     volume_id = api.volume_get(self.table.request, snapshot.volume_id).id
     return reverse(self.link, args=(volume_id,))
コード例 #15
0
ファイル: tables.py プロジェクト: dkuebric/horizon
 def get_raw_data(self, snapshot):
     request = self.table.request
     volume_name = api.volume_get(request, snapshot.volume_id).display_name
     return safestring.mark_safe(volume_name)
コード例 #16
0
 def get_data(self, request, volume_id):
     volume = api.volume_get(request, volume_id)
     return volume
コード例 #17
0
ファイル: tables.py プロジェクト: radez/horizon
 def get_link_url(self, snapshot):
     volume_id = api.volume_get(self.table.request, snapshot.volume_id).id
     return reverse(self.link, args=(volume_id, ))
コード例 #18
0
ファイル: tables.py プロジェクト: radez/horizon
 def get_raw_data(self, snapshot):
     request = self.table.request
     volume_name = api.volume_get(request, snapshot.volume_id).display_name
     return safestring.mark_safe(volume_name)
コード例 #19
0
ファイル: tables.py プロジェクト: jiangy/horizon
 def get_data(self, request, volume_id):
     volume = api.volume_get(request, volume_id)
     return volume