2013-06-17 16:55:44 -04:00
|
|
|
#!/usr/bin/env python
|
2013-06-24 13:43:15 -04:00
|
|
|
"""
|
|
|
|
@author: Jarrod Johnson <jbjohnso@us.ibm.com>
|
2013-06-24 14:37:57 -04:00
|
|
|
|
|
|
|
Copyright 2013 IBM Corporation
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
2013-06-24 13:43:15 -04:00
|
|
|
"""
|
2013-06-25 10:43:02 -04:00
|
|
|
"""This is an example of using the library in a synchronous fashion. For now,
|
|
|
|
it isn't conceived as a general utility to actually use, just help developers
|
|
|
|
understand how the ipmi_command class workes.
|
|
|
|
"""
|
2013-06-17 16:55:44 -04:00
|
|
|
import os
|
2013-07-25 14:19:09 -04:00
|
|
|
import string
|
2013-06-17 16:55:44 -04:00
|
|
|
import sys
|
2013-06-25 08:25:06 -04:00
|
|
|
|
2013-08-07 10:01:16 -04:00
|
|
|
from pyghmi.ipmi import command
|
2013-07-02 06:09:21 -07:00
|
|
|
password = os.environ['IPMIPASSWORD']
|
|
|
|
os.environ['IPMIPASSWORD'] = ""
|
2013-06-17 16:55:44 -04:00
|
|
|
if (len(sys.argv) < 3):
|
|
|
|
print "Usage:"
|
2013-07-02 06:09:21 -07:00
|
|
|
print " IPMIPASSWORD=password %s bmc username <cmd> <optarg>" % sys.argv[0]
|
2013-06-17 16:55:44 -04:00
|
|
|
sys.exit(1)
|
2013-07-02 06:09:21 -07:00
|
|
|
bmc = sys.argv[1]
|
|
|
|
userid = sys.argv[2]
|
2013-07-16 10:59:45 -04:00
|
|
|
args = None
|
|
|
|
if len(sys.argv) >= 5:
|
|
|
|
args = sys.argv[4:]
|
2013-07-25 14:19:09 -04:00
|
|
|
|
|
|
|
ipmicmd = None
|
|
|
|
|
|
|
|
|
|
|
|
def docommand(result, ipmisession):
|
|
|
|
cmmand = sys.argv[3]
|
|
|
|
print "Logged into %s" % ipmisession.bmc
|
|
|
|
if 'error' in result:
|
|
|
|
print result['error']
|
|
|
|
return
|
|
|
|
if cmmand == 'power':
|
|
|
|
if args:
|
|
|
|
print ipmisession.set_power(args[0], wait=True)
|
|
|
|
else:
|
|
|
|
value = ipmisession.get_power()
|
|
|
|
print "%s: %s" % (ipmisession.bmc, value['powerstate'])
|
|
|
|
elif cmmand == 'bootdev':
|
|
|
|
if args:
|
|
|
|
print ipmisession.set_bootdev(args[0])
|
|
|
|
else:
|
|
|
|
print ipmisession.get_bootdev()
|
|
|
|
elif cmmand == 'raw':
|
|
|
|
print ipmisession.raw_command(netfn=args[0],
|
|
|
|
command=args[1], data=args[2:])
|
|
|
|
|
|
|
|
bmcs = string.split(bmc, ",")
|
|
|
|
for bmc in bmcs:
|
|
|
|
ipmicmd = command.Command(bmc=bmc, userid=userid, password=password,
|
|
|
|
onlogon=docommand)
|
|
|
|
ipmicmd.eventloop()
|