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
diff --git a/doc/rtd/topics/capabilities.rst b/doc/rtd/topics/capabilities.rst
0deleted file mode 1006440deleted file mode 100644
index 6d85a99..0000000
--- a/doc/rtd/topics/capabilities.rst
+++ /dev/null
@@ -1,300 +0,0 @@
1.. _capabilities:
2
3************
4Capabilities
5************
6
7- Setting a default locale
8- Setting an instance hostname
9- Generating instance SSH private keys
10- Adding SSH keys to a user's ``.ssh/authorized_keys`` so they can log in
11- Setting up ephemeral mount points
12- Configuring network devices
13
14User configurability
15====================
16
17`Cloud-init`_ 's behavior can be configured via user-data.
18
19 User-data can be given by the user at instance launch time. See
20 :ref:`user_data_formats` for acceptable user-data content.
21
22
23This is done via the ``--user-data`` or ``--user-data-file`` argument to
24ec2-run-instances for example.
25
26* Check your local client's documentation for how to provide a `user-data`
27 string or `user-data` file to cloud-init on instance creation.
28
29
30Feature detection
31=================
32
33Newer versions of cloud-init may have a list of additional features that they
34support. This allows other applications to detect what features the installed
35cloud-init supports without having to parse its version number. If present,
36this list of features will be located at ``cloudinit.version.FEATURES``.
37
38Currently defined feature names include:
39
40 - ``NETWORK_CONFIG_V1`` support for v1 networking configuration,
41 see :ref:`network_config_v1` documentation for examples.
42 - ``NETWORK_CONFIG_V2`` support for v2 networking configuration,
43 see :ref:`network_config_v2` documentation for examples.
44
45
46CLI Interface
47=============
48
49The command line documentation is accessible on any cloud-init installed
50system:
51
52.. code-block:: shell-session
53
54 % cloud-init --help
55 usage: cloud-init [-h] [--version] [--file FILES]
56 [--debug] [--force]
57 {init,modules,single,query,dhclient-hook,features,analyze,devel,collect-logs,clean,status}
58 ...
59
60 optional arguments:
61 -h, --help show this help message and exit
62 --version, -v show program's version number and exit
63 --file FILES, -f FILES
64 additional yaml configuration files to use
65 --debug, -d show additional pre-action logging (default: False)
66 --force force running even if no datasource is found (use at
67 your own risk)
68
69 Subcommands:
70 {init,modules,single,query,dhclient-hook,features,analyze,devel,collect-logs,clean,status}
71 init initializes cloud-init and performs initial modules
72 modules activates modules using a given configuration key
73 single run a single module
74 query Query instance metadata from the command line
75 dhclient-hook run the dhclient hookto record network info
76 features list defined features
77 analyze Devel tool: Analyze cloud-init logs and data
78 devel Run development tools
79 collect-logs Collect and tar all cloud-init debug info
80 clean Remove logs and artifacts so cloud-init can re-run
81 status Report cloud-init status or wait on completion
82
83
84CLI Subcommand details
85======================
86
87.. _cli_features:
88
89cloud-init features
90-------------------
91Print out each feature supported. If cloud-init does not have the
92features subcommand, it also does not support any features described in
93this document.
94
95.. code-block:: shell-session
96
97 % cloud-init features
98 NETWORK_CONFIG_V1
99 NETWORK_CONFIG_V2
100
101.. _cli_status:
102
103cloud-init status
104-----------------
105Report whether cloud-init is running, done, disabled or errored. Exits
106non-zero if an error is detected in cloud-init.
107
108* **--long**: Detailed status information.
109* **--wait**: Block until cloud-init completes.
110
111.. code-block:: shell-session
112
113 % cloud-init status --long
114 status: done
115 time: Wed, 17 Jan 2018 20:41:59 +0000
116 detail:
117 DataSourceNoCloud [seed=/var/lib/cloud/seed/nocloud-net][dsmode=net]
118
119 # Cloud-init running still short versus long options
120 % cloud-init status
121 status: running
122 % cloud-init status --long
123 status: running
124 time: Fri, 26 Jan 2018 21:39:43 +0000
125 detail:
126 Running in stage: init-local
127
128.. _cli_collect_logs:
129
130cloud-init collect-logs
131-----------------------
132Collect and tar cloud-init generated logs, data files and system
133information for triage. This subcommand is integrated with apport.
134
135**Note**: Ubuntu users can file bugs with `ubuntu-bug cloud-init` to
136automaticaly attach these logs to a bug report.
137
138Logs collected are:
139
140 * /var/log/cloud-init*log
141 * /run/cloud-init
142 * cloud-init package version
143 * dmesg output
144 * journalctl output
145 * /var/lib/cloud/instance/user-data.txt
146
147.. _cli_query:
148
149cloud-init query
150------------------
151Query standardized cloud instance metadata crawled by cloud-init and stored
152in ``/run/cloud-init/instance-data.json``. This is a convenience command-line
153interface to reference any cached configuration metadata that cloud-init
154crawls when booting the instance. See :ref:`instance_metadata` for more info.
155
156* **--all**: Dump all available instance data as json which can be queried.
157* **--instance-data**: Optional path to a different instance-data.json file to
158 source for queries.
159* **--list-keys**: List available query keys from cached instance data.
160
161.. code-block:: shell-session
162
163 # List all top-level query keys available (includes standardized aliases)
164 % cloud-init query --list-keys
165 availability_zone
166 base64_encoded_keys
167 cloud_name
168 ds
169 instance_id
170 local_hostname
171 region
172 v1
173
174* **<varname>**: A dot-delimited variable path into the instance-data.json
175 object.
176
177.. code-block:: shell-session
178
179 # Query cloud-init standardized metadata on any cloud
180 % cloud-init query v1.cloud_name
181 aws # or openstack, azure, gce etc.
182
183 # Any standardized instance-data under a <v#> key is aliased as a top-level
184 # key for convenience.
185 % cloud-init query cloud_name
186 aws # or openstack, azure, gce etc.
187
188 # Query datasource-specific metadata on EC2
189 % cloud-init query ds.meta_data.public_ipv4
190
191* **--format** A string that will use jinja-template syntax to render a string
192 replacing
193
194.. code-block:: shell-session
195
196 # Generate a custom hostname fqdn based on instance-id, cloud and region
197 % cloud-init query --format 'custom-{{instance_id}}.{{region}}.{{v1.cloud_name}}.com'
198 custom-i-0e91f69987f37ec74.us-east-2.aws.com
199
200
201.. note::
202 The standardized instance data keys under **v#** are guaranteed not to change
203 behavior or format. If using top-level convenience aliases for any
204 standardized instance data keys, the most value (highest **v#**) of that key
205 name is what is reported as the top-level value. So these aliases act as a
206 'latest'.
207
208
209.. _cli_analyze:
210
211cloud-init analyze
212------------------
213Get detailed reports of where cloud-init spends most of its time. See
214:ref:`boot_time_analysis` for more info.
215
216* **blame** Report ordered by most costly operations.
217* **dump** Machine-readable JSON dump of all cloud-init tracked events.
218* **show** show time-ordered report of the cost of operations during each
219 boot stage.
220* **boot** show timestamps from kernel initialization, kernel finish initialization, and cloud-init start.
221
222.. _cli_devel:
223
224cloud-init devel
225----------------
226Collection of development tools under active development. These tools will
227likely be promoted to top-level subcommands when stable.
228
229 * ``cloud-init devel schema``: A **#cloud-config** format and schema
230 validator. It accepts a cloud-config yaml file and annotates potential
231 schema errors locally without the need for deployment. Schema
232 validation is work in progress and supports a subset of cloud-config
233 modules.
234
235 * ``cloud-init devel render``: Use cloud-init's jinja template render to
236 process **#cloud-config** or **custom-scripts**, injecting any variables
237 from ``/run/cloud-init/instance-data.json``. It accepts a user-data file
238 containing the jinja template header ``## template: jinja`` and renders
239 that content with any instance-data.json variables present.
240
241
242.. _cli_clean:
243
244cloud-init clean
245----------------
246Remove cloud-init artifacts from /var/lib/cloud and optionally reboot the
247machine to so cloud-init re-runs all stages as it did on first boot.
248
249* **--logs**: Optionally remove /var/log/cloud-init*log files.
250* **--reboot**: Reboot the system after removing artifacts.
251
252.. _cli_init:
253
254cloud-init init
255---------------
256Generally run by OS init systems to execute cloud-init's stages
257*init* and *init-local*. See :ref:`boot_stages` for more info.
258Can be run on the commandline, but is generally gated to run only once
259due to semaphores in **/var/lib/cloud/instance/sem/** and
260**/var/lib/cloud/sem**.
261
262* **--local**: Run *init-local* stage instead of *init*.
263
264.. _cli_modules:
265
266cloud-init modules
267------------------
268Generally run by OS init systems to execute *modules:config* and
269*modules:final* boot stages. This executes cloud config :ref:`modules`
270configured to run in the init, config and final stages. The modules are
271declared to run in various boot stages in the file
272**/etc/cloud/cloud.cfg** under keys **cloud_init_modules**,
273**cloud_init_modules** and **cloud_init_modules**. Can be run on the
274commandline, but each module is gated to run only once due to semaphores
275in ``/var/lib/cloud/``.
276
277* **--mode (init|config|final)**: Run *modules:init*, *modules:config* or
278 *modules:final* cloud-init stages. See :ref:`boot_stages` for more info.
279
280.. _cli_single:
281
282cloud-init single
283-----------------
284Attempt to run a single named cloud config module. The following example
285re-runs the cc_set_hostname module ignoring the module default frequency
286of once-per-instance:
287
288* **--name**: The cloud-config module name to run
289* **--frequency**: Optionally override the declared module frequency
290 with one of (always|once-per-instance|once)
291
292.. code-block:: shell-session
293
294 % cloud-init single --name set_hostname --frequency always
295
296**Note**: Mileage may vary trying to re-run each cloud-config module, as
297some are not idempotent.
298
299.. _Cloud-init: https://launchpad.net/cloud-init
300.. vi: textwidth=78
diff --git a/doc/rtd/topics/cli.rst b/doc/rtd/topics/cli.rst
301new file mode 1006440new file mode 100644
index 0000000..b32677b
--- /dev/null
+++ b/doc/rtd/topics/cli.rst
@@ -0,0 +1,304 @@
1.. _cli:
2
3CLI Interface
4*************
5
6For the latest list of subcommands and arguments use cloud-init's ``--help``
7option. This can be used against cloud-init itself or any of its subcommands.
8
9.. code-block:: shell-session
10
11 $ cloud-init --help
12 usage: /usr/bin/cloud-init [-h] [--version] [--file FILES] [--debug] [--force]
13 {init,modules,single,query,dhclient-hook,features,analyze,devel,collect-logs,clean,status}
14 ...
15
16 optional arguments:
17 -h, --help show this help message and exit
18 --version, -v show program's version number and exit
19 --file FILES, -f FILES
20 additional yaml configuration files to use
21 --debug, -d show additional pre-action logging (default: False)
22 --force force running even if no datasource is found (use at
23 your own risk)
24
25 Subcommands:
26 {init,modules,single,query,dhclient-hook,features,analyze,devel,collect-logs,clean,status}
27 init initializes cloud-init and performs initial modules
28 modules activates modules using a given configuration key
29 single run a single module
30 query Query standardized instance metadata from the command
31 line.
32 dhclient-hook Run the dhclient hook to record network info.
33 features list defined features
34 analyze Devel tool: Analyze cloud-init logs and data
35 devel Run development tools
36 collect-logs Collect and tar all cloud-init debug info
37 clean Remove logs and artifacts so cloud-init can re-run.
38 status Report cloud-init status or wait on completion.
39
40The rest of this document will give an overview of each of the subcommands.
41
42
43.. _cli_analyze:
44
45analyze
46=======
47
48Get detailed reports of where cloud-init spends its time during the boot
49process. For more complete reference see :ref:`analyze`.
50
51Possible subcommands include:
52
53* *blame*: report ordered by most costly operations
54* *dump*: machine-readable JSON dump of all cloud-init tracked events
55* *show*: show time-ordered report of the cost of operations during each
56 boot stage
57* *boot*: show timestamps from kernel initialization, kernel finish
58 initialization, and cloud-init start
59
60
61.. _cli_clean:
62
63clean
64=====
65
66Remove cloud-init artifacts from ``/var/lib/cloud`` to simulate a clean
67instance. On reboot, cloud-init will re-run all stages as it did on first boot.
68
69* *\\-\\-logs*: optionally remove all cloud-init log files in ``/var/log/``
70* *\\-\\-reboot*: reboot the system after removing artifacts
71
72
73.. _cli_collect_logs:
74
75collect-logs
76============
77
78Collect and tar cloud-init generated logs, data files, and system
79information for triage. This subcommand is integrated with apport.
80
81Logs collected include:
82
83 * ``/var/log/cloud-init.log``
84 * ``/var/log/cloud-init-output.log``
85 * ``/run/cloud-init``
86 * ``/var/lib/cloud/instance/user-data.txt``
87 * cloud-init package version
88 * ``dmesg`` output
89 * journalctl output
90
91.. note::
92
93 Ubuntu users can file bugs with ``ubuntu-bug cloud-init`` to
94 automatically attach these logs to a bug report
95
96
97.. _cli_devel:
98
99devel
100=====
101
102Collection of development tools under active development. These tools will
103likely be promoted to top-level subcommands when stable.
104
105Do **NOT** rely on the output of these commands as they can and will change.
106
107Current subcommands:
108
109 * ``schema``: a **#cloud-config** format and schema
110 validator. It accepts a cloud-config yaml file and annotates potential
111 schema errors locally without the need for deployment. Schema
112 validation is work in progress and supports a subset of cloud-config
113 modules.
114
115 * ``render``: use cloud-init's jinja template render to
116 process **#cloud-config** or **custom-scripts**, injecting any variables
117 from ``/run/cloud-init/instance-data.json``. It accepts a user-data file
118 containing the jinja template header ``## template: jinja`` and renders
119 that content with any instance-data.json variables present.
120
121
122.. _cli_features:
123
124features
125========
126
127Print out each feature supported. If cloud-init does not have the
128features subcommand, it also does not support any features described in
129this document.
130
131.. code-block:: shell-session
132
133 $ cloud-init features
134 NETWORK_CONFIG_V1
135 NETWORK_CONFIG_V2
136
137
138.. _cli_init:
139
140init
141====
142
143Generally run by OS init systems to execute cloud-init's stages
144*init* and *init-local*. See :ref:`boot_stages` for more info.
145Can be run on the commandline, but is generally gated to run only once
146due to semaphores in ``/var/lib/cloud/instance/sem/`` and
147``/var/lib/cloud/sem``.
148
149* *\\-\\-local*: run *init-local* stage instead of *init*
150
151
152.. _cli_modules:
153
154modules
155=======
156
157Generally run by OS init systems to execute *modules:config* and
158*modules:final* boot stages. This executes cloud config :ref:`modules`
159configured to run in the init, config and final stages. The modules are
160declared to run in various boot stages in the file
161``/etc/cloud/cloud.cfg`` under keys:
162
163* *cloud_init_modules*
164* *cloud_config_modules*
165* *cloud_init_modules*
166
167Can be run on the command line, but each module is gated to run only once due
168to semaphores in ``/var/lib/cloud/``.
169
170* *\\-\\-mode [init|config|final]*: run *modules:init*, *modules:config* or
171 *modules:final* cloud-init stages. See :ref:`boot_stages` for more info.
172
173
174.. _cli_query:
175
176query
177=====
178
179Query standardized cloud instance metadata crawled by cloud-init and stored
180in ``/run/cloud-init/instance-data.json``. This is a convenience command-line
181interface to reference any cached configuration metadata that cloud-init
182crawls when booting the instance. See :ref:`instance_metadata` for more info.
183
184* *\\-\\-all*: dump all available instance data as json which can be queried
185* *\\-\\-instance-data*: optional path to a different instance-data.json file
186 to source for queries
187* *\\-\\-list-keys*: list available query keys from cached instance data
188* *\\-\\-format*: a string that will use jinja-template syntax to render a
189 string replacing
190* *<varname>*: a dot-delimited variable path into the instance-data.json
191 object
192
193Below demonstrates how to list all top-level query keys that are standardized
194aliases:
195
196.. code-block:: shell-session
197
198 $ cloud-init query --list-keys
199 _beta_keys
200 availability_zone
201 base64_encoded_keys
202 cloud_name
203 ds
204 instance_id
205 local_hostname
206 platform
207 public_ssh_keys
208 region
209 sensitive_keys
210 subplatform
211 userdata
212 v1
213 vendordata
214
215Below demonstrates how to query standardized metadata from clouds:
216
217.. code-block:: shell-session
218
219 % cloud-init query v1.cloud_name
220 aws # or openstack, azure, gce etc.
221
222 # Any standardized instance-data under a <v#> key is aliased as a top-level key for convenience.
223 % cloud-init query cloud_name
224 aws # or openstack, azure, gce etc.
225
226 # Query datasource-specific metadata on EC2
227 % cloud-init query ds.meta_data.public_ipv4
228
229.. note::
230
231 The standardized instance data keys under **v#** are guaranteed not to change
232 behavior or format. If using top-level convenience aliases for any
233 standardized instance data keys, the most value (highest **v#**) of that key
234 name is what is reported as the top-level value. So these aliases act as a
235 'latest'.
236
237This data can then be formatted to generate custom strings or data:
238
239.. code-block:: shell-session
240
241 # Generate a custom hostname fqdn based on instance-id, cloud and region
242 % cloud-init query --format 'custom-{{instance_id}}.{{region}}.{{v1.cloud_name}}.com'
243 custom-i-0e91f69987f37ec74.us-east-2.aws.com
244
245
246.. _cli_single:
247
248single
249======
250
251Attempt to run a single named cloud config module.
252
253* *\\-\\-name*: the cloud-config module name to run
254* *\\-\\-frequency*: optionally override the declared module frequency
255 with one of (always|once-per-instance|once)
256
257The following example re-runs the cc_set_hostname module ignoring the module
258default frequency of once-per-instance:
259
260.. code-block:: shell-session
261
262 $ cloud-init single --name set_hostname --frequency always
263
264.. note::
265
266 Mileage may vary trying to re-run each cloud-config module, as
267 some are not idempotent.
268
269
270.. _cli_status:
271
272status
273======
274
275Report whether cloud-init is running, done, disabled or errored. Exits
276non-zero if an error is detected in cloud-init.
277
278* *\\-\\-long*: detailed status information
279* *\\-\\-wait*: block until cloud-init completes
280
281Below are examples of output when cloud-init is running, showing status and
282the currently running modules, as well as when it is done.
283
284.. code-block:: shell-session
285
286 $ cloud-init status
287 status: running
288
289 $ cloud-init status --long
290 status: running
291 time: Fri, 26 Jan 2018 21:39:43 +0000
292 detail:
293 Running in stage: init-local
294
295 $ cloud-init status
296 status: done
297
298 $ cloud-init status --long
299 status: done
300 time: Wed, 17 Jan 2018 20:41:59 +0000
301 detail:
302 DataSourceNoCloud [seed=/var/lib/cloud/seed/nocloud-net][dsmode=net]
303
304.. vi: textwidth=79

Subscribers

People subscribed via source and target branches