-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnodes.py
More file actions
82 lines (71 loc) · 2.1 KB
/
nodes.py
File metadata and controls
82 lines (71 loc) · 2.1 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# -*- coding: utf-8 -*-
from typing import Dict, List
import pandas as pd
import requests
def read(__nodes_file: str, /) -> List[Dict[str, str]]:
"""
Read Fabric nodes from Excel file
Parameters
----------
__nodes_file : str
Fabric nodes Excel file name. e.g. "Fabric-Nodes.xlsx"
Returns
-------
List[Dict[str, str]]
List of dictionaries of Fabric nodes
"""
nodes = pd.read_excel(io=__nodes_file, sheet_name=0, engine="openpyxl")
df = pd.DataFrame(data=nodes)
return (
df.fillna(value="") # Fill nan cells with empty string
.drop_duplicates(subset=["Serial Number"])
.rename(
columns={
"Node Type": "node_type",
"Node Role": "role",
"POD ID": "pod_id",
"Serial Number": "serial",
"Node Name": "name",
"Node ID": "node_id",
}
)
.to_dict(orient="records")
)
def register(
apic: str, headers: Dict[str, str], node: Dict[str, str]
) -> requests.Response:
"""
Register Fabric node to ACI Fabric
Parameters
----------
apic : str
APIC IP Address. e.g. "sandboxapicdc.cisco.com"
headers : Dict[str, str]
Headers from APIC login
node : Dict[str, str]
Fabric node
Returns
-------
requests.Response
Response from APIC register node API
"""
url = f"https://{apic}/api/mo/uni/controller/nodeidentpol.json"
payload = {
"fabricNodeIdentP": {
"attributes": {
"nodeId": str(node.get("node_id")),
"nodeType": node.get("node_type"),
"role": node.get("role"),
"name": node.get("name").strip(),
"serial": node.get("serial").strip(),
}
},
"fabricNodePEp": {
"attributes": {
"tDn": f"topology/pod-{node.get('pod_id', 1)}/{node.get('name')}",
}
},
}
r = requests.post(url=url, headers=headers, json=payload, verify=False)
r.raise_for_status()
return r