summaryrefslogtreecommitdiffstats
path: root/src/lib/Server/Admin/Init.py
diff options
context:
space:
mode:
authorSol Jerome <solj@ices.utexas.edu>2009-02-19 23:04:22 +0000
committerSol Jerome <solj@ices.utexas.edu>2009-02-19 23:04:22 +0000
commit202a3aec707802a85bbf5bfbf82e86a0317c2bbb (patch)
tree6b8b8a3b71bf1a583ea4d86696db1e07e445aeaa /src/lib/Server/Admin/Init.py
parentae82b3a118862bcc10f3d4ad01518e6328f31677 (diff)
downloadbcfg2-202a3aec707802a85bbf5bfbf82e86a0317c2bbb.tar.gz
bcfg2-202a3aec707802a85bbf5bfbf82e86a0317c2bbb.tar.bz2
bcfg2-202a3aec707802a85bbf5bfbf82e86a0317c2bbb.zip
Ask before overwriting existing bcfg2 repos in bcfg2-admin init
Signed-off-by: Sol Jerome <solj@ices.utexas.edu> git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@5087 ce84e21b-d406-0410-9b95-82705330c041
Diffstat (limited to 'src/lib/Server/Admin/Init.py')
-rw-r--r--src/lib/Server/Admin/Init.py52
1 files changed, 30 insertions, 22 deletions
diff --git a/src/lib/Server/Admin/Init.py b/src/lib/Server/Admin/Init.py
index 5c969bee9..8f31b5cf1 100644
--- a/src/lib/Server/Admin/Init.py
+++ b/src/lib/Server/Admin/Init.py
@@ -87,6 +87,7 @@ class Init(Bcfg2.Server.Admin.Mode):
Bcfg2.Server.Admin.Mode.__call__(self, args)
opts = Bcfg2.Options.OptionParser(self.options)
opts.parse([])
+ self.response = ""
# FIXME don't overwrite existing bcfg2.conf file
configfile = raw_input("Store bcfg2 configuration in [%s]: " %
@@ -94,10 +95,13 @@ class Init(Bcfg2.Server.Admin.Mode):
if configfile == '':
configfile = opts['configfile']
- repopath = raw_input("Location of bcfg2 repository [%s]: " %
+ self.repopath = raw_input("Location of bcfg2 repository [%s]: " %
opts['repo'])
- if repopath == '':
- repopath = opts['repo']
+ if self.repopath == '':
+ self.repopath = opts['repo']
+ if os.path.isdir(self.repopath):
+ self.response = raw_input("Directory %s exists. Overwrite? [Y/n]:"\
+ % self.repopath)
password = getpass.getpass(
"Input password used for communication verification "
@@ -116,9 +120,8 @@ class Init(Bcfg2.Server.Admin.Mode):
prompt += "%d: %s\n" % (os_list.index(entry) + 1, entry[0])
prompt += ': '
os_sel = os_list[int(raw_input(prompt))-1][1]
- self.initializeRepo(configfile, repopath, server,
+ self.initializeRepo(configfile, self.repopath, server,
password, os_sel, opts)
- print "Repository created successfuly in %s" % (repopath)
def genPassword(self):
chars = string.letters + string.digits
@@ -152,20 +155,25 @@ class Init(Bcfg2.Server.Admin.Mode):
except:
pass
- # FIXME don't overwrite existing directory/repo?
- # 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())
+ # Overwrite existing directory/repo?
+ if self.response == "n":
+ print "Kept old repository in %s" % (self.repopath)
+ 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())
+ print "Repository created successfuly in %s" % (self.repopath)