def clean(self): datastore_field_value = self.data.get("datastore", None) if datastore_field_value: datastore = datastore_field_value.split(',')[0] if db_capability.is_vertica_datastore(datastore): if not self.data.get("vertica_flavor", None): msg = _("The flavor must be specified.") self._errors["vertica_flavor"] = self.error_class([msg]) 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 not self.data.get("flavor", None): msg = _("The flavor must be specified.") self._errors["flavor"] = self.error_class([msg]) 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]) return self.cleaned_data
def handle(self, request, data): try: datastore = data['datastore'].split('-', 1)[0] datastore_version = data['datastore'].split('-', 1)[1] final_flavor = data['flavor'] num_instances = data['num_instances'] root_password = None if db_capability.is_vertica_datastore(datastore): final_flavor = data['vertica_flavor'] 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", data['name'], data['volume'], final_flavor, datastore, datastore_version) trove_api.trove.cluster_create(request, data['name'], data['volume'], final_flavor, num_instances, datastore=datastore, datastore_version=datastore_version, nics=data['network'], root_password=root_password) 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') % e.message, redirect=redirect)
def populate_flavor_choices(self, request): valid_flavor = [] for ds in self.datastores(request): # TODO(michayu): until capabilities lands if db_capability.is_mongodb_datastore(ds.name): versions = self.datastore_versions(request, ds.name) for version in versions: if version.name == "inactive": continue valid_flavor = self.datastore_flavors(request, ds.name, versions[0].name) if valid_flavor: self.fields['mongodb_flavor'].choices = sorted( [(f.id, "%s" % f.name) for f in valid_flavor]) if db_capability.is_vertica_datastore(ds.name): versions = self.datastore_versions(request, ds.name) for version in versions: if version.name == "inactive": continue valid_flavor = self.datastore_flavors(request, ds.name, versions[0].name) if valid_flavor: self.fields['vertica_flavor'].choices = sorted( [(f.id, "%s" % f.name) for f in valid_flavor])
def handle(self, request, data): try: datastore = data['datastore'].split('-')[0] datastore_version = data['datastore'].split('-')[1] final_flavor = data['mongodb_flavor'] num_instances = data['num_instances_per_shards'] root_password = None if db_capability.is_vertica_datastore(datastore): final_flavor = data['vertica_flavor'] 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", data['name'], data['volume'], final_flavor, datastore, datastore_version) trove_api.trove.cluster_create(request, data['name'], data['volume'], final_flavor, num_instances, datastore=datastore, datastore_version=datastore_version, nics=data['network'], root_password=root_password) 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') % e.message, redirect=redirect)
def filter_cluster_datastores(self, request): datastores = [] for ds in self.datastores(request): # TODO(michayu): until capabilities lands if (db_capability.is_vertica_datastore(ds.name) or db_capability.is_mongodb_datastore(ds.name)): datastores.append(ds) return datastores
def get_size(cluster): if db_capability.is_vertica_datastore(cluster.datastore['type']): return "3" if hasattr(cluster, "full_flavor"): size_string = _("%(name)s | %(RAM)s RAM | %(instances)s instances") vals = {'name': cluster.full_flavor.name, 'RAM': sizeformat.mbformat(cluster.full_flavor.ram), 'instances': len(cluster.instances)} return size_string % vals return _("Not available")
def _add_attr_to_optional_fields(self, datastore, selection_text): fields = [] if db_capability.is_mongodb_datastore(datastore): fields = self.mongodb_fields elif db_capability.is_vertica_datastore(datastore): fields = self.vertica_fields for field in fields: attr_key = 'data-datastore-' + selection_text widget = self.fields[field[0]].widget if attr_key not in widget.attrs: widget.attrs[attr_key] = field[1]
def clean(self): datastore_field_value = self.data.get("datastore", None) if datastore_field_value: datastore = datastore_field_value.split(',')[0] if db_capability.is_mongodb_datastore(datastore): if self.data.get("num_shards", None) < 1: msg = _("The number of shards must be greater than 1.") self._errors["num_shards"] = self.error_class([msg]) elif db_capability.is_vertica_datastore(datastore): if not self.data.get("vertica_flavor", None): msg = _("The flavor must be specified.") self._errors["vertica_flavor"] = self.error_class([msg]) if not self.data.get("root_password", None): msg = _("Password for root user must be specified.") self._errors["root_password"] = self.error_class([msg]) return self.cleaned_data
def allowed(self, request, cluster=None): if (cluster and cluster.task["name"] == 'NONE' and db_capability.is_vertica_datastore(cluster.datastore['type'])): return True return False