pax_global_header00006660000000000000000000000064141673771350014530gustar00rootroot0000000000000052 comment=6417dae19b85ada987dfadac9b9fc97a200ca770 amazon-ec2-utils-1.4/000077500000000000000000000000001416737713500144665ustar00rootroot00000000000000amazon-ec2-utils-1.4/.circleci/000077500000000000000000000000001416737713500163215ustar00rootroot00000000000000amazon-ec2-utils-1.4/.circleci/config.yml000066400000000000000000000031251416737713500203120ustar00rootroot00000000000000# Use the latest 2.1 version of CircleCI pipeline process engine. # See: https://circleci.com/docs/2.0/configuration-reference version: 2.1 # Define a job to be invoked later in a workflow. # See: https://circleci.com/docs/2.0/configuration-reference/#jobs jobs: shellcheck: docker: - image: public.ecr.aws/debian/debian:11 steps: - run: name: "Install dependencies" command: "apt-get update && DEBIAN_FRONTEND=noninteractive apt-get -y install shellcheck git ssh-client" - checkout - run: name: "shellcheck" command: "shellcheck -s bash -S warning ec2-metadata ec2nvme-nsid ec2udev-vbd ec2udev-vcpu" code-checks-al2: docker: - image: public.ecr.aws/amazonlinux/amazonlinux:2 steps: - run: name: "Install dependencies" command: | yum -y install python-pip git pip install flake8 - checkout - run: name: "flake8" command: "git grep -l '^#!/usr/bin/env python' | xargs flake8 ebsnvme-id" build-al2-rpm: docker: - image: public.ecr.aws/amazonlinux/amazonlinux:2 steps: - run: name: "Install dependencies" command: | yum -y install rpm-build python git - checkout - run: name: "rpmbuild" command: "rpmbuild --define \"_sourcedir $PWD\" -bb amazon-ec2-utils.spec" # Invoke jobs via workflows # See: https://circleci.com/docs/2.0/configuration-reference/#workflows workflows: ci-workflow: jobs: - shellcheck - code-checks-al2 - build-al2-rpm amazon-ec2-utils-1.4/51-ec2-hvm-devices.rules000066400000000000000000000004461416737713500206520ustar00rootroot00000000000000# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # # Licensed under the MIT License. See the LICENSE accompanying this file # for the specific language governing permissions and limitations under # the License. KERNEL=="xvd*", PROGRAM="/sbin/ec2udev-vbd %k", SYMLINK+="%c" amazon-ec2-utils-1.4/51-ec2-xen-vbd-devices.rules000066400000000000000000000010771416737713500214240ustar00rootroot00000000000000# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # # Licensed under the MIT License. See the LICENSE accompanying this file # for the specific language governing permissions and limitations under # the License. # Set ID_PATH for xen virtual block devices (vbd) which are no longer # set by udev in systemd versions post v184 thus preserving prior # behaviour and with by-path links generated by corresponding rules from # 60-persistent-storage.rules SUBSYSTEM=="block", SUBSYSTEMS=="xen", DRIVERS=="vbd", ENV{ID_PATH}="xen-%b", ENV{ID_PATH_TAG}="xen-%b" amazon-ec2-utils-1.4/52-ec2-vcpu.rules000066400000000000000000000004541416737713500174150ustar00rootroot00000000000000# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # # Licensed under the MIT License. See the LICENSE accompanying this file # for the specific language governing permissions and limitations under # the License. SUBSYSTEM=="cpu", ACTION=="add", RUN+="/sbin/ec2udev-vcpu $devpath" amazon-ec2-utils-1.4/53-ec2-read-ahead-kb.rules000066400000000000000000000007471416737713500210130ustar00rootroot00000000000000# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # # Licensed under the MIT License. See the LICENSE accompanying this file # for the specific language governing permissions and limitations under # the License. # increase read_ahead_kb when a nfs/efs export is mounted to improve throughput SUBSYSTEM=="bdi", ACTION=="add", PROGRAM="/bin/awk -v bdi=$kernel 'BEGIN{ret=1} {if ($4 == bdi) {ret=0}} END{exit ret}' /proc/fs/nfsfs/volumes", ATTR{read_ahead_kb}="15360" amazon-ec2-utils-1.4/60-cdrom_id.rules000066400000000000000000000005211416737713500175430ustar00rootroot00000000000000# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # # Licensed under the MIT License. See the LICENSE accompanying this file # for the specific language governing permissions and limitations under # the License. # This is an empty placeholder file used to signal udev to # skip probing for cd/dvd drive capabilities. amazon-ec2-utils-1.4/70-ec2-nvme-devices.rules000066400000000000000000000031371416737713500210260ustar00rootroot00000000000000# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # # Licensed under the MIT License. See the LICENSE accompanying this file # for the specific language governing permissions and limitations under # the License. #nvme-ns-* devices ACTION=="add", KERNEL=="nvme[0-9]*n[0-9]*", ENV{DEVTYPE}=="disk", ATTRS{serial}=="?*", ATTRS{model}=="?*", SYMLINK+="disk/by-id/nvme-$attr{model}_$attr{serial}-ns-%n", OPTIONS+="string_escape=replace" #nvme partitions ACTION=="add", KERNEL=="nvme[0-9]*n[0-9]*p[0-9]*", ENV{DEVTYPE}=="partition", ATTRS{serial}=="?*", ATTRS{model}=="?*", IMPORT{program}="ec2nvme-nsid %k" ACTION=="add", KERNEL=="nvme[0-9]*n[0-9]*p[0-9]*", ENV{DEVTYPE}=="partition", ATTRS{serial}=="?*", ATTRS{model}=="?*", ENV{_NS_ID}=="?*", SYMLINK+="disk/by-id/nvme-$attr{model}_$attr{serial}-ns-$env{_NS_ID}-part%n", OPTIONS+="string_escape=replace" # ebs nvme devices ACTION=="add", KERNEL=="nvme[0-9]*n[0-9]*", ENV{DEVTYPE}=="disk", ATTRS{model}=="Amazon Elastic Block Store", PROGRAM="/sbin/ebsnvme-id -u /dev/%k", SYMLINK+="%c" ACTION=="add", KERNEL=="nvme[0-9]*n[0-9]*p[0-9]*", ENV{DEVTYPE}=="partition", ATTRS{model}=="Amazon Elastic Block Store", PROGRAM="/sbin/ebsnvme-id -u /dev/%k", SYMLINK+="%c%n" # Do not timeout I/O operations on EBS volumes. ACTION=="add", KERNEL=="nvme[0-9]*n[0-9]*", ENV{DEVTYPE}=="disk", ATTRS{model}=="Amazon Elastic Block Store", ATTR{queue/io_timeout}="4294967295" # instance store nvme devices ACTION=="add", KERNEL=="nvme[0-9]*n[0-9]*", ENV{DEVTYPE}=="disk", ATTRS{model}=="Amazon EC2 NVMe Instance Storage", ATTR{queue/io_timeout}="90000" amazon-ec2-utils-1.4/CODE_OF_CONDUCT.md000066400000000000000000000004651416737713500172720ustar00rootroot00000000000000## Code of Conduct This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct). For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact opensource-codeofconduct@amazon.com with any additional questions or comments. amazon-ec2-utils-1.4/CONTRIBUTING.md000066400000000000000000000063521416737713500167250ustar00rootroot00000000000000# Contributing Guidelines Thank you for your interest in contributing to our project. Whether it's a bug report, new feature, correction, or additional documentation, we greatly value feedback and contributions from our community. Please read through this document before submitting any issues or pull requests to ensure we have all the necessary information to effectively respond to your bug report or contribution. ## Reporting Bugs/Feature Requests We welcome you to use the GitHub issue tracker to report bugs or suggest features. When filing an issue, please check existing open, or recently closed, issues to make sure somebody else hasn't already reported the issue. Please try to include as much information as you can. Details like these are incredibly useful: * A reproducible test case or series of steps * The version of our code being used * Any modifications you've made relevant to the bug * Anything unusual about your environment or deployment ## Contributing via Pull Requests Contributions via pull requests are much appreciated. Before sending us a pull request, please ensure that: 1. You are working against the latest source on the *master* branch. 2. You check existing open, and recently merged, pull requests to make sure someone else hasn't addressed the problem already. 3. You open an issue to discuss any significant work - we would hate for your time to be wasted. To send us a pull request, please: 1. Fork the repository. 2. Modify the source; please focus on the specific change you are contributing. If you also reformat all the code, it will be hard for us to focus on your change. 3. Ensure local tests pass. 4. Commit to your fork using clear commit messages. 5. Send us a pull request, answering any default questions in the pull request interface. 6. Pay attention to any automated CI failures reported in the pull request, and stay involved in the conversation. GitHub provides additional document on [forking a repository](https://help.github.com/articles/fork-a-repo/) and [creating a pull request](https://help.github.com/articles/creating-a-pull-request/). ## Finding contributions to work on Looking at the existing issues is a great way to find something to contribute on. As our projects, by default, use the default GitHub issue labels (enhancement/bug/duplicate/help wanted/invalid/question/wontfix), looking at any 'help wanted' issues is a great place to start. ## Code of Conduct This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct). For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact opensource-codeofconduct@amazon.com with any additional questions or comments. ## Security issue notifications If you discover a potential security issue in this project we ask that you notify AWS/Amazon Security via our [vulnerability reporting page](http://aws.amazon.com/security/vulnerability-reporting/). Please do **not** create a public github issue. ## Licensing See the [LICENSE](LICENSE) file for our project's licensing. We will ask you to confirm the licensing of your contribution. We may ask you to sign a [Contributor License Agreement (CLA)](http://en.wikipedia.org/wiki/Contributor_License_Agreement) for larger changes. amazon-ec2-utils-1.4/LICENSE000066400000000000000000000021111416737713500154660ustar00rootroot00000000000000Copyright Amazon.com, Inc. and its affiliates. All Rights Reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. amazon-ec2-utils-1.4/NOTICE000066400000000000000000000001251416737713500153700ustar00rootroot00000000000000amazon-ec2-utils Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. amazon-ec2-utils-1.4/README.md000066400000000000000000000010671416737713500157510ustar00rootroot00000000000000## amazon-ec2-utils amazon-ec2-utils contains a set of utilities and settings for Linux deployments in EC2. It includes: * ec2-metadata - Use to retrieve EC2 instance metadata from within a running EC2 instance * ebsnvme-id - Read EBS device information and provide information about the volume. * Various udev rules to ensure consistent device naming ## License The utilities in this package are published under the MIT License. The documentation in the doc subdirectory is licensed under the Creative Commons Attribution-ShareAlike 4.0 International License. amazon-ec2-utils-1.4/amazon-ec2-utils.spec000066400000000000000000000076071416737713500204460ustar00rootroot00000000000000Name: amazon-ec2-utils Summary: A set of tools for running in EC2 Version: 1.3 Release: 5%{?dist} License: MIT Group: System Tools Source0: ec2-metadata Source1: ec2udev-vbd Source2: 51-ec2-hvm-devices.rules Source3: 52-ec2-vcpu.rules Source15: ec2udev-vcpu Source16: 60-cdrom_id.rules Source22: 70-ec2-nvme-devices.rules Source23: ec2nvme-nsid Source24: ebsnvme-id Source25: 51-ec2-xen-vbd-devices.rules Source26: 53-ec2-read-ahead-kb.rules URL: https://github.com/aws/amazon-ec2-utils BuildArch: noarch Provides: ec2-utils Provides: ec2-metadata Obsoletes: ec2-metadata Requires: curl BuildRequires: python BuildRoot: %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX) %description amazon-ec2-utils contains a set of utilities for running in ec2. %prep %build %install rm -rf $RPM_BUILD_ROOT mkdir -p $RPM_BUILD_ROOT%{_bindir} mkdir -p $RPM_BUILD_ROOT/opt/aws/bin %if 0%{?amzn} >= 2 || 0%{?fedora} >= 17 || 0%{?rhel} >= 7 mkdir -p $RPM_BUILD_ROOT/usr/lib/udev %else mkdir -p $RPM_BUILD_ROOT/lib/udev %endif mkdir -p $RPM_BUILD_ROOT/sbin mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/udev/rules.d/ mkdir -p $RPM_BUILD_ROOT%{_mandir}/man8/ install -m755 %{SOURCE0} $RPM_BUILD_ROOT%{_bindir} install -m755 %{SOURCE1} $RPM_BUILD_ROOT/sbin/ install -m755 %{SOURCE15} $RPM_BUILD_ROOT/sbin/ install -m644 %{SOURCE2} $RPM_BUILD_ROOT%{_sysconfdir}/udev/rules.d/ install -m645 %{SOURCE3} $RPM_BUILD_ROOT%{_sysconfdir}/udev/rules.d/ install -m644 %{SOURCE16} $RPM_BUILD_ROOT%{_sysconfdir}/udev/rules.d/ install -m644 %{SOURCE25} $RPM_BUILD_ROOT%{_sysconfdir}/udev/rules.d/ install -m644 %{SOURCE26} $RPM_BUILD_ROOT%{_sysconfdir}/udev/rules.d/ #udev rules for nvme block devices and supporting scripts install -m644 %{SOURCE22} $RPM_BUILD_ROOT%{_sysconfdir}/udev/rules.d/ %if 0%{?amzn} >= 2 || 0%{?fedora} >= 17 || 0%{?rhel} >= 7 install -m755 %{SOURCE23} $RPM_BUILD_ROOT/usr/lib/udev %else install -m755 %{SOURCE23} $RPM_BUILD_ROOT/lib/udev %endif install -m755 %{SOURCE24} $RPM_BUILD_ROOT/sbin/ ln -sf %{_bindir}/ec2-metadata $RPM_BUILD_ROOT/opt/aws/bin/ec2-metadata %check %{__python} -m py_compile %{SOURCE24} %clean rm -rf $RPM_BUILD_ROOT %files %{_bindir}/ec2-metadata /opt/aws/bin/ec2-metadata %if 0%{?amzn} >= 2 || 0%{?fedora} >= 17 || 0%{?rhel} >= 7 /usr/lib/udev/ec2nvme-nsid %else /lib/udev/ec2nvme-nsid %endif /sbin/ebsnvme-id /sbin/ec2udev-vbd /sbin/ec2udev-vcpu %{_sysconfdir}/udev/rules.d/51-ec2-hvm-devices.rules %{_sysconfdir}/udev/rules.d/51-ec2-xen-vbd-devices.rules %{_sysconfdir}/udev/rules.d/52-ec2-vcpu.rules %{_sysconfdir}/udev/rules.d/53-ec2-read-ahead-kb.rules %{_sysconfdir}/udev/rules.d/60-cdrom_id.rules %{_sysconfdir}/udev/rules.d/70-ec2-nvme-devices.rules %changelog * Wed Nov 17 2021 Noah Meyerhans 1.3-5 - Restrict NVME udev rules to "add" events * Wed Nov 17 2021 Hailey Mothershead 1.3-4 - Add udev rule to increase read_ahead_kb when an NFS share is mounted * Thu Jul 14 2021 Sai Harsha 1.3-3 - Disable timeout on EBS volumes * Thu Oct 29 2020 Frederick Lefebvre 1.3-2 - Add testing of python syntax to spec file * Mon May 18 2020 Suraj Jitindar Singh 1.3-1 - Add udev rule to add by-path links for xen vbd devices * Tue Apr 28 2020 Frederick Lefebvre 1.3-1 - Rename the project to amazon-ec2-utils - Add README file * Tue Feb 25 2020 Frederick Lefebvre 1.2-1 - Fix output of multi-line fields * Wed Jan 15 2020 Frederick Lefebvre 1.1-1 - Add IMDSv2 support * Tue Aug 27 2019 Anchal Agarwal 1.0-2 - Add udev rule to define lower timeout for instance storage volumes * Wed Sep 22 2010 Nathan Blackham - move to ec2-utils - add udev code for symlinking xvd* devices to sd* * Tue Sep 07 2010 Nathan Blackham - initial packaging of script as an rpm amazon-ec2-utils-1.4/doc/000077500000000000000000000000001416737713500152335ustar00rootroot00000000000000amazon-ec2-utils-1.4/doc/ebsnvme-id.8000066400000000000000000000022451416737713500173600ustar00rootroot00000000000000.\" Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. .\" .\" This work is licensed under the Creative Commons \" Attribution-ShareAlike 4.0 International License. To view a copy \" of this license, visit \" http://creativecommons.org/licenses/by-sa/4.0/. \" SPDX-License-Identifier: CC-BY-SA-4.0 .TH EBSNVME-ID 8 "May 4 2020" .SH NAME ebsnvme-id \- Reads and prints EBS information from NVMe devices .SH SYNOPSIS .B ebsnvme-id .RI [ options ] " DEVICE" .br .SH DESCRIPTION .B ebsnvme-id uses the NVME Management Interface to read various metadata about NVME-attached EBS storage volumes. It can be used to retrive the EBS Volume ID or EC2 API device mapping value given the local block device name. .SH OPTIONS .TP .B \-v, \-\-volume Return volume-id .TP .B \-b, \-\-block-dev Return block device mapping .TP .B \-u, \-\-udev Output data in format suitable for udev rules .TP .B \-h, \-\-help Show summary of options. .SH SEE ALSO .BR nvme (1), .BR ec2-metadata (1). .PP The storage chapter of the Amazon EC2 User Guide .br https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/Storage.html amazon-ec2-utils-1.4/doc/ec2-metadata.8000066400000000000000000000102761416737713500175610ustar00rootroot00000000000000.\" Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. .\" .\" This work is licensed under the Creative Commons \" Attribution-ShareAlike 4.0 International License. To view a copy \" of this license, visit \" http://creativecommons.org/licenses/by-sa/4.0/. \" SPDX-License-Identifier: CC-BY-SA-4.0 .\" .\" Much of the text in the DESCRIPTION section is taken from .\" https://github.com/awsdocs/amazon-ec2-user-guide/blob/master/doc_source/ec2-instance-metadata.md .\" .TH EC2-METADATA 8 "May 4 2020" .SH NAME ec2-metadata \- Retrieve instance metadata from within a running EC2 instance .SH SYNOPSIS .B ec2-metadata .RI [ options ] .br .SH DESCRIPTION The .B ec2-metadata program is a utility to retrieve EC2 instance metadata from within a running EC2 instance. Instance metadata is data about your instance that you can use to configure or manage the running instance. Instance metadata is divided into categories, for example, host name, events, and security groups. You can also use instance metadata to access user data that you specified when launching your instance. For example, you can specify parameters for configuring your instance, or include a simple script. You can build generic AMIs and use user data to modify the configuration files supplied at launch time. For example, if you run web servers for various small businesses, they can all use the same generic AMI and retrieve their content from the Amazon S3 bucket that you specify in the user data at launch. To add a new customer at any time, create a bucket for the customer, add their content, and launch your AMI with the unique bucket name provided to your code in the user data. If you launch more than one instance at the same time, the user data is available to all instances in that reservation. Each instance that is part of the same reservation has a unique ami-launch-index number, allowing you to write code that controls what to do. For example, the first host might elect itself as an initial master node in a cluster. .PP .SH OPTIONS .B ec2-metadata will print all known metadata fields by default. The following options can be used to restrict the output to the selected fields. .TP .B \-\-all Show all metadata information for this host (also default). .TP .B \-a/\-\-ami-id The AMI ID used to launch this instance .TP .B \-l/\-\-ami-launch-index The index of this instance in the reservation (per AMI). .TP .B \-m/\-\-ami-manifest-path The manifest path of the AMI with which the instance was launched. .TP .B \-n/\-\-ancestor-ami-ids The AMI IDs of any instances that were rebundled to create this AMI. .TP .B \-b/\-\-block-device-mapping Defines native device names to use when exposing virtual devices. .TP .B \-i/\-\-instance-id The ID of this instance .TP .B \-t/\-\-instance-type The type of instance to launch. For more information, see Instance Types. .TP .B \-h/\-\-local-hostname The local hostname of the instance. .TP .B \-o/\-\-local-ipv4 Public IP address if launched with direct addressing; private IP address if launched with public addressing. .TP .B \-k/\-\-kernel-id The ID of the kernel launched with this instance, if applicable. .TP .B \-z/\-\-availability-zone The availability zone in which the instance launched. Same as placement .TP .B \-c/\-\-product-codes Product codes associated with this instance. .TP .B \-p/\-\-public-hostname The public hostname of the instance. .TP .B \-v/\-\-public-ipv4 NATted public IP Address .TP .B \-u/\-\-public-keys Public keys. Only available if supplied at instance launch time .TP .B \-r/\-\-ramdisk-id The ID of the RAM disk launched with this instance, if applicable. .TP .B \-e/\-\-reservation-id ID of the reservation. .TP .B \-s/\-\-security-groups Names of the security groups the instance is launched in. Only available if supplied at instance launch time .TP .B \-d/\-\-user-data User-supplied data.Only available if supplied at instance launch time. .TP .B \-h, \-\-help Show summary of options. .SH SEE ALSO .br .IP " 1." 4 Instance metadata and user data .RS 4 https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-metadata.html .RE .IP " 2." 4 EC2 Instance Metadata Query Tool .RS 4 https://aws.amazon.com/code/ec2-instance-metadata-query-tool/ .RE amazon-ec2-utils-1.4/ebsnvme-id000077500000000000000000000156171416737713500164570ustar00rootroot00000000000000#!/usr/bin/env python # Copyright Amazon.com, Inc. and its affiliates. All Rights Reserved. # # Licensed under the MIT License. See the LICENSE accompanying this file # for the specific language governing permissions and limitations under # the License. """ Usage: Read EBS device information and provide information about the volume. """ from __future__ import print_function import argparse from ctypes import Structure, c_uint8, c_uint16, \ c_uint32, c_uint64, c_char, addressof, sizeof from fcntl import ioctl import sys NVME_ADMIN_IDENTIFY = 0x06 NVME_IOCTL_ADMIN_CMD = 0xC0484E41 AMZN_NVME_VID = 0x1D0F AMZN_NVME_EBS_MN = "Amazon Elastic Block Store" class nvme_admin_command(Structure): _pack_ = 1 _fields_ = [("opcode", c_uint8), # op code ("flags", c_uint8), # fused operation ("cid", c_uint16), # command id ("nsid", c_uint32), # namespace id ("reserved0", c_uint64), ("mptr", c_uint64), # metadata pointer ("addr", c_uint64), # data pointer ("mlen", c_uint32), # metadata length ("alen", c_uint32), # data length ("cdw10", c_uint32), ("cdw11", c_uint32), ("cdw12", c_uint32), ("cdw13", c_uint32), ("cdw14", c_uint32), ("cdw15", c_uint32), ("reserved1", c_uint64)] class nvme_identify_controller_amzn_vs(Structure): _pack_ = 1 _fields_ = [("bdev", c_char * 32), # block device name ("reserved0", c_char * (1024 - 32))] class nvme_identify_controller_psd(Structure): _pack_ = 1 _fields_ = [("mp", c_uint16), # maximum power ("reserved0", c_uint16), ("enlat", c_uint32), # entry latency ("exlat", c_uint32), # exit latency ("rrt", c_uint8), # relative read throughput ("rrl", c_uint8), # relative read latency ("rwt", c_uint8), # relative write throughput ("rwl", c_uint8), # relative write latency ("reserved1", c_char * 16)] class nvme_identify_controller(Structure): _pack_ = 1 _fields_ = [("vid", c_uint16), # PCI Vendor ID ("ssvid", c_uint16), # PCI Subsystem Vendor ID ("sn", c_char * 20), # Serial Number ("mn", c_char * 40), # Module Number ("fr", c_char * 8), # Firmware Revision ("rab", c_uint8), # Recommend Arbitration Burst ("ieee", c_uint8 * 3), # IEEE OUI Identifier ("mic", c_uint8), # Multi-Interface Capabilities ("mdts", c_uint8), # Maximum Data Transfer Size ("reserved0", c_uint8 * (256 - 78)), ("oacs", c_uint16), # Optional Admin Command Support ("acl", c_uint8), # Abort Command Limit ("aerl", c_uint8), # Asynchronous Event Request Limit ("frmw", c_uint8), # Firmware Updates ("lpa", c_uint8), # Log Page Attributes ("elpe", c_uint8), # Error Log Page Entries ("npss", c_uint8), # Number of Power States Support ("avscc", c_uint8), # Admin Vendor Specific Command Configuration # noqa ("reserved1", c_uint8 * (512 - 265)), ("sqes", c_uint8), # Submission Queue Entry Size ("cqes", c_uint8), # Completion Queue Entry Size ("reserved2", c_uint16), ("nn", c_uint32), # Number of Namespaces ("oncs", c_uint16), # Optional NVM Command Support ("fuses", c_uint16), # Fused Operation Support ("fna", c_uint8), # Format NVM Attributes ("vwc", c_uint8), # Volatile Write Cache ("awun", c_uint16), # Atomic Write Unit Normal ("awupf", c_uint16), # Atomic Write Unit Power Fail ("nvscc", c_uint8), # NVM Vendor Specific Command Configuration # noqa ("reserved3", c_uint8 * (704 - 531)), ("reserved4", c_uint8 * (2048 - 704)), ("psd", nvme_identify_controller_psd * 32), # Power State Descriptor # noqa ("vs", nvme_identify_controller_amzn_vs)] # Vendor Specific class ebs_nvme_device: def __init__(self, device): self.device = device self.ctrl_identify() def _nvme_ioctl(self, id_response, id_len): admin_cmd = nvme_admin_command(opcode=NVME_ADMIN_IDENTIFY, addr=id_response, alen=id_len, cdw10=1) with open(self.device, "r") as nvme: ioctl(nvme, NVME_IOCTL_ADMIN_CMD, admin_cmd) def ctrl_identify(self): self.id_ctrl = nvme_identify_controller() self._nvme_ioctl(addressof(self.id_ctrl), sizeof(self.id_ctrl)) if self.id_ctrl.vid != AMZN_NVME_VID \ or self.id_ctrl.mn.decode().strip() != AMZN_NVME_EBS_MN: raise TypeError("[ERROR] Not an EBS device: '{0}'".format(self.device)) # noqa def get_volume_id(self): vol = self.id_ctrl.sn.decode() if vol.startswith("vol") and vol[3] != "-": vol = "vol-" + vol[3:] return vol def get_block_device(self, stripped=False): dev = self.id_ctrl.vs.bdev.decode().strip() if stripped and dev.startswith("/dev/"): dev = dev[5:] return dev if __name__ == "__main__": parser = \ argparse.ArgumentParser(description="Reads EBS information from NVMe devices.") # noqa parser.add_argument("device", nargs=1, help="Device to query") display = parser.add_argument_group("Display Options") display.add_argument("-v", "--volume", action="store_true", help="Return volume-id") display.add_argument("-b", "--block-dev", action="store_true", help="Return block device mapping") display.add_argument("-u", "--udev", action="store_true", help="Output data in format suitable for udev rules") if len(sys.argv) < 2: parser.print_help() sys.exit(1) args = parser.parse_args() get_all = not (args.udev or args.volume or args.block_dev) try: dev = ebs_nvme_device(args.device[0]) except (IOError, TypeError) as err: print(err, file=sys.stderr) sys.exit(1) if get_all or args.volume: print("Volume ID: {0}".format(dev.get_volume_id())) if get_all or args.block_dev or args.udev: print(dev.get_block_device(args.udev)) amazon-ec2-utils-1.4/ec2-metadata000077500000000000000000000173331416737713500166520ustar00rootroot00000000000000#!/bin/bash # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # # Licensed under the MIT License. See the LICENSE accompanying this file # for the specific language governing permissions and limitations under # the License. function print_help() { echo "ec2-metadata v0.1.2 Use to retrieve EC2 instance metadata from within a running EC2 instance. e.g. to retrieve instance id: ec2-metadata -i to retrieve ami id: ec2-metadata -a to get help: ec2-metadata --help For more information on Amazon EC2 instance meta-data, refer to the documentation at https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-metadata.html Usage: ec2-metadata