def delete(self, *args, **kwargs): """ Overrides the delete method so that a database can be put in quarantine and not removed """ #do_something() if self.is_in_quarantine: LOG.warning("Database %s is in quarantine and will be removed" % self.name) for credential in self.credentials.all(): instance = factory_for(self.databaseinfra) instance.remove_user(credential) super(Database, self).delete(*args, **kwargs) # Call the "real" delete() method. else: LOG.warning("Putting database %s in quarantine" % self.name) if self.credentials.exists(): for credential in self.credentials.all(): new_password = make_db_random_password() new_credential = Credential.objects.get(pk=credential.id) new_credential.password = new_password new_credential.save() instance = factory_for(self.databaseinfra) instance.update_user(new_credential) else: LOG.info("There is no credential on this database: %s" % self.databaseinfra) self.is_in_quarantine = True self.quarantine_dt = datetime.datetime.now().date() self.save()
def do(self, workflow_dict): try: workflow_dict['names'] = gen_infra_names( name=workflow_dict['name'], qt=workflow_dict['qt']) databaseinfra = DatabaseInfra() databaseinfra.name = workflow_dict['names']['infra'] databaseinfra.user = '' databaseinfra.password = make_db_random_password() databaseinfra.engine = workflow_dict[ 'plan'].engine databaseinfra.plan = workflow_dict['plan'] databaseinfra.environment = workflow_dict['environment'] databaseinfra.capacity = 1 databaseinfra.per_database_size_mbytes = workflow_dict[ 'plan'].max_db_size databaseinfra.save() LOG.info("DatabaseInfra created!") workflow_dict['databaseinfra'] = databaseinfra return True except Exception: traceback = full_stack() workflow_dict['exceptions']['error_codes'].append(DBAAS_0002) workflow_dict['exceptions']['traceback'].append(traceback) return False
def do(self, workflow_dict): try: workflow_dict['names'] = gen_infra_names( name=workflow_dict['name'], qt=workflow_dict['qt']) databaseinfra = DatabaseInfra() databaseinfra.name = workflow_dict['names']['infra'] databaseinfra.user = '' databaseinfra.password = make_db_random_password() databaseinfra.engine = workflow_dict['plan'].engine databaseinfra.plan = workflow_dict['plan'] databaseinfra.disk_offering = workflow_dict['plan'].disk_offering databaseinfra.environment = workflow_dict['environment'] databaseinfra.capacity = 1 databaseinfra.per_database_size_mbytes = workflow_dict[ 'plan'].max_db_size databaseinfra.save() LOG.info("DatabaseInfra created!") workflow_dict['databaseinfra'] = databaseinfra return True except Exception: traceback = full_stack() workflow_dict['exceptions']['error_codes'].append(DBAAS_0002) workflow_dict['exceptions']['traceback'].append(traceback) return False
def __init__(self, *args, **kwargs): super(CredentialForm, self).__init__(*args, **kwargs) #instance = getattr(self, 'instance', None) # if instance and instanceself.pk: # self.fields['password'].widget.attrs['readonly'] = True self.fields['password'].initial = make_db_random_password() self.fields['password'].required = False self.fields['password'].widget.attrs['readonly'] = True
def create_new_credential(self): """creates a new credential for the database with a random password""" engine = factory_for(self.databaseinfra) LOG.info("creating new credential for database %s" % self.name) credential = Credential(user=Credential.USER_PATTERN % self.name, password=make_db_random_password(), database=self) credential.save() engine.create_user(credential) return credential
def create_new_credential(cls, user, database): credential = Credential() credential.database = database credential.user = user[:cls.USER_MAXIMUM_LENGTH_NAME] credential.password = make_db_random_password() credential.full_clean() credential.driver.create_user(credential) credential.save() return credential
def create_new_credential(cls, user, database): credential = Credential() credential.database = database credential.user = user[:cls.USER_MAXIMUM_LENGTH_NAME] credential.user = slugify(credential.user) credential.password = make_db_random_password() credential.full_clean() credential.driver.create_user(credential) credential.save() return credential
def delete(self, *args, **kwargs): if self.is_in_quarantine: LOG.warning( "Database {} is in quarantine and will be removed".format( self.name ) ) for credential in self.credentials.all(): instance = factory_for(self.databaseinfra) instance.try_remove_user(credential) engine = self.databaseinfra.engine databaseinfra = self.databaseinfra try: DatabaseHistory.objects.create( database_id=self.id, name=self.name, description=self.description, engine='{} {}'.format( engine.engine_type.name, engine.version ), project=self.project.name if self.project else '', team=self.team.name if self.team else '', databaseinfra_name=databaseinfra.name, plan=databaseinfra.plan.name, disk_size_kb=databaseinfra.disk_offering.size_kb, has_persistence=databaseinfra.plan.has_persistence, environment=self.environment.name, created_at=self.created_at ) except Exception as err: LOG.error( ('Error on creating database history for ' '"database {}: {}'.format(self.id, err))) super(Database, self).delete(*args, **kwargs) else: LOG.warning("Putting database {} in quarantine".format(self.name)) self.is_in_quarantine = True self.is_protected = False self.save() if self.credentials.exists(): for credential in self.credentials.all(): new_password = make_db_random_password() new_credential = Credential.objects.get(pk=credential.id) new_credential.password = new_password new_credential.save() instance = factory_for(self.databaseinfra) instance.try_update_user(new_credential)
def delete(self, *args, **kwargs): if self.is_in_quarantine: LOG.warning("Database %s is in quarantine and will be removed" % self.name) for credential in self.credentials.all(): instance = factory_for(self.databaseinfra) instance.remove_user(credential) super(Database, self).delete(*args, **kwargs) # Call the "real" delete() method. else: LOG.warning("Putting database %s in quarantine" % self.name) self.is_in_quarantine = True self.save() if self.credentials.exists(): for credential in self.credentials.all(): new_password = make_db_random_password() new_credential = Credential.objects.get(pk=credential.id) new_credential.password = new_password new_credential.save() instance = factory_for(self.databaseinfra) instance.update_user(new_credential)
def get_or_create_infra(base_name, plan, environment, retry_from=None): if retry_from: infra = retry_from.infra base_name['infra'] = infra.name base_name['name_prefix'] = infra.name_prefix base_name['name_stamp'] = infra.name_stamp else: infra = DatabaseInfra() infra.name = base_name['infra'] infra.name_prefix = base_name['name_prefix'] infra.name_stamp = base_name['name_stamp'] infra.last_vm_created = 0 infra.password = make_db_random_password() infra.engine = plan.engine infra.plan = plan infra.disk_offering = plan.disk_offering infra.environment = environment infra.capacity = 1 infra.per_database_size_mbytes = plan.max_db_size infra.save() return infra
def delete(self, *args, **kwargs): if self.is_in_quarantine: LOG.warning("Database %s is in quarantine and will be removed" % self.name) for credential in self.credentials.all(): instance = factory_for(self.databaseinfra) instance.remove_user(credential) # Call the "real" delete() method. super(Database, self).delete(*args, **kwargs) else: LOG.warning("Putting database %s in quarantine" % self.name) self.is_in_quarantine = True self.save() if self.credentials.exists(): for credential in self.credentials.all(): new_password = make_db_random_password() new_credential = Credential.objects.get(pk=credential.id) new_credential.password = new_password new_credential.save() instance = factory_for(self.databaseinfra) instance.update_user(new_credential)
def do(self, workflow_dict): try: workflow_dict['names'] = gen_infra_names( name=workflow_dict['name'], qt=workflow_dict['qt']) databaseinfra = DatabaseInfra() databaseinfra.name = workflow_dict['names']['infra'] if workflow_dict['enginecod'] == workflow_dict['REDIS']: databaseinfra.user = '' databaseinfra.password = make_db_random_password() else: credentials = get_engine_credentials( engine=str(workflow_dict['plan'].engine_type), environment=workflow_dict['environment']) databaseinfra.user = credentials.user databaseinfra.password = credentials.password databaseinfra.engine = workflow_dict[ 'plan'].engine_type.engines.all()[0] databaseinfra.plan = workflow_dict['plan'] databaseinfra.environment = workflow_dict['environment'] databaseinfra.capacity = 1 databaseinfra.per_database_size_mbytes = workflow_dict[ 'plan'].max_db_size databaseinfra.save() LOG.info("DatabaseInfra created!") workflow_dict['databaseinfra'] = databaseinfra return True except Exception, e: traceback = full_stack() workflow_dict['exceptions']['error_codes'].append(DBAAS_0002) workflow_dict['exceptions']['traceback'].append(traceback) return False
def do(self, workflow_dict): try: workflow_dict['names'] = gen_infra_names( name=workflow_dict['name'], qt=workflow_dict['qt']) databaseinfra = DatabaseInfra() databaseinfra.name = workflow_dict['names']['infra'] if workflow_dict['enginecod'] == workflow_dict['REDIS']: databaseinfra.user = '' databaseinfra.password = make_db_random_password() else: credentials = get_engine_credentials(engine=str(workflow_dict['plan'].engine_type), environment=workflow_dict['environment']) databaseinfra.user = credentials.user databaseinfra.password = credentials.password databaseinfra.engine = workflow_dict[ 'plan'].engine_type.engines.all()[0] databaseinfra.plan = workflow_dict['plan'] databaseinfra.environment = workflow_dict['environment'] databaseinfra.capacity = 1 databaseinfra.per_database_size_mbytes = workflow_dict['plan'].max_db_size databaseinfra.save() LOG.info("DatabaseInfra created!") workflow_dict['databaseinfra'] = databaseinfra return True except Exception, e: traceback = full_stack() workflow_dict['exceptions']['error_codes'].append(DBAAS_0002) workflow_dict['exceptions']['traceback'].append(traceback) return False
except Exception, err: LOG.error( 'Erro ao criar o database history para "o database {}: {}'. format(self.id, err)) super(Database, self).delete(*args, **kwargs) else: LOG.warning("Putting database {} in quarantine".format(self.name)) self.is_in_quarantine = True self.is_protected = False self.save() if self.credentials.exists(): for credential in self.credentials.all(): new_password = make_db_random_password() new_credential = Credential.objects.get(pk=credential.id) new_credential.password = new_password new_credential.save() instance = factory_for(self.databaseinfra) instance.update_user(new_credential) def clean(self): if not self.pk: self.name = slugify(self.name) if self.name in self.__get_database_reserved_names(): raise ValidationError( _("{} is a reserved database name".format(self.name)))
def change_default_pwd(self, instance): new_password = make_db_random_password() self.__query("SET PASSWORD FOR '%s'@'%%' = PASSWORD('%s')" ( instance.databaseinfra.user, new_password)) return new_password
def change_default_pwd(self, instance): new_password = make_db_random_password() self.__query("SET PASSWORD FOR '%s'@'%%' = PASSWORD('%s')" % (instance.databaseinfra.user, new_password)) return new_password
def build_new_infra_auth(self): return '', make_db_random_password(), ''
def change_default_pwd(self, instance): with self.pymongo(instance=instance) as client: new_password = make_db_random_password() client.admin.add_user( name=instance.databaseinfra.user, password=new_password) return new_password
created_at=self.created_at ) except Exception, err: LOG.error('Erro ao criar o database history para "o database {}: {}'.format(self.id, err)) super(Database, self).delete(*args, **kwargs) else: LOG.warning("Putting database {} in quarantine".format(self.name)) self.is_in_quarantine = True self.is_protected = False self.save() if self.credentials.exists(): for credential in self.credentials.all(): new_password = make_db_random_password() new_credential = Credential.objects.get(pk=credential.id) new_credential.password = new_password new_credential.save() instance = factory_for(self.databaseinfra) instance.update_user(new_credential) def clean(self): if not self.pk: self.name = slugify(self.name) if self.name in self.__get_database_reserved_names(): raise ValidationError( _("{} is a reserved database name".format( self.name
def reset_password(self): """ Reset credential password to a new random password """ self.password = make_db_random_password() self.driver.update_user(self) self.save()
def change_default_pwd(self, instance): with self.pymongo(instance=instance) as client: new_password = make_db_random_password() client.admin.add_user(name=instance.databaseinfra.user, password=new_password) return new_password
def __init__(self, *args, **kwargs): super(CredentialForm, self).__init__(*args, **kwargs) self.fields['password'].initial = make_db_random_password() self.fields['password'].required = False self.fields['password'].widget.attrs['readonly'] = True