summaryrefslogtreecommitdiff
path: root/cloudinit/cmd/cloud_id.py
diff options
context:
space:
mode:
authorChad Smith <chad.smith@canonical.com>2022-01-13 10:12:23 -0700
committerGitHub <noreply@github.com>2022-01-13 11:12:23 -0600
commit0de7acb194dc15650eee1d5332efed82ef162f84 (patch)
treee223562b3031a82894ceda71d6361aad9f570732 /cloudinit/cmd/cloud_id.py
parente3f3485d875f021915654bf2b64678e151a8d6f6 (diff)
downloadvyos-cloud-init-0de7acb194dc15650eee1d5332efed82ef162f84.tar.gz
vyos-cloud-init-0de7acb194dc15650eee1d5332efed82ef162f84.zip
cli: cloud-id report not-run or disabled state as cloud-id (#1162)
This fix has two elements: - cloud-init status will not correctly report 'not-run' prior to systemd generator running. Only report "disabled" when generator has run and /run/cloud-init/disabled exists. - Expose not-run and disabled state in cloud-id responses - Add unique error codes from cloud-id for error, disabled and not-run. The new cloud-id exit codes: 0: success 1: error 2: cloud-init is in disabled state 3: cloud-init generator has not run yet
Diffstat (limited to 'cloudinit/cmd/cloud_id.py')
-rwxr-xr-xcloudinit/cmd/cloud_id.py11
1 files changed, 10 insertions, 1 deletions
diff --git a/cloudinit/cmd/cloud_id.py b/cloudinit/cmd/cloud_id.py
index b92b03a8..b71c19de 100755
--- a/cloudinit/cmd/cloud_id.py
+++ b/cloudinit/cmd/cloud_id.py
@@ -6,6 +6,7 @@ import argparse
import json
import sys
+from cloudinit.cmd.status import UXAppStatus, get_status_details
from cloudinit.sources import (
INSTANCE_JSON_FILE,
METADATA_UNKNOWN,
@@ -62,8 +63,16 @@ def handle_args(name, args):
Print the canonical cloud-id on which the instance is running.
- @return: 0 on success, 1 otherwise.
+ @return: 0 on success, 1 on error, 2 on disabled, 3 on cloud-init not-run.
"""
+ status, _status_details, _time = get_status_details()
+ if status == UXAppStatus.DISABLED:
+ sys.stdout.write("{0}\n".format(status.value))
+ return 2
+ elif status == UXAppStatus.NOT_RUN:
+ sys.stdout.write("{0}\n".format(status.value))
+ return 3
+
try:
instance_data = json.load(open(args.instance_data))
except IOError: