From fd604fcd93d2e933e48ea37463a0f4f8697c6a75 Mon Sep 17 00:00:00 2001 From: "saikrishna1511@gmail.com" Date: Tue, 19 Apr 2011 18:21:36 +0530 Subject: Management files except for add/delete user from group --- management/delgroup.py | 39 ++++++++++++++++++++++++++++++++++++ management/getgroup.py | 40 ++++++++++++++++++++++++++++++++++++ management/getgroups.py | 40 ++++++++++++++++++++++++++++++++++++ management/getgroupusers.py | 42 ++++++++++++++++++++++++++++++++++++++ management/getuser.py | 40 ++++++++++++++++++++++++++++++++++++ management/getusergroups.py | 42 ++++++++++++++++++++++++++++++++++++++ management/getusers.py | 42 ++++++++++++++++++++++++++++++++++++++ management/groupadd.py | 42 ++++++++++++++++++++++++++++++++++++++ management/setuserlock.py | 49 +++++++++++++++++++++++++++++++++++++++++++++ management/setuserpswd.py | 41 +++++++++++++++++++++++++++++++++++++ management/updategroup.py | 41 +++++++++++++++++++++++++++++++++++++ management/userupdate.py | 39 ++++++++++++++++++++++++++++++++++++ 12 files changed, 497 insertions(+) create mode 100644 management/delgroup.py create mode 100644 management/getgroup.py create mode 100644 management/getgroups.py create mode 100644 management/getgroupusers.py create mode 100644 management/getuser.py create mode 100644 management/getusergroups.py create mode 100644 management/getusers.py create mode 100644 management/groupadd.py create mode 100644 management/setuserlock.py create mode 100644 management/setuserpswd.py create mode 100644 management/updategroup.py create mode 100644 management/userupdate.py diff --git a/management/delgroup.py b/management/delgroup.py new file mode 100644 index 00000000..df94f846 --- /dev/null +++ b/management/delgroup.py @@ -0,0 +1,39 @@ +# Copyright (c) 2010-2011 OpenStack, LLC. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import optparse +import os +import sqlite3 + + +def main(): + usage = "usage: %prog group_id" + parser = optparse.OptionParser(usage) + options, args = parser.parse_args() + if len(args) != 1: + parser.error("Incorrect number of arguments") + else: + group_id = args[0] + dbpath = os.path.abspath( + os.path.join(os.path.dirname(__file__),'../db/keystone.db')) + con = sqlite3.connect(dbpath) + cur = con.cursor() + cur.execute( + "DELETE FROM groups WHERE group_id='%s'" % group_id) + con.commit() + con.close() + +if __name__ == '__main__': + main() diff --git a/management/getgroup.py b/management/getgroup.py new file mode 100644 index 00000000..3cea4891 --- /dev/null +++ b/management/getgroup.py @@ -0,0 +1,40 @@ +# Copyright (c) 2010-2011 OpenStack, LLC. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import optparse +import os +import sqlite3 + +def main(): + usage = "usage: %prog group_id" + parser = optparse.OptionParser(usage) + options, args = parser.parse_args() + if len(args) != 1: + parser.error("Incorrect number of arguments") + else: + user_id = args[0] + + dbpath = os.path.abspath( + os.path.join(os.path.dirname(__file__),'../db/keystone.db')) + con = sqlite3.connect(dbpath) + cur = con.cursor() + cur.execute( + "select * from groups where group_id = '%s' " % (group_id)) + con.commit() + print cur.fetchall() + con.close() + +if __name__ == '__main__': + main() diff --git a/management/getgroups.py b/management/getgroups.py new file mode 100644 index 00000000..ae7b1a3d --- /dev/null +++ b/management/getgroups.py @@ -0,0 +1,40 @@ +# Copyright (c) 2010-2011 OpenStack, LLC. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import optparse +import os +import sqlite3 + +def main(): + usage = "usage: %prog " + parser = optparse.OptionParser(usage) + options, args = parser.parse_args() + if len(args) != 0: + parser.error("Incorrect number of arguments") + else: + #tenant_id = args[0] + + dbpath = os.path.abspath( + os.path.join(os.path.dirname(__file__),'../db/keystone.db')) + con = sqlite3.connect(dbpath) + cur = con.cursor() + cur.execute( + "select * from groups where tenant_id = ''") + con.commit() + print cur.fetchall() + con.close() + +if __name__ == '__main__': + main() diff --git a/management/getgroupusers.py b/management/getgroupusers.py new file mode 100644 index 00000000..b22683b1 --- /dev/null +++ b/management/getgroupusers.py @@ -0,0 +1,42 @@ +# Copyright (c) 2010-2011 OpenStack, LLC. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import optparse +import os +import sqlite3 + +def main(): + usage = "usage: %prog group_id" + parser = optparse.OptionParser(usage) + options, args = parser.parse_args() + if len(args) != 1: + parser.error("Incorrect number of arguments") + else: + group_id = args[0] + + dbpath = os.path.abspath( + os.path.join(os.path.dirname(__file__),'../db/keystone.db')) + con = sqlite3.connect(dbpath) + cur = con.cursor() + cur.execute( + "select u.* from users u inner join user-group ug on + u.username = ug.user_id where ug.group_id = '%s' " % (group_id) + ) + con.commit() + print cur.fetchall() + con.close() + +if __name__ == '__main__': + main() diff --git a/management/getuser.py b/management/getuser.py new file mode 100644 index 00000000..159ce688 --- /dev/null +++ b/management/getuser.py @@ -0,0 +1,40 @@ +# Copyright (c) 2010-2011 OpenStack, LLC. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import optparse +import os +import sqlite3 + +def main(): + usage = "usage: %prog username" + parser = optparse.OptionParser(usage) + options, args = parser.parse_args() + if len(args) != 1: + parser.error("Incorrect number of arguments") + else: + user_id = args[0] + + dbpath = os.path.abspath( + os.path.join(os.path.dirname(__file__),'../db/keystone.db')) + con = sqlite3.connect(dbpath) + cur = con.cursor() + cur.execute( + "select * from users where ut.username = '%s' " % (user_id)) + con.commit() + print cur.fetchall() + con.close() + +if __name__ == '__main__': + main() diff --git a/management/getusergroups.py b/management/getusergroups.py new file mode 100644 index 00000000..38e2f980 --- /dev/null +++ b/management/getusergroups.py @@ -0,0 +1,42 @@ +# Copyright (c) 2010-2011 OpenStack, LLC. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import optparse +import os +import sqlite3 + +def main(): + usage = "usage: %prog user_id" + parser = optparse.OptionParser(usage) + options, args = parser.parse_args() + if len(args) != 1: + parser.error("Incorrect number of arguments") + else: + user_id = args[0] + + dbpath = os.path.abspath( + os.path.join(os.path.dirname(__file__),'../db/keystone.db')) + con = sqlite3.connect(dbpath) + cur = con.cursor() + cur.execute( + "select g.* from groups g inner join user-group ug on + g.group_id = ug.group_id where ug.user_id = '%s' " % (user_id) + ) + con.commit() + print cur.fetchall() + con.close() + +if __name__ == '__main__': + main() diff --git a/management/getusers.py b/management/getusers.py new file mode 100644 index 00000000..f333d169 --- /dev/null +++ b/management/getusers.py @@ -0,0 +1,42 @@ +# Copyright (c) 2010-2011 OpenStack, LLC. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import optparse +import os +import sqlite3 + +def main(): + usage = "usage: %prog tenant_id" + parser = optparse.OptionParser(usage) + options, args = parser.parse_args() + if len(args) != 1: + parser.error("Incorrect number of arguments") + else: + tenant_id = args[0] + + dbpath = os.path.abspath( + os.path.join(os.path.dirname(__file__),'../db/keystone.db')) + con = sqlite3.connect(dbpath) + cur = con.cursor() + cur.execute( + "select u.* from users u inner join user-tenants ut on + u.username = ut.user_id where ut.tenant_id = '%s' " % (tenant_id) + ) + con.commit() + print cur.fetchall() + con.close() + +if __name__ == '__main__': + main() diff --git a/management/groupadd.py b/management/groupadd.py new file mode 100644 index 00000000..4ba3edb9 --- /dev/null +++ b/management/groupadd.py @@ -0,0 +1,42 @@ +# Copyright (c) 2010-2011 OpenStack, LLC. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import optparse +import os +import sqlite3 + +def main(): + usage = "usage: %prog group_id group_desc" + parser = optparse.OptionParser(usage) + options, args = parser.parse_args() + if len(args) != 2: + parser.error("Incorrect number of arguments") + else: + group_id = args[0] + group_desc = args[1] + dbpath = os.path.abspath( + os.path.join(os.path.dirname(__file__),'../db/keystone.db')) + con = sqlite3.connect(dbpath) + cur = con.cursor() + cur.execute( + "INSERT INTO groups ('group_id','group_desc','tenant_id') + VALUES ('%s', '%s','')" % (group_id, group_desc) + ) + + con.commit() + con.close() + +if __name__ == '__main__': + main() diff --git a/management/setuserlock.py b/management/setuserlock.py new file mode 100644 index 00000000..68af9429 --- /dev/null +++ b/management/setuserlock.py @@ -0,0 +1,49 @@ +# Copyright (c) 2010-2011 OpenStack, LLC. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import optparse +import os +import sqlite3 + +def main(): + usage = "usage: %prog username enabled" + parser = optparse.OptionParser(usage) + options, args = parser.parse_args() + if len(args) != 2: + parser.error("Incorrect number of arguments") + else: + username = args[0] + enabled = args[1].capitalize().strip() + + if enabled == 'True' or enabled == '1' : + enabled=1 + elif enabled == 'False' or enabled == '0' : + enabled=0 + else: + parser.error("Incorrect arguments value") + + dbpath = os.path.abspath( + os.path.join(os.path.dirname(__file__),'../db/keystone.db')) + con = sqlite3.connect(dbpath) + cur = con.cursor() + cur.execute( + "UPDATE users SET enabled = '%d' where username ='%s'" + % (enabled,username) + ) + con.commit() + con.close() + +if __name__ == '__main__': + main() diff --git a/management/setuserpswd.py b/management/setuserpswd.py new file mode 100644 index 00000000..62bb9c05 --- /dev/null +++ b/management/setuserpswd.py @@ -0,0 +1,41 @@ +# Copyright (c) 2010-2011 OpenStack, LLC. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import optparse +import os +import sqlite3 + +def main(): + usage = "usage: %prog username password" + parser = optparse.OptionParser(usage) + options, args = parser.parse_args() + if len(args) != 2: + parser.error("Incorrect number of arguments") + else: + username = args[0] + password = args[1] + dbpath = os.path.abspath( + os.path.join(os.path.dirname(__file__),'../db/keystone.db')) + con = sqlite3.connect(dbpath) + cur = con.cursor() + cur.execute( + "UPDATE users SET password = '%s' where username ='%s'" + % (password,username) + ) + con.commit() + con.close() + +if __name__ == '__main__': + main() diff --git a/management/updategroup.py b/management/updategroup.py new file mode 100644 index 00000000..e29387e1 --- /dev/null +++ b/management/updategroup.py @@ -0,0 +1,41 @@ +# Copyright (c) 2010-2011 OpenStack, LLC. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import optparse +import os +import sqlite3 + +def main(): + usage = "usage: %prog group_id group_desc" + parser = optparse.OptionParser(usage) + options, args = parser.parse_args() + if len(args) != 2: + parser.error("Incorrect number of arguments") + else: + group_id = args[0] + group_desc = args[1] + dbpath = os.path.abspath( + os.path.join(os.path.dirname(__file__),'../db/keystone.db')) + con = sqlite3.connect(dbpath) + cur = con.cursor() + cur.execute( + "update groups set group_desc = '%s' where group_id = '%s')" + % (group_desc,group_id) + ) + con.commit() + con.close() + +if __name__ == '__main__': + main() diff --git a/management/userupdate.py b/management/userupdate.py new file mode 100644 index 00000000..099c8900 --- /dev/null +++ b/management/userupdate.py @@ -0,0 +1,39 @@ +# Copyright (c) 2010-2011 OpenStack, LLC. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import optparse +import os +import sqlite3 + +def main(): + usage = "usage: %prog username email" + parser = optparse.OptionParser(usage) + options, args = parser.parse_args() + if len(args) != 2: + parser.error("Incorrect number of arguments") + else: + username = args[0] + email = args[1] + dbpath = os.path.abspath( + os.path.join(os.path.dirname(__file__),'../db/keystone.db')) + con = sqlite3.connect(dbpath) + cur = con.cursor() + cur.execute( + "update users set email = '%s' where username = '%s')" % (email,username)) + con.commit() + con.close() + +if __name__ == '__main__': + main() -- cgit