diff options
Diffstat (limited to 'doc')
-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 |