summaryrefslogtreecommitdiff
path: root/tools/ds-identify
diff options
context:
space:
mode:
authorScott Moser <smoser@brickies.net>2017-02-23 17:15:27 -0500
committerScott Moser <smoser@brickies.net>2017-02-24 22:51:08 -0500
commit9bb55c6c45bcc5e310cf7e4d42cad53759dcca15 (patch)
treef3f4061e3623237e48f5b0b1c997365f9d16e448 /tools/ds-identify
parent131b6f16a314d863e142d5f59c8488b59e28fa97 (diff)
downloadvyos-cloud-init-9bb55c6c45bcc5e310cf7e4d42cad53759dcca15.tar.gz
vyos-cloud-init-9bb55c6c45bcc5e310cf7e4d42cad53759dcca15.zip
DatasourceEc2: add warning message when not on AWS.
Based on the setting Datasource/Ec2/strict_id, the datasource will now warn once per instance.
Diffstat (limited to 'tools/ds-identify')
-rwxr-xr-xtools/ds-identify40
1 files changed, 31 insertions, 9 deletions
diff --git a/tools/ds-identify b/tools/ds-identify
index bfb55ed1..dfa856ff 100755
--- a/tools/ds-identify
+++ b/tools/ds-identify
@@ -635,28 +635,50 @@ ec2_read_strict_setting() {
return 0
}
-dscheck_Ec2() {
- # http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/identify_ec2_instances.html
- # http://paste.ubuntu.com/23630859/
-
- check_seed_dir "ec2" meta-data user-data && return ${DS_FOUND}
- is_container && return ${DS_NOT_FOUND}
+ec2_identify_platform() {
+ local default="$1"
+ local serial="${DI_DMI_PRODUCT_SERIAL}"
+ # AWS http://docs.aws.amazon.com/AWSEC2/
+ # latest/UserGuide/identify_ec2_instances.html
local uuid="" hvuuid="$PATH_ROOT/sys/hypervisor/uuid"
# if the (basically) xen specific /sys/hypervisor/uuid starts with 'ec2'
if [ -r "$hvuuid" ] && read uuid < "$hvuuid" &&
[ "${uuid#ec2}" != "$uuid" ]; then
- return ${DS_FOUND}
+ _RET="AWS"
+ return 0
fi
# product uuid and product serial start with case insensitive
- local uuid="${DI_DMI_PRODUCT_UUID}" serial="${DI_DMI_PRODUCT_SERIAL}"
+ local uuid="${DI_DMI_PRODUCT_UUID}"
case "$uuid:$serial" in
[Ee][Cc]2*:[Ee][Cc]2)
# both start with ec2, now check for case insenstive equal
- nocase_equal "$uuid" "$serial" && return ${DS_FOUND};;
+ nocase_equal "$uuid" "$serial" &&
+ { _RET="AWS"; return 0; };;
esac
+ _RET="$default"
+ return 0;
+}
+
+dscheck_Ec2() {
+ check_seed_dir "ec2" meta-data user-data && return ${DS_FOUND}
+ is_container && return ${DS_NOT_FOUND}
+
+ local unknown="Unknown" platform=""
+ if ec2_identify_platform "$unknown"; then
+ platform="$_RET"
+ else
+ warn "Failed to identify ec2 platform. Using '$unknown'."
+ platform=$unknown
+ fi
+
+ debug 1 "ec2 platform is '$platform'."
+ if [ "$platform" != "$unknown" ]; then
+ return $DS_FOUND
+ fi
+
local default="true"
if ec2_read_strict_setting "$default"; then
strict="$_RET"