00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 import pprint
00018 import sys
00019 from lsm.plugin.ontap.na import netapp_filer
00020 import lsm.plugin.ontap.na
00021 import os
00022 from optparse import OptionParser
00023
00024
00025 def process_params(p):
00026 rc = {}
00027
00028 if p is None:
00029 return p
00030 else:
00031 for e in p:
00032 if '==' in e:
00033 (name, value) = e.split('==')
00034 rc[name] = value
00035 else:
00036 print 'Param:', e, 'not in the form name==value'
00037 sys.exit(1)
00038 return rc
00039
00040 if __name__ == '__main__':
00041 pp = pprint.PrettyPrinter(indent=2)
00042
00043 user = os.getenv('NA_USER')
00044 password = os.getenv('NA_PASSWORD')
00045
00046 parser = OptionParser()
00047 parser.add_option("-t", "--host", action="store", type="string",
00048 dest="host", help="controller name or IP")
00049 parser.add_option("-c", "--command", action="store", type="string",
00050 dest="command", help="command to execute")
00051 parser.add_option("-p", "--param", action="append", type="string",
00052 dest="params",
00053 help="command parameters in the form name==value")
00054 parser.add_option("-s", "--ssl", action="store_true", dest="ssl",
00055 help="enable ssl")
00056 parser.add_option('-d', "--dumpxml", action="store", dest="xmlfile",
00057 help="file to dump response to for debug")
00058
00059 if user is not None and password is not None:
00060 (options, args) = parser.parse_args()
00061 if options.command and options.host:
00062 if options.xmlfile:
00063 lsm.plugin.ontap.na.xml_debug = options.xmlfile
00064
00065 result = netapp_filer(options.host, user, password, 30,
00066 options.command,
00067 process_params(options.params),
00068 options.ssl)
00069 pp.pprint(result)
00070 else:
00071 parser.error("host and command are required")
00072 else:
00073 print 'Please create environmental variables for ' \
00074 'NA_USER and NA_PASSWORD'
00075 sys.exit(1)