Skip to content

Commit 331a969

Browse files
Merge branch 'main' into toachris/add-az-id
2 parents 48514c3 + fc9ff74 commit 331a969

File tree

4 files changed

+44
-181
lines changed

4 files changed

+44
-181
lines changed

amazon-ec2-utils.spec

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Source24: ebsnvme-id
1515
Source25: 51-ec2-xen-vbd-devices.rules
1616
Source26: 53-ec2-read-ahead-kb.rules
1717
Source27: 51-ec2-ena-ptp-device.rules
18+
Source28: ebsnvme
1819

1920
URL: https://github.com/aws/amazon-ec2-utils
2021
BuildArch: noarch
@@ -39,16 +40,18 @@ amazon-ec2-utils contains a set of utilities for running in ec2.
3940
rm -rf $RPM_BUILD_ROOT
4041
mkdir -p $RPM_BUILD_ROOT%{_bindir}
4142
mkdir -p $RPM_BUILD_ROOT%{_udevrulesdir}
42-
mkdir -p $RPM_BUILD_ROOT/%{_sbindir}
43+
mkdir -p $RPM_BUILD_ROOT%{_sbindir}
4344
mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/udev/rules.d/
4445
mkdir -p $RPM_BUILD_ROOT%{_mandir}/man8/
4546

4647
install -m755 %{SOURCE0} $RPM_BUILD_ROOT%{_bindir}
47-
install -m755 %{SOURCE1} $RPM_BUILD_ROOT/%{_sbindir}
48+
install -m755 %{SOURCE1} $RPM_BUILD_ROOT%{_sbindir}
4849
install -m644 %{SOURCE2} $RPM_BUILD_ROOT%{_udevrulesdir}
50+
install -m755 %{SOURCE24} $RPM_BUILD_ROOT%{_sbindir}
4951
install -m644 %{SOURCE25} $RPM_BUILD_ROOT%{_udevrulesdir}
5052
install -m644 %{SOURCE26} $RPM_BUILD_ROOT%{_udevrulesdir}
5153
install -m644 %{SOURCE27} $RPM_BUILD_ROOT%{_udevrulesdir}
54+
install -m755 %{SOURCE28} $RPM_BUILD_ROOT%{_sbindir}
5255
# Install 60-cdrom_id.rules to /etc rather than %{_udevrulesdir}
5356
# because it is intended as an override of a systemd-provided rules
5457
# file:
@@ -57,7 +60,6 @@ install -m644 %{SOURCE16} $RPM_BUILD_ROOT%{_sysconfdir}/udev/rules.d/
5760
#udev rules for nvme block devices and supporting scripts
5861
install -m644 %{SOURCE22} $RPM_BUILD_ROOT%{_udevrulesdir}
5962
install -m755 %{SOURCE23} $RPM_BUILD_ROOT%{_sbindir}/ec2nvme-nsid
60-
install -m755 %{SOURCE24} $RPM_BUILD_ROOT/%{_sbindir}
6163

6264
%check
6365
%{python3} -m py_compile %{SOURCE24}
@@ -68,6 +70,7 @@ rm -rf $RPM_BUILD_ROOT
6870
%files
6971
%{_bindir}/ec2-metadata
7072
%{_sbindir}/ec2nvme-nsid
73+
%{_sbindir}/ebsnvme
7174
%{_sbindir}/ebsnvme-id
7275
%{_sbindir}/ec2udev-vbd
7376
/usr/lib/udev/rules.d/51-ec2-ena-ptp-device.rules

doc/ec2-metadata.8

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@ Print EC2 resource tags if permitted in EC2 Instance Metadata Options.
119119
.B \-\-quiet
120120
Don't print metadata keys
121121
.TP
122+
.B \-\-path
123+
Show metadata information from the specified path. Can be specified multiple times.
124+
.TP
122125
.B \-h, \-\-help
123126
Show summary of options.
124127
.SH SEE ALSO

ebsnvme-id

Lines changed: 0 additions & 174 deletions
This file was deleted.

ebsnvme-id

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ebsnvme

