Ejemplo n.º 1
0
 def populate_instance_choices(self, request, context):
     LOG.info("Obtaining list of instances.")
     try:
         instances = api.trove.instance_list(request)
     except Exception:
         instances = []
         msg = _("Unable to list database instances to backup.")
         exceptions.handle(request, msg)
     return [(i.id, i.name) for i in instances
             if (i.status in project_tables.ACTIVE_STATES) and
                (db_capability.can_backup(i.datastore['type']))]
Ejemplo n.º 2
0
    def populate_parent_choices(self, request, context):
        try:
            backups = api.trove.backup_list(request)
            choices = [(b.id, b.name) for b in backups
                       if (b.status == 'COMPLETED') and
                          (db_capability.can_backup(b.datastore['type']))]
        except Exception:
            choices = []
            msg = _("Unable to list database backups for parent.")
            exceptions.handle(request, msg)

        if choices:
            choices.insert(0, ("", _("Select parent backup")))
        else:
            choices.insert(0, ("", _("No backups available")))
        return choices
Ejemplo n.º 3
0
 def _has_backup_capability(self, kwargs):
     instance = kwargs['instance']
     if (instance is not None):
         return db_capability.can_backup(instance.datastore['type'])
     return True
    def clean(self):
        cleaned_data = super(AdvancedAction, self).clean()

        datastore = self.data[u'datastore']

        config = self.cleaned_data['config']
        if config:
            try:
                # Make sure the user is not "hacking" the form
                # and that they have access to this configuration
                cfg = api.trove.configuration_get(self.request, config)
                self.cleaned_data['config'] = cfg.id
            except Exception:
                raise forms.ValidationError(_("Unable to find configuration "
                                              "group!"))
        else:
            if db_capability.require_configuration_group(datastore):
                msg = _('This datastore requires a configuration group.')
                self._errors["config"] = self.error_class([msg])

        initial_state = cleaned_data.get("initial_state")

        if initial_state == 'backup':
            cleaned_data['replica_count'] = None
            if not db_capability.can_backup(datastore):
                msg = _('You cannot specify a backup for the initial state '
                        'for this datastore.')
                self._errors["initial_state"] = self.error_class([msg])
            else:
                backup = self.cleaned_data['backup']
                if backup:
                    try:
                        bkup = api.trove.backup_get(self.request, backup)
                        self.cleaned_data['backup'] = bkup.id
                    except Exception:
                        raise forms.ValidationError(
                            _("Unable to find backup!"))
                else:
                    msg = _("A backup must be selected!")
                    self._errors["backup"] = self.error_class([msg])

                cleaned_data['master'] = None
        elif initial_state == 'master':
            if not db_capability.can_launch_from_master(datastore):
                msg = _('You cannot specify a master for the initial state '
                        'for this datastore.')
                self._errors["initial_state"] = self.error_class([msg])
            else:
                master = self.cleaned_data['master']
                if master:
                    try:
                        api.trove.instance_get(self.request, master)
                    except Exception:
                        raise forms.ValidationError(
                            _("Unable to find master instance!"))
                else:
                    msg = _("A master instance must be selected!")
                    self._errors["master"] = self.error_class([msg])

                cleaned_data['backup'] = None
        else:
            cleaned_data['master'] = None
            cleaned_data['backup'] = None
            cleaned_data['replica_count'] = None

        return cleaned_data