Merge ~powersj/cloud-init:docs/cli into cloud-init:master

Proposed by Joshua Powers
Status: Merged
Approved by: Chad Smith
Approved revision: c62f96299293afcae0dab000a1888aaf1016d900
Merge reported by: Server Team CI bot
Merged at revision: not available
Proposed branch: ~powersj/cloud-init:docs/cli
Merge into: cloud-init:master
Diff against target: 616 lines (+304/-300)
2 files modified
dev/null (+0/-300)
doc/rtd/topics/cli.rst (+304/-0)
Reviewer Review Type Date Requested Status
Chad Smith Approve
Server Team CI bot continuous-integration Approve
Review via email: mp+372648@code.launchpad.net

Commit message

docs: create cli specific page

This is formerly the capabilities page.

To post a comment you must log in.
Revision history for this message
Server Team CI bot (server-team-bot) wrote :

PASSED: Continuous integration, rev:c62f96299293afcae0dab000a1888aaf1016d900
https://jenkins.ubuntu.com/server/job/cloud-init-ci/1128/
Executed test runs:
    SUCCESS: Checkout
    SUCCESS: Unit & Style Tests
    SUCCESS: Ubuntu LTS: Build
    SUCCESS: Ubuntu LTS: Integration
    IN_PROGRESS: Declarative: Post Actions

Click here to trigger a rebuild:
https://jenkins.ubuntu.com/server/job/cloud-init-ci/1128//rebuild

review: Approve (continuous-integration)
Revision history for this message
Chad Smith (chad.smith) wrote :