ec2-metadata

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
function print_help()
1010
{
11-
echo "ec2-metadata v0.1.6
11+
echo "ec2-metadata v0.1.3
1212
Use to retrieve EC2 instance metadata from within a running EC2 instance.
1313
e.g. to retrieve instance id: ec2-metadata -i
1414
to retrieve ami id: ec2-metadata -a
@@ -43,11 +43,13 @@ Options:
4343
-s/--security-groups Names of the security groups the instance is launched in. Only available if supplied at instance launch time
4444
-d/--user-data User-supplied data.Only available if supplied at instance launch time.
4545
-g/--tags Tags assigned to this instance.
46-
--quiet Suppress tag keys from the output."
46+
--quiet Suppress tag keys from the output.
47+
--path Show metadata information from the specified path. Can be specified multiple times."
4748
}
4849

4950
METADATA_BASEURL="http://169.254.169.254"
5051
METADATA_TOKEN_PATH="latest/api/token"
52+
METADATA_VERSION="latest"
5153
QUIET=""
5254

5355
function set_imds_token()
@@ -65,7 +67,7 @@ function set_imds_token()
6567
function get_meta()
6668
{
6769
local imds_out
68-
imds_out=$(curl -s -q -H "X-aws-ec2-metadata-token:${IMDS_TOKEN}" -f ${METADATA_BASEURL}/latest/${1})
70+
imds_out=$(curl -s -q -H "X-aws-ec2-metadata-token:${IMDS_TOKEN}" -f ${METADATA_BASEURL}/${METADATA_VERSION}/${1})
6971
echo -n "${imds_out}"
7072
}
7173

@@ -160,6 +162,27 @@ function print_all()
160162
print_tags
161163
}
162164

165+
function print_path()
166+
{
167+
local path
168+
169+
path=$(echo "$1" | sed 's/\/\+/\//g')
170+
171+
if [[ ! "$path" =~ (^/$|^/?(1\.0|[0-9]{4}-[0-9]{2}-[0-9]{2}|latest)) ]]; then
172+
if [[ "$path" =~ ^/?(dynamic|meta-data) ]]; then
173+
path="latest/$path"
174+
else
175+
path="latest/meta-data/$path"
176+
fi
177+
fi
178+
179+
path=$(echo "$path" | sed 's/\/\+/\//g')
180+
181+
METADATA_VERSION=""
182+
print_normal_metric "$path" "$path"
183+
METADATA_VERSION="latest"
184+
}
185+
163186
#check if run inside an EC2 instance
164187
set_imds_token
165188

@@ -169,11 +192,12 @@ if [ "$#" -eq 0 ]; then
169192
fi
170193

171194
declare -a actions
195+
declare -a paths
172196
shortopts=almnDbithokzZPcpvuresdgR
173197
longopts=(ami-id ami-launch-index ami-manifest-path ancestor-ami-ids aws-domain block-device-mapping
174198
instance-id instance-type local-hostname local-ipv4 kernel-id availability-zone availability-zone-id
175199
partition product-codes public-hostname public-ipv4 public-keys ramdisk-id
176-
reservation-id security-groups user-data tags region help all quiet)
200+
reservation-id security-groups user-data tags region help all quiet path:)
177201

178202
oldIFS="$IFS"
179203
IFS=,
@@ -196,6 +220,11 @@ while true; do
196220
--quiet)
197221
QUIET=1 ; shift
198222
;;
223+
--path)
224+
actions+=("$1")
225+
paths+=("$2")
226+
shift 2
227+
;;
199228
--)
200229
shift ; break
201230
;;
@@ -238,6 +267,7 @@ for action in "${actions[@]}"; do
238267
-s | --security-groups ) print_normal_metric security-groups meta-data/security-groups ;;
239268
-d | --user-data ) print_normal_metric user-data user-data ;;
240269
-g | --tags ) print_tags ;;
270+
--path ) print_path "${paths[0]}"; paths=("${paths[@]:1}") ;;
241271
--all ) print_all; exit ;;
242272
esac
243273
shift

0 commit comments

Comments
 (0)