summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/lib/Server/Admin/Init.py60
-rw-r--r--src/lib/Server/Plugin.py11
-rw-r--r--src/lib/Server/Plugins/Metadata.py30
3 files changed, 86 insertions, 15 deletions
diff --git a/src/lib/Server/Admin/Init.py b/src/lib/Server/Admin/Init.py
index eddbb0b43..0930fa1f3 100644
--- a/src/lib/Server/Admin/Init.py
+++ b/src/lib/Server/Admin/Init.py
@@ -5,8 +5,16 @@ import socket
import string
import subprocess
import Bcfg2.Server.Admin
+import Bcfg2.Server.Plugin
import Bcfg2.Options
+from Bcfg2.Server.Plugins import (Account, Base, Bundler, Cfg,
+ Decisions, Deps, Metadata,
+ Packages, Pkgmgr, Probes,
+ Properties, Rules, Snapshots,
+ SSHbase, Svcmgr, TCheetah,
+ TGenshi)
+
# default config file
config = '''
[server]
@@ -171,19 +179,41 @@ class Init(Bcfg2.Server.Admin.Mode):
return
else:
# FIXME repo creation may fail as non-root user
- for subdir in ['SSHbase', 'Cfg', 'Pkgmgr', 'Rules',
- 'etc', 'Metadata', 'Base', 'Bundler']:
- path = "%s/%s" % (repo, subdir)
- newpath = ''
- for subdir in path.split('/'):
- newpath = newpath + subdir + '/'
- try:
- os.mkdir(newpath)
- except:
- continue
-
- open("%s/Metadata/groups.xml" %
- repo, "w").write(groups % os_selection)
- open("%s/Metadata/clients.xml" %
- repo, "w").write(clients % socket.getfqdn())
+ plug_list = ['Account', 'Base', 'Bundler', 'Cfg',
+ 'Decisions', 'Deps', 'Metadata', 'Packages',
+ 'Pkgmgr', 'Probes', 'Properties', 'Rules',
+ 'Snapshots', 'SSHbase', 'Statistics', 'Svcmgr',
+ 'TCheetah', 'TGenshi']
+ default_repo = ['SSHbase', 'Cfg', 'Pkgmgr', 'Rules',
+ 'Metadata', 'Base', 'Bundler']
+ plugins = []
+ print 'Repository configuration, choose plugins:'
+ default = raw_input("Use default plugins? [Y/n]: ").lower()
+ if default == 'y' or default == '':
+ plugins = default_repo
+ else:
+ while True:
+ plugins_are_valid = True
+ plug_str = raw_input("Specify plugins: ")
+ plugins = plug_str.split(',')
+ for plugin in plugins:
+ plugin = plugin.strip()
+ if not plugin in plug_list:
+ plugins_are_valid = False
+ print "ERROR: plugin %s not recognized" % plugin
+ if plugins_are_valid:
+ break
+
+ path = "%s/%s" % (repo, 'etc')
+ newpath = ''
+ for subdir in path.split('/'):
+ newpath = newpath + subdir + '/'
+ try:
+ os.mkdir(newpath)
+ except:
+ continue
+
+ for plugin in plugins:
+ getattr(getattr(getattr(Bcfg2.Server.Plugins, plugin), plugin), 'init_repo')(repo)
+
print "Repository created successfuly in %s" % (self.repopath)
diff --git a/src/lib/Server/Plugin.py b/src/lib/Server/Plugin.py
index 4484a655b..f0cbaa693 100644
--- a/src/lib/Server/Plugin.py
+++ b/src/lib/Server/Plugin.py
@@ -48,6 +48,17 @@ class Plugin(object):
self.core = core
self.data = "%s/%s" % (datastore, self.name)
self.logger = logging.getLogger('Bcfg2.Plugins.%s' % (self.name))
+
+ @classmethod
+ def init_repo(self, repo):
+ path = "%s/%s" % (repo, self.name)
+ newpath = ''
+ for subdir in path.split('/'):
+ newpath = newpath + subdir + '/'
+ try:
+ os.mkdir(newpath)
+ except:
+ return
class Generator(object):
'''Generator plugins contribute to literal client configurations'''
diff --git a/src/lib/Server/Plugins/Metadata.py b/src/lib/Server/Plugins/Metadata.py
index 29c64984a..df6e571e0 100644
--- a/src/lib/Server/Plugins/Metadata.py
+++ b/src/lib/Server/Plugins/Metadata.py
@@ -99,6 +99,14 @@ class Metadata(Bcfg2.Server.Plugin.Plugin,
self.get_client_names_by_profiles,
self.get_all_group_names)
+ @classmethod
+ def init_repo(self, repo):
+ Bcfg2.Server.Plugin.init_repo(repo)
+ open("%s/Metadata/groups.xml" %
+ repo, "w").write(groups % os_selection)
+ open("%s/Metadata/clients.xml" %
+ repo, "w").write(clients % socket.getfqdn())
+
def get_groups(self):
'''return groups xml tree'''
groups_tree = lxml.etree.parse(self.data + "/groups.xml")
@@ -162,6 +170,28 @@ class Metadata(Bcfg2.Server.Plugin.Plugin,
fcntl.lockf(fd, fcntl.LOCK_UN)
client_tree.close()
+ def update_client(self, client_name, attribs):
+ '''Update a client's attributes'''
+ tree = lxml.etree.parse(self.data + "/clients.xml")
+ root = tree.getroot()
+ node = self.search_client(client_name, tree)
+ if node == None:
+ self.logger.error("Client \"%s\" not found" % (client_name))
+ raise MetadataConsistencyError
+ node.attrib.update(attribs)
+ client_tree = open(self.data + "/clients.xml","w")
+ fd = client_tree.fileno()
+ while True:
+ try:
+ fcntl.lockf(fd, fcntl.LOCK_EX | fcntl.LOCK_NB)
+ except IOError:
+ continue
+ else:
+ break
+ tree.write(client_tree)
+ fcntl.lockf(fd, fcntl.LOCK_UN)
+ client_tree.close()
+
def HandleEvent(self, event):
'''Handle update events for data files'''
filename = event.filename.split('/')[-1]