summaryrefslogtreecommitdiffstats
path: root/src/lib/Server/Admin/Init.py
diff options
context:
space:
mode:
authorNarayan Desai <desai@mcs.anl.gov>2007-12-29 04:57:53 +0000
committerNarayan Desai <desai@mcs.anl.gov>2007-12-29 04:57:53 +0000
commit3610288cbcbf4d1adedefa03166cd77ee15aad96 (patch)
tree1588fb78ae1c6e51e4e4ea2dab46a006a3ece0d3 /src/lib/Server/Admin/Init.py
parent6bf7875bc299a1f81061782c8646c90972e06e5a (diff)
downloadbcfg2-3610288cbcbf4d1adedefa03166cd77ee15aad96.tar.gz
bcfg2-3610288cbcbf4d1adedefa03166cd77ee15aad96.tar.bz2
bcfg2-3610288cbcbf4d1adedefa03166cd77ee15aad96.zip
Refactor of bcfg2-admin (all modes moved to discrete modules in Bcfg2.Server.Admin
git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@4125 ce84e21b-d406-0410-9b95-82705330c041
Diffstat (limited to 'src/lib/Server/Admin/Init.py')
-rw-r--r--src/lib/Server/Admin/Init.py119
1 files changed, 119 insertions, 0 deletions
diff --git a/src/lib/Server/Admin/Init.py b/src/lib/Server/Admin/Init.py
new file mode 100644
index 000000000..01bede88e
--- /dev/null
+++ b/src/lib/Server/Admin/Init.py
@@ -0,0 +1,119 @@
+import os, socket
+import Bcfg2.Server.Admin
+
+config = '''
+[server]
+repository = %s
+structures = Bundler,Base
+generators = SSHbase,Cfg,Pkgmgr,Rules
+
+[statistics]
+sendmailpath = /usr/sbin/sendmail
+database_engine = sqlite3
+# 'postgresql', 'mysql', 'mysql_old', 'sqlite3' or 'ado_mssql'.
+database_name =
+# Or path to database file if using sqlite3.
+#<repository>/etc/brpt.sqlite is default path if left empty
+database_user =
+# Not used with sqlite3.
+database_password =
+# Not used with sqlite3.
+database_host =
+# Not used with sqlite3.
+database_port =
+# Set to empty string for default. Not used with sqlite3.
+web_debug = True
+
+
+[communication]
+protocol = xmlrpc/ssl
+password = %s
+key = %s/bcfg2.key
+
+[components]
+bcfg2 = %s
+'''
+
+groups = '''
+<Groups version='3.0'>
+ <Group profile='true' public='false' default='true' name='basic'>
+ <Group name='%s'/>
+ </Group>
+ <Group name='ubuntu'/>
+ <Group name='debian'/>
+ <Group name='freebsd'/>
+ <Group name='gentoo'/>
+ <Group name='redhat'/>
+ <Group name='suse'/>
+ <Group name='mandrake'/>
+ <Group name='solaris'/>
+</Groups>
+'''
+clients = '''
+<Clients version="3.0">
+ <Client profile="basic" pingable="Y" pingtime="0" name="%s"/>
+</Clients>
+'''
+
+os_list = [('Redhat/Fedora/RHEL/RHAS/Centos', 'redhat'),
+ ('SUSE/SLES', 'suse'),
+ ('Mandrake', 'mandrake'),
+ ('Debian', 'debian'),
+ ('Ubuntu', 'ubuntu'),
+ ('Gentoo', 'gentoo'),
+ ('FreeBSD', 'freebsd')]
+
+
+class Init(Bcfg2.Server.Admin.Mode):
+ __shorthelp__ = 'bcfg2-admin init'
+ __longhelp__ = __shorthelp__ + '\n\tCompare two client specifications or directories of specifications'
+ def __call__(self, args):
+ Bcfg2.Server.Admin.Mode.__call__(self, args)
+ repopath = raw_input( "location of bcfg2 repository [/var/lib/bcfg2]: " )
+ if repopath == '':
+ repopath = '/var/lib/bcfg2'
+ password = ''
+ while ( password == '' ):
+ password = raw_input(
+ "Input password used for communication verification: " )
+ server = "https://%s:6789" % socket.getfqdn()
+ rs = raw_input( "Input the server location [%s]: " % server)
+ if rs:
+ server = rs
+ #create the groups.xml file
+ prompt = '''Input base Operating System for clients:\n'''
+ for entry in os_list:
+ prompt += "%d: \n" % (os_list.index(entry) + 1, entry[0])
+ prompt += ': '
+ os_sel = os_list[int(raw_input(prompt))-1][1]
+ self.initializeRepo(repopath, server, password, os_sel)
+ print "Repository created successfuly in %s" % (repopath)
+
+ def initializeRepo(self, repo, server_uri, password, os_selection):
+ '''Setup a new repo'''
+ keypath = os.path.dirname(os.path.abspath(self.configfile))
+ confdata = config % ( repo, password, keypath, server_uri )
+ open(self.configfile,"w").write(confdata)
+ # FIXME automate ssl key generation
+ os.popen('openssl req -x509 -nodes -days 1000 -newkey rsa:1024 -out %s/bcfg2.key -keyout %s/bcfg2.key' % (keypath, keypath))
+ try:
+ os.chmod('%s/bcfg2.key'% keypath,'0600')
+ except:
+ pass
+
+ 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)
+ #now the clients file
+ open("%s/Metadata/clients.xml"%repo, "w").write(clients % socket.getfqdn())
+
+