From b9d39a834af1c6c30122f503aba695e49f4fecca Mon Sep 17 00:00:00 2001 From: Scott Moser Date: Fri, 18 Jun 2010 14:24:48 -0400 Subject: add ssh_import_id cloud-config module --- cloudinit/CloudConfig/cc_ssh_import_id.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 cloudinit/CloudConfig/cc_ssh_import_id.py (limited to 'cloudinit/CloudConfig/cc_ssh_import_id.py') diff --git a/cloudinit/CloudConfig/cc_ssh_import_id.py b/cloudinit/CloudConfig/cc_ssh_import_id.py new file mode 100644 index 00000000..e5d39ae9 --- /dev/null +++ b/cloudinit/CloudConfig/cc_ssh_import_id.py @@ -0,0 +1,29 @@ +import cloudinit.util as util +import subprocess +import traceback + +def handle(name,cfg,cloud,log,args): + if len(args) != 0: + user = args[0] + ids = [ ] + if len(args) > 1: + ids = args[1:] + else: + user = util.get_cfg_option_str(cfg,"user","ubuntu") + ids = util.get_cfg_option_list_or_str(cfg,"ssh_import_id",[]) + + log.warn("here, args = %s. user = %s ids = %s" % ( args, user, ids )) + if len(ids) == 0: return + + cmd = [ "sudo", "-Hu", user, "ssh-import-lp-id" ] + ids + + log.debug("importing ssh ids. cmd = %s" % cmd) + + try: + subprocess.check_call(cmd) + except subprocess.CalledProcessError as e: + log.debug(traceback.format_exc(e)) + raise Exception("Cmd returned %s: %s" % ( e.returncode, cmd)) + except OSError as e: + log.debug(traceback.format_exc(e)) + raise Exception("Cmd failed to execute: %s" % ( cmd )) -- cgit v1.2.3