diff options
author | Daniel Watkins <oddbloke@ubuntu.com> | 2020-04-29 09:49:02 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-29 09:49:02 -0400 |
commit | 32338f57f8b6160ba9758e76b95731a06d5bc2fd (patch) | |
tree | 6aa47f82332b8c8fd3edf04a931c7eb14a9267f9 /doc/rtd/topics/format.rst | |
parent | b70f11079e6d4264ff9a8c12089945f57d903e28 (diff) | |
download | vyos-cloud-init-32338f57f8b6160ba9758e76b95731a06d5bc2fd.tar.gz vyos-cloud-init-32338f57f8b6160ba9758e76b95731a06d5bc2fd.zip |
doc/format: reference make-mime.py instead of an inline script (#334)
`make-mime.py` is a more recent version of the inline script that this
link is replacing.
Diffstat (limited to 'doc/rtd/topics/format.rst')
-rw-r--r-- | doc/rtd/topics/format.rst | 29 |
1 files changed, 9 insertions, 20 deletions
diff --git a/doc/rtd/topics/format.rst b/doc/rtd/topics/format.rst index e3e5f8aa..1d0a7097 100644 --- a/doc/rtd/topics/format.rst +++ b/doc/rtd/topics/format.rst @@ -38,29 +38,18 @@ Supported content-types: Helper script to generate mime messages --------------------------------------- -.. code-block:: python - - #!/usr/bin/python - - import sys - - from email.mime.multipart import MIMEMultipart - from email.mime.text import MIMEText +The cloud-init codebase includes a helper script to generate MIME multi-part +files: `make-mime.py`_. - if len(sys.argv) == 1: - print("%s input-file:type ..." % (sys.argv[0])) - sys.exit(1) +``make-mime.py`` takes pairs of (filename, "text/" mime subtype) separated by +a colon (e.g. ``config.yaml:cloud-config``) and emits a MIME multipart +message to stdout. An example invocation, assuming you have your cloud config +in ``config.yaml`` and a shell script in ``script.sh`` and want to store the +multipart message in ``user-data``:: - combined_message = MIMEMultipart() - for i in sys.argv[1:]: - (filename, format_type) = i.split(":", 1) - with open(filename) as fh: - contents = fh.read() - sub_message = MIMEText(contents, format_type, sys.getdefaultencoding()) - sub_message.add_header('Content-Disposition', 'attachment; filename="%s"' % (filename)) - combined_message.attach(sub_message) + ./tools/make-mime.py -a config.yaml:cloud-config -a script.sh:x-shellscript > user-data - print(combined_message) +.. _make-mime.py: https://github.com/canonical/cloud-init/blob/master/tools/make-mime.py User-Data Script |