Debian Codegraph @

redfishtoollib/ServiceRoot.py

raw symbols SCIP
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: ServiceRoot.py
6 #
7 # contains serviceRoot related subCommands and access functions
8 # Class RfServiceRoot
9 # - getServiceRoot GET /redfish/v1
10 # - getOdataServiceDocument GET /redfish/v1/odata
11 # - getOdataMetadataDocument GET /redfish/v1/$metadata
12 #
13 import requests
14 import json
15 from urllib.parse import urljoin, urlparse, urlunparse
16
17 class RfServiceRoot:
18 def __init__(self):
19 # option parsing variables
20 self.serviceRootDict=None
21 self.url=None
22
23 def getServiceRoot(self,rft, cmdTop=False, prop=None):
24 rft.printVerbose(4,"ServiceRoot: in getServiceRoot")
25
26 if(rft.help):
27 print(" {} {} -r<rhost> [-vh] -- get serviceRoot resource".format(rft.program,rft.subcommand))
28 return(0,None,False,None)
29
30 # execute GET /redfish to negotiate protocol version and get root path
31 # rootPath is stored in rft.rootPath
32 rc,r,j,d=rft.getVersionsAndSetRootPath(rft)
33 if( rc!=0): return(rc,r,j,d)
34 #
35 if cmdTop is True: prop=rft.prop
36
37 # get root service. if -P prop, showproperty
38 rc,r,j,d=rft.rftSendRecvRequest(rft.UNAUTHENTICATED_API, 'GET', rft.rootUri, relPath=rft.rootPath,prop=prop)
39
40 #save the rootService response. The transport may need it later to get link to session and login
41 rft.rootResponseDict=d
42
43 if(rc==0 and cmdTop is True):
44 rft.printVerbose(1," Service Root:",skip1=True, printV12=cmdTop)
45 return(rc,r,j,d)
46
47
48 def getOdataServiceDocument(self,rft,cmdTop=False):
49 rft.printVerbose(4,"ServiceRoot: in getOdataServiceDocument")
50
51 if(rft.help):
52 print(" {} {} -r<rhost> [-vh] -- get the Odata Service Document".format(rft.program,rft.subcommand))
53 return(0,None,False,None)
54
55 #get root path, scheme, and create URL
56 rc,r,j,d=rft.getVersionsAndSetRootPath(rft)
57 if( rc!=0): return(rc,r,j,d)
58
59 #calculate relative path = rootPath / odata
60 rpath=urljoin(rft.rootPath, "odata")
61
62 rc,r,j,d=rft.rftSendRecvRequest(rft.UNAUTHENTICATED_API, 'GET', rft.rootUri, relPath=rpath)
63 if(rc==0 ):
64 rft.printVerbose(1," Odata Service Document:",skip1=True, printV12=cmdTop)
65 return(rc,r,j,d)
66
67
68
69 def getOdataMetadataDocument(self,rft,cmdTop=False):
70 rft.printVerbose(4,"ServiceRoot: in getOdataMetadataDocument")
71
72 if(rft.help):
73 print(" {} {} -r<rhost> [-vh] -- get the CSDL metadata document".format(rft.program,rft.subcommand))
74 return(0,None,False,None)
75
76 #get root path, scheme, and create URL
77 rc,r,j,d=rft.getVersionsAndSetRootPath(rft)
78 if( rc!=0): return(rc,r,j,d)
79
80 #calculate relative path = rootPath / $metadata
81 rpath=urljoin(rft.rootPath, "$metadata")
82
83 # set content-type to xml (dflt is application/json)
84 hdrs = {"Accept": "application/xml", "OData-Version": "4.0" }
85
86
87 rc,r,j,d=rft.rftSendRecvRequest(rft.UNAUTHENTICATED_API, 'GET', rft.rootUri, relPath=rpath, jsonData=False, headersInput=hdrs )
88 if(rc==0):
89 rft.printVerbose(1," Odata Metadata Document:",skip1=True,printV12=cmdTop)
90 return(rc,r,j,d)
91
92 '''
93 TODO:
94 1.
95
96
97 '''