diff options
Diffstat (limited to 'src/lib/Server/Admin')
-rw-r--r-- | src/lib/Server/Admin/Init.py | 19 | ||||
-rw-r--r-- | src/lib/Server/Admin/Viz.py | 36 |
2 files changed, 33 insertions, 22 deletions
diff --git a/src/lib/Server/Admin/Init.py b/src/lib/Server/Admin/Init.py index 8f31b5cf1..af307ec4e 100644 --- a/src/lib/Server/Admin/Init.py +++ b/src/lib/Server/Admin/Init.py @@ -1,4 +1,9 @@ -import getpass, os, random, socket, string +import getpass +import os +import random +import socket +import string +import subprocess import Bcfg2.Server.Admin import Bcfg2.Options @@ -130,7 +135,8 @@ class Init(Bcfg2.Server.Admin.Mode): newpasswd = newpasswd + random.choice(chars) return newpasswd - def initializeRepo(self, configfile, repo, server_uri, password, os_selection, opts): + def initializeRepo(self, configfile, repo, server_uri, + password, os_selection, opts): '''Setup a new repo''' keypath = os.path.dirname(os.path.abspath(configfile)) @@ -149,7 +155,10 @@ class Init(Bcfg2.Server.Admin.Mode): # FIXME automate ssl key generation # FIXME key generation may fail as non-root user - os.popen('openssl req -x509 -nodes -days 1000 -newkey rsa:1024 -out %s/bcfg2.key -keyout %s/bcfg2.key' % (keypath, keypath)) + subprocess.call(("openssl " \ + "req -x509 -nodes -days 1000 -newkey rsa:1024 " \ + "-out %s/bcfg2.key -keyout %s/bcfg2.key" % \ + (keypath, keypath)), shell=True) try: os.chmod('%s/bcfg2.key'% keypath, 0600) except: @@ -161,8 +170,8 @@ 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']: + for subdir in ['SSHbase', 'Cfg', 'Pkgmgr', 'Rules', + 'etc', 'Metadata', 'Base', 'Bundler']: path = "%s/%s" % (repo, subdir) newpath = '' for subdir in path.split('/'): diff --git a/src/lib/Server/Admin/Viz.py b/src/lib/Server/Admin/Viz.py index 0a5a8b9d6..f973e90c5 100644 --- a/src/lib/Server/Admin/Viz.py +++ b/src/lib/Server/Admin/Viz.py @@ -1,4 +1,5 @@ -import getopt, popen2 +import getopt +from subprocess import Popen, PIPE import Bcfg2.Server.Admin class Viz(Bcfg2.Server.Admin.MetadataCore): @@ -71,25 +72,26 @@ class Viz(Bcfg2.Server.Admin.MetadataCore): cmd = "dot -Tpng" if output: cmd += " -o %s" % output - dotpipe = popen2.Popen4(cmd) + dotpipe = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE, + stdout=subprocess.PIPE, close_fds=True) try: - dotpipe.tochild.write("digraph groups {\n") + dotpipe.stdin.write("digraph groups {\n") except: print "write to dot process failed. Is graphviz installed?" raise SystemExit(1) - dotpipe.tochild.write('\trankdir="LR";\n') - dotpipe.tochild.write(self.metadata.viz(hosts, bundles, + dotpipe.stdin.write('\trankdir="LR";\n') + dotpipe.stdin.write(self.metadata.viz(hosts, bundles, key, self.colors)) if key: - dotpipe.tochild.write("\tsubgraph cluster_key {\n") - dotpipe.tochild.write('''\tstyle="filled";\n''') - dotpipe.tochild.write('''\tcolor="lightblue";\n''') - dotpipe.tochild.write('''\tBundle [ shape="septagon" ];\n''') - dotpipe.tochild.write('''\tGroup [shape="ellipse"];\n''') - dotpipe.tochild.write('''\tProfile [style="bold", shape="ellipse"];\n''') - dotpipe.tochild.write('''\tHblock [label="Host1|Host2|Host3", shape="record"];\n''') - dotpipe.tochild.write('''\tlabel="Key";\n''') - dotpipe.tochild.write("\t}\n") - dotpipe.tochild.write("}\n") - dotpipe.tochild.close() - return dotpipe.fromchild.read() + dotpipe.stdin.write("\tsubgraph cluster_key {\n") + dotpipe.stdin.write('''\tstyle="filled";\n''') + dotpipe.stdin.write('''\tcolor="lightblue";\n''') + dotpipe.stdin.write('''\tBundle [ shape="septagon" ];\n''') + dotpipe.stdin.write('''\tGroup [shape="ellipse"];\n''') + dotpipe.stdin.write('''\tProfile [style="bold", shape="ellipse"];\n''') + dotpipe.stdin.write('''\tHblock [label="Host1|Host2|Host3", shape="record"];\n''') + dotpipe.stdin.write('''\tlabel="Key";\n''') + dotpipe.stdin.write("\t}\n") + dotpipe.stdin.write("}\n") + dotpipe.stdin.close() + return dotpipe.stdout.read() |