1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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)
|