ISE ERSでSGT・SGACLと通信policyを作る3 / 4

Group間のpolicy

EmployeesとServersのSGT、および許可するSGACLを作成・取得しUUIDを確定する。以下はそのUUIDを使い、新規cellを作成する部分例である。sは正しいERS credential/CAを構成したrequests.Session、baseはそのISE APIのHTTPS originである。

payload = {"EgressMatrixCell":{
    "name":"Employees_to_Servers",
    "sourceSgtId":employees_id, "destinationSgtId":servers_id,
    "matrixCellStatus":"ENABLED", "defaultRule":"DENY_IP",
    "sgacls":[https_sgacl_id],
}}
r = s.post(base + "/ers/config/egressmatrixcell/", json=payload, timeout=(5,20))
r.raise_for_status()
r = s.get(base + "/ers/config/egressmatrixcell/",
          params={"filter":"name.EQ.Employees_to_Servers"}, timeout=(5,20))
r.raise_for_status()
resources = r.json()["SearchResult"]["resources"]
if len(resources) != 1:
    raise RuntimeError("Policy cell is not unique")
cell_id = resources[0]["id"]
r = s.get(base + "/ers/config/egressmatrixcell/" + cell_id, timeout=(5,20))
r.raise_for_status()
actual = r.json()["EgressMatrixCell"]
if any(actual.get(k) != v for k,v in payload["EgressMatrixCell"].items()):
    raise RuntimeError("Policy read-back differs")

この例は同じsource/destinationの既存cellがないことを確認してから使う。既存cellがあればGETで差分を読み、IDを指定した対応updateを使う。create timeout後に再POSTを繰り返さず、同名・group pairを照合する。list APIのpage/filterと全件取得、create応答のLocation/空body等もAPI契約へ合わせる。

学習パスへ
参考資料