Exemple #1
0
    def clean(self):
        datastore_field_value = self.data.get("datastore", None)
        if datastore_field_value:
            datastore, datastore_version = (
                create_instance.parse_datastore_and_version_text(
                    common_utils.unhexlify(datastore_field_value)))

            flavor_field_name = self._build_widget_field_name(
                datastore, datastore_version)
            if not self.data.get(flavor_field_name, None):
                msg = _("The flavor must be specified.")
                self._errors[flavor_field_name] = self.error_class([msg])

            if db_capability.is_vertica_datastore(datastore):
                if not self.data.get("root_password", None):
                    msg = _("Password for root user must be specified.")
                    self._errors["root_password"] = self.error_class([msg])
            else:
                if int(self.data.get("num_instances", 0)) < 1:
                    msg = _("The number of instances must be greater than 1.")
                    self._errors["num_instances"] = self.error_class([msg])

                if db_capability.is_mongodb_datastore(datastore):
                    if int(self.data.get("num_shards", 0)) < 1:
                        msg = _("The number of shards must be greater than 1.")
                        self._errors["num_shards"] = self.error_class([msg])

        if not self.data.get("locality", None):
            self.cleaned_data["locality"] = None

        return self.cleaned_data
Exemple #2
0
 def handle(self, request, context):
     datastore_and_version = context["datastore"]
     if datastore_and_version:
         datastore, datastore_version = parse_datastore_and_version_text(
             common_utils.unhexlify(context["datastore"]))
         field_name = self._build_flavor_field_name(datastore,
                                                    datastore_version)
         flavor = self.data[field_name]
         if flavor:
             context["flavor"] = flavor
             return context
     return None
Exemple #3
0
    def clean(self):
        datastore_and_version = self.data.get("datastore", None)
        if not datastore_and_version:
            msg = _("You must select a datastore type and version.")
            self._errors["datastore"] = self.error_class([msg])
        else:
            datastore, datastore_version = parse_datastore_and_version_text(
                common_utils.unhexlify(datastore_and_version))
            field_name = self._build_flavor_field_name(datastore,
                                                       datastore_version)
            flavor = self.data.get(field_name, None)
            if not flavor:
                msg = _("You must select a flavor.")
                self._errors[field_name] = self.error_class([msg])

        if not self.data.get("locality", None):
            self.cleaned_data["locality"] = None

        return self.cleaned_data
Exemple #4
0
    def handle(self, request, context):
        try:
            datastore, datastore_version = parse_datastore_and_version_text(
                common_utils.unhexlify(self.context['datastore']))
            avail_zone = context.get('availability_zone', None)
            LOG.info(
                "Launching database instance with parameters "
                "{name=%s, volume=%s, volume_type=%s, flavor=%s, "
                "datastore=%s, datastore_version=%s, "
                "dbs=%s, "
                "backups=%s, nics=%s, replica_of=%s replica_count=%s, "
                "configuration=%s, locality=%s, "
                "availability_zone=%s}", context['name'], context['volume'],
                self._get_volume_type(context), context['flavor'], datastore,
                datastore_version, self._get_databases(context),
                self._get_backup(context), self._get_nics(context),
                context.get('master'), context['replica_count'],
                context.get('config'), self._get_locality(context), avail_zone)

            api.trove.instance_create(
                request,
                context['name'],
                context['volume'],
                context['flavor'],
                datastore=datastore,
                datastore_version=datastore_version,
                databases=self._get_databases(context),
                users=self._get_users(context),
                restore_point=self._get_backup(context),
                nics=self._get_nics(context),
                replica_of=context.get('master'),
                replica_count=context['replica_count'],
                volume_type=self._get_volume_type(context),
                configuration=context.get('config'),
                locality=self._get_locality(context),
                availability_zone=avail_zone,
                access=self._get_access(context))
            return True
        except Exception:
            exceptions.handle(request)
            return False
Exemple #5
0
    def handle(self, request, data):
        try:
            datastore, datastore_version = (
                create_instance.parse_datastore_and_version_text(
                    common_utils.unhexlify(data['datastore'])))

            flavor_field_name = self._build_widget_field_name(
                datastore, datastore_version)
            flavor = data[flavor_field_name]
            num_instances = data['num_instances']
            root_password = None
            if db_capability.is_vertica_datastore(datastore):
                root_password = data['root_password']
                num_instances = data['num_instances_vertica']
            LOG.info(
                "Launching cluster with parameters "
                "{name=%s, volume=%s, flavor=%s, "
                "datastore=%s, datastore_version=%s", "locality=%s",
                data['name'], data['volume'], flavor, datastore,
                datastore_version, self._get_locality(data))

            trove_api.trove.cluster_create(request,
                                           data['name'],
                                           data['volume'],
                                           flavor,
                                           num_instances,
                                           datastore=datastore,
                                           datastore_version=datastore_version,
                                           nics=data['network'],
                                           root_password=root_password,
                                           locality=self._get_locality(data))
            messages.success(request,
                             _('Launched cluster "%s"') % data['name'])
            return True
        except Exception as e:
            redirect = reverse("horizon:project:database_clusters:index")
            exceptions.handle(request,
                              _('Unable to launch cluster. %s') %
                              six.text_type(e),
                              redirect=redirect)