bring it home

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/doc/rtd/topics/capabilities.rst b/doc/rtd/topics/capabilities.rst
2deleted file mode 100644
3index 6d85a99..0000000
4--- a/doc/rtd/topics/capabilities.rst
5+++ /dev/null
6@@ -1,300 +0,0 @@
7-.. _capabilities:
8-
9-************
10-Capabilities
11-************
12-
13-- Setting a default locale
14-- Setting an instance hostname
15-- Generating instance SSH private keys
16-- Adding SSH keys to a user's ``.ssh/authorized_keys`` so they can log in
17-- Setting up ephemeral mount points
18-- Configuring network devices
19-
20-User configurability
21-====================
22-
23-`Cloud-init`_ 's behavior can be configured via user-data.
24-
25- User-data can be given by the user at instance launch time. See
26- :ref:`user_data_formats` for acceptable user-data content.
27-
28-
29-This is done via the ``--user-data`` or ``--user-data-file`` argument to
30-ec2-run-instances for example.
31-
32-* Check your local client's documentation for how to provide a `user-data`
33- string or `user-data` file to cloud-init on instance creation.
34-
35-
36-Feature detection
37-=================
38-
39-Newer versions of cloud-init may have a list of additional features that they
40-support. This allows other applications to detect what features the installed
41-cloud-init supports without having to parse its version number. If present,
42-this list of features will be located at ``cloudinit.version.FEATURES``.
43-
44-Currently defined feature names include:
45-
46- - ``NETWORK_CONFIG_V1`` support for v1 networking configuration,
47- see :ref:`network_config_v1` documentation for examples.
48- - ``NETWORK_CONFIG_V2`` support for v2 networking configuration,
49- see :ref:`network_config_v2` documentation for examples.
50-
51-
52-CLI Interface
53-=============
54-
55-The command line documentation is accessible on any cloud-init installed
56-system:
57-
58-.. code-block:: shell-session
59-
60- % cloud-init --help
61- usage: cloud-init [-h] [--version] [--file FILES]
62- [--debug] [--force]
63- {init,modules,single,query,dhclient-hook,features,analyze,devel,collect-logs,clean,status}
64- ...
65-
66- optional arguments:
67- -h, --help show this help message and exit
68- --version, -v show program's version number and exit
69- --file FILES, -f FILES
70- additional yaml configuration files to use
71- --debug, -d show additional pre-action logging (default: False)
72- --force force running even if no datasource is found (use at
73- your own risk)
74-
75- Subcommands:
76- {init,modules,single,query,dhclient-hook,features,analyze,devel,collect-logs,clean,status}
77- init initializes cloud-init and performs initial modules
78- modules activates modules using a given configuration key
79- single run a single module
80- query Query instance metadata from the command line
81- dhclient-hook run the dhclient hookto record network info
82- features list defined features
83- analyze Devel tool: Analyze cloud-init logs and data
84- devel Run development tools
85- collect-logs Collect and tar all cloud-init debug info
86- clean Remove logs and artifacts so cloud-init can re-run
87- status Report cloud-init status or wait on completion
88-
89-
90-CLI Subcommand details
91-======================
92-
93-.. _cli_features:
94-
95-cloud-init features
96--------------------
97-Print out each feature supported. If cloud-init does not have the
98-features subcommand, it also does not support any features described in
99-this document.
100-
101-.. code-block:: shell-session
102-
103- % cloud-init features
104- NETWORK_CONFIG_V1
105- NETWORK_CONFIG_V2
106-
107-.. _cli_status:
108-
109-cloud-init status
110------------------
111-Report whether cloud-init is running, done, disabled or errored. Exits
112-non-zero if an error is detected in cloud-init.
113-
114-* **--long**: Detailed status information.
115-* **--wait**: Block until cloud-init completes.
116-
117-.. code-block:: shell-session
118-
119- % cloud-init status --long
120- status: done
121- time: Wed, 17 Jan 2018 20:41:59 +0000
122- detail:
123- DataSourceNoCloud [seed=/var/lib/cloud/seed/nocloud-net][dsmode=net]
124-
125- # Cloud-init running still short versus long options
126- % cloud-init status
127- status: running
128- % cloud-init status --long
129- status: running
130- time: Fri, 26 Jan 2018 21:39:43 +0000
131- detail:
132- Running in stage: init-local
133-
134-.. _cli_collect_logs:
135-
136-cloud-init collect-logs
137------------------------
138-Collect and tar cloud-init generated logs, data files and system
139-information for triage. This subcommand is integrated with apport.
140-
141-**Note**: Ubuntu users can file bugs with `ubuntu-bug cloud-init` to
142-automaticaly attach these logs to a bug report.
143-
144-Logs collected are:
145-
146- * /var/log/cloud-init*log
147- * /run/cloud-init
148- * cloud-init package version
149- * dmesg output
150- * journalctl output
151- * /var/lib/cloud/instance/user-data.txt
152-
153-.. _cli_query:
154-
155-cloud-init query
156-------------------
157-Query standardized cloud instance metadata crawled by cloud-init and stored
158-in ``/run/cloud-init/instance-data.json``. This is a convenience command-line
159-interface to reference any cached configuration metadata that cloud-init
160-crawls when booting the instance. See :ref:`instance_metadata` for more info.
161-
162-* **--all**: Dump all available instance data as json which can be queried.
163-* **--instance-data**: Optional path to a different instance-data.json file to
164- source for queries.
165-* **--list-keys**: List available query keys from cached instance data.
166-
167-.. code-block:: shell-session
168-
169- # List all top-level query keys available (includes standardized aliases)
170- % cloud-init query --list-keys
171- availability_zone
172- base64_encoded_keys
173- cloud_name
174- ds
175- instance_id
176- local_hostname
177- region
178- v1
179-
180-* **<varname>**: A dot-delimited variable path into the instance-data.json
181- object.
182-
183-.. code-block:: shell-session
184-
185- # Query cloud-init standardized metadata on any cloud
186- % cloud-init query v1.cloud_name
187- aws # or openstack, azure, gce etc.
188-
189- # Any standardized instance-data under a <v#> key is aliased as a top-level
190- # key for convenience.
191- % cloud-init query cloud_name
192- aws # or openstack, azure, gce etc.
193-
194- # Query datasource-specific metadata on EC2
195- % cloud-init query ds.meta_data.public_ipv4
196-
197-* **--format** A string that will use jinja-template syntax to render a string
198- replacing
199-
200-.. code-block:: shell-session
201-
202- # Generate a custom hostname fqdn based on instance-id, cloud and region
203- % cloud-init query --format 'custom-{{instance_id}}.{{region}}.{{v1.cloud_name}}.com'
204- custom-i-0e91f69987f37ec74.us-east-2.aws.com
205-
206-
207-.. note::
208- The standardized instance data keys under **v#** are guaranteed not to change
209- behavior or format. If using top-level convenience aliases for any
210- standardized instance data keys, the most value (highest **v#**) of that key
211- name is what is reported as the top-level value. So these aliases act as a
212- 'latest'.
213-
214-
215-.. _cli_analyze:
216-
217-cloud-init analyze
218-------------------
219-Get detailed reports of where cloud-init spends most of its time. See
220-:ref:`boot_time_analysis` for more info.
221-
222-* **blame** Report ordered by most costly operations.
223-* **dump** Machine-readable JSON dump of all cloud-init tracked events.
224-* **show** show time-ordered report of the cost of operations during each
225- boot stage.
226-* **boot** show timestamps from kernel initialization, kernel finish initialization, and cloud-init start.
227-
228-.. _cli_devel:
229-
230-cloud-init devel
231-----------------
232-Collection of development tools under active development. These tools will
233-likely be promoted to top-level subcommands when stable.
234-
235- * ``cloud-init devel schema``: A **#cloud-config** format and schema
236- validator. It accepts a cloud-config yaml file and annotates potential
237- schema errors locally without the need for deployment. Schema
238- validation is work in progress and supports a subset of cloud-config
239- modules.
240-
241- * ``cloud-init devel render``: Use cloud-init's jinja template render to
242- process **#cloud-config** or **custom-scripts**, injecting any variables
243- from ``/run/cloud-init/instance-data.json``. It accepts a user-data file
244- containing the jinja template header ``## template: jinja`` and renders
245- that content with any instance-data.json variables present.
246-
247-
248-.. _cli_clean:
249-
250-cloud-init clean
251-----------------
252-Remove cloud-init artifacts from /var/lib/cloud and optionally reboot the
253-machine to so cloud-init re-runs all stages as it did on first boot.
254-
255-* **--logs**: Optionally remove /var/log/cloud-init*log files.
256-* **--reboot**: Reboot the system after removing artifacts.
257-
258-.. _cli_init:
259-
260-cloud-init init
261----------------
262-Generally run by OS init systems to execute cloud-init's stages
263-*init* and *init-local*. See :ref:`boot_stages` for more info.
264-Can be run on the commandline, but is generally gated to run only once
265-due to semaphores in **/var/lib/cloud/instance/sem/** and
266-**/var/lib/cloud/sem**.
267-
268-* **--local**: Run *init-local* stage instead of *init*.
269-
270-.. _cli_modules:
271-
272-cloud-init modules
273-------------------
274-Generally run by OS init systems to execute *modules:config* and
275-*modules:final* boot stages. This executes cloud config :ref:`modules`
276-configured to run in the init, config and final stages. The modules are
277-declared to run in various boot stages in the file
278-**/etc/cloud/cloud.cfg** under keys **cloud_init_modules**,
279-**cloud_init_modules** and **cloud_init_modules**. Can be run on the
280-commandline, but each module is gated to run only once due to semaphores
281-in ``/var/lib/cloud/``.
282-
283-* **--mode (init|config|final)**: Run *modules:init*, *modules:config* or
284- *modules:final* cloud-init stages. See :ref:`boot_stages` for more info.
285-
286-.. _cli_single:
287-
288-cloud-init single
289------------------
290-Attempt to run a single named cloud config module. The following example
291-re-runs the cc_set_hostname module ignoring the module default frequency
292-of once-per-instance:
293-
294-* **--name**: The cloud-config module name to run
295-* **--frequency**: Optionally override the declared module frequency
296- with one of (always|once-per-instance|once)
297-
298-.. code-block:: shell-session
299-
300- % cloud-init single --name set_hostname --frequency always
301-
302-**Note**: Mileage may vary trying to re-run each cloud-config module, as
303-some are not idempotent.
304-
305-.. _Cloud-init: https://launchpad.net/cloud-init
306-.. vi: textwidth=78
307diff --git a/doc/rtd/topics/cli.rst b/doc/rtd/topics/cli.rst
308new file mode 100644
309index 0000000..b32677b
310--- /dev/null
311+++ b/doc/rtd/topics/cli.rst
312@@ -0,0 +1,304 @@
313+.. _cli:
314+
315+CLI Interface
316+*************
317+
318+For the latest list of subcommands and arguments use cloud-init's ``--help``
319+option. This can be used against cloud-init itself or any of its subcommands.
320+
321+.. code-block:: shell-session
322+
323+ $ cloud-init --help
324+ usage: /usr/bin/cloud-init [-h] [--version] [--file FILES] [--debug] [--force]
325+ {init,modules,single,query,dhclient-hook,features,analyze,devel,collect-logs,clean,status}
326+ ...
327+
328+ optional arguments:
329+ -h, --help show this help message and exit
330+ --version, -v show program's version number and exit
331+ --file FILES, -f FILES
332+ additional yaml configuration files to use
333+ --debug, -d show additional pre-action logging (default: False)
334+ --force force running even if no datasource is found (use at
335+ your own risk)
336+
337+ Subcommands:
338+ {init,modules,single,query,dhclient-hook,features,analyze,devel,collect-logs,clean,status}
339+ init initializes cloud-init and performs initial modules
340+ modules activates modules using a given configuration key
341+ single run a single module
342+ query Query standardized instance metadata from the command
343+ line.
344+ dhclient-hook Run the dhclient hook to record network info.
345+ features list defined features
346+ analyze Devel tool: Analyze cloud-init logs and data
347+ devel Run development tools
348+ collect-logs Collect and tar all cloud-init debug info
349+ clean Remove logs and artifacts so cloud-init can re-run.
350+ status Report cloud-init status or wait on completion.
351+
352+The rest of this document will give an overview of each of the subcommands.
353+
354+
355+.. _cli_analyze:
356+
357+analyze
358+=======
359+
360+Get detailed reports of where cloud-init spends its time during the boot
361+process. For more complete reference see :ref:`analyze`.
362+
363+Possible subcommands include:
364+
365+* *blame*: report ordered by most costly operations
366+* *dump*: machine-readable JSON dump of all cloud-init tracked events
367+* *show*: show time-ordered report of the cost of operations during each
368+ boot stage
369+* *boot*: show timestamps from kernel initialization, kernel finish
370+ initialization, and cloud-init start
371+
372+
373+.. _cli_clean:
374+
375+clean
376+=====
377+
378+Remove cloud-init artifacts from ``/var/lib/cloud`` to simulate a clean
379+instance. On reboot, cloud-init will re-run all stages as it did on first boot.
380+
381+* *\\-\\-logs*: optionally remove all cloud-init log files in ``/var/log/``
382+* *\\-\\-reboot*: reboot the system after removing artifacts
383+
384+
385+.. _cli_collect_logs:
386+
387+collect-logs
388+============
389+
390+Collect and tar cloud-init generated logs, data files, and system
391+information for triage. This subcommand is integrated with apport.
392+
393+Logs collected include:
394+
395+ * ``/var/log/cloud-init.log``
396+ * ``/var/log/cloud-init-output.log``
397+ * ``/run/cloud-init``
398+ * ``/var/lib/cloud/instance/user-data.txt``
399+ * cloud-init package version
400+ * ``dmesg`` output
401+ * journalctl output
402+
403+.. note::
404+
405+ Ubuntu users can file bugs with ``ubuntu-bug cloud-init`` to
406+ automatically attach these logs to a bug report
407+
408+
409+.. _cli_devel:
410+
411+devel
412+=====
413+
414+Collection of development tools under active development. These tools will
415+likely be promoted to top-level subcommands when stable.
416+
417+Do **NOT** rely on the output of these commands as they can and will change.
418+
419+Current subcommands:
420+
421+ * ``schema``: a **#cloud-config** format and schema
422+ validator. It accepts a cloud-config yaml file and annotates potential
423+ schema errors locally without the need for deployment. Schema
424+ validation is work in progress and supports a subset of cloud-config
425+ modules.
426+
427+ * ``render``: use cloud-init's jinja template render to
428+ process **#cloud-config** or **custom-scripts**, injecting any variables
429+ from ``/run/cloud-init/instance-data.json``. It accepts a user-data file
430+ containing the jinja template header ``## template: jinja`` and renders
431+ that content with any instance-data.json variables present.
432+
433+
434+.. _cli_features:
435+
436+features
437+========
438+
439+Print out each feature supported. If cloud-init does not have the
440+features subcommand, it also does not support any features described in
441+this document.
442+
443+.. code-block:: shell-session
444+
445+ $ cloud-init features
446+ NETWORK_CONFIG_V1
447+ NETWORK_CONFIG_V2
448+
449+
450+.. _cli_init:
451+
452+init
453+====
454+
455+Generally run by OS init systems to execute cloud-init's stages
456+*init* and *init-local*. See :ref:`boot_stages` for more info.
457+Can be run on the commandline, but is generally gated to run only once
458+due to semaphores in ``/var/lib/cloud/instance/sem/`` and
459+``/var/lib/cloud/sem``.
460+
461+* *\\-\\-local*: run *init-local* stage instead of *init*
462+
463+
464+.. _cli_modules:
465+
466+modules
467+=======
468+
469+Generally run by OS init systems to execute *modules:config* and
470+*modules:final* boot stages. This executes cloud config :ref:`modules`
471+configured to run in the init, config and final stages. The modules are
472+declared to run in various boot stages in the file
473+``/etc/cloud/cloud.cfg`` under keys:
474+
475+* *cloud_init_modules*
476+* *cloud_config_modules*
477+* *cloud_init_modules*
478+
479+Can be run on the command line, but each module is gated to run only once due
480+to semaphores in ``/var/lib/cloud/``.
481+
482+* *\\-\\-mode [init|config|final]*: run *modules:init*, *modules:config* or
483+ *modules:final* cloud-init stages. See :ref:`boot_stages` for more info.
484+
485+
486+.. _cli_query:
487+
488+query
489+=====
490+
491+Query standardized cloud instance metadata crawled by cloud-init and stored
492+in ``/run/cloud-init/instance-data.json``. This is a convenience command-line
493+interface to reference any cached configuration metadata that cloud-init
494+crawls when booting the instance. See :ref:`instance_metadata` for more info.
495+
496+* *\\-\\-all*: dump all available instance data as json which can be queried
497+* *\\-\\-instance-data*: optional path to a different instance-data.json file
498+ to source for queries
499+* *\\-\\-list-keys*: list available query keys from cached instance data
500+* *\\-\\-format*: a string that will use jinja-template syntax to render a
501+ string replacing
502+* *<varname>*: a dot-delimited variable path into the instance-data.json
503+ object
504+
505+Below demonstrates how to list all top-level query keys that are standardized
506+aliases:
507+
508+.. code-block:: shell-session
509+
510+ $ cloud-init query --list-keys
511+ _beta_keys
512+ availability_zone
513+ base64_encoded_keys
514+ cloud_name
515+ ds
516+ instance_id
517+ local_hostname
518+ platform
519+ public_ssh_keys
520+ region
521+ sensitive_keys
522+ subplatform
523+ userdata
524+ v1
525+ vendordata
526+
527+Below demonstrates how to query standardized metadata from clouds:
528+
529+.. code-block:: shell-session
530+
531+ % cloud-init query v1.cloud_name
532+ aws # or openstack, azure, gce etc.
533+
534+ # Any standardized instance-data under a <v#> key is aliased as a top-level key for convenience.
535+ % cloud-init query cloud_name
536+ aws # or openstack, azure, gce etc.
537+
538+ # Query datasource-specific metadata on EC2
539+ % cloud-init query ds.meta_data.public_ipv4
540+
541+.. note::
542+
543+ The standardized instance data keys under **v#** are guaranteed not to change
544+ behavior or format. If using top-level convenience aliases for any
545+ standardized instance data keys, the most value (highest **v#**) of that key
546+ name is what is reported as the top-level value. So these aliases act as a
547+ 'latest'.
548+
549+This data can then be formatted to generate custom strings or data:
550+
551+.. code-block:: shell-session
552+
553+ # Generate a custom hostname fqdn based on instance-id, cloud and region
554+ % cloud-init query --format 'custom-{{instance_id}}.{{region}}.{{v1.cloud_name}}.com'
555+ custom-i-0e91f69987f37ec74.us-east-2.aws.com
556+
557+
558+.. _cli_single:
559+
560+single
561+======
562+
563+Attempt to run a single named cloud config module.
564+
565+* *\\-\\-name*: the cloud-config module name to run
566+* *\\-\\-frequency*: optionally override the declared module frequency
567+ with one of (always|once-per-instance|once)
568+
569+The following example re-runs the cc_set_hostname module ignoring the module
570+default frequency of once-per-instance:
571+
572+.. code-block:: shell-session
573+
574+ $ cloud-init single --name set_hostname --frequency always
575+
576+.. note::
577+
578+ Mileage may vary trying to re-run each cloud-config module, as
579+ some are not idempotent.
580+
581+
582+.. _cli_status:
583+
584+status
585+======
586+
587+Report whether cloud-init is running, done, disabled or errored. Exits
588+non-zero if an error is detected in cloud-init.
589+
590+* *\\-\\-long*: detailed status information
591+* *\\-\\-wait*: block until cloud-init completes
592+
593+Below are examples of output when cloud-init is running, showing status and
594+the currently running modules, as well as when it is done.
595+
596+.. code-block:: shell-session
597+
598+ $ cloud-init status
599+ status: running
600+
601+ $ cloud-init status --long
602+ status: running
603+ time: Fri, 26 Jan 2018 21:39:43 +0000
604+ detail:
605+ Running in stage: init-local
606+
607+ $ cloud-init status
608+ status: done
609+
610+ $ cloud-init status --long
611+ status: done
612+ time: Wed, 17 Jan 2018 20:41:59 +0000
613+ detail:
614+ DataSourceNoCloud [seed=/var/lib/cloud/seed/nocloud-net][dsmode=net]
615+
616+.. vi: textwidth=79

Subscribers

People subscribed via source and target branches