QuestionQ22

Network Element Programmability

Which Python snippet creates an application policy named OrderProcess containing two application endpoint groups under the SuperEats tenant by making direct calls to the ACI REST API? Assume authentication and library imports are correct.

Drag & Drop
DATA = { "FVTenant": {"attributes": {"name": "SuperEats"}, "children": [{"FVAP": {"attributes": {"name": "OrderProcess"}, "children": [ {"FVAEPg": {"attributes": {"name": "app"}}}, {"FVAEPg": {"attributes": {"name": "web"}}} ] }}] } } RESPONSE = requests.post(APIC+OPERATION, json=DATA, cookies=COOKIE)
DATA = { "fvTenant": {"attributes": {"name": "SuperEats"}, "children": [{"fvAp": {"attributes": {"name": "OrderProcess"}, "children": [ {"fvAEPg": {"attributes": {"name": "app"}}}, {"fvAEPg": {"attributes": {"name": "web"}}} ] }}] } } RESPONSE = requests.get(APIC+OPERATION, cookies=COOKIE)
DATA = { "fvTenant": {"attributes": {"rn": "SuperEats"}, "children": [{"fvAp": {"attributes": {"rn": "OrderProcess"}, "children": [ {"fvAEPg": {"attributes": {"rn": "app"}}}, {"fvAEPg": {"attributes": {"rn": "web"}}} ] }}] } } RESPONSE = requests.post(APIC+OPERATION, json=DATA, cookies=COOKIE)
DATA = { "fvTenant": {"attributes": {"name": "SuperEats"}, "children": [{"fvAp": {"attributes": {"name": "OrderProcess"}, "children": [ {"fvAEPg": {"attributes": {"name": "app"}}}, {"fvAEPg": {"attributes": {"name": "web"}}} ] }}] } } RESPONSE = requests.post(APIC+OPERATION, json=DATA, cookies=COOKIE)
import requests

USER = "admin"
PASS = "password"
APIC = 'https://apic.supereats.com'

OPERATION = 'api/aaaLogin.json'
DATA = {"aaaUser": {"attributes": {"name":USER, "pwd":PASS}}}
RESPONSE = requests.post(APIC+OPERATION, json=DATA, verify=False)

TOKEN = RESPONSE.json()["imdata"][0]["aaaLogin"]["attributes"]["token"]
COOKIE = {'APIC-cookie': TOKEN}



OPERATION = 'api/aaaLogout.json'
DATA = {
    "aaaLogout": {
        "attributes": {
            "token":TOKEN
        }
    }
}
RESPONSE = requests.post(APIC+OPERATION, json=DATA, cookies=COOKIE, verify=False)
Explanation

Creating ACI managed objects through the REST API requires the correct case-sensitive managed-object classes (fvTenant, fvAp, and fvAEPg) and a POST request. The name attributes create the SuperEats tenant, the OrderProcess application profile, and the app and web endpoint groups; the APIC authentication cookie authorizes the request.

Community Discussion

No comments yet. Be the first to start the discussion!