blob: 544abda68fd6d315fa18882e3ff77f62e1aa7130 [file] [log] [blame]
George Keishingd3d04a32018-08-07 12:03:46 -05001#!/usr/bin/env python
2
3r"""
4Redfish function for traversing the resource model.
5"""
6
7
8def get_url_list(json_data):
9 r"""
10 Return list of fully qualified URI paths.
11
12 Description of argument(s):
13 json_data Dictionary data from "GET" request.
14
15 Resource model tree layout:
16 root("/redfish/v1/") -> "/redfish/v1/Chassis" -> End resource
17
18 Example: JSON response data input
19 {
20 "@odata.context": "/redfish/v1/$metadata#ServiceRoot.ServiceRoot",
21 "@odata.id": "/redfish/v1/",
22 "@odata.type": "#ServiceRoot.v1_1_1.ServiceRoot",
23 "AccountService": {
24 "@odata.id": "/redfish/v1/AccountService"
25 },
26 "Chassis": {
27 "@odata.id": "/redfish/v1/Chassis"
28 },
29 "Id": "RootService",
30 "Links": {
31 "Sessions": {
32 "@odata.id": "/redfish/v1/SessionService/Sessions"
33 }
34 },
35 "Managers": {
36 "@odata.id": "/redfish/v1/Managers"
37 },
38 "Name": "Root Service",
39 "RedfishVersion": "1.1.0",
40 "SessionService": {
41 "@odata.id": "/redfish/v1/SessionService/"
42 },
43 "Systems": {
44 "@odata.id": "/redfish/v1/Systems"
45 },
46 "UUID": "00000000-0000-0000-0000-000000000000",
47 "UpdateService": {
48 "@odata.id": "/redfish/v1/UpdateService"
49 }
50 }
51
52 Returns list of URI's ['/redfish/v1/Managers',
53 '/redfish/v1/Links',
54 '/redfish/v1/AccountService',
55 '/redfish/v1/UpdateService',
56 '/redfish/v1/Chassis',
57 '/redfish/v1/Systems',
58 '/redfish/v1/SessionService']
59 """
60
61 base_uri = "/redfish/v1/"
62 qualified_uri_list = []
63
64 # Example of non-root child resource object schema.
65 # {
66 # "@odata.context": "/redfish/v1/$metadata#ChassisCollection.ChassisCollection",
67 # "@odata.id": "/redfish/v1/Chassis",
68 # "@odata.type": "#ChassisCollection.ChassisCollection",
69 # "Members": [
70 # {
71 # "@odata.id": "/redfish/v1/Chassis/motherboard"
72 # },
73 # {
74 # "@odata.id": "/redfish/v1/Chassis/system"
75 # }
76 # ],
77 # "Members@odata.count": 2,
78 # "Name": "Chassis Collection"
79 # }
80
81 # If non-root resource schema.
82 if "Members" in json_data:
83 for member in json_data["Members"]:
84 qualified_uri_list.extend(member.values())
85 return qualified_uri_list
86
87 # Example of non-root and is the last child resource in the tree.
88 # {
89 # "@odata.context": "/redfish/v1/$metadata#Chassis.Chassis",
90 # "@odata.id": "/redfish/v1/Chassis",
91 # "@odata.type": "#Chassis.v1_4_0.Chassis",
92 # "BuildDate": "1996-01-01 - 00:00:00",
93 # "ChassisType": "RackMount",
94 # "Id": "motherboard",
95 # "Manufacturer": "0000000000000000",
96 # "Model": "",
97 # "Name": "motherboard",
98 # "PartNumber": "00VK525 ",
99 # "SerialNumber": "Y130UF72700J ",
100 # "Thermal": {
101 # "@odata.id": "/redfish/v1/Chassis/motherboard/Thermal"
102 # }
103 # }
104
105 # If non-root and is the last child resource.
106 if json_data["Name"] != "Root Service" and "Members" not in json_data:
107 # Return empty list.
108 return qualified_uri_list
109
110 # If root "/redfish/v1/" path resource schema.
111 for k, v in json_data.items():
112 # Find if the dictionary contains a nested dict.
113 # The instance existence indicates a sub-uri which hold by that
114 # dictionary is a resource object for next sub tree elements.
115 if isinstance(v, dict):
116 # Example : 'Managers', 'Links', 'AccountService' etc.
117 # into qualified URI '/redfish/v1/Managers'
118 qualified_uri = base_uri + str(k)
119 qualified_uri_list.append(qualified_uri)
120
121 return qualified_uri_list