| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
import sys |
| 18 |
import getopt |
| 19 |
import re |
| 20 |
import json |
| 21 |
import os |
| 22 |
from .redfishtoolTransport import RfTransport |
| 23 |
from .ServiceRoot import RfServiceRoot |
| 24 |
from .Systems import RfSystemsMain |
| 25 |
from .Chassis import RfChassisMain |
| 26 |
from .Managers import RfManagersMain |
| 27 |
from .SessionService import RfSessionServiceMain |
| 28 |
from .AccountService import RfAccountServiceMain |
| 29 |
from .raw import RfRawMain |
| 30 |
|
| 31 |
def displayUsage(rft,*argv,**kwargs): |
| 32 |
rft.printErr(" Usage:",noprog=True) |
| 33 |
rft.printErr(" {} [OPTIONS] <SubCommand> <operation> [<args>]... ",prepend=" ") |
| 34 |
rft.printErr(" {} [OPTIONS] hmraw <method> <hmUrl> [<data>]", prepend=" ") |
| 35 |
|
| 36 |
def displayOptions(rft): |
| 37 |
print("") |
| 38 |
print(" Common OPTIONS:") |
| 39 |
print(" -V, --version -- show {} version, and exit".format(rft.program)) |
| 40 |
print(" -h, --help -- show Usage, Options, and list of subCommands, and exit".format(rft.program)) |
| 41 |
print(" -v, --verbose -- verbose level, can repeat up to 5 times for more verbose output") |
| 42 |
print(" -v(header), -vv(+addl info), -vvv(Request trace), -vvvv(+subCmd dbg), -vvvvv(max dbg)") |
| 43 |
print(" -s, --status -- status level, can repeat up to 5 times for more status output") |
| 44 |
print(" -s(http_status), ") |
| 45 |
print(" -ss(+r.url, +r.elapsed executionTime ), ") |
| 46 |
print(" -sss(+request hdrs,data,authType, +response status_code, +response executionTime, ") |
| 47 |
print(" +login auth token/sessId/sessUri)") |
| 48 |
print(" -ssss(+response headers), -sssss(+response data") |
| 49 |
print(" -u <user>, --user=<usernm> -- username used for remote redfish authentication") |
| 50 |
print(" -p <passwd>, --password=<passwd> -- password used for remote redfish authentication") |
| 51 |
print(" -r <rhost>, --rhost=<rhost> -- remote redfish service hostname or IP:port") |
| 52 |
print(" -t <token>, --token=<token> -- redfish auth session token-for sessions across multiple calls") |
| 53 |
print(" -q, --quiet -- quiet mode--suppress error, warning, and diagnostic messages") |
| 54 |
print(" -c <cfgFile>,--config=<cfgFile> -- read options (including credentials) from file <cfgFile>") |
| 55 |
print(" -T <timeout>,--Timeout=<timeout> -- timeout in seconds for each http request. Default=10") |
| 56 |
print("") |
| 57 |
print(" -P <property>, --Prop=<property> -- return only the specified property. Applies only to all \"get\" operations") |
| 58 |
print(" -E, --Entries -- Fetch the Logs entries. Applies to Logs sub-command of Systems, Chassis and Managers") |
| 59 |
print("") |
| 60 |
print(" Options used by \"raw\" subcommand:") |
| 61 |
print(" -d <data> --data=<data> -- the http request \"data\" to send on PATCH,POST,or PUT requests") |
| 62 |
print("") |
| 63 |
print(" Options to specify top-level collection members: eg: Systems -I <sysId>") |
| 64 |
print(" -I <Id>, --Id=<Id> -- Use <Id> to specify the collection member") |
| 65 |
print(" -M <prop>:<val> --Match=<prop>:<val>-- Use <prop>=<val> search to find the collection member") |
| 66 |
print(" -F, --First -- Use the 1st link returned in the collection or 1st \"matching\" link if used with -M") |
| 67 |
print(" -1, --One -- Use the single link returned in the collection. Return error if more than one member exists") |
| 68 |
print(" -a, --all -- Returns all members if the operation is a Get on a top-level collection like Systems") |
| 69 |
print(" -L <Link>, --Link=<Link> -- Use <Link> (eg /redfish/v1/Systems/1) to reference the collection member. ") |
| 70 |
print(" -- If <Link> is not one of the links in the collection, and error is returned.") |
| 71 |
print(" Options to specify 2nd-level collection members: eg: Systems -I<sysId> Processors -i<procId>") |
| 72 |
print(" -i <id>, --id=<id> -- use <id> to specify the 2nd-level collection member") |
| 73 |
print(" -m <prop>:<val> --match=<prop>:val>--use <prop>=<val> search of 2nd-level collection to specify member") |
| 74 |
print(" -l <link> --link=<link> -- Use <link> (eg /redfish/v1/SYstems/1/Processors/1) to reference a 2nd level resource") |
| 75 |
print(" -- A -I|M|F|1|L option is still required to specify the link to the top-lvl collection") |
| 76 |
print(" -a, --all -- Returns all members of the 2nd level collection if the operation is a Get on the ") |
| 77 |
print(" -- 2nd level collection (eg Processors). -I|M|F|1|L still specifies the top-lvl collection.") |
| 78 |
print("") |
| 79 |
print(" Additional OPTIONS:") |
| 80 |
print(" -W <num>:<connTimeout>, -- Send up to <num> {GET /redfish} requests with <connTimeout> TCP connection timeout") |
| 81 |
print(" --Wait=<num>:<ConnTimeout> -- before sending subcommand to rhost. Default is -W 1:3") |
| 82 |
print(" -A <Authn>, --Auth <Authn> -- Authentication type to use: Authn={None|Basic|Session} Default is Basic") |
| 83 |
print(" -S <Secure>, --Secure=<Secure> -- When to use https: (Note: doesn't stop rhost from redirect http to https)") |
| 84 |
print(" <Secure>={Always | IfSendingCredentials | IfLoginOrAuthenticatedApi(default) }") |
| 85 |
print(" -R <ver>, --RedfishVersion=<ver>-- The Major Redfish Protocol version to use: ver={v1(dflt), v<n>, Latest}") |
| 86 |
print(" -C --CheckRedfishVersion -- tells Redfishtool to execute GET /redfish to verify that the rhost supports") |
| 87 |
print(" the specified redfish protocol version before executing a sub-command. ") |
| 88 |
print(" The -C flag is auto-set if the -R Latest or -W ... options are selected") |
| 89 |
print(" -N, --NonBlocking -- Do not wait for asynchronous requests to complete.") |
| 90 |
print(" -n, --no-proxy -- Ignore any PROXY environment variables.") |
| 91 |
print(" -H <hdrs>, --Headers=<hdrs> -- Specify the request header list--overrides defaults. Format \"{ A:B, C:D...}\" ") |
| 92 |
print(" -D <flag>, --Debug=<flag> -- Flag for dev debug. <flag> is a 32-bit uint: 0x<hex> or <dec> format") |
| 93 |
print("") |
| 94 |
|
| 95 |
def listSubcommands(rft): |
| 96 |
|
| 97 |
print(" Subcommands:") |
| 98 |
print(" hello -- redfishtool hello world subcommand for dev testing") |
| 99 |
print(" about -- display version and other information about this version of {}".format(rft.program)) |
| 100 |
print(" versions -- get redfishProtocol versions supported by rhost: GET ^/redfish") |
| 101 |
print(" root | serviceRoot -- get serviceRoot resouce: GET ^/redfish/v1/") |
| 102 |
print(" Systems -- operations on Computer Systems in the /Systems collection ") |
| 103 |
print(" Chassis -- operations on Chassis in the /Chassis collection") |
| 104 |
print(" Managers -- operations on Managers in the /Managers collection") |
| 105 |
print(" AccountService -- operations on AccountService including user administration") |
| 106 |
print(" SessionService -- operations on SessionService including Session login/logout") |
| 107 |
print(" odata -- get the Odata Service document: GET ^/redfish/v1/odata") |
| 108 |
print(" metadata -- get the CSDL metadata document: GET ^/redfish/v1/$metadata") |
| 109 |
print(" raw -- subcommand to execute raw http methods(GET,PATCH,POST...) and URIs") |
| 110 |
|
| 111 |
return(0) |
| 112 |
|
| 113 |
def displayHelp(rft): |
| 114 |
displayUsage(rft,file=sys.stdout) |
| 115 |
displayOptions(rft) |
| 116 |
listSubcommands(rft) |
| 117 |
print("") |
| 118 |
print(" For Subcommand usage, options, operations, help:") |
| 119 |
print(" {} <SubCommand> -h -- usage and options for specific subCommand".format(rft.program)) |
| 120 |
print("") |
| 121 |
|
| 122 |
def main(argv): |
| 123 |
|
| 124 |
rft=RfTransport() |
| 125 |
|
| 126 |
try: |
| 127 |
opts, args = getopt.gnu_getopt(argv[1:],"Vhvsqu:p:r:t:c:T:P:d:EI:M:F1L:i:m:l:aW:A:S:R:H:D:CNn", |
| 128 |
["Version", "help", "verbose", "status", "quiet", |
| 129 |
"user=", "password=", "rhost=", "token=", "config=", "Timeout=", |
| 130 |
"Prop=", "data=", "Entries", "Id=", "Match=", "First", "One", "Link=", |
| 131 |
"id=", "match=", "link", "all", |
| 132 |
"Wait=", "Auth=","Secure=", "RedfishVersion=", "Headers=", "Debug=", |
| 133 |
"CheckRedfishVersion", "NonBlocking", "no-proxy"]) |
| 134 |
except getopt.GetoptError: |
| 135 |
rft.printErr("Error parsing options") |
| 136 |
displayUsage(rft) |
| 137 |
sys.exit(1) |
| 138 |
|
| 139 |
for opt, arg in opts: |
| 140 |
if opt in ("-h", "--help"): |
| 141 |
rft.help=True |
| 142 |
elif opt in ("-V", "--Version", "--version"): |
| 143 |
print("{} Version: {}".format(rft.program, rft.version)) |
| 144 |
sys.exit(0) |
| 145 |
elif opt in ("-v", "--verbose"): |
| 146 |
rft.verbose = min((rft.verbose+1), 5) |
| 147 |
elif opt in ("-s", "--status"): |
| 148 |
rft.status = min((rft.status+1), 5) |
| 149 |
elif opt in ("-q", "--quiet"): |
| 150 |
rft.quiet=True |
| 151 |
elif opt in ("-u", "--user"): |
| 152 |
rft.user=arg |
| 153 |
elif opt in ("-p", "--password"): |
| 154 |
rft.password=arg |
| 155 |
elif opt in ("-r", "--rhost"): |
| 156 |
rft.rhost=arg |
| 157 |
elif opt in ("-t", "--token"): |
| 158 |
rft.token=arg |
| 159 |
rft.authToken=rft.token |
| 160 |
elif opt in ("-c", "--config"): |
| 161 |
rft.configFile=arg |
| 162 |
try: |
| 163 |
with open(arg, 'r') as f: |
| 164 |
configdata = json.load(f) |
| 165 |
if 'user' in configdata and 'password' in configdata: |
| 166 |
rft.user = configdata['user'] |
| 167 |
rft.password = configdata['password'] |
| 168 |
rft.printVerbose(1,"Main: get pw from configfile, usr:{}, pw:{}".format(rft.user, rft.password)) |
| 169 |
else: |
| 170 |
rft.printErr("Invalid --config= filedata: {}".format(configdata)) |
| 171 |
except IOError: |
| 172 |
rft.printErr("Invalid: Failed to read configfile") |
| 173 |
|
| 174 |
elif opt in ("-T", "--Timeout"): |
| 175 |
timePattern="^([1-9][0-9]*)$" |
| 176 |
timeMatch=re.search(timePattern,arg) |
| 177 |
if( timeMatch ): |
| 178 |
rft.timeout=int(arg) |
| 179 |
else: |
| 180 |
rft.printErr("Invalid -Timeout value: {}".format(arg)) |
| 181 |
rft.printErr(" Expect: -T <timeout> where <timeout> is a decimal int",noprog=True) |
| 182 |
sys.exit(1) |
| 183 |
|
| 184 |
elif opt in ("-P", "--Prop"): |
| 185 |
rft.prop=arg |
| 186 |
rft.gotPropOptn=True |
| 187 |
|
| 188 |
elif opt in ("-d", "--data"): |
| 189 |
rft.requestData=arg |
| 190 |
|
| 191 |
elif opt in ("-E", "--Entries"): |
| 192 |
rft.gotEntriesOptn = True |
| 193 |
|
| 194 |
elif opt in ("-I", "--Id"): |
| 195 |
rft.Id=arg |
| 196 |
rft.gotIdOptn=True |
| 197 |
rft.IdOptnCount+=1 |
| 198 |
elif opt in ("-M", "--Match"): |
| 199 |
|
| 200 |
pair = arg.split(':', 1) |
| 201 |
if len(pair) == 2: |
| 202 |
rft.matchProp = pair[0] |
| 203 |
rft.matchValue = pair[1] |
| 204 |
rft.IdOptnCount += 1 |
| 205 |
rft.gotMatchOptn = True |
| 206 |
else: |
| 207 |
rft.printErr("Invalid --Match= option format: {}".format(arg)) |
| 208 |
rft.printErr(" Expect --Match=<prop>:<value> Ex -M AssetTag:5555, -Match=AssetTag:5555",noprog=True) |
| 209 |
sys.exit(1) |
| 210 |
elif opt in ("-F", "--First"): |
| 211 |
rft.firstOptn=True |
| 212 |
rft.IdOptnCount+=1 |
| 213 |
elif opt in ("-1", "--One"): |
| 214 |
rft.oneOptn=True |
| 215 |
rft.IdOptnCount+=1 |
| 216 |
elif opt in ("-L", "--Link"): |
| 217 |
rft.Link=arg |
| 218 |
rft.gotIdOptn=True |
| 219 |
rft.IdOptnCount+=1 |
| 220 |
elif opt in ("-i", "--id"): |
| 221 |
rft.IdLevel2=arg |
| 222 |
rft.gotIdLevel2Optn=True |
| 223 |
rft.IdLevel2OptnCount+=1 |
| 224 |
elif opt in ("-m", "--match"): |
| 225 |
|
| 226 |
pair = arg.split(':', 1) |
| 227 |
if len(pair) == 2: |
| 228 |
rft.matchLevel2Prop = pair[0] |
| 229 |
rft.matchLevel2Value = pair[1] |
| 230 |
rft.IdLevel2OptnCount += 1 |
| 231 |
rft.gotMatchLevel2Optn = True |
| 232 |
else: |
| 233 |
rft.printErr("Invalid level2 --match= option format: {}".format(arg)) |
| 234 |
rft.printErr(" Expect --match=<prop>:<value> Ex -m ProcessorType:CPU, -match=ProcessorType:CPU",noprog=True) |
| 235 |
sys.exit(1) |
| 236 |
elif opt in ("-l", "--link"): |
| 237 |
rft.linkLevel2=arg |
| 238 |
rft.gotIdLevel2Optn=True |
| 239 |
rft.IdLevel2OptnCount+=1 |
| 240 |
elif opt in ("-a", "--all"): |
| 241 |
rft.allOptn=True |
| 242 |
rft.IdLevel2OptnCount+=1 |
| 243 |
elif opt in ("-W", "--Wait"): |
| 244 |
|
| 245 |
rft.checkProtocolVer=True |
| 246 |
waitPattern="^([1-9][0-9]*):([1-9][0-9]*)$" |
| 247 |
waitMatch=re.search(waitPattern,arg) |
| 248 |
if( waitMatch ): |
| 249 |
rft.waitNum=int(waitMatch.group(1)) |
| 250 |
rft.waitTime=int(waitMatch.group(2)) |
| 251 |
print("num: {}, time: {}".format(rft.waitNum, rft.waitTime)) |
| 252 |
else: |
| 253 |
rft.printErr("Invalid --Wait= option format: {}".format(arg)) |
| 254 |
rft.printErr(" Expect --Wait=<num>:<time> where num and time are decimals. Ex -W 10:5",noprog=True) |
| 255 |
sys.exit(1) |
| 256 |
elif opt in ("-A", "--Auth"): |
| 257 |
rft.auth=arg |
| 258 |
if not rft.auth in rft.authValidValues: |
| 259 |
rft.printErr("Invalid --Auth option: {}".format(rft.auth)) |
| 260 |
rft.printErr(" Valid values: {}".format(rft.authValidValues),noprog=True) |
| 261 |
sys.exit(1) |
| 262 |
elif opt in ("-S", "--Secure"): |
| 263 |
rft.secure=arg |
| 264 |
if not rft.secure in rft.secureValidValues: |
| 265 |
rft.printErr("Invalid --Secure option: {}".format(rft.secure)) |
| 266 |
rft.printErr(" Valid values: {}".format(rft.secureValidValues),noprog=True) |
| 267 |
sys.exit(1) |
| 268 |
elif opt in ("-R", "--RedfishVersion"): |
| 269 |
rft.protocolVer=arg |
| 270 |
if(rft.protocolVer=="Latest"): |
| 271 |
rft.checkProtocolVer=True |
| 272 |
elif opt in ("-H", "--Headers"): |
| 273 |
try: |
| 274 |
rft.headers=json.loads(arg) |
| 275 |
except ValueError: |
| 276 |
rft.printErr("Invalid -H arg: invalid Json data format: {}".format(arg)) |
| 277 |
sys.exit(1) |
| 278 |
elif opt in ("-D", "--Debug"): |
| 279 |
dbgPattern="(^(0[xX]([0-9a-fA-F]){1,8}$))|(^0$)|(^([1-9][0-9]*)$)" |
| 280 |
dbgMatch=re.search(dbgPattern,arg) |
| 281 |
if( dbgMatch ): |
| 282 |
rft.dgbFlag=int(arg,0) |
| 283 |
rft.printVerbose(4,"Main: Flag=0x{:08x}".format(rft.dbgFlag)) |
| 284 |
else: |
| 285 |
rft.printErr("Invalid -Flag value: {}".format(arg)) |
| 286 |
rft.printErr(" Expect --Flag=<flag> where <flag> is a decimal int",noprog=True) |
| 287 |
sys.exit(1) |
| 288 |
elif opt in ("-C", "--CheckRedfishVersion"): |
| 289 |
rft.checkProtocolVer=True |
| 290 |
elif opt in ("-N", "--NonBlocking"): |
| 291 |
rft.blocking=False |
| 292 |
elif opt in ("-n", "--no-proxy"): |
| 293 |
rft.no_proxy = True |
| 294 |
else: |
| 295 |
rft.printErr("Error: Unsupported option: {}".format(opt)) |
| 296 |
displayUsage(rft) |
| 297 |
sys.exit(1) |
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
if( rft.help ): |
| 302 |
if( not args ): |
| 303 |
displayHelp(rft) |
| 304 |
sys.exit(0) |
| 305 |
|
| 306 |
|
| 307 |
if (rft.token is not None) and (rft.auth != "Session"): |
| 308 |
rft.printErr("Invalid mix of --Auth and --token options") |
| 309 |
rft.printErr(" if --token=<authToken> is specified, --Auth must be Session", noprog=True) |
| 310 |
sys.exit(1) |
| 311 |
|
| 312 |
|
| 313 |
if( rft.IdOptnCount > 1 ): |
| 314 |
if( not (rft.firstOptn and rft.gotMatchOptn ) ): |
| 315 |
rft.printErr("Syntax error: invalid combination of -I,-M,-1,-F options.") |
| 316 |
rft.printErr(" Valid combinations: -I | -M[F] | -1 | -F ",noprog=True) |
| 317 |
displayUsage(rft) |
| 318 |
sys.exit(1) |
| 319 |
|
| 320 |
|
| 321 |
if( rft.gotIdOptn is True ): |
| 322 |
rft.matchProp="Id" |
| 323 |
rft.matchValue=rft.Id |
| 324 |
rft.gotMatchOptn=True |
| 325 |
rft.firstOptn=True |
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
if( rft.gotIdLevel2Optn is True ): |
| 330 |
rft.matchLevel2Prop="Id" |
| 331 |
rft.matchLevel2Value=rft.IdLevel2 |
| 332 |
rft.gotMatchLevel2Optn=True |
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
if( rft.IdLevel2OptnCount > 1): |
| 338 |
rft.printErr("Syntax error: invalid mix of options -i,-m,-a used to specify a 2nd-level collection member.") |
| 339 |
rft.printErr(" Valid combinations: -i | -m | -l | -a ",noprog=True) |
| 340 |
displayUsage(rft) |
| 341 |
sys.exit(1) |
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
if( not args ): |
| 350 |
rft.printErr("Syntax error. No subcommand specified.") |
| 351 |
displayUsage(rft) |
| 352 |
sys.exit(1) |
| 353 |
else: |
| 354 |
rft.subcommand=args[0] |
| 355 |
rft.subcommandArgv=list(args) |
| 356 |
|
| 357 |
|
| 358 |
if rft.no_proxy: |
| 359 |
os.environ['NO_PROXY'] = '*' |
| 360 |
|
| 361 |
rft.printVerbose(5,"Main: subcmd: {}, subCmdArgs:{}".format(rft.subcommand,rft.subcommandArgv)) |
| 362 |
rft.printVerbose(5,"Main: verbose={}, status={}, user={}, password={}, rhost={}".format(rft.verbose, rft.status, |
| 363 |
rft.user,rft.password,rft.rhost)) |
| 364 |
rft.printVerbose(5,"Main: token={}, RedfishVersion={}, Auth={}, Timeout={}, NonBlocking={}".format(rft.token, |
| 365 |
rft.protocolVer, rft.auth, rft.timeout, not rft.blocking)) |
| 366 |
rft.printVerbose(5,"Main: prop={}, Id={}, Match={}:{}, First={}, -1={}, Link={}".format( rft.prop, |
| 367 |
rft.Id, rft.matchProp,rft.matchValue, rft.firstOptn, rft.oneOptn, rft.Link)) |
| 368 |
rft.printVerbose(5,"Main: gotIdOptn={}, IdOptnCount={}, gotPropOptn={}, gotMatchOptn={}, gotEntriesOptn={}".format( |
| 369 |
rft.gotIdOptn, rft.IdOptnCount, rft.gotPropOptn, rft.gotMatchOptn, rft.gotEntriesOptn)) |
| 370 |
rft.printVerbose(5,"Main: 2nd-Level Collection Member reference options: -i<id>={}, -m<match>={}:{}, -l<link>={} -all={}".format( |
| 371 |
rft.IdLevel2, rft.matchLevel2Prop, rft.matchLevel2Value, rft.linkLevel2, rft.allOptn)) |
| 372 |
rft.printVerbose(5,"Main: 2nd-level Collection Member parsing: gotIdLevel2Optn={}, gotMatchLevel2Optn={}, IdLevel2OptnCount={}".format( |
| 373 |
rft.gotIdLevel2Optn, rft.gotMatchLevel2Optn, rft.IdLevel2OptnCount )) |
| 374 |
rft.printVerbose(5,"Main: configFile={}, Secure={}, waitNum:waitTime={}:{}, Degug={:08x}".format( |
| 375 |
rft.configFile,rft.secure, rft.waitNum,rft.waitTime,rft.dbgFlag)) |
| 376 |
rft.printVerbose(5,"Main: Headers={}".format(rft.headers)) |
| 377 |
|
| 378 |
rft.printVerbose(5,"Main: options parsed. Now lookup subcommand and execute it") |
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
rc,r,j,d=runSubCmd(rft) |
| 384 |
if(rc !=0 ): |
| 385 |
rft.printVerbose(5,"#DB4:Main: subcommand returned with error: rc={}".format(rc)) |
| 386 |
rft.printVerbose(1,"Main: Error: rc={}".format(rc)) |
| 387 |
if r is not None: |
| 388 |
rft.printVerbose(5," Response status code:{}".format(r.status_code)) |
| 389 |
rft.printVerbose(5," Response headers: {}".format(r.headers)) |
| 390 |
|
| 391 |
rft.rfCleanup(rft) |
| 392 |
sys.exit(rc) |
| 393 |
|
| 394 |
rft.printVerbose(5,"Main: subcommand exited OK.") |
| 395 |
if( r is not None ): |
| 396 |
rft.printVerbose(5," Status code:{}".format(r.status_code)) |
| 397 |
rft.printStatus(1,r=r) |
| 398 |
rft.printStatus(2,r=r) |
| 399 |
|
| 400 |
|
| 401 |
if( j is True and d is not None): |
| 402 |
output=json.dumps(d,indent=4) |
| 403 |
print(output) |
| 404 |
elif( j is False and d is not None): |
| 405 |
output=r.text |
| 406 |
print(output) |
| 407 |
else: |
| 408 |
pass |
| 409 |
|
| 410 |
|
| 411 |
rft.rfCleanup(rft) |
| 412 |
|
| 413 |
rft.printVerbose(5,"Main: Done") |
| 414 |
|
| 415 |
|
| 416 |
sys.exit(0) |
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
def runSubCmd(rft): |
| 428 |
|
| 429 |
root=RfServiceRoot() |
| 430 |
systems=RfSystemsMain() |
| 431 |
chassis=RfChassisMain() |
| 432 |
managers=RfManagersMain() |
| 433 |
sessionService=RfSessionServiceMain() |
| 434 |
accountService=RfAccountServiceMain() |
| 435 |
raw=RfRawMain() |
| 436 |
|
| 437 |
|
| 438 |
subCmdTable = { |
| 439 |
"help": helpSubcmd, |
| 440 |
"about": aboutSubcmd, |
| 441 |
"versions": rft.getVersions, |
| 442 |
"serviceRoot": root.getServiceRoot, |
| 443 |
"root": root.getServiceRoot, |
| 444 |
"odata": root.getOdataServiceDocument, |
| 445 |
"metadata": root.getOdataMetadataDocument, |
| 446 |
"Systems": systems.SystemsMain, |
| 447 |
"Chassis": chassis.ChassisMain, |
| 448 |
"Managers": managers.ManagersMain, |
| 449 |
"AccountService": accountService.AccountServiceMain, |
| 450 |
"SessionService": sessionService.SessionServiceMain, |
| 451 |
"raw": raw.RawMain, |
| 452 |
"hello": helloSubcmd |
| 453 |
} |
| 454 |
|
| 455 |
rft.printVerbose(5,"runSubCmd: subcmd: {}".format(rft.subcommand)) |
| 456 |
rft.printVerbose(5,"runSubCmd: argvs: {}".format(rft.subcommandArgv)) |
| 457 |
|
| 458 |
if rft.subcommand in subCmdTable: |
| 459 |
rft.printVerbose(5,"runSubCmd: found SubCmd: {} in table. executing".format(rft.subcommand)) |
| 460 |
rc,r,j,d=subCmdTable[rft.subcommand](rft,cmdTop=True) |
| 461 |
return(rc,r,j,d) |
| 462 |
|
| 463 |
else: |
| 464 |
rft.printErr("Invalid SubCommand: {}".format(rft.subcommand)) |
| 465 |
return(1,None,False,None) |
| 466 |
|
| 467 |
|
| 468 |
def helloSubcmd(rft, cmdTop=False): |
| 469 |
rft.printVerbose(5,"Main: in hello subcommand") |
| 470 |
if(rft.help): |
| 471 |
print("# {} [OPTIONS] hello ---prints hello world message for debug".format(rft.program)) |
| 472 |
return(0,None,False,None) |
| 473 |
print("#\n# Hello World \n#") |
| 474 |
return(0,None,False,None) |
| 475 |
|
| 476 |
def helpSubcmd(rft, cmdTop=False): |
| 477 |
rft.printVerbose(5,"Main: in help subcommand") |
| 478 |
displayHelp(rft) |
| 479 |
return(0,None,False,None) |
| 480 |
|
| 481 |
def aboutSubcmd(rft, cmdTop=False): |
| 482 |
rft.printVerbose(5,"Main: in about subcommand") |
| 483 |
if(rft.help): |
| 484 |
print("# {} [OPTIONS] about ---prints information about {}".format(rft.program,rft.program)) |
| 485 |
return(0,None,False,None) |
| 486 |
print("#") |
| 487 |
print("# {} {}:".format(rft.program,rft.subcommand)) |
| 488 |
print("# Version: {}".format(rft.version)) |
| 489 |
print("# Supports Redfish Protocol Versions: {}".format(rft.supportedVersions)) |
| 490 |
print("# Release date: {}".format(rft.releaseDate)) |
| 491 |
print("# Download from: {}".format(rft.downloadFrom)) |
| 492 |
print("#") |
| 493 |
return(0,None,False,None) |
| 494 |
|
| 495 |
|
| 496 |
if __name__ == "__main__": |
| 497 |
main(sys.argv) |
| 498 |
|
| 499 |
|
| 500 |
''' |
| 501 |
TODO |
| 502 |
1. implement -c cfgfile |
| 503 |
2. implement -d <data> -d @<file> for raw subcommand POST or PATCH data |
| 504 |
3. |
| 505 |
|
| 506 |
|
| 507 |
''' |
| 508 |
|