linux没有找到可用磁盘,在Linux上,有没有一种更像python的方法来获取可用磁盘设备名的列表?...

编辑我不明白为什么这被标记为重复,因为标识的重复需要导入pyudev。甚至不可能是复制品。在

这很管用,但感觉“蛮力”。在

有没有一种更像python的方法来获取Linux上可用磁盘设备名的列表。在def get_list_of_available_disk_device_names():

# device names are prefixed with xvd

# any alpha characters after the prefix identify the specific device,

# it is possible that there are numbers after the fourth character

# https://rwmj.wordpress.com/2011/01/09/how-are-linux-drives-named-beyond-drive-26-devsdz/

# in this case we are hard coding the limit to an arbitrary 26 so device names do not go beyond z

# the device name prefix can vary across operating systems. 'xvd' is Xen devices on Linux

device_name_prefix = 'xvd'

device_letters = [x[3] for x in os.listdir('/dev') if x.startswith(device_name_prefix) and x[3] in string.lowercase]

device_letter_alpha_numbers = [string.lowercase.index(device_letter) for device_letter in device_letters]

next_available_device_number = max(device_letter_alpha_numbers) + 1

if next_available_device_number > 25: # a is 0, z is 25

raise Exception('No more devices available')

return ['xvd{}'.format(string.lowercase[x]) for x in range(next_available_device_number, 25)]

使用:

^{pr2}$

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值