Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Tachashi/b4018363b8b66173119a215b84af38b6 to your computer and use it in GitHub Desktop.
Save Tachashi/b4018363b8b66173119a215b84af38b6 to your computer and use it in GitHub Desktop.
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"# Pybatfishをインポート\n",
"from pybatfish.client.commands import *\n",
"from pybatfish.question.question import load_questions, list_questions\n",
"from pybatfish.question import bfq\n",
"\n",
"import pprint"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Successfully loaded 42 questions from remote\n"
]
}
],
"source": [
"# questionテンプレートをBatfishサービスからPybatfishへロード\n",
"load_questions()"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"status: TRYINGTOASSIGN\n",
".... no task information\n",
"status: TERMINATEDNORMALLY\n",
".... Sun Dec 2 07:47:14 2018 UTC Deserializing objects of type 'org.batfish.datamodel.Configuration' from files 7 / 7\n",
"Default snapshot is now set to ss_286bb6f7-20b0-4c5c-884f-2cacb31a5d4d\n"
]
},
{
"data": {
"text/plain": [
"'ss_286bb6f7-20b0-4c5c-884f-2cacb31a5d4d'"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# config等のスナップショットを保管したパスを指定し、読み込みを実施\n",
"SNAPSHOT_PATH = \"networks/branch\"\n",
"bf_init_snapshot(SNAPSHOT_PATH)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"scrolled": false
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"status: TRYINGTOASSIGN\n",
".... no task information\n",
"status: TERMINATEDNORMALLY\n",
".... Sun Dec 2 07:47:19 2018 UTC Begin job\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"[{'Access_VLAN': 0,\n",
" 'Active': True,\n",
" 'Additional_ARP_IPs': None,\n",
" 'All_Prefixes': ['10.1.1.9/30'],\n",
" 'Allowed_VLANs': '',\n",
" 'Auto_State_VLAN': True,\n",
" 'Bandwidth': 100000.0,\n",
" 'Blacklisted': False,\n",
" 'Channel_Group': None,\n",
" 'Channel_Group_Members': [],\n",
" 'DHCP_Relay_Addresses': [],\n",
" 'Declared_Names': ['Tunnel1'],\n",
" 'Description': '<< To brborder2 >>',\n",
" 'HSRP_Groups': [],\n",
" 'HSRP_Version': None,\n",
" 'Incoming_Filter_Name': None,\n",
" 'Interface': {'hostname': 'hqborder2', 'interface': 'Tunnel1'},\n",
" 'Interface_Type': 'TUNNEL',\n",
" 'MTU': 1500,\n",
" 'Native_VLAN': 1,\n",
" 'OSPF_Area_Name': None,\n",
" 'OSPF_Cost': None,\n",
" 'OSPF_Enabled': False,\n",
" 'OSPF_Hello_Multiplier': 0,\n",
" 'OSPF_Passive': False,\n",
" 'OSPF_Point_To_Point': False,\n",
" 'Outgoing_Filter_Name': None,\n",
" 'Primary_Address': '10.1.1.9/30',\n",
" 'Primary_Network': '10.1.1.8/30',\n",
" 'Proxy_ARP': True,\n",
" 'Rip_Enabled': False,\n",
" 'Rip_Passive': False,\n",
" 'Routing_Policy_Name': None,\n",
" 'Source_NATs': [],\n",
" 'Spanning_Tree_Portfast': False,\n",
" 'Switchport': None,\n",
" 'Switchport_Mode': 'NONE',\n",
" 'Switchport_Trunk_Encapsulation': 'DOT1Q',\n",
" 'VRF': 'default',\n",
" 'VRRP_Groups': [],\n",
" 'Zone_Name': None}]\n"
]
}
],
"source": [
"# ノード\"hqborder2\"のインターフェース\"Tunnel1\"プロパティ情報を抽出&出力\n",
"interface_properties = bfq.interfaceProperties(nodes=\"hqborder2\", interfaces=\"Tunnel1\", properties=\".*\").answer()\n",
"pprint.pprint(interface_properties.rows)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"status: TRYINGTOASSIGN\n",
".... no task information\n",
"status: TERMINATEDNORMALLY\n",
".... Sun Dec 2 07:47:25 2018 UTC Begin job\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"0 OK (閉塞状態) hqborder2:FastEthernet4\n",
"1 NG (設定なし) hqborder2:Loopback0\n",
"2 OK (閉塞状態) hqborder2:FastEthernet3\n",
"3 OK (閉塞状態) hqborder2:FastEthernet8\n",
"4 OK (閉塞状態) hqborder2:FastEthernet9\n",
"5 OK (閉塞状態) hqborder2:BRI0\n",
"6 OK (設定あり) hqborder2:Tunnel1\n",
"7 OK (閉塞状態) hqborder2:Vlan1\n",
"8 OK (設定あり) hqborder2:FastEthernet2\n",
"9 OK (閉塞状態) hqborder2:FastEthernet5\n",
"10 OK (閉塞状態) hqborder2:FastEthernet6\n",
"11 OK (閉塞状態) hqborder2:FastEthernet7\n",
"12 OK (設定あり) hqborder2:FastEthernet0\n",
"13 OK (設定あり) hqborder2:FastEthernet1\n",
"14 OK (設定あり) hqborder2:Vlan203\n"
]
}
],
"source": [
"# ノード\"hqborder2\"の使用中インターフェースにDescriptionが設定されているかチェック(1回目)\n",
"int_props = bfq.interfaceProperties(nodes=\"hqborder2\", interfaces=\".*\", properties=\".*\").answer().frame()\n",
"\n",
"for i in range(len(int_props)):\n",
" if int_props[\"Active\"][i]:\n",
" if int_props[\"Description\"][i] is not None:\n",
" print(i, \"OK (設定あり)\", int_props[\"Interface\"][i])\n",
" else:\n",
" print(i, \"NG (設定なし)\", int_props[\"Interface\"][i])\n",
" else:\n",
" print(i, \"OK (閉塞状態)\", int_props[\"Interface\"][i])"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"status: TRYINGTOASSIGN\n",
".... no task information\n",
"status: TERMINATEDNORMALLY\n",
".... Sun Dec 2 07:51:04 2018 UTC Deserializing objects of type 'org.batfish.datamodel.Configuration' from files 7 / 7\n",
"Default snapshot is now set to ss_4a8fab8c-cd12-42f7-899e-f2d643129c97\n"
]
},
{
"data": {
"text/plain": [
"'ss_4a8fab8c-cd12-42f7-899e-f2d643129c97'"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# config等のスナップショットを保管したパスを指定し、読み込みを実施(再読み込み)\n",
"SNAPSHOT_PATH = \"networks/branch\"\n",
"bf_init_snapshot(SNAPSHOT_PATH)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"status: TRYINGTOASSIGN\n",
".... no task information\n",
"status: TERMINATEDNORMALLY\n",
".... Sun Dec 2 07:51:11 2018 UTC Begin job\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"0 OK (閉塞状態) hqborder2:FastEthernet4\n",
"1 OK (閉塞状態) hqborder2:FastEthernet3\n",
"2 OK (閉塞状態) hqborder2:FastEthernet8\n",
"3 OK (閉塞状態) hqborder2:FastEthernet9\n",
"4 OK (閉塞状態) hqborder2:BRI0\n",
"5 OK (設定あり) hqborder2:Tunnel1\n",
"6 OK (閉塞状態) hqborder2:Vlan1\n",
"7 OK (設定あり) hqborder2:FastEthernet2\n",
"8 OK (閉塞状態) hqborder2:FastEthernet5\n",
"9 OK (閉塞状態) hqborder2:FastEthernet6\n",
"10 OK (閉塞状態) hqborder2:FastEthernet7\n",
"11 OK (設定あり) hqborder2:Loopback0\n",
"12 OK (設定あり) hqborder2:FastEthernet0\n",
"13 OK (設定あり) hqborder2:FastEthernet1\n",
"14 OK (設定あり) hqborder2:Vlan203\n"
]
}
],
"source": [
"# ノード\"hqborder2\"の使用中インターフェースにDescriptionが設定されているかチェック(2回目)\n",
"int_props = bfq.interfaceProperties(nodes=\"hqborder2\", interfaces=\".*\", properties=\".*\").answer().frame()\n",
"\n",
"for i in range(len(int_props)):\n",
" if int_props[\"Active\"][i]:\n",
" if int_props[\"Description\"][i] is not None:\n",
" print(i, \"OK (設定あり)\", int_props[\"Interface\"][i])\n",
" else:\n",
" print(i, \"NG (設定なし)\", int_props[\"Interface\"][i])\n",
" else:\n",
" print(i, \"OK (閉塞状態)\", int_props[\"Interface\"][i])"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.2"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment