| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
import requests |
| 14 |
import json |
| 15 |
from urllib.parse import urljoin, urlparse, urlunparse |
| 16 |
|
| 17 |
class RfServiceRoot: |
| 18 |
def __init__(self): |
| 19 |
|
| 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 |
|
| 31 |
|
| 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 |
|
| 38 |
rc,r,j,d=rft.rftSendRecvRequest(rft.UNAUTHENTICATED_API, 'GET', rft.rootUri, relPath=rft.rootPath,prop=prop) |
| 39 |
|
| 40 |
|
| 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 |
|
| 56 |
rc,r,j,d=rft.getVersionsAndSetRootPath(rft) |
| 57 |
if( rc!=0): return(rc,r,j,d) |
| 58 |
|
| 59 |
|
| 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 |
|
| 77 |
rc,r,j,d=rft.getVersionsAndSetRootPath(rft) |
| 78 |
if( rc!=0): return(rc,r,j,d) |
| 79 |
|
| 80 |
|
| 81 |
rpath=urljoin(rft.rootPath, "$metadata") |
| 82 |
|
| 83 |
|
| 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 |
''' |