Exemple #1
0
 def default_config_update(self, name, description, datastore, datastore_version, config_id):
     try:
         self.db_api.configure_db(CONF)
         context = TroveContext(tenant = CONF.default_template_tenant_id)
         context.is_admin = True
         tenant_id = CONF.default_template_tenant_id
         
         #datastore = ds_models.DBDatastore.find_by(name=datastore)
         ds = ds_models.Datastore.load(datastore)
         version_id = ds.default_version_id
         if datastore_version:
             version = ds_models.DatastoreVersion.load(ds, datastore_version)
             if  version:
                 version_id = version.id
                 
         try:
             group = config_models.KSC_Configuration.load(context, config_id)
             group.name = name
             group.description = description
             group.datastore_version_id = version_id
             self.db_api.save(group)
         except exception.ModelNotFoundError:
             # Create a new one
             config_models.KSC_Configuration.create(name, description, tenant_id, ds, version_id)
         print("Configuration '%s' update." % name)
     except exception as e:
         print(e)        
Exemple #2
0
 def default_config_delete(self, id):
     try:
         self.db_api.configure_db(CONF)
         context = TroveContext(tenant = CONF.default_template_tenant_id)
         context.is_admin = True
         group = config_models.KSC_Configuration.load(context, id)
         config_models.KSC_Configuration.delete(context, group)
         print("Configuration '%s' delete." % id)
     except exception as e:
         print(e)
Exemple #3
0
 def default_config_items_update(self, id, value_file, config_name = None, description = None):
     try:
         self.db_api.configure_db(CONF)
         context = TroveContext(tenant = CONF.default_template_tenant_id)
         context.is_admin = True
         group = config_models.KSC_Configuration.load(context, id)
         '''
         instances = instances_models.DBInstance.find_all(
             tenant_id=context.tenant,
             configuration_id=id,
             deleted=False).all()
         '''
         # if name/description are provided in the request body, update the
         # model with these values as well.
         if  config_name is not None:
             group.name = config_name
 
         if description is not None:
             group.description = description
         
         fmt_values = {}
         if value_file is not None and os.path.isfile(value_file):
             config = open(value_file).read()
             cfg_parser = configurations.MySQLConfParser(config)
             parsed = cfg_parser.parse()
             values = dict(parsed)
             
             rules = configurations.get_validation_rules(datastore_manager='mysql')
             
             fmt_values = {}
             for k, v in values.iteritems():
                 # get the validation rule dictionary, which will ensure there is a
                 # rule for the given key name. An exception will be thrown if no
                 # valid rule is located.
                 rule = config_service.ConfigurationsController._get_item(k, rules['configuration-parameters'])
                 valueType = rule.get('type')
                 if "integer" == valueType:
                     fmt_values[k] = int(v)
                 elif "boolean" == valueType:
                     fmt_values[k] = bool(v)
                 else:
                     fmt_values[k] = v
                     
         if len(fmt_values) > 0:
             config_service.ConfigurationsController._validate_configuration(fmt_values, datastore_manager='mysql')
             config_models.KSC_Configuration.remove_all_items(context,id, utils.utcnow())
             items = config_models.KSC_Configuration.get_items_by_overrides(context,id, fmt_values)
             config_models.KSC_Configuration.save(context, group, items, [])
     except exception as e:
         print(e)