Exemplo n.º 1
0
    def handle(self, request, data):
        volume_id = self.initial['volume_id']
        try:
            cinder.volume_update(request, volume_id, data['name'],
                                 data['description'])
        except Exception:
            redirect = reverse("horizon:project:volumes:index")
            exceptions.handle(request,
                              _('Unable to update volume.'),
                              redirect=redirect)

        # only update bootable flag if modified
        make_bootable = data['bootable']
        if make_bootable != self.initial['bootable']:
            try:
                cinder.volume_set_bootable(request, volume_id, make_bootable)
            except Exception:
                redirect = reverse("horizon:project:volumes:index")
                exceptions.handle(request,
                                  _('Unable to set bootable flag on volume.'),
                                  redirect=redirect)

        message = _('Updating volume "%s"') % data['name']
        messages.info(request, message)
        return True
Exemplo n.º 2
0
    def handle(self, request, data):
        volume_id = self.initial['volume_id']
        try:
            cinder.volume_update(request, volume_id, data['name'],
                                 data['description'])
        except Exception:
            redirect = reverse("horizon:admin:volumes:index")
            exceptions.handle(request,
                              _('Unable to update volume.'),
                              redirect=redirect)

        # only update bootable flag if modified
        make_bootable = data['bootable']
        if make_bootable != self.initial['bootable']:
            try:
                cinder.volume_set_bootable(request, volume_id, make_bootable)
            except Exception:
                redirect = reverse("horizon:admin:volumes:index")
                exceptions.handle(request,
                                  _('Unable to set bootable flag on volume.'),
                                  redirect=redirect)

        message = _('Updating volume "%s"') % data['name']
        messages.info(request, message)
        return True
Exemplo n.º 3
0
    def handle(self, request, data):
        volume_id = self.initial['volume_id']
        try:
            cinder.volume_update(request, volume_id, data['name'],
                                 data['description'])
        except Exception:
            redirect = reverse("horizon:project:volumes:index")
            exceptions.handle(request,
                              _('Unable to update volume.'),
                              redirect=redirect)

        # only update bootable flag if modified
        make_bootable = data['bootable']
        if make_bootable != self.initial['bootable']:
            try:
                cinder.volume_set_bootable(request, volume_id, make_bootable)
            except Exception:
                redirect = reverse("horizon:project:volumes:index")
                exceptions.handle(request,
                                  _('Unable to set bootable flag on volume.'),
                                  redirect=redirect)

        meta = {}
        metadata_list = request.POST.getlist("metadata")
        if metadata_list:
            for item in metadata_list:
                if "=" in item:
                    key, val = item.split("=")
                    meta[key] = val
        old_meta = {}
        try:
            volume = cinder.volume_get(self.request, volume_id)
            old_meta = volume.metadata
        except Exception:
            msg = _('Unable to retrieve instance details.')
            exceptions.handle(self.request, msg)

        delete_meta = dict((k,v) for k,v in old_meta.items() if k not in meta)
        update_meta =  dict((k,v) for k,v in meta.items() if k not in old_meta
                or meta[k] != old_meta[k])

        if update_meta:
            try:
                cinder.volume_update_meta(request, volume_id, update_meta)
            except Exception as e:
                exceptions.handle(request, str(e))

        if delete_meta:
            try:
                cinder.volume_delete_meta(request, volume_id, delete_meta)
            except Exception as e:
                exceptions.handle(request, str(e))
                return False

        message = _('Updating volume "%s"') % data['name']
        messages.info(request, message)
        return True
