diff options
author | John Estabrook <jestabro@vyos.io> | 2023-09-22 09:51:48 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-22 09:51:48 -0500 |
commit | 90ce099f065325841c4c18b4a4beadaf141a35b2 (patch) | |
tree | d2e9a3c78199669f887d2a8c376811d9e011f7df /python/vyos/utils/disk.py | |
parent | e0ce69365f46db5339144cb27bff6b3dd5924871 (diff) | |
parent | 7447b4ef6e6cc8a9b1e7b8062935c52d3b4429cb (diff) | |
download | vyos-1x-90ce099f065325841c4c18b4a4beadaf141a35b2.tar.gz vyos-1x-90ce099f065325841c4c18b4a4beadaf141a35b2.zip |
Merge pull request #2301 from vyos/mergify/bp/sagitta/pr-2298
smoketest: T5607: support getting SCSI device by drive-id (backport #2298)
Diffstat (limited to 'python/vyos/utils/disk.py')
-rw-r--r-- | python/vyos/utils/disk.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/python/vyos/utils/disk.py b/python/vyos/utils/disk.py new file mode 100644 index 000000000..ee540b107 --- /dev/null +++ b/python/vyos/utils/disk.py @@ -0,0 +1,23 @@ +# Copyright 2023 VyOS maintainers and contributors <maintainers@vyos.io> +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library. If not, see <http://www.gnu.org/licenses/>. + +from pathlib import Path + +def device_from_id(id): + """ Return the device name from (partial) disk id """ + path = Path('/dev/disk/by-id') + for device in path.iterdir(): + if device.name.endswith(id): + return device.readlink().stem |