devicepm.py Script

Return to "How to Use the Power Management Controls on SPARC CMT Servers"




# Enable auto PM at 7am M-F
#0 7 * * 1,2,3,4,5 /pm/devicepm -e >> /pm/devicepm.log 2>&1
# Disable auto PM at 5pm M-F
#0 17 * * 1,2,3,4,5 /pm/devicepm -d >> /pm/devicepm.log 2>&1

#!/bin/env python
#
# This script enables or disabled the device PM feature
# for this system only.  A time schedule can be setup in
# CRON to select a time period for this management of device PM.
#
# Input:
#   arg1: -e | -d  | -h
#    e: enable device PM
#    d: disable device PM
#    h: Help message

import os, sys, getopt
from subprocess import *

def usage():
    print 'USAGE: devicepm {-h | d | e}'
    print '\t-h: This help message'
    print '\t-d: Disable device PM'
    print '\t-e: Enable device PM\n'
    sys.exit(0)

act = ""
opts, args = getopt.getopt(sys.argv[1:], 'deh')
if opts == []:
    usage()

for opt, arg in opts:
    if opt == '-h':
        usage()
    if opt == '-d':
        act = 'd'
    elif opt == '-e':
        act = 'e'
    else:
        usage()

tmpfile = '/tmp/power.conf' + str(os.getpid())

if act == 'e':
    call('/usr/bin/sed -e \'/^autopm/s/disable/enable/\' /etc/power.conf > ' + tmpfile, shell=True)
elif act == 'd':
    call('/usr/bin/sed -e \'/^autopm/s/enable/disable/\' /etc/power.conf > ' + tmpfile, shell=True)
else:
    os.exit(1)

call('/usr/bin/cp /etc/power.conf /etc/power.conf.bak', shell=True)
call('/usr/bin/mv ' + tmpfile + ' /etc/power.conf', shell=True)
call('/usr/sbin/pmconfig', shell=True)