def handle(name, cfg, cloud, log, _args): if "bootcmd" not in cfg: log.debug(("Skipping module named %s," " no 'bootcmd' key in configuration"), name) return with util.ExtendedTemporaryFile(suffix=".sh") as tmpf: try: content = util.shellify(cfg["bootcmd"]) tmpf.write(util.encode_text(content)) tmpf.flush() except Exception: util.logexc(log, "Failed to shellify bootcmd") raise try: env = os.environ.copy() iid = cloud.get_instance_id() if iid: env['INSTANCE_ID'] = str(iid) cmd = ['/bin/sh', tmpf.name] util.subp(cmd, env=env, capture=False) except Exception: util.logexc(log, "Failed to run bootcmd module %s", name) raise
def handle(name, cfg, cloud, log, _args): if "bootcmd" not in cfg: log.debug(("Skipping module named %s," " no 'bootcmd' key in configuration"), name) return validate_cloudconfig_schema(cfg, schema) with temp_utils.ExtendedTemporaryFile(suffix=".sh") as tmpf: try: content = util.shellify(cfg["bootcmd"]) tmpf.write(util.encode_text(content)) tmpf.flush() except Exception as e: util.logexc(log, "Failed to shellify bootcmd: %s", str(e)) raise try: env = os.environ.copy() iid = cloud.get_instance_id() if iid: env['INSTANCE_ID'] = str(iid) cmd = ['/bin/sh', tmpf.name] util.subp(cmd, env=env, capture=False) except Exception: util.logexc(log, "Failed to run bootcmd module %s", name) raise
def handle(name, cfg, cloud, log, _args): if "bootcmd" not in cfg: log.debug( "Skipping module named %s, no 'bootcmd' key in configuration", name) return validate_cloudconfig_schema(cfg, schema) with temp_utils.ExtendedTemporaryFile(suffix=".sh") as tmpf: try: content = util.shellify(cfg["bootcmd"]) tmpf.write(util.encode_text(content)) tmpf.flush() except Exception as e: util.logexc(log, "Failed to shellify bootcmd: %s", str(e)) raise try: env = os.environ.copy() iid = cloud.get_instance_id() if iid: env["INSTANCE_ID"] = str(iid) cmd = ["/bin/sh", tmpf.name] subp.subp(cmd, env=env, capture=False) except Exception: util.logexc(log, "Failed to run bootcmd module %s", name) raise
def test_supports_strings_and_lists(self): self.assertEqual( '\n'.join([ "#!/bin/sh", "echo hi mom", "'echo' 'hi dad'", "'echo' 'hi' 'sis'", "" ]), util.shellify( ["echo hi mom", ["echo", "hi dad"], ('echo', 'hi', 'sis')]))
def handle(_name, cfg, cloud, log, _args): if "runcmd" not in cfg: return outfile = "%s/runcmd" % cloud.get_ipath('scripts') try: content = util.shellify(cfg["runcmd"]) util.write_file(outfile, content, 0700) except: log.warn("failed to open %s for runcmd" % outfile)
def handle(name, cfg, cloud, log, _args): if "runcmd" not in cfg: log.debug(("Skipping module named %s," " no 'runcmd' key in configuration"), name) return out_fn = os.path.join(cloud.get_ipath('scripts'), "runcmd") cmd = cfg["runcmd"] try: content = util.shellify(cmd) util.write_file(out_fn, content, 0o700) except Exception: util.logexc(log, "Failed to shellify %s into file %s", cmd, out_fn)
def handle(name, cfg, cloud, log, _args): if "runcmd" not in cfg: log.debug("Skipping module named %s, no 'runcmd' key in configuration", name) return out_fn = os.path.join(cloud.get_ipath("scripts"), "runcmd") cmd = cfg["runcmd"] try: content = util.shellify(cmd) util.write_file(out_fn, content, 0o700) except Exception as e: raise type(e)("Failed to shellify {} into file {}".format(cmd, out_fn))
def handle(_name, cfg, cloud, log, _args): if "bootcmd" not in cfg: return try: content = util.shellify(cfg["bootcmd"]) tmpf = tempfile.TemporaryFile() tmpf.write(content) tmpf.seek(0) except: log.warn("failed to shellify bootcmd") raise try: env = os.environ.copy() env["INSTANCE_ID"] = cloud.get_instance_id() subprocess.check_call(["/bin/sh"], env=env, stdin=tmpf) tmpf.close() except: log.warn("failed to run commands from bootcmd") raise
def handle(_name, cfg, cloud, log, _args): if "bootcmd" not in cfg: return try: content = util.shellify(cfg["bootcmd"]) tmpf = tempfile.TemporaryFile() tmpf.write(content) tmpf.seek(0) except: log.warn("failed to shellify bootcmd") raise try: env = os.environ.copy() env['INSTANCE_ID'] = cloud.get_instance_id() subprocess.check_call(['/bin/sh'], env=env, stdin=tmpf) tmpf.close() except: log.warn("failed to run commands from bootcmd") raise
def handle(name, cfg, cloud, log, _args): if "runcmd" not in cfg: log.debug(("Skipping module named %s," " no 'runcmd' key in configuration"), name) return out_fn = os.path.join(cloud.get_ipath('scripts'), "runcmd") cmd = cfg["runcmd"] try: content = util.shellify(cmd) util.write_file(out_fn, content, 0700) except: util.logexc(log, "Failed to shellify %s into file %s", cmd, out_fn) try: env = os.environ.copy() iid = cloud.get_instance_id() if iid: env['INSTANCE_ID'] = str(iid) cmd = ['/bin/sh', out_fn] util.subp(cmd, env=env, capture=False) except: util.logexc(log, "Failed to run runcmd module %s", name) raise
def test_supports_strings_and_lists(self): self.assertEqual( '\n'.join(["#!/bin/sh", "echo hi mom", "'echo' 'hi dad'", "'echo' 'hi' 'sis'", ""]), util.shellify(["echo hi mom", ["echo", "hi dad"], ('echo', 'hi', 'sis')]))
def test_supports_comments(self): self.assertEqual( '\n'.join(["#!/bin/sh", "echo start", "echo end", ""]), util.shellify(["echo start", None, "echo end"]))