刀片式服务器IMPI管理--修改启动方式并重启

import subprocess
def set_boot_or_power_state( addr, action,user="", passwd="",):
if action in ['on', 'off', 'reset']:
device = 'power'
elif action in ['pxe', 'disk',"bios"]:
device = 'bootdev'
else:
return

cmd = ['ipmitool', '-I', 'lanplus', '-H', addr, '-U', user,
'-P', passwd, 'chassis', device, action]
if device == 'bootdev':
cmd.append('options=persistent')
_PIPE = subprocess.PIPE
print " ".join(cmd)
try:
obj = subprocess.Popen(cmd, stdin=_PIPE, stdout=_PIPE,
stderr=_PIPE, shell=False)
obj.communicate()
except Exception as e:
msg = "%s set_boot_or_power_state error: %s" % (addr, e)
print msg
return -1

return obj.returncode,obj

if __name__=="__main__":
host_list_end_tail =("31","32","33")
for host in host_list_end_tail:
host_list="102.3.100.".strip()+host
set_boot_or_power_state(host_list,"bios")
set_boot_or_power_state(host_list, "reset")
说明代码来源:opentack daisy开源项目
有一点点改动,还未验证。。。。

posted on 2017-12-03 16:51  yaxin1989  阅读(1084)  评论(0编辑  收藏  举报

导航