Closed rzerres closed 5 years ago
Thanks for the update, @rzerres ! I played around with the new code a bit, and I noticed that the database migrate
command is broken now. I tried to enable it back via __get_methods__()
, but it still doesn't work, since the code has been refactored around it:
(opensips-cli): database migrate opensips opensips_copied
Please provide the URL to connect to the database: mysql://root:liviusmysqlpassword@localhost
Creating database opensips_copied...
Traceback (most recent call last):
File "/usr/lib/python3.6/cmd.py", line 214, in onecmd
func = getattr(self, 'do_' + cmd)
AttributeError: 'OpenSIPSCLIShell' object has no attribute 'do_database'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/bin/opensips-cli", line 4, in <module>
__import__('pkg_resources').run_script('opensipscli==0.1', 'opensips-cli')
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 658, in run_script
self.require(requires)[0].run_script(script_name, ns)
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 1438, in run_script
exec(code, namespace, namespace)
File "/usr/local/lib/python3.6/dist-packages/opensipscli-0.1-py3.6.egg/EGG-INFO/scripts/opensips-cli", line 9, in <module>
run_console()
File "/usr/local/lib/python3.6/dist-packages/opensipscli-0.1-py3.6.egg/EGG-INFO/scripts/opensips-cli", line 6, in run_console
main.main()
File "/home/liviu/src/opensips-cli/opensipscli/main.py", line 78, in main
sys.exit(shell.cmdloop())
File "/home/liviu/src/opensips-cli/opensipscli/cli.py", line 232, in cmdloop
super(OpenSIPSCLIShell, self).cmdloop(intro='')
File "/usr/lib/python3.6/cmd.py", line 138, in cmdloop
stop = self.onecmd(line)
File "/usr/lib/python3.6/cmd.py", line 216, in onecmd
return self.default(line)
File "/home/liviu/src/opensips-cli/opensipscli/cli.py", line 342, in default
self.run_command(module, cmd, params)
File "/home/liviu/src/opensips-cli/opensipscli/cli.py", line 331, in run_command
return mod[0].__invoke__(cmd, params)
File "/home/liviu/src/opensips-cli/opensipscli/module.py", line 36, in __invoke__
return f(params)
File "/home/liviu/src/opensips-cli/opensipscli/modules/database.py", line 692, in do_migrate
self.do_create(db, new_db)
TypeError: do_create() takes from 1 to 2 positional arguments but 3 were given
Just to avoid any confusion: database migrate
is currently only meant to work for MySQL opensips 2.4 databases.
Database Integration
rebased on the the lastes git, opensips-cli doesn't support the postgresql backend out of the box. To create an 'opensips' database, an administrator has to asure, that a role will grant enought rights to a database user, that can login to the database and handle the needed administrative tasks. That of course includes transaction based tasks.
PostgreSQL specific
PostgreSQL is using the 'role' concept. Thus, it will assign a 'role' object, that will hold assinged rights. A role can inherit rights to other roles .... Since a role is an abstract object, it is consumed as a global definition, as a group or as a user. If a database user should be allowed to login, that user is assingend to a role, that inherits the right 'LOGIN'. The attached patchset will introduce all methods, that are needed to implement and handle roles. That can be consumed by a opensips user.
It should be noted, that the role The database.md has been enhanced as needed.
Tests
I did following test, in interactive and in scripting mode:
create_role: create new role
get_role: list role attributes
alter_role: change role attributes of an existing role
drop_role: remove an existing role (only possible if not assigned to any database)
create: create new database
(flow: create the db, create the role, assign/grant rights to the db, create tables)
drop: drop an existing database (flow: drop db including all tables, drop role)
opensips-cli documentation
while digging into the code, i have adapted the inline documentation, to be more in line with the python style.
please feel free to validate and incorporate into the project
Ralf