Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change ec2nvme-nsid to use Bash built-ins #32

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion amazon-ec2-utils.spec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Name: amazon-ec2-utils
Summary: A set of tools for running in EC2
Version: 2.1.0
Version: 2.2.0
Release: 1%{?dist}
License: MIT
Group: System Tools
Expand Down Expand Up @@ -75,6 +75,9 @@ rm -rf $RPM_BUILD_ROOT
/etc/udev/rules.d/60-cdrom_id.rules

%changelog
* Thu Jan 18 2024 Keith Gable <gablk@amazon.com> - 2.2.0-1
- Change ec2nvme-nsid to use Bash string manipulation to improve
performance and reliability

* Thu Apr 6 2023 Noah Meyerhans <nmeyerha@amazon.com> - 2.1.0-1
- Add --quiet option to ec2-metadata
Expand Down
15 changes: 11 additions & 4 deletions ec2nvme-nsid
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,18 @@
# for the specific language governing permissions and limitations under
# the License.

#Expected input if partition's kernel name like nvme0n1p2
if [ $# -eq 0 ] ; then
# Expected input is partition's kernel name like nvme0n1p2 or nvme0n1, output would be 1

if [[ $# -ne 1 ]]; then
exit 1
else
# extract ns id from partition's kernel name and export it
NSID=$(echo -n "$@" | cut -f 3 -d 'n' | cut -f 1 -d 'p')
kernel_name=$1

# Remove nvme prefix (also deals with any /dev that might accidentally get passed in)
prefix_removed=${kernel_name#*nvme*n}

# Remove partition suffix
NSID=${prefix_removed%p*}

echo "_NS_ID=${NSID}"
fi