summaryrefslogtreecommitdiff
path: root/cloudinit/cmd/query.py
diff options
context:
space:
mode:
authorChad Smith <chad.smith@canonical.com>2018-10-30 20:02:38 +0000
committerServer Team CI Bot <josh.powers+server-team-bot@canonical.com>2018-10-30 20:02:38 +0000
commitd74d3f0ff5c8d453f626b113f4e6065322f822fa (patch)
tree9bccbc3de8cc63f1624e2188d8d869f102987c0c /cloudinit/cmd/query.py
parentdc0be9c56f78537f1808934d26f5aa0868ae7842 (diff)
downloadvyos-cloud-init-d74d3f0ff5c8d453f626b113f4e6065322f822fa.tar.gz
vyos-cloud-init-d74d3f0ff5c8d453f626b113f4e6065322f822fa.zip
query: better error when missing read permission on instance-data
Emit a permissions error instead of "Missing instance-data.json" when non-root user doesn't have read-permission on /run/cloud-init/instance-data.json
Diffstat (limited to 'cloudinit/cmd/query.py')
-rw-r--r--cloudinit/cmd/query.py8
1 files changed, 6 insertions, 2 deletions
diff --git a/cloudinit/cmd/query.py b/cloudinit/cmd/query.py
index ff03de94..1d888b9d 100644
--- a/cloudinit/cmd/query.py
+++ b/cloudinit/cmd/query.py
@@ -3,6 +3,7 @@
"""Query standardized instance metadata from the command line."""
import argparse
+from errno import EACCES
import os
import six
import sys
@@ -106,8 +107,11 @@ def handle_args(name, args):
try:
instance_json = util.load_file(instance_data_fn)
- except IOError:
- LOG.error('Missing instance-data.json file: %s', instance_data_fn)
+ except (IOError, OSError) as e:
+ if e.errno == EACCES:
+ LOG.error("No read permission on '%s'. Try sudo", instance_data_fn)
+ else:
+ LOG.error('Missing instance-data file: %s', instance_data_fn)
return 1
instance_data = util.load_json(instance_json)