python為ipmi再新增一個具有管理員許可權的使用者
阿新 • • 發佈:2019-02-15
以下指令碼將根據IP地址為10.0.40.6的IPMI現有管理員admin(密碼也為admin),再新增一個具有管理員許可權的使用者sgi,密碼為sgisgi
#!/usr/bin/env python import os class Ipmi(object): def __init__(self, host, username="admin", passwd='admin'): self.__host = host self.__username = username self.__passwd = passwd def get_lastid_number(self): UserList = os.popen("ipmitool -H %s -U %s -P %s user list") % ( self.__host, self.__username, self.__passwd) lines = [line for line in UserList] UserList.close() lastid = int(lines[-1][0]) return lastid def add_new_ipmiuser(self, newuser, newpasswd): newid = self.get_lastid_number() + 1 os.system("ipmitool -H %s -U %s -P %s user set name %s %s") % ( self.__host, self.__username, self.__passwd, newid, newuser) os.system("ipmitool -H %s -U %s -P %s user set password %s %s") % ( self.__host, self.__username, self.__passwd, newid, newpasswd) os.system("ipmitool -H %s -U %s -P %s user priv %s 4") % ( self.__host, self.__username, self.__passwd, newid) os.system("ipmitool -H %s -U %s -P %s user enable %s") % ( self.__host, self.__username, self.__passwd, newid) def show_ipmiuser(self): os.system("ipmitool -H %s -U %s -P %s user list") % (self.__host, self.__username, self.__passwd) def main(): newuser = Ipmi("10.0.40.6") newuser.add_new_ipmiuser("sgi", "sgisgi") newuser.show_ipmiuser() if __name__ == "__main__": main()