代码拉取完成,页面将自动刷新
from base64 import encode
from cmd import Ssh
from cmd import encoding
import re
from time import sleep
from collections import OrderedDict
from cmd import Cmd
class Disk():
def setCmd(self, cmd: Cmd):
self.cmd = cmd
def setSsh(self, ssh: Ssh):
self.ssh = ssh
def getDiskSlot(self):
out = self.ssh.ssh("storcli64 /c0/eall/sall show all")
d = OrderedDict()
updateFlag = False
for line in out.split("\n"):
if "Device attributes" in line:
g = re.search(r"/e(\d+)/s(\d+)", line)
eid = g.group(1)
slot = g.group(2)
sl = "eid:{},slot:{}".format(eid, slot)
updateFlag = True
if updateFlag:
if "SN" in line:
sn = line.split("=")[1].strip()
d.update({sn: sl})
updateFlag = False
sn_dev = self.getDevSn()
for sn, slot in d.items():
print("{slot}<->{sn}<->{dev}".format(slot=slot,
sn=sn, dev=sn_dev.get(sn)))
def getSnFromDev(self, dev):
out = self.ssh.ssh("smartctl -i /dev/{}".format(dev))
for line in out.split("\n"):
if "Serial" in line:
sn = line.split(":")[-1].strip()
return sn
def getDevSn(self):
out = self.ssh.ssh("lsblk")
d = {}
for line in out.split("\n"):
if "disk" in line:
dev = line.split()[0].strip()
sn = self.getSnFromDev(dev)
d.update({sn: dev})
return d
def closeDiskLocate(self, cid, eid, sid, count):
for i in range(count):
self.ssh.ssh(
"storcli64 /c{}/e{}/s{} stop locate".format(cid, eid, sid, i))
sleep(1)
if __name__ == "__main__": # test
r = Disk()
s = Ssh("172.17.0.62", "root", "1")
r.setSsh(s)
# r.getDiskSlot()
# r.closeDiskLocate(0, 252, 7, 8)
d = r.getDevSn()
for sn, dev in d.items():
print("{sn}<->{dev}".format(sn=sn, dev=dev))
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。