2 Documentation Utils for Restconf operations for GBP
4 Library RequestsLibrary
5 Library OperatingSystem
8 Variables ../../variables/Variables.py
9 Resource ../Utils.robot
13 ${ENDPOINT_UNREG_PATH} ${GBP_UNREGEP_API}
14 ${ENDPOINTS_OPER_PATH} /restconf/operational/endpoint:endpoints
19 [Documentation] Unregister Endpoints Endpoints from ODL
20 ${result} RequestsLibrary.Get Request session ${ENDPOINTS_OPER_PATH}
21 ${json_result} json.loads ${result.text}
22 Pass Execution If ${json_result['endpoints']}=={} No Endpoints available
23 ${L2_ENDPOINTS} Set Variable ${json_result['endpoints']['endpoint']}
24 ${L3_ENDPOINTS} Set Variable ${json_result['endpoints']['endpoint-l3']}
26 Unregister L2Endpoints ${L2_ENDPOINTS}
28 Unregister L3Endpoints ${L3_ENDPOINTS}
29 ${result} RequestsLibrary.Get Request session ${ENDPOINTS_OPER_PATH}
30 ${json_result} json.loads ${result.text}
31 Should Be Empty ${json_result['endpoints']}
33 Unregister L2Endpoints
34 [Documentation] Unregister Endpoints L2Endpoints from ODL
36 FOR ${endpoint} IN @{l2_eps}
37 ${l2_data} Create L2 Endpoint JSON Data ${endpoint}
38 Post Elements To URI ${ENDPOINT_UNREG_PATH} ${l2_data} ${HEADERS_YANG_JSON}
41 Unregister L3Endpoints
42 [Documentation] Unregister Endpoints L3Endpoints from ODL
44 FOR ${endpoint} IN @{l3_eps}
45 ${l3_data} Create L3 Endpoint JSON Data ${endpoint}
46 Post Elements To URI ${ENDPOINT_UNREG_PATH} ${l3_data} ${HEADERS_YANG_JSON}
49 Create L2 Endpoint JSON Data
50 [Documentation] Generate the JSON data required for unregistering L2 Endpoints
51 [Arguments] ${endpoint}
53 ... {"input": {"l2": [{"mac-address": "${endpoint['mac-address']}", "l2-context": "${endpoint['l2-context']}"}]}}
56 Create L3 Endpoint JSON Data
57 [Documentation] Generate the JSON data required for unregistering L3 Endpoints
58 [Arguments] ${endpoint}
60 ... {"input": {"l3": [{"l3-context": "${endpoint['l3-context']}", "ip-address": "${endpoint['ip-address']}"}]}}
64 [Documentation] Returns path for a registered endpoint based on key in arguments
65 [Arguments] ${l2-context} ${mac_address}
66 ${mac_address} Convert To Uppercase ${mac_address}
67 RETURN restconf/operational/endpoint:endpoints/endpoint/${l2-context}/${mac_address}
70 [Documentation] Returns path for a registered endpoint-l3 based on key in arguments
71 [Arguments] ${l3-context} ${ip_address}
72 RETURN restconf/operational/endpoint:endpoints/endpoint-l3/${l3-context}/${ip_address}
75 [Documentation] Returns path for a tenant based on key in arguments
76 [Arguments] ${tenant_id}
77 RETURN ${TENANTS_CONF_PATH}/policy:tenant/${tenant_id}
80 [Documentation] Returns policy path for a particular tenant
81 [Arguments] ${tenant_id}
82 ${tenant_path} Get Tenant Path ${tenant_id}
83 RETURN ${tenant_path}/policy
86 [Documentation] Returns path for a contract based on key and tenant-id in arguments
87 [Arguments] ${tenant_id} ${contract_id}
88 ${policy_path} Get Policy Path ${tenant_id}
89 RETURN ${policy_path}/contract/${contract_id}
91 Get Endpoint Group Path
92 [Documentation] Returns path for an EPG based on key and tenant-id in arguments
93 [Arguments] ${tenant_id} ${endpoint_group_id}
94 ${policy_path} Get Policy Path ${tenant_id}
95 RETURN ${policy_path}/endpoint-group/${endpoint_group_id}
97 Get Classifier Instance Path
98 [Documentation] Returns path for a classifier-instance based on key and tenant-id in arguments
99 [Arguments] ${tenant_id} ${classif_instance_id}
100 ${policy_path} Get Policy Path ${tenant_id}
101 RETURN ${policy_path}/subject-feature-instances/classifier-instance/${classif_instance_id}
103 Get Forwarding Context Path
104 [Documentation] Returns forwarding path for a particular tenant
105 [Arguments] ${tenant_id}
106 ${tenant_path} Get Tenant Path ${tenant_id}
107 RETURN ${tenant_path}/forwarding-context
110 [Documentation] Returns l3-context path based on key and tenant-id in arguments
111 [Arguments] ${tenant_id} ${l3_ctx_id}
112 ${fwd_ctx_path} Get Forwarding Context Path ${tenant_id}
113 RETURN ${fwd_ctx_path}/l3-context/${l3_ctx_id}
115 Get L2 Bridge Domain Path
116 [Documentation] Returns l2-bridge-domain path based on key and tenant-id in arguments
117 [Arguments] ${tenant_id} ${l2_br_domain_id}
118 ${fwd_ctx_path} Get Forwarding Context Path ${tenant_id}
119 RETURN ${fwd_ctx_path}/l2-bridge-domain/${l2_br_domain_id}
121 Get L2 Flood Domain Path
122 [Documentation] Returns l2-flood-domain path based on key and tenant-id in arguments
123 [Arguments] ${tenant_id} ${l2_flood_domain_id}
124 ${fwd_ctx_path} Get Forwarding Context Path ${tenant_id}
125 RETURN ${fwd_ctx_path}/l2-flood-domain/${l2_flood_domain_id}
128 [Documentation] Returns path for a subnet based on key and tenant-id in arguments
129 [Arguments] ${tenant_id} ${subnet_id}
130 ${fwd_ctx_path} Get Forwarding Context Path ${tenant_id}
131 RETURN ${fwd_ctx_path}/subnet/${subnet_id}
133 Get Prefix Constraint of Single Rule Contract
134 [Documentation] Returns first prefix-constraint from a single rule contract
135 [Arguments] ${contract}
136 ${contract_json} To Json ${contract}
138 ... ${contract_json['contract'][0]['clause'][0]['consumer-matchers']['endpoint-identification-constraints']}
139 RETURN ${eic['l3-endpoint-identification-constraints']['prefix-constraint'][0]}
141 Get Action of Single Rule Contract
142 [Documentation] Returns first action-ref from a single rule contract
143 [Arguments] ${contract}
144 ${contract_json} To Json ${contract}
145 RETURN ${contract_json['contract'][0]['subject'][0]['rule'][0]['action-ref'][0]}
147 Get Ip Prefix of Subnet
148 [Documentation] Returns ip-prefix from a given subnet
149 [Arguments] ${subnet}
150 ${subnet_json} To Json ${subnet}
151 RETURN ${subnet_json['subnet'][0]['ip-prefix']}
153 Get Action Instance Name of Single Rule Contract
154 [Documentation] Returns action-instance name from a single rule contract
155 [Arguments] ${contract}
156 ${contract_json} To Json ${contract}
157 RETURN ${contract_json['contract'][0]['subject'][0]['rule'][0]['classifier-ref'][0]['instance-name']}
159 Get Groups of Endpoint
160 [Documentation] Returns endpoint-groups from a given endpoint
161 [Arguments] ${endpoint}
162 ${endpoint_json} To Json ${endpoint}
163 RETURN ${endpoint_json['endpoint'][0]['endpoint-groups']}
165 Get Groups of Endpoint-L3
166 [Documentation] Returns endpoint-groups from a given endpoint-l3
167 [Arguments] ${endpoint-l3}
168 ${endpoint_json} To Json ${endpoint-l3}
169 RETURN ${endpoint_json['endpoint-l3'][0]['endpoint-groups']}
171 Get L3-Addresses of Endpoint
172 [Documentation] Returns l3-addresses from a given endpoint
173 [Arguments] ${endpoint}
174 ${endpoint_json} To Json ${endpoint}
175 RETURN ${endpoint_json['endpoint'][0]['l3-address']}
177 Get Tenant of Endpoint
178 [Documentation] Returns tenant-id from a given endpoint
179 [Arguments] ${endpoint}
180 ${endpoint_json} To Json ${endpoint}
181 RETURN ${endpoint_json['endpoint'][0]['tenant']}
183 Get Tenant of Endpoint-L3
184 [Documentation] Returns tenant-id from a given endpoint-l3
185 [Arguments] ${endpoint-l3}
186 ${endpoint_json} To Json ${endpoint-l3}
187 RETURN ${endpoint_json['endpoint-l3'][0]['tenant']}
189 Get Network Containment of Endpoint
190 [Documentation] Returns network-containment from a given endpoint
191 [Arguments] ${endpoint}
192 ${endpoint_json} To Json ${endpoint}
193 RETURN ${endpoint_json['endpoint'][0]['network-containment']}
195 Get Network Containment of Endpoint-L3
196 [Documentation] Returns network-containment from a given endpoint-l3
197 [Arguments] ${endpoint-l3}
198 ${endpoint_json} To Json ${endpoint-l3}
199 RETURN ${endpoint_json['endpoint-l3'][0]['network-containment']}
201 Get Mac Address of Endpoint
202 [Documentation] Returns mac-address from a given endpoint
203 [Arguments] ${endpoint}
204 ${endpoint_json} To Json ${endpoint}
205 RETURN ${endpoint_json['endpoint'][0]['mac-address']}
207 Get Mac Address of Endpoint-L3
208 [Documentation] Returns mac-address from a given endpoint-l3
209 [Arguments] ${endpoint-l3}
210 ${endpoint_json} To Json ${endpoint-l3}
211 RETURN ${endpoint_json['endpoint-l3'][0]['mac-address']}
213 Get L2 Context of Endpoint-L3
214 [Documentation] Returns l2-context from a given endpoint-l3
215 [Arguments] ${endpoint-l3}
216 ${endpoint_json} To Json ${endpoint-l3}
217 RETURN ${endpoint_json['endpoint-l3'][0]['l2-context']}