summaryrefslogtreecommitdiff
path: root/cloudinit
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2012-01-17 15:59:21 -0500
committerScott Moser <smoser@ubuntu.com>2012-01-17 15:59:21 -0500
commit1e746f00edbf478cf0ae43b66ff7899b6819fa33 (patch)
tree533a5f7b80ce1ec9a5cd2c670d2a781b6a54a4f1 /cloudinit
parentd4c5cfd23e693959a1478e4bf59a08e4dce9ca6c (diff)
parentdcb543887bcb0770bbb7b102e9d6a7c732d0228d (diff)
downloadvyos-cloud-init-1e746f00edbf478cf0ae43b66ff7899b6819fa33.tar.gz
vyos-cloud-init-1e746f00edbf478cf0ae43b66ff7899b6819fa33.zip
miscellaneous cleanups, and add tools/run-pylint
adding run-pylint makes it easy to run pylint with given configuration against the code.
Diffstat (limited to 'cloudinit')
-rw-r--r--cloudinit/CloudConfig/cc_mounts.py4
-rw-r--r--cloudinit/CloudConfig/cc_set_passwords.py8
-rw-r--r--cloudinit/CloudConfig/cc_ssh.py8
-rw-r--r--cloudinit/DataSourceOVF.py30
-rw-r--r--cloudinit/SshUtil.py70
-rw-r--r--cloudinit/UserDataHandler.py15
-rw-r--r--cloudinit/__init__.py1
7 files changed, 70 insertions, 66 deletions
diff --git a/cloudinit/CloudConfig/cc_mounts.py b/cloudinit/CloudConfig/cc_mounts.py
index dbd9c454..2fa57362 100644
--- a/cloudinit/CloudConfig/cc_mounts.py
+++ b/cloudinit/CloudConfig/cc_mounts.py
@@ -18,7 +18,7 @@
import cloudinit.util as util
import os
import re
-import string
+from string import whitespace # pylint: disable=W0402
def is_mdname(name):
@@ -139,7 +139,7 @@ def handle(_name, cfg, cloud, log, _args):
fstab_lines = []
fstab = open("/etc/fstab", "r+")
- ws = re.compile("[%s]+" % string.whitespace)
+ ws = re.compile("[%s]+" % whitespace)
for line in fstab.read().splitlines():
try:
toks = ws.split(line)
diff --git a/cloudinit/CloudConfig/cc_set_passwords.py b/cloudinit/CloudConfig/cc_set_passwords.py
index 05384f4f..f40544b3 100644
--- a/cloudinit/CloudConfig/cc_set_passwords.py
+++ b/cloudinit/CloudConfig/cc_set_passwords.py
@@ -19,7 +19,7 @@
import cloudinit.util as util
import sys
import random
-import string
+from string import letters, digits # pylint: disable=W0402
def handle(_name, cfg, _cloud, log, args):
@@ -117,11 +117,11 @@ def handle(_name, cfg, _cloud, log, args):
return
-def rand_str(strlen=32, select_from=string.letters + string.digits):
+def rand_str(strlen=32, select_from=letters + digits):
return("".join([random.choice(select_from) for _x in range(0, strlen)]))
def rand_user_password(pwlen=9):
- selfrom = (string.letters.translate(None, 'loLOI') +
- string.digits.translate(None, '01'))
+ selfrom = (letters.translate(None, 'loLOI') +
+ digits.translate(None, '01'))
return(rand_str(pwlen, select_from=selfrom))
diff --git a/cloudinit/CloudConfig/cc_ssh.py b/cloudinit/CloudConfig/cc_ssh.py
index 39862117..cdf90bdc 100644
--- a/cloudinit/CloudConfig/cc_ssh.py
+++ b/cloudinit/CloudConfig/cc_ssh.py
@@ -25,12 +25,8 @@ DISABLE_ROOT_OPTS = "no-port-forwarding,no-agent-forwarding," \
"no-X11-forwarding,command=\"echo \'Please login as the user \\\"$USER\\\" " \
"rather than the user \\\"root\\\".\';echo;sleep 10\""
-global_log = None
-
def handle(_name, cfg, cloud, log, _args):
- global global_log
- global_log = log
# remove the static keys from the pristine image
if cfg.get("ssh_deletekeys", True):
@@ -87,14 +83,14 @@ def handle(_name, cfg, cloud, log, _args):
cfgkeys = cfg["ssh_authorized_keys"]
keys.extend(cfgkeys)
- apply_credentials(keys, user, disable_root, disable_root_opts)
+ apply_credentials(keys, user, disable_root, disable_root_opts, log)
except:
util.logexc(log)
log.warn("applying credentials failed!\n")
def apply_credentials(keys, user, disable_root,
- disable_root_opts=DISABLE_ROOT_OPTS, log=global_log):
+ disable_root_opts=DISABLE_ROOT_OPTS, log=None):
keys = set(keys)
if user:
sshutil.setup_user_keys(keys, user, '', log)
diff --git a/cloudinit/DataSourceOVF.py b/cloudinit/DataSourceOVF.py
index 630afc2e..1a527524 100644
--- a/cloudinit/DataSourceOVF.py
+++ b/cloudinit/DataSourceOVF.py
@@ -21,7 +21,6 @@ import cloudinit.DataSource as DataSource
from cloudinit import seeddir as base_seeddir
from cloudinit import log
import cloudinit.util as util
-import sys
import os.path
import os
from xml.dom import minidom
@@ -313,16 +312,19 @@ def get_datasource_list(depends):
if __name__ == "__main__":
- import sys
- envStr = open(sys.argv[1]).read()
- props = getProperties(envStr)
- import pprint
- pprint.pprint(props)
-
- md, ud, cfg = read_ovf_environment(envStr)
- print "=== md ==="
- pprint.pprint(md)
- print "=== ud ==="
- pprint.pprint(ud)
- print "=== cfg ==="
- pprint.pprint(cfg)
+ def main():
+ import sys
+ envStr = open(sys.argv[1]).read()
+ props = getProperties(envStr)
+ import pprint
+ pprint.pprint(props)
+
+ md, ud, cfg = read_ovf_environment(envStr)
+ print "=== md ==="
+ pprint.pprint(md)
+ print "=== ud ==="
+ pprint.pprint(ud)
+ print "=== cfg ==="
+ pprint.pprint(cfg)
+
+ main()
diff --git a/cloudinit/SshUtil.py b/cloudinit/SshUtil.py
index c6c30c5c..9db0c6b4 100644
--- a/cloudinit/SshUtil.py
+++ b/cloudinit/SshUtil.py
@@ -156,39 +156,6 @@ def setup_user_keys(keys, user, key_prefix, log=None):
os.umask(saved_umask)
-if __name__ == "__main__":
- import sys
- # usage: orig_file, new_keys, [key_prefix]
- # prints out merged, where 'new_keys' will trump old
- ## example
- ## ### begin auth_keys ###
- # ssh-rsa AAAAB3NzaC1xxxxxxxxxV3csgm8cJn7UveKHkYjJp8= smoser-work
- # ssh-rsa AAAAB3NzaC1xxxxxxxxxCmXp5Kt5/82cD/VN3NtHw== smoser@brickies
- # ### end authorized_keys ###
- #
- # ### begin new_keys ###
- # ssh-rsa nonmatch smoser@newhost
- # ssh-rsa AAAAB3NzaC1xxxxxxxxxV3csgm8cJn7UveKHkYjJp8= new_comment
- # ### end new_keys ###
- #
- # Then run as:
- # program auth_keys new_keys \
- # 'no-port-forwarding,command=\"echo hi world;\"'
- def_prefix = None
- orig_key_file = sys.argv[1]
- new_key_file = sys.argv[2]
- if len(sys.argv) > 3:
- def_prefix = sys.argv[3]
- fp = open(new_key_file)
-
- newkeys = []
- for line in fp.readlines():
- newkeys.append(AuthKeyEntry(line, def_prefix))
-
- fp.close()
- print update_authorized_keys(orig_key_file, newkeys)
-
-
def parse_ssh_config(fname="/etc/ssh/sshd_config"):
ret = {}
fp = open(fname)
@@ -200,3 +167,40 @@ def parse_ssh_config(fname="/etc/ssh/sshd_config"):
ret[key] = val
fp.close()
return(ret)
+
+if __name__ == "__main__":
+ def main():
+ import sys
+ # usage: orig_file, new_keys, [key_prefix]
+ # prints out merged, where 'new_keys' will trump old
+ ## example
+ ## ### begin auth_keys ###
+ # ssh-rsa AAAAB3NzaC1xxxxxxxxxV3csgm8cJn7UveKHkYjJp8= smoser-work
+ # ssh-rsa AAAAB3NzaC1xxxxxxxxxCmXp5Kt5/82cD/VN3NtHw== smoser@brickies
+ # ### end authorized_keys ###
+ #
+ # ### begin new_keys ###
+ # ssh-rsa nonmatch smoser@newhost
+ # ssh-rsa AAAAB3NzaC1xxxxxxxxxV3csgm8cJn7UveKHkYjJp8= new_comment
+ # ### end new_keys ###
+ #
+ # Then run as:
+ # program auth_keys new_keys \
+ # 'no-port-forwarding,command=\"echo hi world;\"'
+ def_prefix = None
+ orig_key_file = sys.argv[1]
+ new_key_file = sys.argv[2]
+ if len(sys.argv) > 3:
+ def_prefix = sys.argv[3]
+ fp = open(new_key_file)
+
+ newkeys = []
+ for line in fp.readlines():
+ newkeys.append(AuthKeyEntry(line, def_prefix))
+
+ fp.close()
+ print update_authorized_keys(orig_key_file, newkeys)
+
+ main()
+
+# vi: ts=4 expandtab
diff --git a/cloudinit/UserDataHandler.py b/cloudinit/UserDataHandler.py
index 48bd9780..9331aa17 100644
--- a/cloudinit/UserDataHandler.py
+++ b/cloudinit/UserDataHandler.py
@@ -246,9 +246,12 @@ def walk_userdata(istr, callback, data=None):
if __name__ == "__main__":
- import sys
- data = decomp_str(file(sys.argv[1]).read())
- newmsg = MIMEMultipart()
- process_includes(message_from_string(data), newmsg)
- print newmsg
- print "#found %s parts" % multi_part_count(newmsg)
+ def main():
+ import sys
+ data = decomp_str(file(sys.argv[1]).read())
+ newmsg = MIMEMultipart()
+ process_includes(message_from_string(data), newmsg)
+ print newmsg
+ print "#found %s parts" % multi_part_count(newmsg)
+
+ main()
diff --git a/cloudinit/__init__.py b/cloudinit/__init__.py
index 90d6b77d..0bf2da02 100644
--- a/cloudinit/__init__.py
+++ b/cloudinit/__init__.py
@@ -53,7 +53,6 @@ per_once = "once"
parsed_cfgs = {}
import os
-from configobj import ConfigObj
import cPickle
import sys