Debian Codegraph @

redfishtoollib/Managers.py

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
1 # Copyright Notice:
2 # Copyright 2016 DMTF. All rights reserved.
3 # License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/Redfishtool/blob/master/LICENSE.md
4
5 # redfishtool: Managers.py
6 #
7 # contains Managers related subCommands and access functions
8 #
9 # Class RfManagersMain
10 # - functions init, displayUsage, displayHelp, displayOperations,
11 # - runOperation - Managers command table, dispatch of operation eg get, reset
12 # - ManagersMain - called from redfishMain, enforce legal option combinations,
13 # and call runOperation to run Managers operation (sub-sub-command)
14 #
15 # Class RfManagersOperations
16 # All of the Managers sub-command operations eg: Managers reset, setTime etc
17 # - hello - test cmd
18 # - getCollection - return the Managers collection
19 # - get - get a member of a collection -or property of the member
20 # - list - show of list of collection members and key idetifying properties
21 # (Id, UUID, UriPath)
22 # - patch - raw subcommand to patch a Managers Member, with etag support
23 # - reset --reset a system instance
24 # - setDateTime -- set the manager dataTime setting
25 # - setTimeOffset -- set the local time offset w/o changing time
26 # - getNetworkProtocol - get Network Protocol sub-resource
27 # - getEnetInterfaces - get Ethernet collection, instance, all
28 # - getSerialInterfaces - get SerialInterfaces collection, instance, all
29 # - getLogService - get LogService collection, instance, all
30 # - clearLog -- clears a specified log (not implemented yet)
31 # - examples --prints some example apis
32 #
33 from .redfishtoolTransport import RfTransport
34 import requests
35 import json
36 import getopt
37 import re
38 import sys
39 from .ServiceRoot import RfServiceRoot
40 from urllib.parse import urljoin
41
42 class RfManagersMain():
43 def __init__(self):
44 # operation string and remaining args
45 self.operation=None
46 self.args=None
47 self.argnum=0
48 self.nonIdCommands=None
49
50 def displayUsage(self,rft):
51 if(rft.quiet): return(0)
52 print(" Usage:")
53 print(" {} [OPTNS] Managers <operation> [<args>] -- perform <operation> on the Managers specified ".format(rft.program))
54
55 def displayHelp(self,rft):
56 self.displayUsage(rft)
57 self.displayOperations(rft)
58 print("")
59
60 def displayOperations(self,rft):
61 print(" <operations>:")
62 print(" [collection] -- get the main Managers collection. (Default operation if no member specified)")
63 print(" [get] -- get the specified Manager object. (Default operation if collection member specified)")
64 print(" list -- list information about the Managers collection members(\"Id\", URI, and UUID)")
65 print(" patch {A: B,C: D,...} -- patch the json-formatted {prop: value...} data to the object")
66 print(" reset <resetType> -- reset a Manager. <resetType>= On, GracefulShutdown, GracefulRestart, ")
67 print(" ForceRestart, ForceOff, ForceOn, Nmi, PushPowerButton, PowerCycle")
68 print(" setDateTime <dateTimeString>--set the date and time")
69 print(" setTimeOffset offset=<offsetString> --set the time offset w/o changing time setting")
70 print(" <offsetString> is of form \"[+/-]mm:ss\". Ex: \"-10:01\" ")
71 print(" NetworkProtocol -- get the \"NetworkProtocol\" resource under the specified manager.")
72 print(" setIpAddress [-i<indx>]... -- set the Manager IP address -NOT IMPLEMENTED YET")
73 print("")
74 print(" EthernetInterfaces [list] -- get the managers \"EthernetInterfaces\" collection, or list \"id\",URI, Name of members.")
75 print(" EthernetInterfaces [IDOPTN]-- get the member specified by IDOPTN: -i<id>, -m<prop>:<val>, -a #all")
76 print("")
77 print(" SerialInterfaces [list] -- get the managers \"SerialInterfaces\" collection, or list \"id\",URI, Name of members.")
78 print(" SerialInterfaces [IDOPTN] -- get the member specified by IDOPTN: -i<id>, -m<prop>:<val>, -l<link>, -a #all")
79 print("")
80 print(" Logs [list] -- get the Managers \"LogServices\" collection , or list \"id\",URI, Name of members.")
81 print(" Logs [IDOPTN] -- get the member specified by IDOPTN: -i<id>, -m<prop>:<val>, -l<link>, -a #all")
82 print(" clearLog <id> -- clears the log defined by <id>")
83 print(" examples -- example commands with syntax")
84 print(" hello -- Systems hello -- debug command")
85 return(0)
86
87
88 def runOperation(self,rft):
89 # instantiate SystemsOperations class
90 op=RfManagersOperations()
91
92 # dispatch table for each subcommand: "cmdName": cmdClass.cmdFunction"
93 operationTable = {
94 "collection": op.getCollection,
95 "get": op.get,
96 "list": op.list,
97 "patch": op.patch,
98 "reset": op.reset,
99 "setDateTime": op.setDateTime,
100 "setTimeOffset": op.setTimeOffset,
101 "setIpAddress": op.setIpAddress,
102 "NetworkProtocol": op.getNetworkProtocol,
103 "EthernetInterfaces": op.getEnetInterfaces,
104 "SerialInterfaces": op.getSerialInterfaces,
105 "Logs": op.getLogService,
106 "clearLog": op.clearLog,
107 "hello": op.hello,
108 "examples": op.examples
109 }
110
111 rft.printVerbose(5,"Managers:runOperation: operation: {}".format(self.operation))
112 rft.printVerbose(5,"Managers:runOperation: args: {}".format(self.args))
113
114 if self.operation in operationTable:
115 rft.printVerbose(5,"Managers:runOperation: found Oper: {} in table. executing".format(rft.subcommand))
116 rc,r,j,d=operationTable[self.operation](self, op, rft, cmdTop=True)
117 return(rc,r,j,d)
118
119 else: # invalid operation
120 rft.printErr("Managers: Invalid operation: {}".format(self.operation))
121 return(2,None,False,None)
122
123
124
125 def ManagersMain(self,rft,cmdTop=False):
126 rft.printVerbose(4,"ManagersMain: subcommand: {}".format(rft.subcommand))
127
128 if( rft.help ):
129 self.displayHelp(rft)
130 return(0,None,False,None)
131
132 # we will validate usage of -P and -a in action processing
133 # actually, if a non 'get' action is specified, -P and -a are just ignored :)
134
135 args=rft.subcommandArgv[0:]
136
137 #if no args, then if no member Id was specified (with -I|-M|-1|-F) then assume it is a "collection" operation
138 # if a -IM1F was specified, then assume it is a "get" operation for that member
139 if( len(args) < 2 ):
140 if( rft.IdOptnCount==0 ):
141 self.operation="collection"
142 else:
143 self.operation="get"
144 self.args= None
145 else:
146 self.operation=args[1]
147 self.args = args[1:] # now args points to the 1st argument
148 self.argnum =len(self.args)
149
150 rft.printVerbose(5,"Managers: operation={}, args={}".format(self.operation,self.args))
151
152 # check if the command requires a collection member target -I|-M|-L|-1|-F eg sysIdoptn
153 nonIdCommands=["collection", "list", "examples", "hello"]
154 if( ( not self.operation in nonIdCommands ) and (rft.IdOptnCount==0) ):
155 # default to --One if no Id option specified
156 rft.oneOptn = True
157 rft.IdOptnCount += 1
158
159 # now execute the operation.
160 rc,r,j,d = self.runOperation(rft)
161
162 if(rc !=0 ):
163 rft.printVerbose(5,"Managers: operation returned with error: rc={}".format(rc))
164 return(rc,r,False,None)
165
166 #else, if here, the subcommand executed without error. Return with 0 exit code
167 rft.printVerbose(5,"Managers: operation exited OK")
168 return(rc,r,j,d)
169
170
171 #
172 # contains operations related to the Managers subCommand
173 #
174 class RfManagersOperations():
175 def __init__(self):
176 self.managersPath=None
177 self.managersollectionDict=None
178
179
180 def hello(self,sc,op,rft,cmdTop=False):
181 rft.printVerbose(4,"in hello")
182 rft.printVerbose(4," subcmd:{}, operation:{}, args:{}".format(rft.subcommand,sc.operation,sc.args))
183 print("hello world from Managers")
184 return(0,None,False,None)
185
186 def getCollection(self,sc,op,rft,cmdTop=False, prop=None):
187 rft.printVerbose(4,"{}:{}: in getCollection".format(rft.subcommand,sc.operation))
188
189 # 1st get serviceRoot
190 svcRoot=RfServiceRoot()
191 rc,r,j,d = svcRoot.getServiceRoot(rft)
192 if( rc != 0 ):
193 rft.printErr("getCollection: Error getting service root, aborting")
194 return(rc,r,False,None)
195
196 # get the link to the Managers collection
197 # need to test we got good data
198 if (("Managers" in d) and ("@odata.id" in d["Managers"])):
199 systemsLink=d["Managers"]["@odata.id"]
200 else:
201 rft.printErr("Error: service root does not have a Managers link")
202 return(4)
203
204 rft.printVerbose(4,"Managers:getCollection: link is: {}".format(systemsLink))
205
206
207 # if a -a option was entered with "Managers" or "Managers collection" operation,
208 # then return all members of the Managers collection expanded
209 if((cmdTop is True) and (rft.allOptn is True) ):
210 collName="Managers"
211 rft.printVerbose(4,"Expand Managers collection to return ALL Managers collection members fully expanded in response")
212 rc,r,j,d=rft.getAllCollectionMembers(rft, r.url, relPath=systemsLink)
213 if(rc==0):
214 rft.printVerbose(1," Get ALL {} Collection Members".format(collName,skip1=True, printV12=cmdTop))
215
216 # otherwise, just return the collection
217 # now read the /Managers collection
218 # use the returned url as the base url to read the Managers collection
219 else:
220 if cmdTop is True: prop=rft.prop
221 rc,r,j,d=rft.rftSendRecvRequest(rft.AUTHENTICATED_API, 'GET', r.url, relPath=systemsLink, prop=prop)
222 if(rc==0):
223 rft.printVerbose(1," Managers Collection:",skip1=True, printV12=cmdTop)
224
225 return(rc,r,j,d)
226
227
228 def get(self,sc,op,rft, cmdTop=False, prop=None):
229 rft.printVerbose(4,"{}:{}: in operation".format(rft.subcommand,sc.operation))
230
231 # getCollection
232 rc,r,j,d=op.getCollection(sc,op, rft)
233 if( rc != 0): return(rc,r,False,None)
234 collUrl=r.url
235
236 # search collection to find path to the Manager
237 sysPath,rc,r,j,d=rft.getPathBy(rft, r, d)
238 if( rc !=0 ): #if a path was not found, its an error
239 return(rc,r,j,d)
240
241 rft.printVerbose(4,"ManagersOperations:get: got a path, now get entries")
242
243 if cmdTop is True: prop=rft.prop
244
245 #if here, rc=0
246 #if sysPath returned a response but we need to extract the property do it here
247 if( (r is not None) and (prop is not None) ):
248 rc,r,j,d=rft.getPropFromDict(rft,r,d,prop)
249
250 # otherwise, we need to do a GET to get the Manager, if -P show property, else show full response
251 elif( r is None ):
252 rc,r,j,d=rft.rftSendRecvRequest(rft.AUTHENTICATED_API, 'GET', collUrl, relPath=sysPath, prop=prop)
253
254 if(rc==0): rft.printVerbose(1," Managers Resource:",skip1=True, printV12=cmdTop)
255 return(rc,r,j,d)
256
257
258 def list(self,sc,op,rft, cmdTop=False, prop=None):
259 rft.printVerbose(4,"{}:{}: in operation".format(rft.subcommand,sc.operation))
260
261 # getCollection
262 collName="Managers"
263 rc,r,j,d=op.getCollection(sc,op, rft)
264 if( rc != 0): return(rc,r,False,None)
265 #loop through the members and create the list sub-operation response
266 rc,r,j,d=rft.listCollection(rft, r, d, prop="UUID")
267 if(rc==0):
268 rft.printVerbose(1," list {} Collection member info: Id, URI, UUID".format(collName,skip1=True, printV12=cmdTop))
269 return(rc,r,j,d)
270
271
272 def patch(self,sc,op,rft,cmdTop=False, prop=None, patchData=None, r=None):
273 rft.printVerbose(4,"{}:{}: in operation".format(rft.subcommand,sc.operation))
274 # verify we have got an argument which is the patch structure
275 # its in form '{ "AssetTag": <val>, "IndicatorLed": <val> }'
276 ##print("patchData: {}".format(patchData))
277 if( len( sc.args) == 2):
278 try:
279 patchData=json.loads(sc.args[1])
280 except ValueError:
281 rft.printErr("Patch: invalid Json input data:{}".format(sc.args[1]))
282 return(5,None,False,None)
283 else:
284 rft.printErr("Patch: error: invalid argument format")
285 rft.printErr(" : args={}".format(sc.args))
286 rft.printErr(" : expect: Systems patch \"{ <prop>: <value> }\"")
287 return(4,None,False,None)
288
289 # read the Managers resource
290 # this is used by the generic rft.patchResource() function to see if there is an etag in the response
291 # if an etag is in response hdr, then we must include the etag on the patch, so this get is required
292 # note: the format of etag header for redfish is: ETag: W/"<string>" or "<string"
293 rc,r,j,d=op.get(sc,op,rft)
294 if( rc != 0):
295 return(rc,r,False,None)
296
297 # now call the generic patch function to send the patch
298 rc,r,j,d=rft.patchResource(rft, r, patchData)
299
300 if(rc==0): rft.printVerbose(1," Managers Patch:",skip1=True, printV12=cmdTop)
301 return(rc,r,j,d)
302
303
304 def reset(self,sc,op,rft,cmdTop=False, prop=None):
305 # this operation has argument syntaxes below:
306 # ...reset <resetType>
307 # where <resetType> is a subset of Redfish defined redfish resetType values
308 # and will be validated against the allowable values read from the remote service
309 rft.printVerbose(4,"{}:{}: in operation".format(rft.subcommand,sc.operation))
310
311 # get the resetType from args
312 validResetTypes=["On","ForceOff","GracefulShutdown","ForceRestart","Nmi","GracefulRestart",
313 "ForceOn","PushPowerButton","PowerCycle"]
314 if(len(sc.args) < 2 ):
315 rft.printErr("Error, no resetType value specified")
316 return(8,None,False,None)
317
318 resetType=sc.args[1]
319 if not resetType in validResetTypes:
320 rft.printErr("Error, Invalid <resetType> value specified: {}".format(resetType))
321 return(8,None,False,None)
322
323 #now read remote service to find out if specified resetType is one of the allowable values for this rhost
324 rc,r,j,d=op.get(sc,op,rft,prop="Actions")
325 if(rc != 0):
326 print("Error, cant read Actions properties from remote service")
327 return(8,None,False,None)
328
329 if( (j is True) and ("Actions" in d) and ("#Manager.Reset" in d["Actions"])):
330 resetProps=d["Actions"]["#Manager.Reset"]
331 if( "[email protected]" in resetProps ):
332 supportedResetTypes=resetProps["[email protected]"]
333 if not resetType in supportedResetTypes:
334 rft.printErr("Error, the resetType specified is not supported by the remote service (via @Redfish.AllowableValues)")
335 return(8,None,False,None)
336 elif "@Redfish.ActionInfo" in resetProps:
337 action_info_path = resetProps["@Redfish.ActionInfo"]
338 supportedResetTypes = rft.getActionInfoAllowableValues(rft, r, action_info_path, "ResetType")
339 if supportedResetTypes is not None and resetType not in supportedResetTypes:
340 rft.printErr("Error, the resetType specified is not supported by the remote service (via @Redfish.ActionInfo)")
341 return(8,None,False,None)
342 else: # rhost didn't return any AllowableValues, but it isn't required, so allow the action
343 rft.printVerbose(2, "The remote service does not have a [email protected] or @Redfish.ActionInfo prop")
344 else:
345 rft.printErr("Error, the remote service does not have an Actions: Manager.Reset property")
346 return(8,None,False,None)
347
348 # now get the target URI from the remote host
349 if( not "target" in resetProps ):
350 rft.printErr("Error, the remote service doesnt have a Reset Target property (the reset path)")
351 return(8,None,False,None)
352 resetPath=resetProps["target"]
353
354 resetData={"ResetType": resetType }
355
356 #since we already did a get, we have the path and can just execute the post directly.
357 #output the post data in json to send over the network
358 reqPostData=json.dumps(resetData)
359 # send post to rhost. Use the resetPath as the relative path
360 rc,r,j,d=rft.rftSendRecvRequest(rft.AUTHENTICATED_API, 'POST', r.url, relPath=resetPath,
361 reqData=reqPostData)
362
363 if(rc==0):
364 rft.printVerbose(1," Managers reset: ", resetType, skip1=True, printV12=cmdTop)
365 resetd=None
366 return(rc,r,False,resetd)
367 else: return(rc,r,False,None)
368
369
370 # setDateTime -- command to set the Managers time--and timezone
371 def setDateTime(self,sc,op,rft,cmdTop=False, prop=None):
372 rft.printVerbose(4,"{}:{}: in operation".format(rft.subcommand,sc.operation))
373
374 propName="DateTime"
375 # get the target dateTime from args
376 if(len(sc.args) < 2 ):
377 rft.printErr("Error, no dateTime argument specified")
378 rft.printErr("Syntax: {} [options] Managers setDateTime <dateTimeString>".format(rft.program))
379 rft.printErr(" <dateTimeString> in form: \"YYYY-MM-DDThh:mm:ss[+/-]hh:ss\"")
380 return(8,None,False,None)
381 else: #we have an arg[1]
•382 datePattern=r"(^[2][0]\d{2}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}[-+][0-1][0-9]:[0-5][0-9]$)" # YYYY-MM-DDTHH:mm:ss[+/-]hh:ss
383 dateMatch=re.search(datePattern,sc.args[1]) # sc.args[1]=<dateTimeString>
384 if( dateMatch ):
385 dateTimeString=(sc.args[1]) # keep it a string
386 rft.printVerbose(4,"setDateTime: dateTime={}".format(dateTimeString))
387 else:
388 rft.printErr("Error: setDateTime: invalid <dateTime> value specified: {}".format(sc.args[1]))
389 rft.printErr("Managers setDateTime <dateTimeString> # eg: YYYY-MM-DDThh:mm:ss[+/-]hh:ss")
390 return(8,None,False,None)
391
392 patchData={propName: dateTimeString}
393
394 # get the resource to verify it includes dateTime property,
395 # the response will also be used by Patch() to check for etag
396 rc,r,j,d=op.get(sc,op,rft)
397 if( rc != 0): return(rc,r,False,None)
398 if( not propName in d ):
399 rft.printErr("Managers resource does not have a {} property.".format(propName))
400 return(8,r,False,None)
401
402 rc,r,j,d=rft.patchResource(rft, r, patchData)
403 if(rc==0):
404 rft.printVerbose(1," setDateTime:",skip1=True, printV12=cmdTop)
405 dateTimeReturned={propName: d[propName]}
406 return(rc,r,j,dateTimeReturned)
407 else: return(rc,r,False,None)
408
409
410
411 # setTimeOffset -- command to change the Managers timezone offset (w/o changing time)
412 def setTimeOffset(self,sc,op, rft, cmdTop=False, prop=None):
413 rft.printVerbose(4,"{}:{}: in operation".format(rft.subcommand,sc.operation))
414
415 propName="DateTimeLocalOffset"
416 # get the target offset from args
417 if(len(sc.args) < 2 ):
418 rft.printErr("Error, no timeOffset argument specified")
419 rft.printErr("Syntax: {} [options] Managers setTimeOffset offset=<timeOffsetString>".format(rft.program))
420 rft.printErr(" where <timeOffsetString> in form: \"[+/-]hh:ss\", ex: -06:00 ")
421 return(8,None,False,None)
422 else: #we have an arg[1]
423 datePattern="^offset=([-+][0-1][0-9]:[0-5][0-9])$" # [+/-]hh:ss
424 dateMatch=re.search(datePattern,sc.args[1]) # sc.args[1]=<timeOffset>
425 if( dateMatch ):
426 timeOffsetString=dateMatch.group(1) # keep it a string. <timeOffsetString>
427 rft.printVerbose(4,"setDateTime: timeOffset={}".format(timeOffsetString))
428 else:
429 rft.printErr("Error: setTimeOffset: invalid <timeOffset> value specified: {}".format(sc.args[1]))
430 rft.printErr("Managers setTimeOffset offset=<timeOffset> # eg: where <timeOffset>=[+/-]hh:ss")
431 return(8,None,False,None)
432
433 patchData={propName: timeOffsetString}
434
435 # get the resource to verify it includes DateTimeLocalOffset property,
436 # the response will also be used by Patch() to check for etag
437 rc,r,j,d=op.get(sc,op,rft)
438 if( rc != 0): return(rc,r,False,None)
439 if( not propName in d ):
440 rft.printErr("Managers resource does not have a {} property.".format(propName))
441 return(8,r,False,None)
442
443 rc,r,j,d=rft.patchResource(rft, r, patchData)
444 if(rc==0):
445 rft.printVerbose(1," setTimeOffset:",skip1=True, printV12=cmdTop)
446 timeOffsetReturned={propName: d[propName]}
447 return(rc,r,j,timeOffsetReturned)
448 else: return(rc,r,False,None)
449
450
451 def getNetworkProtocol(self,sc,op, rft, cmdTop=False, prop=None):
452 rft.printVerbose(4,"{}:{}: in operation".format(rft.subcommand,sc.operation))
453
454 # get the Manager resource first
455 rc,r,j,d=op.get(sc,op, rft)
456 if( rc != 0): return(rc,r,False,None)
457
458 resName="NetworkProtocol"
459 # get the link to the NetworkProtocol resource under Manager
460 if ((resName in d) and ("@odata.id" in d[resName])):
461 resLink=d[resName]["@odata.id"]
462 else:
463 rft.printErr("Error: Manager resource does not have a {} link".format(resName))
464 return(6,None,False,None)
465
466 if cmdTop is True: prop=rft.prop
467
468 rc,r,j,d=rft.rftSendRecvRequest(rft.AUTHENTICATED_API, 'GET', r.url, relPath=resLink, prop=prop)
469 if(rc==0):
470 rft.printVerbose(1," {} Resource ".format(resName,skip1=True, printV12=cmdTop))
471
472 return(rc,r,j,d)
473
474
475 # setIpAddress -- command to set the IP address of the MC
476 def setIpAddress(self,sc,op, rft, cmdTop=False, prop=None):
477 rft.printVerbose(4,"{}:{}: in operation".format(rft.subcommand,sc.operation))
478 print("Not Implemented Yet")
479 return(6,None,False,None)
480
481
482 def getEnetInterfaces(self,sc,op,rft,cmdTop=False, prop=None):
483 rft.printVerbose(4,"{}:{}: in operation".format(rft.subcommand,sc.operation))
484
485 # get the Manager resource
486 rc,r,j,d=op.get(sc,op, rft)
487 if( rc != 0): return(rc,r,False,None)
488
489 collName="EthernetInterfaces"
490 # get the link to the EthernetInterfaces collection
491 if ((collName in d) and ("@odata.id" in d[collName])):
492 nicLink=d[collName]["@odata.id"]
493 else:
494 rft.printErr("Error: Manager resource does not have a {} link".format(collName))
495 return(6,None,False,None)
496
497 if cmdTop is True: prop=rft.prop
498
499 # check if there is a list arg for the operation
500 if( sc.argnum > 1 and sc.args[1] == 'list' ):
501 #get the collection
502 rc,r,j,d=rft.rftSendRecvRequest(rft.AUTHENTICATED_API, 'GET', r.url, relPath=nicLink)
503 #loop through the members and create the list sub-operation response
504 rc,r,j,d=rft.listCollection(rft, r, d, prop="Name")
505 if(rc==0):
506 rft.printVerbose(1," list {} Collection member info: Id, URI, Name".format(collName,skip1=True, printV12=cmdTop))
507
508 # else: check if no NIC was specified. If not, return the collection
509 elif(rft.IdLevel2OptnCount==0):
510 rc,r,j,d=rft.rftSendRecvRequest(rft.AUTHENTICATED_API, 'GET', r.url, relPath=nicLink, prop=prop)
511 if(rc==0):
512 rft.printVerbose(1," {} Collection ".format(collName,skip1=True, printV12=cmdTop))
513
514 # else: check if the -a (all) option is set. If not, return the proc specific by -i or -m
515 # search collection to find path using getPath2
516 elif( rft.allOptn is not True ):
517 # get the EthernetInterfaces collection
518 rc,r,j,d=rft.rftSendRecvRequest(rft.AUTHENTICATED_API, 'GET', r.url, relPath=nicLink, prop=prop)
519 collUrl=r.url
520
521 # now search for 2nd level resource and return
522 path2,rc,r,j,d=rft.getLevel2ResourceById(rft,r,d)
523 if(rc!=0):
524 return(rc,r,j,d)
525 # so rc=0
526 #if sysPath returned a response but we need to extract the property do it here
527 if( (r is not None) and (prop is not None) ):
528 rc,r,j,d=rft.getPropFromDict(rft,r,d,prop)
529
530 # otherwise, we need to do a GET to get the EthernetInterfaces, if -P show property, else show full response
531 elif( r is None ):
532 rc,r,j,d=rft.rftSendRecvRequest(rft.AUTHENTICATED_API, 'GET', collUrl, relPath=path2, prop=prop)
533 if(rc==0):
534 rft.printVerbose(1," {} Collection Member ".format(collName,skip1=True, printV12=cmdTop))
535
536 # else, return ALL of the EthernetInterfaces members
537 else:
538 rft.printVerbose(4,"getting expanded EthernetInterfaces Collection")
539 rc,r,j,d=rft.getAllCollectionMembers(rft, r.url, relPath=nicLink)
540 if(rc==0):
541 rft.printVerbose(1," Get ALL {} Collection Members".format(collName,skip1=True, printV12=cmdTop))
542
543 return(rc,r,j,d)
544
545
546
547 def getSerialInterfaces(self,sc,op,rft,cmdTop=False, prop=None):
548 rft.printVerbose(4,"{}:{}: in operation".format(rft.subcommand,sc.operation))
549
550 # get the Manager resource
551 rc,r,j,d=op.get(sc,op, rft)
552 if( rc != 0): return(rc,r,False,None)
553
554 collName="SerialInterfaces"
555 # get the link to the SerialInterfaces collection
556 if ((collName in d) and ("@odata.id" in d[collName])):
557 cntlrLink=d[collName]["@odata.id"]
558 else:
559 rft.printErr("Error: Manager resource does not have a {} link".format(collName))
560 return(6,None,False,None)
561
562 if cmdTop is True: prop=rft.prop
563
564 # check if there is a list arg for the operation
565 if( sc.argnum > 1 and sc.args[1] == 'list' ):
566 #get the collection
567 rc,r,j,d=rft.rftSendRecvRequest(rft.AUTHENTICATED_API, 'GET', r.url, relPath=cntlrLink)
568 #loop through the members and create the list sub-operation response
569 rc,r,j,d=rft.listCollection(rft, r, d, prop="Name" )
570 if(rc==0):
571 rft.printVerbose(1," list {} Collection member info: Id, URI, Name".format(collName,skip1=True, printV12=cmdTop))
572
573 # else: check if no SerialInterfaces controller was specified. If not, return the collection
574 elif(rft.IdLevel2OptnCount==0):
575 rc,r,j,d=rft.rftSendRecvRequest(rft.AUTHENTICATED_API, 'GET', r.url, relPath=cntlrLink, prop=prop)
576 if(rc==0):
577 rft.printVerbose(1," {} Collection ".format(collName,skip1=True, printV12=cmdTop))
578
579 # else: check if the -a (all) option is set. If not, return the proc specific by -i or -m
580 # search collection to find path using getPath2
581 elif( rft.allOptn is not True ):
582 # get the SerialInterfaces collection
583 rc,r,j,d=rft.rftSendRecvRequest(rft.AUTHENTICATED_API, 'GET', r.url, relPath=cntlrLink, prop=prop)
584 collUrl=r.url
585
586 # now search for 2nd level resource and return
587 path2,rc,r,j,d=rft.getLevel2ResourceById(rft,r,d)
588 if(rc!=0):
589 return(rc,r,j,d)
590 # so rc=0
591 #if sysPath returned a response but we need to extract the property do it here
592 if( (r is not None) and (prop is not None) ):
593 rc,r,j,d=rft.getPropFromDict(rft,r,d,prop)
594
595 # otherwise, we need to do a GET to get the SerialInterfaces, if -P show property, else show full response
596 elif( r is None ):
597 rc,r,j,d=rft.rftSendRecvRequest(rft.AUTHENTICATED_API, 'GET', collUrl, relPath=path2, prop=prop)
598 if(rc==0):
599 rft.printVerbose(1," {} Collection Member ".format(collName,skip1=True, printV12=cmdTop))
600
601 # else, return ALL of the SerialInterfaces members
602 else:
603 rft.printVerbose(4,"getting expanded SerialInterfaces Collection")
604 rc,r,j,d=rft.getAllCollectionMembers(rft, r.url, relPath=cntlrLink)
605 if(rc==0):
606 rft.printVerbose(1," Get ALL {} Collection Members".format(collName,skip1=True, printV12=cmdTop))
607
608 return(rc,r,j,d)
609
610
611
612 def getLogService(self,sc,op,rft,cmdTop=False, prop=None):
613 rft.printVerbose(4,":{}:{}: in operation".format(rft.subcommand,sc.operation))
614
615 # get the Manager resource
616 rc,r,j,d=op.get(sc,op, rft)
617 if( rc != 0): return(rc,r,False,None)
618
619 collName="LogServices"
620 # get the link to the LogServices collection
621 if ((collName in d) and ("@odata.id" in d[collName])):
622 logLink=d[collName]["@odata.id"]
623 else:
624 rft.printErr("Error: Manager resource does not have a {} link".format(collName))
625 return(6,None,False,None)
626
627 if cmdTop is True: prop=rft.prop
628
629 # check if there is a list arg for the operation
630 if( sc.argnum > 1 and sc.args[1] == 'list' ):
631 #get the collection
632 rc,r,j,d=rft.rftSendRecvRequest(rft.AUTHENTICATED_API, 'GET', r.url, relPath=logLink)
633 #loop through the members and create the list sub-operation response
634 rc,r,j,d=rft.listCollection(rft, r, d, prop="Name")
635 if(rc==0):
636 rft.printVerbose(1," list {} Collection member info: Id, URI, Name".format(collName,skip1=True, printV12=cmdTop))
637
638 # else: check if no Log was specified. If not, return the collection
639 elif(rft.IdLevel2OptnCount==0):
640 rc,r,j,d=rft.rftSendRecvRequest(rft.AUTHENTICATED_API, 'GET', r.url, relPath=logLink, prop=prop)
641 if(rc==0):
642 rft.printVerbose(1," {} Collection ".format(collName,skip1=True, printV12=cmdTop))
643
644 # else: check if the -a (all) option is set. If not, return the proc specific by -i or -m
645 # search collection to find path using getPath2
646 elif( rft.allOptn is not True ):
647 # get the LogServices collection
648 rc,r,j,d=rft.rftSendRecvRequest(rft.AUTHENTICATED_API, 'GET', r.url, relPath=logLink, prop=prop)
649 collUrl=r.url
650
651 # now search for 2nd level resource and return
652 path2,rc,r,j,d=rft.getLevel2ResourceById(rft,r,d)
653 if(rc!=0):
654 return(rc,r,j,d)
655 # so rc=0
656 #if sysPath returned a response but we need to extract the property do it here
657 if( (r is not None) and (prop is not None) ):
658 rc,r,j,d=rft.getPropFromDict(rft,r,d,prop)
659
660 # otherwise, we need to do a GET to get the LogServices, if -P show property, else show full response
661 elif( r is None ):
662 rc,r,j,d=rft.rftSendRecvRequest(rft.AUTHENTICATED_API, 'GET', collUrl, relPath=path2, prop=prop)
663 if(rc==0):
664 rft.printVerbose(1," {} Collection Member ".format(collName,skip1=True, printV12=cmdTop))
665
666 # If '--Entries' specified, get "Entries" nav link and read it
667 if rc == 0 and rft.gotEntriesOptn:
668 if r is not None and j and isinstance(d, dict):
669 rft.printVerbose(1, 'getLogService: attempting to get Entries for Logs')
670 entries = d.get('Entries')
671 if entries is not None and isinstance(entries, dict):
672 entries_uri = entries.get('@odata.id')
673 if entries_uri is not None:
674 rc, r, j, d = rft.rftSendRecvRequest(rft.AUTHENTICATED_API, 'GET', r.url,
675 relPath=entries_uri, prop=prop)
676 else:
677 rft.printErr('getLogService: @odata.id not found in "Entries" property')
678 else:
679 rft.printErr('getLogService: "Entries" property not found in JSON payload')
680 else:
681 rft.printErr(
682 'Unable to fetch Entries property from previous response: response = {}, is_json = {}, type(json) = {}'
683 .format(r, j, type(d)))
684
685 # else, client specified the -a option requesting ALL of the LogServices members
686 # for logs, we will not support this. Its too much data.
687 else:
688 rft.printErr("Error: -a option not supported for LogServices")
689 return(6,None,False,None)
690
691 return(rc,r,j,d)
692
693
694 def clearLog(self,sc,op,rft,cmdTop=False, prop=None):
695 rft.printVerbose(4,"{}:{}: in operation".format(rft.subcommand,sc.operation))
696 print("NOT IMPLEMENTED YET")
697 return(8,None,False,None)
698
699
700 def examples(self,sc,op,rft,cmdTop=False,prop=None):
701 rft.printVerbose(4,"{}:{}: in operation".format(rft.subcommand,sc.operation))
702 print(" {} -r<ip> # shows the Managers collection".format(rft.program))
703 print(" {} -r<ip> Managers list # lists Id, Uri, AssetTag for all Managers".format(rft.program))
704 print(" {} -r<ip> Managers -I <id> # gets the Manager with Id=<d>".format(rft.program))
705 print(" {} -r<ip> Managers -M AssetTag:12345 # gets the Manager with AssetTag=12345".format(rft.program))
706 print(" {} -r<ip> Managers -L <mgrUrl> # gets the Manager at URI=<mgrUrl".format(rft.program))
707 print(" {} -r<ip> Managers -F # get the First Manager returned (for debug)".format(rft.program))
708 print(" {} -r<ip> Managers -1 # get the first Manager and verify that there is only one Manager".format(rft.program))
709 print(" {} -r<ip> Managers -I <id> patch {{A: B,C: D,...}}# patch the json-formatted {{prop: value...}} data to the object".format(rft.program))
710 print(" {} -r<ip> Managers -I <id> reset <resetType> # reset a Manager. <resetType>=the redfish-defined values: On, Off, gracefulOff...".format(rft.program))
711 print(" {} -r<ip> Managers -I<Id> NetworkProtocol # get the NetworkProtocol resource under the specified manager".format(rft.program))
712 print(" {} -r<ip> Managers -I<Id> EthernetInterfaces list # lists Id, Uri, and Name for all of the NICs for Manager w/ Id=<Id>".format(rft.program))
713 print(" {} -r<ip> Managers -I<Id> EthernetInterfaces -i 1 # get the NIC with id=1 in manager with Id=<Id>".format(rft.program))
714 print(" {} -r<ip> Managers -L <Url> EthernetInterfaces -m MACAddress:AA:BB:CC:DD:EE:FF # get NIC with MAC AA:BB... for manager at url <Url>".format(rft.program))
715 return(0,None,False,None)
716
717
718
719 '''
720 TODO:
721 1. clearlog not implemented
722 2. setIpAddress not implemented
723
724 '''
725
726
727
728