@@ 171-192 (lines=22) @@ | ||
168 | ) |
|
169 | ||
170 | ||
171 | @retry( |
|
172 | stop=stop_after_attempt(5), |
|
173 | wait=wait_combine(wait_fixed(3), wait_random(min=2, max=7)), |
|
174 | before_sleep=before_sleep, |
|
175 | retry=retry_if_exception_type(httpx.RequestError), |
|
176 | ) |
|
177 | async def add_proxy_port_metadata(intf_id: str, port_no: int) -> dict: |
|
178 | """Add proxy_port metadata.""" |
|
179 | async with httpx.AsyncClient(base_url=settings.topology_url) as client: |
|
180 | response = await client.post( |
|
181 | f"/interfaces/{intf_id}/metadata", |
|
182 | timeout=10, |
|
183 | json={"proxy_port": port_no}, |
|
184 | ) |
|
185 | if response.is_success: |
|
186 | return response.json() |
|
187 | if response.status_code == 404: |
|
188 | raise ValueError(f"interface_id {intf_id} not found") |
|
189 | if response.is_server_error: |
|
190 | raise httpx.RequestError(response.text) |
|
191 | raise UnrecoverableError( |
|
192 | f"Failed to add_proxy_port {port_no} metadata for intf_id {intf_id} " |
|
193 | f"status code {response.status_code}, response text: {response.text}" |
|
194 | ) |
|
195 | ||
@@ 197-217 (lines=21) @@ | ||
194 | ) |
|
195 | ||
196 | ||
197 | @retry( |
|
198 | stop=stop_after_attempt(5), |
|
199 | wait=wait_combine(wait_fixed(3), wait_random(min=2, max=7)), |
|
200 | before_sleep=before_sleep, |
|
201 | retry=retry_if_exception_type(httpx.RequestError), |
|
202 | ) |
|
203 | async def delete_proxy_port_metadata(intf_id: str) -> dict: |
|
204 | """Delete proxy_port metadata.""" |
|
205 | async with httpx.AsyncClient(base_url=settings.topology_url) as client: |
|
206 | response = await client.delete( |
|
207 | f"/interfaces/{intf_id}/metadata/proxy_port", |
|
208 | timeout=10, |
|
209 | ) |
|
210 | if response.is_success: |
|
211 | return response.json() |
|
212 | if response.status_code == 404: |
|
213 | raise ValueError(f"interface_id {intf_id} or metadata proxy_port not found") |
|
214 | if response.is_server_error: |
|
215 | raise httpx.RequestError(response.text) |
|
216 | raise UnrecoverableError( |
|
217 | f"Failed to delete_proxy_port metadata for intf_id {intf_id} " |
|
218 | f"status code {response.status_code}, response text: {response.text}" |
|
219 | ) |
|
220 |