def create(cls, context, instance_id, user): load_and_verify(context, instance_id) root = create_guest_client(context, instance_id).enable_root() root_user = guest_models.RootUser() root_user.deserialize(root) RootHistory.create(context, instance_id, user) return root_user
def enable_root(cls, root_password=None): """Enable access with the sys user and/or reset the sys password. """ if root_password: sys_pwd = root_password else: sys_pwd = utils.generate_random_password(password_length=30) ora_admin = OracleAdmin() databases, marker = ora_admin.list_databases() for database in databases: oradb = models.OracleSchema.deserialize_schema(database) with LocalOracleClient(oradb.name, service=True) as client: client.execute('alter user sys identified by "%s"' % sys_pwd) oracnf = OracleConfig() oracnf.enable_root() oracnf.sys_password = sys_pwd LOG.debug('enable_root completed') user = models.RootUser() user.name = "sys" user.host = "%" user.password = sys_pwd return user.serialize()
def enable_root(self, root_password=None): """Resets the root password.""" LOG.info(_LI("Enabling root.")) user = models.RootUser() user.name = "root" user.host = "%" user.password = root_password or utils.generate_random_password() if not self.is_root_enabled(): self._create_user(user.name, user.password, 'pseudosuperuser') else: LOG.debug("Updating %s password." % user.name) try: out, err = system.exec_vsql_command( self._get_database_password(), system.ALTER_USER_PASSWORD % (user.name, user.password)) if err: if err.is_warning(): LOG.warning(err) else: LOG.error(err) raise RuntimeError( _("Failed to update %s " "password.") % user.name) except exception.ProcessExecutionError: LOG.error(_("Failed to update %s password.") % user.name) raise RuntimeError( _("Failed to update %s password.") % user.name) return user.serialize()
def enable_root(cls, root_password=None): user = models.RootUser() user.name = "root" user.host = "%" user.password = root_password or utils.generate_random_password() if root_password: CouchbaseRootAccess().write_password_to_file(root_password) else: CouchbaseRootAccess().set_password(user.password) return user.serialize()
def load(cls, context, instance_id, username, hostname, root_user=False): load_and_verify(context, instance_id) if root_user: validate = guest_models.RootUser() else: validate = guest_models.MySQLUser() validate.name = username validate.host = hostname client = create_guest_client(context, instance_id) found_user = client.get_user(username=username, hostname=hostname) if not found_user: return None database_names = [{ 'name': db['_name'] } for db in found_user['_databases']] return cls(found_user['_name'], found_user['_host'], found_user['_password'], database_names)
def create(cls, context, instance_id, user, root_password, cluster_instances_list=None): load_and_verify(context, instance_id) if root_password: root = create_guest_client( context, instance_id).enable_root_with_password(root_password) else: root = create_guest_client(context, instance_id).enable_root() root_user = guest_models.RootUser() root_user.deserialize(root) # if cluster_instances_list none, then root create is called for # single instance, adding an RootHistory entry for the instance_id if cluster_instances_list is None: RootHistory.create(context, instance_id, user) return root_user
def enable_root(cls, root_password=None): """Enable the root user global access and/or reset the root password. """ user = models.RootUser() user.name = "root" user.host = "%" user.password = root_password or utils.generate_random_password() with LocalSqlClient(get_engine()) as client: print(client) try: cu = sql_query.CreateUser(user.name, host=user.host) t = text(str(cu)) client.execute(t, **cu.keyArgs) except exc.OperationalError as err: # Ignore, user is already created, just reset the password # TODO(rnirmal): More fine grained error checking later on LOG.debug(err) with LocalSqlClient(get_engine()) as client: print(client) uu = sql_query.UpdateUser(user.name, host=user.host, clear=user.password) t = text(str(uu)) client.execute(t) LOG.debug("CONF.root_grant: %s CONF.root_grant_option: %s." % (CONF.root_grant, CONF.root_grant_option)) g = sql_query.Grant(permissions=CONF.root_grant, user=user.name, host=user.host, grant_option=CONF.root_grant_option, clear=user.password) t = text(str(g)) client.execute(t) return user.serialize()
def enable_root(self, root_password=None): """Enable the sys user global access and/or reset the sys password. """ LOG.debug("Enabling root.") if self.database_open_mode.startswith('READ ONLY'): raise exception.TroveError( _("Cannot root enable a read only database.")) if not root_password: root_password = new_oracle_password() with self.cursor(self.database_name) as cursor: cursor.execute( str( sql_query.AlterUser.change_password( self.root_user_name, root_password))) self.ora_config.enable_root() self.ora_config.root_password = root_password user = models.RootUser() user.name = self.root_user_name user.host = '%' user.password = root_password LOG.debug("Successfully enabled root.") return user.serialize()