Beispiel #1
0
    def handle(self, request, data):
        try:
            name = data.get("name", None)
            description = data.get("description", None)
            master_id = data.get('master_volume', None)
            slave_id = data.get('slave_volume', None)
            master_vol = sg_api.volume_get(request, master_id)
            slave_vol = sg_api.volume_get(request, slave_id)

            if master_id == slave_id:
                error_message = (_('The slave volume and master volume can not'
                                   ' be the same'))
                raise ValidationError(error_message)
            if master_vol.availability_zone == slave_vol.availability_zone:
                error_message = (_('The slave volume and master volume can not'
                                   ' be the same availability_zone'))
                raise ValidationError(error_message)

            replication = sg_api.volume_replication_create(
                request, master_id, slave_id, name, description)
            message = _('Creating replication "%s"') % data['name']
            messages.info(request, message)
            return replication
        except ValidationError as e:
            self.api_error(e.messages[0])
            return False
        except Exception:
            redirect = reverse("horizon:storage-gateway:replications:index")
            exceptions.handle(request,
                              _("Unable to create replication."),
                              redirect=redirect)
 def get_data(self, request, volume_id):
     volume = None
     try:
         volume = sg_api.volume_get(request, volume_id)
     except Exception:
         pass
     return volume
 def get_data(self, request, snapshot_id):
     snapshot = None
     try:
         snapshot = sg_api.volume_snapshot_get(request, snapshot_id)
         snapshot._volume = sg_api.volume_get(request, snapshot.volume_id)
     except Exception:
         pass
     return snapshot
Beispiel #4
0
 def get_object(self):
     volume_id = self.kwargs['volume_id']
     try:
         return sg_api.volume_get(self.request, volume_id)
     except Exception:
         self._object = None
         exceptions.handle(self.request,
                           _('Unable to retrieve volume information.'))
Beispiel #5
0
 def get_data(self, request, backup_id):
     backup = None
     try:
         backup = sg_api.volume_backup_get(request, backup_id)
         backup.volume = sg_api.volume_get(request, backup.volume_id)
     except Exception:
         pass
     return backup
 def get_context_data(self, request):
     try:
         snapshot = self.tab_group.kwargs['snapshot']
         volume = sg_api.volume_get(request, snapshot.volume_id)
     except Exception:
         redirect = self.get_redirect_url()
         exceptions.handle(self.request,
                           _('Unable to retrieve snapshot details.'),
                           redirect=redirect)
     return {"snapshot": snapshot, "volume": volume}
Beispiel #7
0
 def get_object(self):
     if not hasattr(self, "_object"):
         vol_id = self.kwargs['volume_id']
         try:
             self._object = sg_api.volume_get(self.request, vol_id)
         except Exception:
             msg = _('Unable to retrieve volume.')
             url = reverse('horizon:storage-gateway:volumes:index')
             exceptions.handle(self.request, msg, redirect=url)
     return self._object
Beispiel #8
0
 def get_data(self):
     try:
         volume_id = self.kwargs['volume_id']
         volume = sg_api.volume_get(self.request, volume_id)
     except Exception:
         redirect = self.get_redirect_url()
         exceptions.handle(self.request,
                           _('Unable to retrieve volume details.'),
                           redirect=redirect)
     return volume
Beispiel #9
0
 def get_context_data(self, request):
     try:
         backup = self.tab_group.kwargs['backup']
         try:
             volume = sg_api.volume_get(request, backup.volume_id)
         except Exception:
             volume = None
         return {'backup': backup, 'volume': volume}
     except Exception:
         redirect = reverse('horizon:storage-gateway:backups:index')
         exceptions.handle(self.request,
                           _('Unable to retrieve backup details.'),
                           redirect=redirect)
 def handle(self, request, data):
     try:
         volume = sg_api.volume_get(request, data['volume_id'])
         message = _('Creating volume snapshot "%s".') % data['name']
         if volume.status == 'in-use':
             message = _('Forcing to create snapshot "%s" '
                         'from attached volume.') % data['name']
         snapshot = sg_api.volume_snapshot_create(request,
                                                  data['volume_id'],
                                                  data['name'],
                                                  data['description'])
         messages.info(request, message)
         return snapshot
     except Exception:
         redirect = reverse("horizon:storage-gateway:volumes:index")
         msg = _('Unable to create volume snapshot.')
         exceptions.handle(request, msg, redirect=redirect)
Beispiel #11
0
 def get_context_data(self, **kwargs):
     context = super(CreateSnapshotView, self).get_context_data(**kwargs)
     context['volume_id'] = self.kwargs['volume_id']
     args = (self.kwargs['volume_id'],)
     context['submit_url'] = reverse(self.submit_url, args=args)
     try:
         volume = sg_api.volume_get(self.request, context['volume_id'])
         if (volume.status == 'in-use'):
             context['attached'] = True
             context['form'].set_warning(_("This volume is currently "
                                           "attached to an instance. "
                                           "In some cases, creating a "
                                           "snapshot from an attached "
                                           "volume can result in a "
                                           "corrupted snapshot."))
     except Exception:
         exceptions.handle(self.request,
                           _('Unable to retrieve volume information.'))
     return context
    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:
            sg_api.volume_attach(request, data['volume_id'], data['instance'])
            volume = sg_api.volume_get(request, data['volume_id'])
            message = _('Attaching volume %(vol)s to instance '
                        '%(inst)s.') % {
                            "vol": volume.name,
                            "inst": instance_name
                        }
            messages.info(request, message)
            return True
        except Exception:
            redirect = reverse("horizon:storage-gateway:volumes:index")
            exceptions.handle(request,
                              _('Unable to attach volume.'),
                              redirect=redirect)
 def get_volume(self, request, id):
     return sg_api.volume_get(request, id)