forked from mehdiBezahaf/intent-deploy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy.py
31 lines (25 loc) · 843 Bytes
/
deploy.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
"""Deploys policy via the onos-reroute-api"""
# @simmsb: I don't think this is acutually used any more
import httpx
from yarl import URL
from intent_deployer.types import (
IntentDeployException,
Policy,
)
async def deploy_policy(url: URL, policy: Policy):
async with httpx.AsyncClient() as client:
resp = await client.post(
str(url),
content=policy.json(),
headers={"Content-Type": "application/json"},
)
try:
resp.raise_for_status()
except httpx.HTTPError as e:
if resp.status_code == 409:
raise IntentDeployException("Service protection is active") from e
if not resp.status_code in range(200, 300):
raise IntentDeployException("Policy deployment failed") from e
r = resp.json()
print(url, r)
return r