summaryrefslogtreecommitdiff
path: root/doc/rtd/topics
diff options
context:
space:
mode:
authorJoshua Harlow <harlowja@yahoo-inc.com>2013-01-24 18:41:26 -0800
committerJoshua Harlow <harlowja@yahoo-inc.com>2013-01-24 18:41:26 -0800
commit6fb6fe24d5ba185d42f2d7a82c3c54d26fea3392 (patch)
tree44154d0e09b265078bda33e85f171de55b11b48e /doc/rtd/topics
parent6f0756e5501ae660b2173ff558867941ab963a42 (diff)
downloadvyos-cloud-init-6fb6fe24d5ba185d42f2d7a82c3c54d26fea3392.tar.gz
vyos-cloud-init-6fb6fe24d5ba185d42f2d7a82c3c54d26fea3392.zip
Add docs which can be used on readthedocs.org
Include a new set of docs that can be used to create a readthedocs.org site, which includes examples, directory layout, capabilities and such. This in-code documentation then allows for readthedocs.org to create a website directly from the cloud-init codebase.
Diffstat (limited to 'doc/rtd/topics')
-rw-r--r--doc/rtd/topics/availability.rst20
-rw-r--r--doc/rtd/topics/capabilities.rst24
-rw-r--r--doc/rtd/topics/dir_layout.rst81
-rw-r--r--doc/rtd/topics/examples.rst121
-rw-r--r--doc/rtd/topics/format.rst159
-rw-r--r--doc/rtd/topics/modules.rst3
-rw-r--r--doc/rtd/topics/moreinfo.rst12
7 files changed, 420 insertions, 0 deletions
diff --git a/doc/rtd/topics/availability.rst b/doc/rtd/topics/availability.rst
new file mode 100644
index 00000000..2d58f808
--- /dev/null
+++ b/doc/rtd/topics/availability.rst
@@ -0,0 +1,20 @@
+============
+Availability
+============
+
+It is currently installed in the `Ubuntu Cloud Images`_ and also in the official `Ubuntu`_ images available on EC2.
+
+Versions for other systems can be (or have been) created for the following distributions:
+
+- Ubuntu
+- Fedora
+- Debian
+- RHEL
+- CentOS
+- *and more...*
+
+So ask your distribution provider where you can obtain an image with it built-in if one is not already available ☺
+
+
+.. _Ubuntu Cloud Images: http://cloud-images.ubuntu.com/
+.. _Ubuntu: http://www.ubuntu.com/
diff --git a/doc/rtd/topics/capabilities.rst b/doc/rtd/topics/capabilities.rst
new file mode 100644
index 00000000..63b34270
--- /dev/null
+++ b/doc/rtd/topics/capabilities.rst
@@ -0,0 +1,24 @@
+=====================
+Capabilities
+=====================
+
+- Setting a default locale
+- Setting a instance hostname
+- Generating instance ssh private keys
+- Adding ssh keys to a users ``.ssh/authorized_keys`` so they can log in
+- Setting up ephemeral mount points
+
+User configurability
+--------------------
+
+`Cloud-init`_ 's behavior can be configured via user-data.
+
+ User-data can be given by the user at instance launch time.
+
+This is done via the ``--user-data`` or ``--user-data-file`` argument to ec2-run-instances for example.
+
+* Check your local clients documentation for how to provide a `user-data` string
+ or `user-data` file for usage by cloud-init on instance creation.
+
+
+.. _Cloud-init: https://launchpad.net/cloud-init
diff --git a/doc/rtd/topics/dir_layout.rst b/doc/rtd/topics/dir_layout.rst
new file mode 100644
index 00000000..f072c585
--- /dev/null
+++ b/doc/rtd/topics/dir_layout.rst
@@ -0,0 +1,81 @@
+=========
+Directory layout
+=========
+
+Cloudinits's directory structure is somewhat different from a regular application::
+
+ /var/lib/cloud/
+ - data/
+ - instance-id
+ - previous-instance-id
+ - datasource
+ - previous-datasource
+ - previous-hostname
+ - handlers/
+ - instance
+ - instances/
+ i-00000XYZ/
+ - boot-finished
+ - cloud-config.txt
+ - datasource
+ - handlers/
+ - obj.pkl
+ - scripts/
+ - sem/
+ - user-data.txt
+ - user-data.txt.i
+ - scripts/
+ - per-boot/
+ - per-instance/
+ - per-once/
+ - seed/
+ - sem/
+
+``/var/lib/cloud``
+
+ The main directory containing the cloud-init specific subdirectories.
+ It is typically located at ``/var/lib`` but there are certain configuration
+ scenarios where this can be altered.
+
+ TBD, describe this overriding more.
+
+``data/``
+
+ Contains information releated to instance ids, datasources and hostnames of the previous
+ and current instance if they are different. These can be examined as needed to
+ determine any information releated to a previous boot (if applicable).
+
+``handlers/``
+
+ Custom ``part-handlers`` code is written out here. Files that end up here are written
+ out with in the scheme of ``part-handler-XYZ`` where ``XYZ`` is the handler number (the
+ first handler found starts at 0).
+
+
+``instance``
+
+ A symlink to the current ``instances/`` subdirectory that points to the currently
+ active instance (which is active is dependent on the datasource loaded).
+
+``instances/``
+
+ All instances that were created using this image end up with instance identifer
+ subdirectories (and corresponding data for each instance). The currently active
+ instance will be symlinked the the ``instance`` symlink file defined previously.
+
+``scripts/``
+
+ Scripts that are downloaded/created by the corresponding ``part-handler`` will end up
+ in one of these subdirectories.
+
+``seed/``
+
+ TBD
+
+``sem/``
+
+ Cloud-init has a concept of a module sempahore, which basically consists
+ of the module name and its frequency. These files are used to ensure a module
+ is only ran `per-once`, `per-instance`, `per-always`. This folder contains
+ sempaphore `files` which are only supposed to run `per-once` (not tied to the instance id).
+
diff --git a/doc/rtd/topics/examples.rst b/doc/rtd/topics/examples.rst
new file mode 100644
index 00000000..9bbc33cc
--- /dev/null
+++ b/doc/rtd/topics/examples.rst
@@ -0,0 +1,121 @@
+.. _yaml_examples:
+
+=========
+Cloud config examples
+=========
+
+Including users and groups
+---------------------------
+
+.. literalinclude:: ../../examples/cloud-config-user-groups.txt
+ :language: yaml
+ :linenos:
+
+
+Writing out arbitrary files
+---------------------------
+
+.. literalinclude:: ../../examples/cloud-config-write-files.txt
+ :language: yaml
+ :linenos:
+
+
+Adding a yum repository
+---------------------------
+
+.. literalinclude:: ../../examples/cloud-config-yum-repo.txt
+ :language: yaml
+ :linenos:
+
+Configure an instance's trusted CA certificates
+------------------------------------------------------
+
+.. literalinclude:: ../../examples/cloud-config-ca-certs.txt
+ :language: yaml
+ :linenos:
+
+Install and run `chef`_ recipes
+------------------------------------------------------
+
+.. literalinclude:: ../../examples/cloud-config-chef.txt
+ :language: yaml
+ :linenos:
+
+Setup and run `puppet`_
+------------------------------------------------------
+
+.. literalinclude:: ../../examples/cloud-config-puppet.txt
+ :language: yaml
+ :linenos:
+
+Add apt repositories
+---------------------------
+
+.. literalinclude:: ../../examples/cloud-config-add-apt-repos.txt
+ :language: yaml
+ :linenos:
+
+Run commands on first boot
+---------------------------
+
+.. literalinclude:: ../../examples/cloud-config-boot-cmds.txt
+ :language: yaml
+ :linenos:
+
+.. literalinclude:: ../../examples/cloud-config-run-cmds.txt
+ :language: yaml
+ :linenos:
+
+
+Alter the completion message
+---------------------------
+
+.. literalinclude:: ../../examples/cloud-config-final-message.txt
+ :language: yaml
+ :linenos:
+
+Install arbitrary packages
+---------------------------
+
+.. literalinclude:: ../../examples/cloud-config-install-packages.txt
+ :language: yaml
+ :linenos:
+
+Run apt or yum upgrade
+---------------------------
+
+.. literalinclude:: ../../examples/cloud-config-update-packages.txt
+ :language: yaml
+ :linenos:
+
+Adjust mount points mounted
+---------------------------
+
+.. literalinclude:: ../../examples/cloud-config-mount-points.txt
+ :language: yaml
+ :linenos:
+
+Call a url when finished
+---------------------------
+
+.. literalinclude:: ../../examples/cloud-config-phone-home.txt
+ :language: yaml
+ :linenos:
+
+Reboot/poweroff when finished
+---------------------------
+
+.. literalinclude:: ../../examples/cloud-config-power-state.txt
+ :language: yaml
+ :linenos:
+
+Configure instances ssh-keys
+---------------------------
+
+.. literalinclude:: ../../examples/cloud-config-ssh-keys.txt
+ :language: yaml
+ :linenos:
+
+
+.. _chef: http://www.opscode.com/chef/
+.. _puppet: http://puppetlabs.com/
diff --git a/doc/rtd/topics/format.rst b/doc/rtd/topics/format.rst
new file mode 100644
index 00000000..eba9533f
--- /dev/null
+++ b/doc/rtd/topics/format.rst
@@ -0,0 +1,159 @@
+=========
+Formats
+=========
+
+User data that will be acted upon by cloud-init must be in one of the following types.
+
+Gzip Compressed Content
+------------------------
+
+Content found to be gzip compressed will be uncompressed.
+The uncompressed data will then be used as if it were not compressed.
+This is typically is useful because user-data is limited to ~16384 [#]_ bytes.
+
+Mime Multi Part Archive
+------------------------
+
+This list of rules is applied to each part of this multi-part file.
+Using a mime-multi part file, the user can specify more than one type of data.
+
+For example, both a user data script and a cloud-config type could be specified.
+
+Supported content-types:
+
+- text/x-include-once-url
+- text/x-include-url
+- text/cloud-config-archive
+- text/upstart-job
+- text/cloud-config
+- text/part-handler
+- text/x-shellscript
+- text/cloud-boothook
+
+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
+
+ if len(sys.argv) == 1:
+ print("%s input-file:type ..." % (sys.argv[0]))
+ sys.exit(1)
+
+ 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)
+
+ print(combined_message)
+
+
+User-Data Script
+------------------------
+
+Typically used by those who just want to execute a shell script.
+
+Begins with: ``#!`` or ``Content-Type: text/x-shellscript`` when using a MIME archive.
+
+Example
+~~~~~~~
+
+::
+
+ $ cat myscript.sh
+
+ #!/bin/sh
+ echo "Hello World. The time is now $(date -R)!" | tee /root/output.txt
+
+ $ euca-run-instances --key mykey --user-data-file myscript.sh ami-a07d95c9
+
+Include File
+------------
+
+This content is a ``include`` file.
+
+The file contains a list of urls, one per line.
+Each of the URLs will be read, and their content will be passed through this same set of rules.
+Ie, the content read from the URL can be gzipped, mime-multi-part, or plain text.
+
+Begins with: ``#include`` or ``Content-Type: text/x-include-url`` when using a MIME archive.
+
+Cloud Config Data
+-----------------
+
+Cloud-config is the simplest way to accomplish some things
+via user-data. Using cloud-config syntax, the user can specify certain things in a human friendly format.
+
+These things include:
+
+- apt upgrade should be run on first boot
+- a different apt mirror should be used
+- additional apt sources should be added
+- certain ssh keys should be imported
+- *and many more...*
+
+**Note:** The file must be valid yaml syntax.
+
+See the :ref:`yaml_examples` section for a commented set of examples of supported cloud config formats.
+
+Begins with: ``#cloud-config`` or ``Content-Type: text/cloud-config`` when using a MIME archive.
+
+Upstart Job
+-----------
+
+Content is placed into a file in ``/etc/init``, and will be consumed by upstart as any other upstart job.
+
+Begins with: ``#upstart-job`` or ``Content-Type: text/upstart-job`` when using a MIME archive.
+
+Cloud Boothook
+--------------
+
+This content is ``boothook`` data. It is stored in a file under ``/var/lib/cloud`` and then executed immediately.
+This is the earliest ``hook`` available. Note, that there is no mechanism provided for running only once. The boothook must take care of this itself.
+It is provided with the instance id in the environment variable ``INSTANCE_I``. This could be made use of to provide a 'once-per-instance' type of functionality.
+
+Begins with: ``#cloud-boothook`` or ``Content-Type: text/cloud-boothook`` when using a MIME archive.
+
+Part Handler
+------------
+
+This is a ``part-handler``. It will be written to a file in ``/var/lib/cloud/data`` based on its filename (which is generated).
+This must be python code that contains a ``list_types`` method and a ``handle_type`` method.
+Once the section is read the ``list_types`` method will be called. It must return a list of mime-types that this part-handler handles.
+
+The ``handle_type`` method must be like:
+
+.. code-block:: python
+
+ def handle_part(data, ctype, filename, payload):
+ # data = the cloudinit object
+ # ctype = "__begin__", "__end__", or the mime-type of the part that is being handled.
+ # filename = the filename of the part (or a generated filename if none is present in mime data)
+ # payload = the parts' content
+
+Cloud-init will then call the ``handle_type`` method once at begin, once per part received, and once at end.
+The ``begin`` and ``end`` calls are to allow the part handler to do initialization or teardown.
+
+Begins with: ``#part-handler`` or ``Content-Type: text/part-handler`` when using a MIME archive.
+
+Example
+~~~~~~~
+
+.. literalinclude:: ../../examples/part-handler.txt
+ :language: python
+ :linenos:
+
+Also this `blog`_ post offers another example for more advanced usage.
+
+.. [#] See your cloud provider for applicable user-data size limitations...
+.. _blog: http://foss-boss.blogspot.com/2011/01/advanced-cloud-init-custom-handlers.html
diff --git a/doc/rtd/topics/modules.rst b/doc/rtd/topics/modules.rst
new file mode 100644
index 00000000..d4dd55df
--- /dev/null
+++ b/doc/rtd/topics/modules.rst
@@ -0,0 +1,3 @@
+=========
+Modules
+=========
diff --git a/doc/rtd/topics/moreinfo.rst b/doc/rtd/topics/moreinfo.rst
new file mode 100644
index 00000000..2e436c3c
--- /dev/null
+++ b/doc/rtd/topics/moreinfo.rst
@@ -0,0 +1,12 @@
+=========
+More information
+=========
+
+Useful external references
+----------------
+
+- `The beauty of cloudinit`_
+- `Introduction to cloud-init`_ (video)
+
+.. _Introduction to cloud-init: http://www.youtube.com/watch?v=-zL3BdbKyGY
+.. _The beauty of cloudinit: http://brandon.fuller.name/archives/2011/05/02/06.40.57/