| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 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 |
|
| 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 |
|
| 90 |
op=RfManagersOperations() |
| 91 |
|
| 92 |
|
| 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: |
| 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 |
|
| 133 |
|
| 134 |
|
| 135 |
args=rft.subcommandArgv[0:] |
| 136 |
|
| 137 |
|
| 138 |
|
| 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:] |
| 148 |
self.argnum =len(self.args) |
| 149 |
|
| 150 |
rft.printVerbose(5,"Managers: operation={}, args={}".format(self.operation,self.args)) |
| 151 |
|
| 152 |
|
| 153 |
nonIdCommands=["collection", "list", "examples", "hello"] |
| 154 |
if( ( not self.operation in nonIdCommands ) and (rft.IdOptnCount==0) ): |
| 155 |
|
| 156 |
rft.oneOptn = True |
| 157 |
rft.IdOptnCount += 1 |
| 158 |
|
| 159 |
|
| 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 |
|
| 167 |
rft.printVerbose(5,"Managers: operation exited OK") |
| 168 |
return(rc,r,j,d) |
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 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 |
|
| 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 |
|
| 197 |
|
| 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 |
|
| 208 |
|
| 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 |
|
| 217 |
|
| 218 |
|
| 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 |
|
| 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 |
|
| 237 |
sysPath,rc,r,j,d=rft.getPathBy(rft, r, d) |
| 238 |
if( rc !=0 ): |
| 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 |
|
| 246 |
|
| 247 |
if( (r is not None) and (prop is not None) ): |
| 248 |
rc,r,j,d=rft.getPropFromDict(rft,r,d,prop) |
| 249 |
|
| 250 |
|
| 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 |
|
| 262 |
collName="Managers" |
| 263 |
rc,r,j,d=op.getCollection(sc,op, rft) |
| 264 |
if( rc != 0): return(rc,r,False,None) |
| 265 |
|
| 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 |
|
| 275 |
|
| 276 |
|
| 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 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
rc,r,j,d=op.get(sc,op,rft) |
| 294 |
if( rc != 0): |
| 295 |
return(rc,r,False,None) |
| 296 |
|
| 297 |
|
| 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 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
rft.printVerbose(4,"{}:{}: in operation".format(rft.subcommand,sc.operation)) |
| 310 |
|
| 311 |
|
| 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 |
|
| 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: |
| 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 |
|
| 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 |
|
| 357 |
|
| 358 |
reqPostData=json.dumps(resetData) |
| 359 |
|
| 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 |
|
| 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 |
|
| 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: |
| •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]$)" |
| 383 |
dateMatch=re.search(datePattern,sc.args[1]) |
| 384 |
if( dateMatch ): |
| 385 |
dateTimeString=(sc.args[1]) |
| 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 |
|
| 395 |
|
| 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 |
|
| 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 |
|
| 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: |
| 423 |
datePattern="^offset=([-+][0-1][0-9]:[0-5][0-9])$" |
| 424 |
dateMatch=re.search(datePattern,sc.args[1]) |
| 425 |
if( dateMatch ): |
| 426 |
timeOffsetString=dateMatch.group(1) |
| 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 |
|
| 436 |
|
| 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 |
|
| 455 |
rc,r,j,d=op.get(sc,op, rft) |
| 456 |
if( rc != 0): return(rc,r,False,None) |
| 457 |
|
| 458 |
resName="NetworkProtocol" |
| 459 |
|
| 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 |
|
| 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 |
|
| 486 |
rc,r,j,d=op.get(sc,op, rft) |
| 487 |
if( rc != 0): return(rc,r,False,None) |
| 488 |
|
| 489 |
collName="EthernetInterfaces" |
| 490 |
|
| 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 |
|
| 500 |
if( sc.argnum > 1 and sc.args[1] == 'list' ): |
| 501 |
|
| 502 |
rc,r,j,d=rft.rftSendRecvRequest(rft.AUTHENTICATED_API, 'GET', r.url, relPath=nicLink) |
| 503 |
|
| 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 |
|
| 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 |
|
| 515 |
|
| 516 |
elif( rft.allOptn is not True ): |
| 517 |
|
| 518 |
rc,r,j,d=rft.rftSendRecvRequest(rft.AUTHENTICATED_API, 'GET', r.url, relPath=nicLink, prop=prop) |
| 519 |
collUrl=r.url |
| 520 |
|
| 521 |
|
| 522 |
path2,rc,r,j,d=rft.getLevel2ResourceById(rft,r,d) |
| 523 |
if(rc!=0): |
| 524 |
return(rc,r,j,d) |
| 525 |
|
| 526 |
|
| 527 |
if( (r is not None) and (prop is not None) ): |
| 528 |
rc,r,j,d=rft.getPropFromDict(rft,r,d,prop) |
| 529 |
|
| 530 |
|
| 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 |
|
| 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 |
|
| 551 |
rc,r,j,d=op.get(sc,op, rft) |
| 552 |
if( rc != 0): return(rc,r,False,None) |
| 553 |
|
| 554 |
collName="SerialInterfaces" |
| 555 |
|
| 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 |
|
| 565 |
if( sc.argnum > 1 and sc.args[1] == 'list' ): |
| 566 |
|
| 567 |
rc,r,j,d=rft.rftSendRecvRequest(rft.AUTHENTICATED_API, 'GET', r.url, relPath=cntlrLink) |
| 568 |
|
| 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 |
|
| 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 |
|
| 580 |
|
| 581 |
elif( rft.allOptn is not True ): |
| 582 |
|
| 583 |
rc,r,j,d=rft.rftSendRecvRequest(rft.AUTHENTICATED_API, 'GET', r.url, relPath=cntlrLink, prop=prop) |
| 584 |
collUrl=r.url |
| 585 |
|
| 586 |
|
| 587 |
path2,rc,r,j,d=rft.getLevel2ResourceById(rft,r,d) |
| 588 |
if(rc!=0): |
| 589 |
return(rc,r,j,d) |
| 590 |
|
| 591 |
|
| 592 |
if( (r is not None) and (prop is not None) ): |
| 593 |
rc,r,j,d=rft.getPropFromDict(rft,r,d,prop) |
| 594 |
|
| 595 |
|
| 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 |
|
| 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 |
|
| 616 |
rc,r,j,d=op.get(sc,op, rft) |
| 617 |
if( rc != 0): return(rc,r,False,None) |
| 618 |
|
| 619 |
collName="LogServices" |
| 620 |
|
| 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 |
|
| 630 |
if( sc.argnum > 1 and sc.args[1] == 'list' ): |
| 631 |
|
| 632 |
rc,r,j,d=rft.rftSendRecvRequest(rft.AUTHENTICATED_API, 'GET', r.url, relPath=logLink) |
| 633 |
|
| 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 |
|
| 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 |
|
| 645 |
|
| 646 |
elif( rft.allOptn is not True ): |
| 647 |
|
| 648 |
rc,r,j,d=rft.rftSendRecvRequest(rft.AUTHENTICATED_API, 'GET', r.url, relPath=logLink, prop=prop) |
| 649 |
collUrl=r.url |
| 650 |
|
| 651 |
|
| 652 |
path2,rc,r,j,d=rft.getLevel2ResourceById(rft,r,d) |
| 653 |
if(rc!=0): |
| 654 |
return(rc,r,j,d) |
| 655 |
|
| 656 |
|
| 657 |
if( (r is not None) and (prop is not None) ): |
| 658 |
rc,r,j,d=rft.getPropFromDict(rft,r,d,prop) |
| 659 |
|
| 660 |
|
| 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 |
|
| 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 |
|
| 686 |
|
| 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 |
|