diff options
-rwxr-xr-x | cloud-init.py | 10 | ||||
-rw-r--r-- | cloudinit/CloudConfig/cc_chef.py | 4 | ||||
-rw-r--r-- | cloudinit/CloudConfig/cc_foo.py | 2 | ||||
-rw-r--r-- | cloudinit/CloudConfig/cc_resizefs.py | 6 | ||||
-rw-r--r-- | cloudinit/CloudConfig/cc_update_etc_hosts.py | 58 | ||||
-rw-r--r-- | cloudinit/netinfo.py | 14 | ||||
-rw-r--r-- | cloudinit/util.py | 94 |
7 files changed, 94 insertions, 94 deletions
diff --git a/cloud-init.py b/cloud-init.py index bc673265..8279a0b0 100755 --- a/cloud-init.py +++ b/cloud-init.py @@ -56,12 +56,12 @@ def main(): now = time.strftime("%a, %d %b %Y %H:%M:%S %z",time.gmtime()) try: - uptimef=open("/proc/uptime") - uptime=uptimef.read().split(" ")[0] - uptimef.close() + uptimef=open("/proc/uptime") + uptime=uptimef.read().split(" ")[0] + uptimef.close() except IOError as e: - warn("unable to open /proc/uptime\n") - uptime = "na" + warn("unable to open /proc/uptime\n") + uptime = "na" try: cfg = cloudinit.get_base_cfg(cfg_path) diff --git a/cloudinit/CloudConfig/cc_chef.py b/cloudinit/CloudConfig/cc_chef.py index 14960a3c..f093d0b2 100644 --- a/cloudinit/CloudConfig/cc_chef.py +++ b/cloudinit/CloudConfig/cc_chef.py @@ -90,9 +90,9 @@ def get_ruby_packages(version): def install_chef_from_gems(ruby_version, chef_version = None): cc.install_packages(get_ruby_packages(ruby_version)) if not os.path.exists('/usr/bin/gem'): - os.symlink('/usr/bin/gem%s' % ruby_version, '/usr/bin/gem') + os.symlink('/usr/bin/gem%s' % ruby_version, '/usr/bin/gem') if not os.path.exists('/usr/bin/ruby'): - os.symlink('/usr/bin/ruby%s' % ruby_version, '/usr/bin/ruby') + os.symlink('/usr/bin/ruby%s' % ruby_version, '/usr/bin/ruby') if chef_version: subprocess.check_call(['/usr/bin/gem','install','chef', '-v %s' % chef_version, '--no-ri', diff --git a/cloudinit/CloudConfig/cc_foo.py b/cloudinit/CloudConfig/cc_foo.py index aa95578f..fb14707e 100644 --- a/cloudinit/CloudConfig/cc_foo.py +++ b/cloudinit/CloudConfig/cc_foo.py @@ -21,4 +21,4 @@ from cloudinit.CloudConfig import per_instance frequency = per_instance def handle(name,cfg,cloud,log,args): - print "hi" + print "hi" diff --git a/cloudinit/CloudConfig/cc_resizefs.py b/cloudinit/CloudConfig/cc_resizefs.py index 6615636f..d3a22fd6 100644 --- a/cloudinit/CloudConfig/cc_resizefs.py +++ b/cloudinit/CloudConfig/cc_resizefs.py @@ -41,9 +41,9 @@ def handle(name,cfg,cloud,log,args): os.close(fd) try: - st_dev=os.stat("/").st_dev - dev=os.makedev(os.major(st_dev),os.minor(st_dev)) - os.mknod(devpth, 0400 | stat.S_IFBLK, dev) + st_dev=os.stat("/").st_dev + dev=os.makedev(os.major(st_dev),os.minor(st_dev)) + os.mknod(devpth, 0400 | stat.S_IFBLK, dev) except: if util.islxc(): log.debug("inside lxc, ignoring mknod failure in resizefs") diff --git a/cloudinit/CloudConfig/cc_update_etc_hosts.py b/cloudinit/CloudConfig/cc_update_etc_hosts.py index 1dc9c1e9..cf2ad046 100644 --- a/cloudinit/CloudConfig/cc_update_etc_hosts.py +++ b/cloudinit/CloudConfig/cc_update_etc_hosts.py @@ -49,36 +49,36 @@ def handle(name,cfg,cloud,log,args): def update_etc_hosts(hostname, fqdn, log): - with open('/etc/hosts', 'r') as etchosts: - header = "# Added by cloud-init\n" - hosts_line = "127.0.1.1\t%s %s\n" % (fqdn, hostname) - need_write = False - need_change = True - new_etchosts = StringIO.StringIO() - for line in etchosts: - split_line = [s.strip() for s in line.split()] - if len(split_line) < 2: + with open('/etc/hosts', 'r') as etchosts: + header = "# Added by cloud-init\n" + hosts_line = "127.0.1.1\t%s %s\n" % (fqdn, hostname) + need_write = False + need_change = True + new_etchosts = StringIO.StringIO() + for line in etchosts: + split_line = [s.strip() for s in line.split()] + if len(split_line) < 2: new_etchosts.write(line) continue - if line == header: + if line == header: continue - ip, hosts = split_line[0], split_line[1:] - if ip == "127.0.1.1": - if sorted([hostname, fqdn]) == sorted(hosts): - need_change = False - if need_change == True: - line = "%s%s" % (header, hosts_line) - need_change = False - need_write = True - new_etchosts.write(line) - etchosts.close() - if need_change == True: - new_etchosts.write("%s%s" % (header, hosts_line)) - need_write = True - if need_write == True: - new_etcfile = open ('/etc/hosts','wb') - new_etcfile.write(new_etchosts.getvalue()) - new_etcfile.close() - new_etchosts.close() - return + ip, hosts = split_line[0], split_line[1:] + if ip == "127.0.1.1": + if sorted([hostname, fqdn]) == sorted(hosts): + need_change = False + if need_change == True: + line = "%s%s" % (header, hosts_line) + need_change = False + need_write = True + new_etchosts.write(line) + etchosts.close() + if need_change == True: + new_etchosts.write("%s%s" % (header, hosts_line)) + need_write = True + if need_write == True: + new_etcfile = open ('/etc/hosts','wb') + new_etcfile.write(new_etchosts.getvalue()) + new_etcfile.close() + new_etchosts.close() + return diff --git a/cloudinit/netinfo.py b/cloudinit/netinfo.py index 3ba922e8..a6b32c4f 100644 --- a/cloudinit/netinfo.py +++ b/cloudinit/netinfo.py @@ -68,16 +68,16 @@ def debug_info(pre="ci-info: "): lines.append("%s%-6s: %i %-15s %-15s %s" % (pre, dev, d["up"], d["addr"],d["mask"], d["hwaddr"])) try: - routes = route_info() + routes = route_info() except Exception as e: - lines.append("route_info failed") - routes = [] + lines.append("route_info failed") + routes = [] n = 0 for r in routes: - lines.append("%sroute-%d: %-15s %-15s %-15s %-6s %s" % - (pre, n, r[0], r[1], r[2], r[7], r[3])) - n = n+1 + lines.append("%sroute-%d: %-15s %-15s %-15s %-6s %s" % + (pre, n, r[0], r[1], r[2], r[7], r[3])) + n = n+1 return('\n'.join(lines)) if __name__ == '__main__': - print debug_info() + print debug_info() diff --git a/cloudinit/util.py b/cloudinit/util.py index de95ec79..8409c586 100644 --- a/cloudinit/util.py +++ b/cloudinit/util.py @@ -112,18 +112,18 @@ def mergedict(src,cand): return src def write_file(file,content,mode=0644,omode="wb"): - try: - os.makedirs(os.path.dirname(file)) - except OSError as e: - if e.errno != errno.EEXIST: - raise e + try: + os.makedirs(os.path.dirname(file)) + except OSError as e: + if e.errno != errno.EEXIST: + raise e - f=open(file,omode) - if mode != None: - os.chmod(file,mode) - f.write(content) - f.close() - restorecon_if_possible(file) + f=open(file,omode) + if mode != None: + os.chmod(file,mode) + f.write(content) + f.close() + restorecon_if_possible(file) def restorecon_if_possible(path, recursive=False): if HAVE_LIBSELINUX and selinux.is_selinux_enabled(): @@ -131,20 +131,20 @@ def restorecon_if_possible(path, recursive=False): # get keyid from keyserver def getkeybyid(keyid,keyserver): - shcmd=""" - k=${1} ks=${2}; - exec 2>/dev/null - [ -n "$k" ] || exit 1; - armour=$(gpg --list-keys --armour "${k}") - if [ -z "${armour}" ]; then - gpg --keyserver ${ks} --recv $k >/dev/null && - armour=$(gpg --export --armour "${k}") && - gpg --batch --yes --delete-keys "${k}" - fi - [ -n "${armour}" ] && echo "${armour}" - """ - args=['sh', '-c', shcmd, "export-gpg-keyid", keyid, keyserver] - return(subp(args)[0]) + shcmd=""" + k=${1} ks=${2}; + exec 2>/dev/null + [ -n "$k" ] || exit 1; + armour=$(gpg --list-keys --armour "${k}") + if [ -z "${armour}" ]; then + gpg --keyserver ${ks} --recv $k >/dev/null && + armour=$(gpg --export --armour "${k}") && + gpg --batch --yes --delete-keys "${k}" + fi + [ -n "${armour}" ] && echo "${armour}" + """ + args=['sh', '-c', shcmd, "export-gpg-keyid", keyid, keyserver] + return(subp(args)[0]) def runparts(dirp, skip_no_exist=True): if skip_no_exist and not os.path.isdir(dirp): return @@ -377,17 +377,17 @@ def ensure_dirs(dirlist, mode=0755): os.chmod(d, mode) def chownbyname(fname,user=None,group=None): - uid = -1 - gid = -1 - if user == None and group == None: return - if user: - import pwd - uid = pwd.getpwnam(user).pw_uid - if group: - import grp - gid = grp.getgrnam(group).gr_gid - - os.chown(fname,uid,gid) + uid = -1 + gid = -1 + if user == None and group == None: return + if user: + import pwd + uid = pwd.getpwnam(user).pw_uid + if group: + import grp + gid = grp.getgrnam(group).gr_gid + + os.chown(fname,uid,gid) def readurl(url, data=None, timeout=None): openargs = { } @@ -526,14 +526,14 @@ def search_for_mirror(candidates): return None def close_stdin(): - """ - reopen stdin as /dev/null so even subprocesses or other os level things get - /dev/null as input. - - if _CLOUD_INIT_SAVE_STDIN is set in environment to a non empty or '0' value - then input will not be closed (only useful potentially for debugging). - """ - if os.environ.get("_CLOUD_INIT_SAVE_STDIN") in ("", "0", False): - return - with open(os.devnull) as fp: - os.dup2(fp.fileno(), sys.stdin.fileno()) + """ + reopen stdin as /dev/null so even subprocesses or other os level things get + /dev/null as input. + + if _CLOUD_INIT_SAVE_STDIN is set in environment to a non empty or '0' value + then input will not be closed (only useful potentially for debugging). + """ + if os.environ.get("_CLOUD_INIT_SAVE_STDIN") in ("", "0", False): + return + with open(os.devnull) as fp: + os.dup2(fp.fileno(), sys.stdin.fileno()) |