diff options
author | James Yang <jjyang@mcs.anl.gov> | 2009-07-07 16:48:46 +0000 |
---|---|---|
committer | James Yang <jjyang@mcs.anl.gov> | 2009-07-07 16:48:46 +0000 |
commit | 5fdcc21d2d3a3bd0340b3393ac41443060c14fec (patch) | |
tree | c7d92ab5b6cf5a60591fc07805229f224bb2f3c1 | |
parent | 429fae8a7c1fa9d56c1f7eca163ef5a7b9eae92b (diff) | |
download | bcfg2-5fdcc21d2d3a3bd0340b3393ac41443060c14fec.tar.gz bcfg2-5fdcc21d2d3a3bd0340b3393ac41443060c14fec.tar.bz2 bcfg2-5fdcc21d2d3a3bd0340b3393ac41443060c14fec.zip |
Added Bundle and Group for bcfg2-admin.
git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@5313 ce84e21b-d406-0410-9b95-82705330c041
-rw-r--r-- | src/lib/Server/Admin/Bundle.py | 33 | ||||
-rw-r--r-- | src/lib/Server/Admin/Group.py | 66 |
2 files changed, 99 insertions, 0 deletions
diff --git a/src/lib/Server/Admin/Bundle.py b/src/lib/Server/Admin/Bundle.py new file mode 100644 index 000000000..b9d26758a --- /dev/null +++ b/src/lib/Server/Admin/Bundle.py @@ -0,0 +1,33 @@ +import Bcfg2.Server.Admin +from Bcfg2.Server.Plugins.Metadata import MetadataConsistencyError + +class Bundle(Bcfg2.Server.Admin.MetadataCore): + __shorthelp__ = "Create or delete bundle entries" + __longhelp__ = (__shorthelp__ + "\n\nbcfg2-admin bundle add <bundle> " + "bcfg2-admin bundle del <bundle>") + __usage__ = ("bcfg2-admin bundle [options] [add|del] [group]") + + def __init__(self, configfile): + Bcfg2.Server.Admin.MetadataCore.__init__(self, configfile, + self.__usage__) + + def __call__(self, args): + Bcfg2.Server.Admin.MetadataCore.__call__(self, args) + if len(args) == 0: + self.errExit("No argument specified.\n" + "Please see bcfg2-admin bundle help for usage.") + if args[0] == 'add': + try: + self.metadata.add_bundle(args[1]) + except MetadataConsistencyError: + print "Error in adding bundle" + raise SystemExit(1) + elif args[0] in ['delete', 'remove', 'del', 'rm']: + try: + self.metadata.remove_bundle(args[1]) + except MetadataConsistencyError: + print "Error in deleting bundle" + raise SystemExit(1) + else: + print "No command specified" + raise SystemExit(1) diff --git a/src/lib/Server/Admin/Group.py b/src/lib/Server/Admin/Group.py new file mode 100644 index 000000000..c9619d534 --- /dev/null +++ b/src/lib/Server/Admin/Group.py @@ -0,0 +1,66 @@ +import lxml.etree +import Bcfg2.Server.Admin +from Bcfg2.Server.Plugins.Metadata import MetadataConsistencyError + +class Group(Bcfg2.Server.Admin.MetadataCore): + __shorthelp__ = "Create, delete, or modify group entries" + __longhelp__ = (__shorthelp__ + "\n\nbcfg2-admin group add <group> " + "attr1=val1 attr2=val2\n" + "\n\nbcfg2-admin group update <group> " + "attr1=val1 attr2=val2\n" + "\n\nbcfg2-admin group list\n" + "bcfg2-admin group del <group>") + __usage__ = ("bcfg2-admin group [options] [add|del|update|list] [attr=val]") + + def __init__(self, configfile): + Bcfg2.Server.Admin.MetadataCore.__init__(self, configfile, + self.__usage__) + + def __call__(self, args): + Bcfg2.Server.Admin.MetadataCore.__call__(self, args) + if len(args) == 0: + self.errExit("No argument specified.\n" + "Please see bcfg2-admin group help for usage.") + if args[0] == 'add': + attr_d = {} + for i in args[2:]: + attr, val = i.split('=', 1) + if attr not in ['profile', 'public', 'default', + 'name', 'auth', 'toolset', 'category', + 'comment']: + print "Attribute %s unknown" % attr + raise SystemExit(1) + attr_d[attr] = val + try: + self.metadata.add_group(args[1], attr_d) + except MetadataConsistencyError: + print "Error in adding group" + raise SystemExit(1) + elif args[0] in ['update', 'up']: + attr_d = {} + for i in args[2:]: + attr, val = i.split('=', 1) + if attr not in ['profile', 'public', 'default', + 'name', 'auth', 'toolset', 'category', + 'comment']: + print "Attribute %s unknown" % attr + raise SystemExit(1) + attr_d[attr] = val + try: + self.metadata.update_group(args[1], attr_d) + except MetadataConsistencyError: + print "Error in updating group" + raise SystemExit(1) + elif args[0] in ['delete', 'remove', 'del', 'rm']: + try: + self.metadata.remove_group(args[1]) + except MetadataConsistencyError: + print "Error in deleting group" + raise SystemExit(1) + elif args[0] in ['list', 'ls']: + tree = lxml.etree.parse(self.metadata.data + "/groups.xml") + for node in tree.findall("//Group"): + print node.attrib["name"] + else: + print "No command specified" + raise SystemExit(1) |