1 Star 0 Fork 0

ningbo/pl

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
disk.py 2.06 KB
一键复制 编辑 原始数据 按行查看 历史
ningbo 提交于 2022-03-02 08:32 . add ledlocate.py getmem.py
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))
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/ningbocai/pl.git
git@gitee.com:ningbocai/pl.git
ningbocai
pl
pl
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385