Exemplo n.º 4
0
    def handle(self, request, data):
        volume_id = self.initial['volume_id']
        try:
            cinder.volume_update(request, volume_id, data['name'],
                                 data['description'])
            # operation log
            config = _('Volume Name: %s') % data['name']
            api.logger.Logger(request).create(resource_type='volume',
                                              action_name='Update Volume',
                                              resource_name='Volume',
                                              config=config,
                                              status='Success')
        except Exception:
            redirect = reverse("horizon:storage:volumes:index")
            exceptions.handle(request,
                              _('Unable to update volume.'),
                              redirect=redirect)

            # operation log
            api.logger.Logger(request).create(
                resource_type='volume',
                action_name='Update Volume',
                resource_name='Volume',
                config=_('Unable to update volume.'),
                status='Error')

        # only update bootable flag if modified
        make_bootable = data['bootable']
        if make_bootable != self.initial['bootable']:
            try:
                cinder.volume_set_bootable(request, volume_id, make_bootable)

                # operation log
                api.logger.Logger(request).create(resource_type='volume',
                                                  action_name='Update Volume',
                                                  resource_name='Volume',
                                                  config=_('Bootable: %s') %
                                                  str(data['bootable']),
                                                  status='Success')
            except Exception:
                redirect = reverse("horizon:storage:volumes:index")
                exceptions.handle(request,
                                  _('Unable to set bootable flag on volume.'),
                                  redirect=redirect)

                # operation log
                api.logger.Logger(request).create(
                    resource_type='volume',
                    action_name='Update Volume',
                    resource_name='Volume',
                    config=_('Unable to set bootable flag on volume.'),
                    status='Error')

        message = _('Updating volume "%s"') % data['name']
        messages.info(request, message)
        return True
Exemplo n.º 5
0
    def handle(self, request, data):
        volume_id = self.initial["volume_id"]
        try:
            cinder.volume_update(request, volume_id, data["name"], data["description"])

            message = _('Updating volume "%s"') % data["name"]
            messages.info(request, message)
            return True
        except Exception:
            redirect = reverse("horizon:project:volumes:index")
            exceptions.handle(request, _("Unable to update volume."), redirect=redirect)
Exemplo n.º 6
0
    def test_update_volume(self):
        volume = self.cinder_volumes.get(name="my_volume")

        cinder.volume_get(IsA(http.HttpRequest), volume.id).AndReturn(volume)
        cinder.volume_update(IsA(http.HttpRequest), volume.id, volume.name, volume.description)

        self.mox.ReplayAll()

        formData = {"method": "UpdateForm", "name": volume.name, "description": volume.description}

        url = reverse("horizon:project:volumes:volumes:update", args=[volume.id])
        res = self.client.post(url, formData)
        self.assertRedirectsNoFollow(res, VOLUME_INDEX_URL)
Exemplo n.º 7
0
    def handle(self, request, data):
        volume_id = self.initial['volume_id']
        try:
            cinder.volume_update(request, volume_id, data['name'],
                                 data['description'])

            message = _('Updating volume "%s"') % data['name']
            messages.info(request, message)
            return True
        except Exception:
            redirect = reverse("horizon:project:volumes:index")
            exceptions.handle(request,
                              _('Unable to update volume.'),
                              redirect=redirect)
Exemplo n.º 8
0
    def test_update_volume(self):
        volume = self.cinder_volumes.get(name="my_volume")

        cinder.volume_get(IsA(http.HttpRequest), volume.id).AndReturn(volume)
        cinder.volume_update(IsA(http.HttpRequest),
                             volume.id,
                             volume.name,
                             volume.description)

        self.mox.ReplayAll()

        formData = {'method': 'UpdateForm',
                    'name': volume.name,
                    'description': volume.description}

        url = reverse('horizon:project:volumes:volumes:update',
                      args=[volume.id])
        res = self.client.post(url, formData)
        self.assertRedirectsNoFollow(res, VOLUME_INDEX_URL)
Exemplo n.º 9
0
    def test_update_volume(self):
        volume = self.volumes.get(name="my_volume")

        cinder.volume_get(IsA(http.HttpRequest), volume.id).AndReturn(volume)
        cinder.volume_update(IsA(http.HttpRequest),
                             volume.id,
                             volume.display_name,
                             volume.display_description)

        self.mox.ReplayAll()

        formData = {'method': 'UpdateForm',
                    'name': volume.display_name,
                    'description': volume.display_description}

        url = reverse('horizon:project:volumes:update',
                      args=[volume.id])
        res = self.client.post(url, formData)
        self.assertRedirectsNoFollow(res, VOLUME_INDEX_URL)