f@nXp$@8OnS<9CId87Df}&?A?0}SauH7!)^VFBNE90}SyHrwyl~WW
z)OR#ctj$h&6Ag+?#nDa%#>#%u({VLVF4<^11G_6J=6EVm3bZkCVA28TQ_RKaeCL!w
zh%V2czgX_PZ?@jP>7)atJFNtamTRq7awD;c+#EnJu||H)&|K@l?hg8$te@E|$ve9`
zA8J?{9u%RJq?EEknbeRlUKxLfb;^9{^3MMupn_UVyUUMxn*mmpHALYV3*ZaElV&5JYXp>(MI>c!p!Rd(Yf|p*CwX}S6a&+*fUMUv`$1B3_2rLK0Q!*vO^Lvj-pF1VE=F%nn7DKX+Rj5M=2
z(X+&fF8(QC>!TEmxbjgJ;{<{x+(m1LVqxK&FQ3sAHY#ure=v*WVy4!2vs}5cPm0I|
z-NbZE9Hn&N_=X2__@D@K{YB?+pDbK;jcb^B)Df;1b)ZD&Igqy5;841bLz+{Y^|Y&V
hS#~OwgT!5)FzXzYUB6QH@G}C
+-
+
+
+ Router
+ Switch
+
+
+
+
+ Coffee Table
+ 180
+ 80
+
+
\ No newline at end of file
diff --git a/Parse API Data Formats/initial/lab01.py b/Parse API Data Formats/initial/lab01.py
new file mode 100644
index 0000000..ddff92b
--- /dev/null
+++ b/Parse API Data Formats/initial/lab01.py
@@ -0,0 +1,141 @@
+# Import modules
+import sys
+from helper import *
+
+import xml.etree.ElementTree as ET
+
+import xml.dom.minidom as MD
+
+# Main function
+if __name__ == "__main__":
+ #########################################
+ # Procedure 1 #
+ #########################################
+ # Add print statement here
+
+
+ #########################################
+ # Procedure 2 #
+ #########################################
+ print('##################')
+ print('###### YAML ######')
+ print('##################')
+
+ # Open the user.yaml file as read only
+
+ # Load the stream using safe_load
+
+ # Print the object type
+ print("Type of user_yaml variable:")
+
+ print('----------------------')
+
+ # Iterate over the keys of the user_yaml and print them
+ print('Keys in user_yaml:')
+
+ print('----------------------')
+
+ # Create a new instance of class User
+
+ # Assign values form the user_yaml to the object user
+
+ # Print the user object
+ print('User object:')
+
+
+ #########################################
+ # Procedure 3 #
+ #########################################
+ print('##################')
+ print('###### JSON ######')
+ print('##################')
+
+ # Create JSON structure from the user object
+
+ # Print the created JSON structure
+ print('Print user_json:')
+
+ print('----------------------')
+
+ # Create JSON structre with indents and soreted keys
+ print('JSON with indents and sorted keys')
+
+
+ #########################################
+ # Procedure 4 #
+ #########################################
+ print('######################')
+ print('# XML - Element Tree #')
+ print('######################')
+
+ # Parse the user.xml file
+
+ # Get the root element
+
+ # Print the tags
+ print('Tags in the XML:')
+
+ print('----------------------')
+
+ # Print the value of id tag
+ print('id tag value:')
+
+ print('----------------------')
+
+ # Find all elements with the tag address in root
+
+ # Print the adresses in the xml
+ print('Addresses:')
+
+ print('----------------------')
+
+ # Print the elements in root with their tags and values
+ print('Print the structure')
+
+ # Parsing XML files with MiniDOM
+ print('######################')
+ print('### XML - MiniDOM ####')
+ print('######################')
+
+ # Parse the user.xml file
+
+ # Print the tags
+
+ print('----------------------')
+
+ # Accessing element value
+ print('Accessing element value')
+
+ print('----------------------')
+
+ # Print elements from the DOM with tag name 'address'
+ print('Addresses:')
+
+ print('----------------------')
+
+ # Print the entire structure with printNodes
+ print('The structure:')
+
+
+ #########################################
+ # Procedure 5 #
+ #########################################
+ print('######################')
+ print('# Use Namespaces #')
+ print('######################')
+
+ # Parse the user.xml file
+
+ # Get the root element
+
+ # Define namespaces
+
+ # Set table as the root element
+
+ # Elements in NS a
+ print('Elements in NS a:')
+
+ print('----------------------')
+
+ # Elements in NS b
+ print('Elements in NS b:')
\ No newline at end of file
diff --git a/Parse API Data Formats/initial/user.xml b/Parse API Data Formats/initial/user.xml
new file mode 100644
index 0000000..486163b
--- /dev/null
+++ b/Parse API Data Formats/initial/user.xml
@@ -0,0 +1,22 @@
+
+
+ 3242
+ Ray
+ Smith
+ 1979-08-15
+
+ 94873 Ledner Rue
+ Royal Oak
+ 44663
+ OH
+ 1
+
+
+ 832 William Ave
+ Elnaville
+ 17319
+ EL
+ 0
+
+ 18.3
+
\ No newline at end of file
diff --git a/Parse API Data Formats/initial/user.yaml b/Parse API Data Formats/initial/user.yaml
new file mode 100644
index 0000000..d50eca1
--- /dev/null
+++ b/Parse API Data Formats/initial/user.yaml
@@ -0,0 +1,16 @@
+id: 3242
+first_name: 'Ray'
+last_name: 'Smith'
+birth_date: 1979-08-15
+address:
+ - street: '94873 Ledner Rue'
+ city: 'Royal Oak'
+ postal_code: 44663
+ state: 'OH'
+ primary: 1
+ - street: '832 William Ave'
+ city: 'Elnaville'
+ postal_code: 17319
+ state: 'EL'
+ primary: 0
+score: 18.3
\ No newline at end of file
diff --git a/Parse API Data Formats/solution/lab01(edited).py b/Parse API Data Formats/solution/lab01(edited).py
new file mode 100644
index 0000000..99c2a81
--- /dev/null
+++ b/Parse API Data Formats/solution/lab01(edited).py
@@ -0,0 +1,173 @@
+# Import modules
+import sys
+from helper import *
+from ruamel import yaml
+import json
+
+import xml.etree.ElementTree as ET
+
+import xml.dom.minidom as MD
+
+# Main function
+if __name__ == "__main__":
+ #########################################
+ # Procedure 1 #
+ #########################################
+ # Add print statement here
+ print('Devnet')
+
+
+ #########################################
+ # Procedure 2 #
+ #########################################
+ print('##################')
+ print('###### YAML ######')
+ print('##################')
+
+ # Open the user.yaml file as read only
+ with open('user.yaml','r') as stream:
+ # Load the stream using safe_load
+ user_yaml = yaml.safe_load(stream)
+
+ # Print the object type
+ print("Type of user_yaml variable:")
+ print(type(user_yaml))
+ print('----------------------')
+
+ # Iterate over the keys of the user_yaml and print them
+ print('Keys in user_yaml:')
+ for key in user_yaml:
+ print(key)
+ print('----------------------')
+
+ # Create a new instance of class User
+ user = User()
+ # Assign values form the user_yaml to the object user
+ user.id = user_yaml['id']
+ user.first_name = user_yaml['first_name']
+ user.last_name = user_yaml['last_name']
+ user.birth_date = user_yaml['birth_date']
+ user.address = user_yaml['address']
+ user.score = user_yaml['score']
+ # Print the user object
+ print('User object:')
+ print(user)
+
+ #########################################
+ # Procedure 3 #
+ #########################################
+ print('##################')
+ print('###### JSON ######')
+ print('##################')
+
+ # Create JSON structure from the user object
+ user_json = json.dumps(user, default = serializeUser)
+ # Print the created JSON structure
+ print('Print user_json:')
+ print(user_json)
+ print('----------------------')
+
+ # Create JSON structre with indents and soreted keys
+ print('JSON with indents and sorted keys')
+ user_json = json.dumps(user, default = serializeUser, indent = 4, sort_keys = True)
+ print(user_json)
+ # Print to file user.json
+ file = open("user.json","w")
+ file.write(user_json)
+ file.close()
+ #########################################
+ # Procedure 4 #
+ #########################################
+ print('######################')
+ print('# XML - Element Tree #')
+ print('######################')
+
+ # Parse the user.xml file
+ tree = ET.parse('user.xml')
+ # Get the root element
+ root = tree.getroot()
+ # Print the tags
+ print('Tags in the XML:')
+ for element in root:
+ print(element.tag)
+ print('----------------------')
+
+ # Print the value of id tag
+ print('id tag value:')
+ print(root.find('id').text)
+ print('----------------------')
+
+ # Find all elements with the tag address in root
+ addresses = root.findall('address')
+ # Print the adresses in the xml
+ print('Addresses:')
+ for address in addresses:
+ for i in address:
+ print(i.tag + ':' + i.text)
+ print('----------------------')
+
+ # Print the elements in root with their tags and values
+ print('Print the structure')
+ for k in root.iter(): #Lấy từng phần tử của nó tại thời điểm nhất định
+ print(k.tag + ':' + k.text)
+ # Parsing XML files with MiniDOM
+ print('######################')
+ print('### XML - MiniDOM ####')
+ print('######################')
+
+ # Parse the user.xml file
+ dom = MD.parse('user.xml')
+ # Print the tags
+ print('Tags in the XML:')
+ for node in dom.childNodes:
+ printTags(node.childNodes)
+ print('----------------------')
+
+ # Accessing element value
+ print('Accessing element value')
+ idElements = dom.getElementsByTagName('id')
+ print(idElements)
+ elementId= idElements.item(0)
+ print(elementId.childNodes)
+ idValue = elementId.firstChild.data
+ print(idValue)
+ print('----------------------')
+
+ # Print elements from the DOM with tag name 'address'
+ print('Addresses:')
+ for node in dom.getElementsByTagName('address'):
+ printNodes(node.childNodes)
+ print('----------------------')
+
+ # Print the entire structure with printNodes
+ print('The structure:')
+ for node in dom.childNodes:
+ printNodes(node.childNodes)
+
+ #########################################
+ # Procedure 5 #
+ #########################################
+ print('######################')
+ print('# Use Namespaces #')
+ print('######################')
+
+ # Parse the item.xml file
+ itemTree = ET.parse('item.xml')
+ # Get the root element
+ root = itemTree.getroot()
+ # Define namespaces
+ namespaces = {'a':'https://www.example.com/network','b':'https://www.example.com/furniture'}
+ # Set table as the root element
+ elementsInNSa = root.findall('a:table',namespaces)
+ elementsInNSb = root.findall('b:table',namespaces)
+ # Elements in NS a
+ print('Elements in NS a:')
+ for e in elementsInNSa:
+ for i in e.iter():
+ print(i.tag + ':'+ i.text)
+ print('----------------------')
+
+ # Elements in NS b
+ print('Elements in NS b:')
+ for element in list(elementsInNSb[0]):
+ print(element.tag + ":" + element.text)
From 667c2b1d13946207bc0079344cc27fb43003b250 Mon Sep 17 00:00:00 2001
From: hotuanhoanh8 <55940179+hotuanhoanh8@users.noreply.github.com>
Date: Wed, 24 Jun 2020 15:15:01 +0700
Subject: [PATCH 29/44] Delete helper.py
---
Parse API Data Formats/helper.py | 38 --------------------------------
1 file changed, 38 deletions(-)
delete mode 100644 Parse API Data Formats/helper.py
diff --git a/Parse API Data Formats/helper.py b/Parse API Data Formats/helper.py
deleted file mode 100644
index d987155..0000000
--- a/Parse API Data Formats/helper.py
+++ /dev/null
@@ -1,38 +0,0 @@
-# Helper module with User class and additional functions
-from datetime import date
-
-## User Class
-class User:
- def __init__(self):
- self.id = None
- self.first_name = None
- self.last_name = None
- self.birth_date = None
- self.address = None
- self.score = None
-
- # Print the object
- def __repr__(self):
- return str(self.__dict__)
-
-# User object serialization
-def serializeUser(object):
- if isinstance(object, User):
- return object.__dict__
-
- if isinstance(object, date):
- return object.__str__()
-
-## Used For MiniDom
-# Print the tags of a nodeList object
-def printTags(nodeList):
- for node in nodeList:
- if node.nodeName != '#text':
- print(node.nodeName)
-
-# Recursively print the node list childern's name (tag) and its value
-def printNodes (nodeList, level=0):
- for node in nodeList:
- if node.nodeName != '#text':
- print( (" ")*level + node.nodeName + ':' + node.firstChild.data)
- printNodes(node.childNodes, level+1)
\ No newline at end of file
From ff1d75fe0ed339c06f4a11a889196062a04ec560 Mon Sep 17 00:00:00 2001
From: hotuanhoanh8 <55940179+hotuanhoanh8@users.noreply.github.com>
Date: Wed, 24 Jun 2020 15:15:25 +0700
Subject: [PATCH 30/44] Delete item.xml
---
Parse API Data Formats/item.xml | 15 ---------------
1 file changed, 15 deletions(-)
delete mode 100644 Parse API Data Formats/item.xml
diff --git a/Parse API Data Formats/item.xml b/Parse API Data Formats/item.xml
deleted file mode 100644
index 90ffb4d..0000000
--- a/Parse API Data Formats/item.xml
+++ /dev/null
@@ -1,15 +0,0 @@
-
--
-
-
- Router
- Switch
-
-
-
-
- Coffee Table
- 180
- 80
-
-
\ No newline at end of file
From 65c6254f237795ef792e8d60ad68f1a898e0b62d Mon Sep 17 00:00:00 2001
From: hotuanhoanh8 <55940179+hotuanhoanh8@users.noreply.github.com>
Date: Wed, 24 Jun 2020 15:16:01 +0700
Subject: [PATCH 31/44] Delete lab01(edited).py
---
Parse API Data Formats/lab01(edited).py | 173 ------------------------
1 file changed, 173 deletions(-)
delete mode 100644 Parse API Data Formats/lab01(edited).py
diff --git a/Parse API Data Formats/lab01(edited).py b/Parse API Data Formats/lab01(edited).py
deleted file mode 100644
index 99c2a81..0000000
--- a/Parse API Data Formats/lab01(edited).py
+++ /dev/null
@@ -1,173 +0,0 @@
-# Import modules
-import sys
-from helper import *
-from ruamel import yaml
-import json
-
-import xml.etree.ElementTree as ET
-
-import xml.dom.minidom as MD
-
-# Main function
-if __name__ == "__main__":
- #########################################
- # Procedure 1 #
- #########################################
- # Add print statement here
- print('Devnet')
-
-
- #########################################
- # Procedure 2 #
- #########################################
- print('##################')
- print('###### YAML ######')
- print('##################')
-
- # Open the user.yaml file as read only
- with open('user.yaml','r') as stream:
- # Load the stream using safe_load
- user_yaml = yaml.safe_load(stream)
-
- # Print the object type
- print("Type of user_yaml variable:")
- print(type(user_yaml))
- print('----------------------')
-
- # Iterate over the keys of the user_yaml and print them
- print('Keys in user_yaml:')
- for key in user_yaml:
- print(key)
- print('----------------------')
-
- # Create a new instance of class User
- user = User()
- # Assign values form the user_yaml to the object user
- user.id = user_yaml['id']
- user.first_name = user_yaml['first_name']
- user.last_name = user_yaml['last_name']
- user.birth_date = user_yaml['birth_date']
- user.address = user_yaml['address']
- user.score = user_yaml['score']
- # Print the user object
- print('User object:')
- print(user)
-
- #########################################
- # Procedure 3 #
- #########################################
- print('##################')
- print('###### JSON ######')
- print('##################')
-
- # Create JSON structure from the user object
- user_json = json.dumps(user, default = serializeUser)
- # Print the created JSON structure
- print('Print user_json:')
- print(user_json)
- print('----------------------')
-
- # Create JSON structre with indents and soreted keys
- print('JSON with indents and sorted keys')
- user_json = json.dumps(user, default = serializeUser, indent = 4, sort_keys = True)
- print(user_json)
- # Print to file user.json
- file = open("user.json","w")
- file.write(user_json)
- file.close()
- #########################################
- # Procedure 4 #
- #########################################
- print('######################')
- print('# XML - Element Tree #')
- print('######################')
-
- # Parse the user.xml file
- tree = ET.parse('user.xml')
- # Get the root element
- root = tree.getroot()
- # Print the tags
- print('Tags in the XML:')
- for element in root:
- print(element.tag)
- print('----------------------')
-
- # Print the value of id tag
- print('id tag value:')
- print(root.find('id').text)
- print('----------------------')
-
- # Find all elements with the tag address in root
- addresses = root.findall('address')
- # Print the adresses in the xml
- print('Addresses:')
- for address in addresses:
- for i in address:
- print(i.tag + ':' + i.text)
- print('----------------------')
-
- # Print the elements in root with their tags and values
- print('Print the structure')
- for k in root.iter(): #Lấy từng phần tử của nó tại thời điểm nhất định
- print(k.tag + ':' + k.text)
- # Parsing XML files with MiniDOM
- print('######################')
- print('### XML - MiniDOM ####')
- print('######################')
-
- # Parse the user.xml file
- dom = MD.parse('user.xml')
- # Print the tags
- print('Tags in the XML:')
- for node in dom.childNodes:
- printTags(node.childNodes)
- print('----------------------')
-
- # Accessing element value
- print('Accessing element value')
- idElements = dom.getElementsByTagName('id')
- print(idElements)
- elementId= idElements.item(0)
- print(elementId.childNodes)
- idValue = elementId.firstChild.data
- print(idValue)
- print('----------------------')
-
- # Print elements from the DOM with tag name 'address'
- print('Addresses:')
- for node in dom.getElementsByTagName('address'):
- printNodes(node.childNodes)
- print('----------------------')
-
- # Print the entire structure with printNodes
- print('The structure:')
- for node in dom.childNodes:
- printNodes(node.childNodes)
-
- #########################################
- # Procedure 5 #
- #########################################
- print('######################')
- print('# Use Namespaces #')
- print('######################')
-
- # Parse the item.xml file
- itemTree = ET.parse('item.xml')
- # Get the root element
- root = itemTree.getroot()
- # Define namespaces
- namespaces = {'a':'https://www.example.com/network','b':'https://www.example.com/furniture'}
- # Set table as the root element
- elementsInNSa = root.findall('a:table',namespaces)
- elementsInNSb = root.findall('b:table',namespaces)
- # Elements in NS a
- print('Elements in NS a:')
- for e in elementsInNSa:
- for i in e.iter():
- print(i.tag + ':'+ i.text)
- print('----------------------')
-
- # Elements in NS b
- print('Elements in NS b:')
- for element in list(elementsInNSb[0]):
- print(element.tag + ":" + element.text)
From 62c32bd9be0a1539951ccb2053aeb3c080f92744 Mon Sep 17 00:00:00 2001
From: hotuanhoanh8 <55940179+hotuanhoanh8@users.noreply.github.com>
Date: Wed, 24 Jun 2020 15:16:16 +0700
Subject: [PATCH 32/44] Delete lab01.py
---
Parse API Data Formats/lab01.py | 169 --------------------------------
1 file changed, 169 deletions(-)
delete mode 100644 Parse API Data Formats/lab01.py
diff --git a/Parse API Data Formats/lab01.py b/Parse API Data Formats/lab01.py
deleted file mode 100644
index 31b1937..0000000
--- a/Parse API Data Formats/lab01.py
+++ /dev/null
@@ -1,169 +0,0 @@
-# Import modules
-import sys
-from helper import *
-from ruamel import yaml
-import json
-
-import xml.etree.ElementTree as ET
-
-import xml.dom.minidom as MD
-
-# Main function
-if __name__ == "__main__":
- #########################################
- # Procedure 1 #
- #########################################
- # Add print statement here
- print('Devnet')
-
-
- #########################################
- # Procedure 2 #
- #########################################
- print('##################')
- print('###### YAML ######')
- print('##################')
-
- # Open the user.yaml file as read only
- with open('user.yaml','r') as stream:
- # Load the stream using safe_load
- user_yaml = yaml.safe_load(stream)
-
- # Print the object type
- print("Type of user_yaml variable:")
- print(type(user_yaml))
- print('----------------------')
-
- # Iterate over the keys of the user_yaml and print them
- print('Keys in user_yaml:')
- for key in user_yaml:
- print(key)
- print('----------------------')
-
- # Create a new instance of class User
- user = User()
- # Assign values form the user_yaml to the object user
- user.id = user_yaml['id']
- user.first_name = user_yaml['first_name']
- user.last_name = user_yaml['last_name']
- user.birth_date = user_yaml['birth_date']
- user.address = user_yaml['address']
- user.score = user_yaml['score']
- # Print the user object
- print('User object:')
- print(user)
-
- #########################################
- # Procedure 3 #
- #########################################
- print('##################')
- print('###### JSON ######')
- print('##################')
-
- # Create JSON structure from the user object
- user_json = json.dumps(user, default = serializeUser)
- # Print the created JSON structure
- print('Print user_json:')
- print(user_json)
- print('----------------------')
-
- # Create JSON structre with indents and soreted keys
- print('JSON with indents and sorted keys')
- user_json = json.dumps(user, default = serializeUser, indent = 4, sort_keys = True)
- print(user_json)
- #########################################
- # Procedure 4 #
- #########################################
- print('######################')
- print('# XML - Element Tree #')
- print('######################')
-
- # Parse the user.xml file
- tree = ET.parse('user.xml')
- # Get the root element
- root = tree.getroot()
- # Print the tags
- print('Tags in the XML:')
- for element in root:
- print(element.tag)
- print('----------------------')
-
- # Print the value of id tag
- print('id tag value:')
- print(root.find('id').text)
- print('----------------------')
-
- # Find all elements with the tag address in root
- addresses = root.findall('address')
- # Print the adresses in the xml
- print('Addresses:')
- for address in addresses:
- for i in address:
- print(i.tag + ':' + i.text)
- print('----------------------')
-
- # Print the elements in root with their tags and values
- print('Print the structure')
- for k in root.iter():
- print(k.tag + ':' + k.text)
- # Parsing XML files with MiniDOM
- print('######################')
- print('### XML - MiniDOM ####')
- print('######################')
-
- # Parse the user.xml file
- dom = MD.parse('user.xml')
- # Print the tags
- print('Tags in the XML:')
- for node in dom.childNodes:
- printTags(node.childNodes)
- print('----------------------')
-
- # Accessing element value
- print('Accessing element value')
- idElements = dom.getElementsByTagName('id')
- print(idElements)
- elementId= idElements.item(0)
- print(elementId.childNodes)
- idValue = elementId.firstChild.data
- print(idValue)
- print('----------------------')
-
- # Print elements from the DOM with tag name 'address'
- print('Addresses:')
- for node in dom.getElementsByTagName('address'):
- printNodes(node.childNodes)
- print('----------------------')
-
- # Print the entire structure with printNodes
- print('The structure:')
- for node in dom.childNodes:
- printNodes(node.childNodes)
-
- #########################################
- # Procedure 5 #
- #########################################
- print('######################')
- print('# Use Namespaces #')
- print('######################')
-
- # Parse the user.xml file
- itemTree = ET.parse('item.xml')
- # Get the root element
- root = itemTree.getroot()
- # Define namespaces
- namespaces = {'a':'https://www.example.com/network','b':'https://www.example.com/furniture'}
- # Set table as the root element
- elementsInNSa = root.findall('a:table',namespaces)
- elementsInNSb = root.findall('b:table',namespaces)
- # Elements in NS a
- print('Elements in NS a:')
- for e in elementsInNSa:
- for i in e.iter():
- print(i.tag + ':'+ i.text)
- print('----------------------')
-
- # Elements in NS b
- print('Elements in NS b:')
- for element in list(elementsInNSb[0]):
- print(element.tag + ":" + element.text)
From 92e2d9e3920b5c19c47213d2bbb287e75f17e1ff Mon Sep 17 00:00:00 2001
From: hotuanhoanh8 <55940179+hotuanhoanh8@users.noreply.github.com>
Date: Wed, 24 Jun 2020 15:16:27 +0700
Subject: [PATCH 33/44] Delete user.xml
---
Parse API Data Formats/user.xml | 22 ----------------------
1 file changed, 22 deletions(-)
delete mode 100644 Parse API Data Formats/user.xml
diff --git a/Parse API Data Formats/user.xml b/Parse API Data Formats/user.xml
deleted file mode 100644
index 486163b..0000000
--- a/Parse API Data Formats/user.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-
-
- 3242
- Ray
- Smith
- 1979-08-15
-
- 94873 Ledner Rue
- Royal Oak
- 44663
- OH
- 1
-
-
- 832 William Ave
- Elnaville
- 17319
- EL
- 0
-
- 18.3
-
\ No newline at end of file
From a55ae53a122b84502011aa556a2d4dc5f3df5bf6 Mon Sep 17 00:00:00 2001
From: hotuanhoanh8 <55940179+hotuanhoanh8@users.noreply.github.com>
Date: Wed, 24 Jun 2020 15:16:39 +0700
Subject: [PATCH 34/44] Delete user.yaml
---
Parse API Data Formats/user.yaml | 16 ----------------
1 file changed, 16 deletions(-)
delete mode 100644 Parse API Data Formats/user.yaml
diff --git a/Parse API Data Formats/user.yaml b/Parse API Data Formats/user.yaml
deleted file mode 100644
index d50eca1..0000000
--- a/Parse API Data Formats/user.yaml
+++ /dev/null
@@ -1,16 +0,0 @@
-id: 3242
-first_name: 'Ray'
-last_name: 'Smith'
-birth_date: 1979-08-15
-address:
- - street: '94873 Ledner Rue'
- city: 'Royal Oak'
- postal_code: 44663
- state: 'OH'
- primary: 1
- - street: '832 William Ave'
- city: 'Elnaville'
- postal_code: 17319
- state: 'EL'
- primary: 0
-score: 18.3
\ No newline at end of file
From a4e1c755bce18b1927955ecd202037c36a87d393 Mon Sep 17 00:00:00 2001
From: hotuanhoanh8 <55940179+hotuanhoanh8@users.noreply.github.com>
Date: Tue, 7 Jul 2020 20:40:10 +0700
Subject: [PATCH 35/44] Add files via upload
---
Token.py | 1 +
Webex API.py | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 62 insertions(+)
create mode 100644 Token.py
create mode 100644 Webex API.py
diff --git a/Token.py b/Token.py
new file mode 100644
index 0000000..709a539
--- /dev/null
+++ b/Token.py
@@ -0,0 +1 @@
+access_token = "ZDk3NTM1OWMtMTBjMy00YTE1LWE2OWMtNjUyZjdkZDRkZjFmMDdhMWMzZTAtZjNj_PF84_consumer"
diff --git a/Webex API.py b/Webex API.py
new file mode 100644
index 0000000..3a7e5fc
--- /dev/null
+++ b/Webex API.py
@@ -0,0 +1,61 @@
+import requests
+import sys
+import Token
+
+url = "https://api.ciscospark.com/v1/"
+
+def get_room(url=url, access_token = Token.access_token):
+ url = url + 'rooms'
+ headers = {"Content-type" : "application/json", "Authorization" : "Bearer " + access_token}
+ queryParams = {"sortBy" : "lastactivity", "max" : "2"}
+ response = requests.get(url=url, headers=headers, params=queryParams)
+
+ print("Thong tin ve cac phong chat:")
+ print("Status: " + str(response.status_code))
+ return response.text
+
+def post_message(url=url, access_token = Token.access_token):
+ url = url + 'messages'
+ message = input("Nhap tin nhan muon gui:")
+ headers = {"Content-type" : "application/json", "Authorization" : "Bearer " + access_token}
+ body = {"toPersonEmail" : "hotuanhoanh8@webex.bot", "text" : "" + message}
+ response = requests.post(url=url, json=body, headers=headers)
+
+ print("Tin nhan dang gui di...")
+ print("Status: " + str(response.status_code))
+ if response.status_code == 200:
+ print("Tin nhan gui thanh cong")
+ else:
+ print("Xay ra loi")
+ return response.text
+
+def menu():
+ print("\n******************************************************\n")
+ print("\t\tBai thuc hanh Webex API\nChon chuc nang can thuc hien:")
+ print("1.Lay thong tin ve cac phong chat cua token vua nhap")
+ print("2.Gui tin nhan")
+ print("0.Thoat")
+ choice = int(input("Nhap so cua chuc nang muon chon:"))
+ print("\n=================================")
+ print("Dang xu ly")
+ print("=================================\n")
+ return choice
+
+def main():
+ while True:
+ choice = menu()
+ if choice == 0:
+ print("Thoat chuong trinh")
+ break
+ elif choice == 1:
+ result = get_room()
+ print(result)
+ elif choice == 2:
+ result = post_message()
+ print(result)
+ else:
+ print("Ban nhap so sai, moi chon lai")
+ print("========================================")
+
+if __name__ == '__main__':
+ sys.exit(main())
From d74440b952733ffa53fa38c24887a7c6d4fc24f0 Mon Sep 17 00:00:00 2001
From: hotuanhoanh8 <55940179+hotuanhoanh8@users.noreply.github.com>
Date: Wed, 8 Jul 2020 09:12:49 +0700
Subject: [PATCH 36/44] Delete Token.py
---
Token.py | 1 -
1 file changed, 1 deletion(-)
delete mode 100644 Token.py
diff --git a/Token.py b/Token.py
deleted file mode 100644
index 709a539..0000000
--- a/Token.py
+++ /dev/null
@@ -1 +0,0 @@
-access_token = "ZDk3NTM1OWMtMTBjMy00YTE1LWE2OWMtNjUyZjdkZDRkZjFmMDdhMWMzZTAtZjNj_PF84_consumer"
From 91ee35aa09de8f629379365264a05418103d39de Mon Sep 17 00:00:00 2001
From: hotuanhoanh8 <55940179+hotuanhoanh8@users.noreply.github.com>
Date: Wed, 8 Jul 2020 09:13:03 +0700
Subject: [PATCH 37/44] Delete Webex API.py
---
Webex API.py | 61 ----------------------------------------------------
1 file changed, 61 deletions(-)
delete mode 100644 Webex API.py
diff --git a/Webex API.py b/Webex API.py
deleted file mode 100644
index 3a7e5fc..0000000
--- a/Webex API.py
+++ /dev/null
@@ -1,61 +0,0 @@
-import requests
-import sys
-import Token
-
-url = "https://api.ciscospark.com/v1/"
-
-def get_room(url=url, access_token = Token.access_token):
- url = url + 'rooms'
- headers = {"Content-type" : "application/json", "Authorization" : "Bearer " + access_token}
- queryParams = {"sortBy" : "lastactivity", "max" : "2"}
- response = requests.get(url=url, headers=headers, params=queryParams)
-
- print("Thong tin ve cac phong chat:")
- print("Status: " + str(response.status_code))
- return response.text
-
-def post_message(url=url, access_token = Token.access_token):
- url = url + 'messages'
- message = input("Nhap tin nhan muon gui:")
- headers = {"Content-type" : "application/json", "Authorization" : "Bearer " + access_token}
- body = {"toPersonEmail" : "hotuanhoanh8@webex.bot", "text" : "" + message}
- response = requests.post(url=url, json=body, headers=headers)
-
- print("Tin nhan dang gui di...")
- print("Status: " + str(response.status_code))
- if response.status_code == 200:
- print("Tin nhan gui thanh cong")
- else:
- print("Xay ra loi")
- return response.text
-
-def menu():
- print("\n******************************************************\n")
- print("\t\tBai thuc hanh Webex API\nChon chuc nang can thuc hien:")
- print("1.Lay thong tin ve cac phong chat cua token vua nhap")
- print("2.Gui tin nhan")
- print("0.Thoat")
- choice = int(input("Nhap so cua chuc nang muon chon:"))
- print("\n=================================")
- print("Dang xu ly")
- print("=================================\n")
- return choice
-
-def main():
- while True:
- choice = menu()
- if choice == 0:
- print("Thoat chuong trinh")
- break
- elif choice == 1:
- result = get_room()
- print(result)
- elif choice == 2:
- result = post_message()
- print(result)
- else:
- print("Ban nhap so sai, moi chon lai")
- print("========================================")
-
-if __name__ == '__main__':
- sys.exit(main())
From f3cced1665fb3753fbf0d458231d541d2603e908 Mon Sep 17 00:00:00 2001
From: hotuanhoanh8 <55940179+hotuanhoanh8@users.noreply.github.com>
Date: Wed, 8 Jul 2020 09:15:02 +0700
Subject: [PATCH 38/44] Add files via upload
---
Webex/Token.py | 1 +
Webex/Webex API.py | 61 ++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 62 insertions(+)
create mode 100644 Webex/Token.py
create mode 100644 Webex/Webex API.py
diff --git a/Webex/Token.py b/Webex/Token.py
new file mode 100644
index 0000000..6affd19
--- /dev/null
+++ b/Webex/Token.py
@@ -0,0 +1 @@
+access_token = "YzdkZWEzYzItYzcxMC00NmZiLWFkODUtZjkwZjA1MGM1NTllYzZlYmZjOGUtYTYz_PF84_consumer"
diff --git a/Webex/Webex API.py b/Webex/Webex API.py
new file mode 100644
index 0000000..3a7e5fc
--- /dev/null
+++ b/Webex/Webex API.py
@@ -0,0 +1,61 @@
+import requests
+import sys
+import Token
+
+url = "https://api.ciscospark.com/v1/"
+
+def get_room(url=url, access_token = Token.access_token):
+ url = url + 'rooms'
+ headers = {"Content-type" : "application/json", "Authorization" : "Bearer " + access_token}
+ queryParams = {"sortBy" : "lastactivity", "max" : "2"}
+ response = requests.get(url=url, headers=headers, params=queryParams)
+
+ print("Thong tin ve cac phong chat:")
+ print("Status: " + str(response.status_code))
+ return response.text
+
+def post_message(url=url, access_token = Token.access_token):
+ url = url + 'messages'
+ message = input("Nhap tin nhan muon gui:")
+ headers = {"Content-type" : "application/json", "Authorization" : "Bearer " + access_token}
+ body = {"toPersonEmail" : "hotuanhoanh8@webex.bot", "text" : "" + message}
+ response = requests.post(url=url, json=body, headers=headers)
+
+ print("Tin nhan dang gui di...")
+ print("Status: " + str(response.status_code))
+ if response.status_code == 200:
+ print("Tin nhan gui thanh cong")
+ else:
+ print("Xay ra loi")
+ return response.text
+
+def menu():
+ print("\n******************************************************\n")
+ print("\t\tBai thuc hanh Webex API\nChon chuc nang can thuc hien:")
+ print("1.Lay thong tin ve cac phong chat cua token vua nhap")
+ print("2.Gui tin nhan")
+ print("0.Thoat")
+ choice = int(input("Nhap so cua chuc nang muon chon:"))
+ print("\n=================================")
+ print("Dang xu ly")
+ print("=================================\n")
+ return choice
+
+def main():
+ while True:
+ choice = menu()
+ if choice == 0:
+ print("Thoat chuong trinh")
+ break
+ elif choice == 1:
+ result = get_room()
+ print(result)
+ elif choice == 2:
+ result = post_message()
+ print(result)
+ else:
+ print("Ban nhap so sai, moi chon lai")
+ print("========================================")
+
+if __name__ == '__main__':
+ sys.exit(main())
From 9d9e639e5cb416a3370a018e09b8c64f99e2cc59 Mon Sep 17 00:00:00 2001
From: BlackDrag0n
Date: Wed, 8 Jul 2020 14:48:52 +0700
Subject: [PATCH 39/44] Them bai lab netmiko 2 - kiem tra vlan da gan interface
---
netmiko/check_vlan_int/device_list.py | 39 +++++++++++++++++
netmiko/check_vlan_int/main.py | 61 +++++++++++++++++++++++++++
2 files changed, 100 insertions(+)
create mode 100755 netmiko/check_vlan_int/device_list.py
create mode 100755 netmiko/check_vlan_int/main.py
diff --git a/netmiko/check_vlan_int/device_list.py b/netmiko/check_vlan_int/device_list.py
new file mode 100755
index 0000000..0c30178
--- /dev/null
+++ b/netmiko/check_vlan_int/device_list.py
@@ -0,0 +1,39 @@
+from getpass import getpass
+#passwd=getpass("Nhap mat khau SSH: ")
+passwd="123"
+sw1 = {
+ "device_type":"cisco_ios",
+ "ip":"192.168.225.138",
+ "username":"admin",
+ "password":passwd,
+ "secret":"321"
+ }
+sw2 = {
+ "device_type":"cisco_ios",
+ "ip":"192.168.225.135",
+ "username":"admin",
+ "password":passwd,
+ "secret":"321"
+ }
+sw3 = {
+ "device_type":"cisco_ios",
+ "ip":"192.168.225.136",
+ "username":"admin",
+ "password":passwd,
+ "secret":"321"
+ }
+sw4 = {
+ "device_type":"cisco_ios",
+ "ip":"10.215.26.233",
+ "username":"admin",
+ "password":passwd,
+ "secret":"321"
+}
+sw5 = {
+ "device_type":"cisco_ios",
+ "ip":"10.215.26.233",
+ "username":"admin",
+ "password":passwd,
+ "secret":"321"
+ }
+device_list=[sw1]
\ No newline at end of file
diff --git a/netmiko/check_vlan_int/main.py b/netmiko/check_vlan_int/main.py
new file mode 100755
index 0000000..579d6ab
--- /dev/null
+++ b/netmiko/check_vlan_int/main.py
@@ -0,0 +1,61 @@
+from netmiko import ConnectHandler
+from multiprocessing import Process
+from device_list import device_list as devices #Nhap danh sach thiet bi ben file device_list voi ten bien la device
+from ntc_templates.parse import parse_output
+def show_vlan(device,id_vlan):
+ ssh=ConnectHandler(**device)
+ ssh.enable()
+ data=ssh.send_command("show vlan")
+ data_parse=parse_output(platform="cisco_ios",command="show vlan",data=data)
+
+ '''
+ ###data_parse output###
+ [{'interfaces': ['Et0/1', 'Et0/2', 'Et0/3'],
+ 'name': 'default',
+ 'status': 'active',
+ 'vlan_id': '1'},
+ {'interfaces': [],
+ 'name': 'fddi-default',
+ 'status': 'act/unsup',
+ 'vlan_id': '1002'},
+ {'interfaces': [],
+ 'name': 'token-ring-default',
+ 'status': 'act/unsup',
+ 'vlan_id': '1003'},
+ {'interfaces': [],
+ 'name': 'fddinet-default',
+ 'status': 'act/unsup',
+ 'vlan_id': '1004'},
+ {'interfaces': [],
+ 'name': 'trnet-default',
+ 'status': 'act/unsup',
+ 'vlan_id': '1005'}]
+ '''
+ vlan={}
+ ###Command
+ access_int=["int range e0/1-2","switchport access vlan " + id_vlan]
+ ###tao ra tu dien co dang vlan={"vlan_ID":"Interfaces"}
+ for i in data_parse:
+ vlan[i["vlan_id"]]=i["interfaces"]
+ ###Tao ham kiem tra interface cua vlan
+ try:
+ if "Et0/2" and "Et0/1" in vlan[id_vlan]:
+ print("vlan {} da duoc gan cac cong e0/1 va e0/2".format(id_vlan))
+ ssh.disconnect()
+ else:
+ print("Vlan {} chua duoc gan cac cong e0/1 va e0/2".format(id_vlan))
+ print(ssh.send_config_set(access_int))
+ print(ssh.send_command("show vlan br"))
+ ssh.disconnect()
+ except KeyError: #Neu vlan id ko co trong tu dien vlan o tren se bao loi KeyError
+ print("Khong co vlan tien hanh tao vlan va gan cong")
+ print(ssh.send_config_set(access_int))
+ print(ssh.send_command("show vlan br"))
+ ssh.disconnect()
+def main():
+ id_vlan=input("Nhap vlan muon kiem tra: ")
+ for device in devices:
+ my_proc=Process(target=show_vlan,args=(device,id_vlan,))
+ my_proc.start()
+if __name__ == "__main__":
+ main()
From ae883d1cda6334ca0953b1245e7850432d630b30 Mon Sep 17 00:00:00 2001
From: BlackDrag0n
Date: Wed, 8 Jul 2020 14:55:01 +0700
Subject: [PATCH 40/44] change name netmiko folder to netmiko_example
---
netmiko_example/check_vlan_int/device_list.py | 39 ++++++++++++
netmiko_example/check_vlan_int/main.py | 61 +++++++++++++++++++
2 files changed, 100 insertions(+)
create mode 100755 netmiko_example/check_vlan_int/device_list.py
create mode 100755 netmiko_example/check_vlan_int/main.py
diff --git a/netmiko_example/check_vlan_int/device_list.py b/netmiko_example/check_vlan_int/device_list.py
new file mode 100755
index 0000000..0c30178
--- /dev/null
+++ b/netmiko_example/check_vlan_int/device_list.py
@@ -0,0 +1,39 @@
+from getpass import getpass
+#passwd=getpass("Nhap mat khau SSH: ")
+passwd="123"
+sw1 = {
+ "device_type":"cisco_ios",
+ "ip":"192.168.225.138",
+ "username":"admin",
+ "password":passwd,
+ "secret":"321"
+ }
+sw2 = {
+ "device_type":"cisco_ios",
+ "ip":"192.168.225.135",
+ "username":"admin",
+ "password":passwd,
+ "secret":"321"
+ }
+sw3 = {
+ "device_type":"cisco_ios",
+ "ip":"192.168.225.136",
+ "username":"admin",
+ "password":passwd,
+ "secret":"321"
+ }
+sw4 = {
+ "device_type":"cisco_ios",
+ "ip":"10.215.26.233",
+ "username":"admin",
+ "password":passwd,
+ "secret":"321"
+}
+sw5 = {
+ "device_type":"cisco_ios",
+ "ip":"10.215.26.233",
+ "username":"admin",
+ "password":passwd,
+ "secret":"321"
+ }
+device_list=[sw1]
\ No newline at end of file
diff --git a/netmiko_example/check_vlan_int/main.py b/netmiko_example/check_vlan_int/main.py
new file mode 100755
index 0000000..579d6ab
--- /dev/null
+++ b/netmiko_example/check_vlan_int/main.py
@@ -0,0 +1,61 @@
+from netmiko import ConnectHandler
+from multiprocessing import Process
+from device_list import device_list as devices #Nhap danh sach thiet bi ben file device_list voi ten bien la device
+from ntc_templates.parse import parse_output
+def show_vlan(device,id_vlan):
+ ssh=ConnectHandler(**device)
+ ssh.enable()
+ data=ssh.send_command("show vlan")
+ data_parse=parse_output(platform="cisco_ios",command="show vlan",data=data)
+
+ '''
+ ###data_parse output###
+ [{'interfaces': ['Et0/1', 'Et0/2', 'Et0/3'],
+ 'name': 'default',
+ 'status': 'active',
+ 'vlan_id': '1'},
+ {'interfaces': [],
+ 'name': 'fddi-default',
+ 'status': 'act/unsup',
+ 'vlan_id': '1002'},
+ {'interfaces': [],
+ 'name': 'token-ring-default',
+ 'status': 'act/unsup',
+ 'vlan_id': '1003'},
+ {'interfaces': [],
+ 'name': 'fddinet-default',
+ 'status': 'act/unsup',
+ 'vlan_id': '1004'},
+ {'interfaces': [],
+ 'name': 'trnet-default',
+ 'status': 'act/unsup',
+ 'vlan_id': '1005'}]
+ '''
+ vlan={}
+ ###Command
+ access_int=["int range e0/1-2","switchport access vlan " + id_vlan]
+ ###tao ra tu dien co dang vlan={"vlan_ID":"Interfaces"}
+ for i in data_parse:
+ vlan[i["vlan_id"]]=i["interfaces"]
+ ###Tao ham kiem tra interface cua vlan
+ try:
+ if "Et0/2" and "Et0/1" in vlan[id_vlan]:
+ print("vlan {} da duoc gan cac cong e0/1 va e0/2".format(id_vlan))
+ ssh.disconnect()
+ else:
+ print("Vlan {} chua duoc gan cac cong e0/1 va e0/2".format(id_vlan))
+ print(ssh.send_config_set(access_int))
+ print(ssh.send_command("show vlan br"))
+ ssh.disconnect()
+ except KeyError: #Neu vlan id ko co trong tu dien vlan o tren se bao loi KeyError
+ print("Khong co vlan tien hanh tao vlan va gan cong")
+ print(ssh.send_config_set(access_int))
+ print(ssh.send_command("show vlan br"))
+ ssh.disconnect()
+def main():
+ id_vlan=input("Nhap vlan muon kiem tra: ")
+ for device in devices:
+ my_proc=Process(target=show_vlan,args=(device,id_vlan,))
+ my_proc.start()
+if __name__ == "__main__":
+ main()
From 1c2657e4fed95effcf1be5501feb7e50f97b3a66 Mon Sep 17 00:00:00 2001
From: BlackDrag0n
Date: Wed, 8 Jul 2020 14:58:56 +0700
Subject: [PATCH 41/44] change name netmiko folder to netmiko_example and del
old folder
---
netmiko/check_vlan_int/device_list.py | 39 -----------------
netmiko/check_vlan_int/main.py | 61 ---------------------------
2 files changed, 100 deletions(-)
delete mode 100755 netmiko/check_vlan_int/device_list.py
delete mode 100755 netmiko/check_vlan_int/main.py
diff --git a/netmiko/check_vlan_int/device_list.py b/netmiko/check_vlan_int/device_list.py
deleted file mode 100755
index 0c30178..0000000
--- a/netmiko/check_vlan_int/device_list.py
+++ /dev/null
@@ -1,39 +0,0 @@
-from getpass import getpass
-#passwd=getpass("Nhap mat khau SSH: ")
-passwd="123"
-sw1 = {
- "device_type":"cisco_ios",
- "ip":"192.168.225.138",
- "username":"admin",
- "password":passwd,
- "secret":"321"
- }
-sw2 = {
- "device_type":"cisco_ios",
- "ip":"192.168.225.135",
- "username":"admin",
- "password":passwd,
- "secret":"321"
- }
-sw3 = {
- "device_type":"cisco_ios",
- "ip":"192.168.225.136",
- "username":"admin",
- "password":passwd,
- "secret":"321"
- }
-sw4 = {
- "device_type":"cisco_ios",
- "ip":"10.215.26.233",
- "username":"admin",
- "password":passwd,
- "secret":"321"
-}
-sw5 = {
- "device_type":"cisco_ios",
- "ip":"10.215.26.233",
- "username":"admin",
- "password":passwd,
- "secret":"321"
- }
-device_list=[sw1]
\ No newline at end of file
diff --git a/netmiko/check_vlan_int/main.py b/netmiko/check_vlan_int/main.py
deleted file mode 100755
index 579d6ab..0000000
--- a/netmiko/check_vlan_int/main.py
+++ /dev/null
@@ -1,61 +0,0 @@
-from netmiko import ConnectHandler
-from multiprocessing import Process
-from device_list import device_list as devices #Nhap danh sach thiet bi ben file device_list voi ten bien la device
-from ntc_templates.parse import parse_output
-def show_vlan(device,id_vlan):
- ssh=ConnectHandler(**device)
- ssh.enable()
- data=ssh.send_command("show vlan")
- data_parse=parse_output(platform="cisco_ios",command="show vlan",data=data)
-
- '''
- ###data_parse output###
- [{'interfaces': ['Et0/1', 'Et0/2', 'Et0/3'],
- 'name': 'default',
- 'status': 'active',
- 'vlan_id': '1'},
- {'interfaces': [],
- 'name': 'fddi-default',
- 'status': 'act/unsup',
- 'vlan_id': '1002'},
- {'interfaces': [],
- 'name': 'token-ring-default',
- 'status': 'act/unsup',
- 'vlan_id': '1003'},
- {'interfaces': [],
- 'name': 'fddinet-default',
- 'status': 'act/unsup',
- 'vlan_id': '1004'},
- {'interfaces': [],
- 'name': 'trnet-default',
- 'status': 'act/unsup',
- 'vlan_id': '1005'}]
- '''
- vlan={}
- ###Command
- access_int=["int range e0/1-2","switchport access vlan " + id_vlan]
- ###tao ra tu dien co dang vlan={"vlan_ID":"Interfaces"}
- for i in data_parse:
- vlan[i["vlan_id"]]=i["interfaces"]
- ###Tao ham kiem tra interface cua vlan
- try:
- if "Et0/2" and "Et0/1" in vlan[id_vlan]:
- print("vlan {} da duoc gan cac cong e0/1 va e0/2".format(id_vlan))
- ssh.disconnect()
- else:
- print("Vlan {} chua duoc gan cac cong e0/1 va e0/2".format(id_vlan))
- print(ssh.send_config_set(access_int))
- print(ssh.send_command("show vlan br"))
- ssh.disconnect()
- except KeyError: #Neu vlan id ko co trong tu dien vlan o tren se bao loi KeyError
- print("Khong co vlan tien hanh tao vlan va gan cong")
- print(ssh.send_config_set(access_int))
- print(ssh.send_command("show vlan br"))
- ssh.disconnect()
-def main():
- id_vlan=input("Nhap vlan muon kiem tra: ")
- for device in devices:
- my_proc=Process(target=show_vlan,args=(device,id_vlan,))
- my_proc.start()
-if __name__ == "__main__":
- main()
From f23afd49b7c0cc3696a3754712fd5542a6787a99 Mon Sep 17 00:00:00 2001
From: BlackDrag0n
Date: Fri, 17 Jul 2020 23:56:48 +0700
Subject: [PATCH 42/44] Add check version bang netmiko
---
netmiko_example/check_version/device_list.py | 29 ++++++++++++++++++
netmiko_example/check_version/main.py | 32 ++++++++++++++++++++
2 files changed, 61 insertions(+)
create mode 100755 netmiko_example/check_version/device_list.py
create mode 100755 netmiko_example/check_version/main.py
diff --git a/netmiko_example/check_version/device_list.py b/netmiko_example/check_version/device_list.py
new file mode 100755
index 0000000..9a826bc
--- /dev/null
+++ b/netmiko_example/check_version/device_list.py
@@ -0,0 +1,29 @@
+sw1 = {
+ "device_type":"cisco_ios",
+ "ip":"10.215.26.170",
+ "username":"admin",
+ "password":"vnpro@149",
+ #"secret":"321"
+ }
+sw2 = {
+ "device_type":"cisco_ios",
+ "ip":"10.215.26.171",
+ "username":"admin",
+ "password":"vnpro@149",
+ #"secret":"321"
+ }
+sw3 = {
+ "device_type":"cisco_ios",
+ "ip":"10.215.26.170",
+ "username":"admin",
+ "password":"vnpro@149",
+ #"secret":"321"
+ }
+sw4 = {
+ "device_type":"cisco_ios",
+ "ip":"10.215.26.173",
+ "username":"admin",
+ "password":"vnpro@149",
+ #"secret":"321"
+ }
+devices=[sw3]
\ No newline at end of file
diff --git a/netmiko_example/check_version/main.py b/netmiko_example/check_version/main.py
new file mode 100755
index 0000000..50f9612
--- /dev/null
+++ b/netmiko_example/check_version/main.py
@@ -0,0 +1,32 @@
+from netmiko import ConnectHandler
+from multiprocessing import Process
+from ntc_templates.parse import parse_output
+from device_list import devices #Nhap danh sach thiet bi ben file device_list
+def check_ver(device):
+ ssh=ConnectHandler(**device)
+ data=ssh.send_command("show ver")
+ data_dict=parse_output(platform="cisco_ios",command="show ver",data=data)
+ '''#Data_dict
+ [{'config_register': '0x2102',
+ 'hardware': ['CSR1000V'],
+ 'hostname': 'CSR1000V',
+ 'mac': [],
+ 'reload_reason': 'Unknown reason',
+ 'rommon': 'IOS-XE',
+ 'running_image': 'packages.conf',
+ 'serial': ['97XPYZH1ERC'],
+ 'uptime': '1 week, 4 days, 19 hours, 36 minutes',
+ 'version': '16.12.3'}]
+ '''
+ for i in data_dict:
+ if i["version"] <= "16.12.2":
+ print("{} IP {} version hien tai {} can update version".format(i["rommon"],device["ip"],i["version"]))
+ else:
+ print("{} IP {} version hien tai {} dang o version moi nhat".format(i["rommon"],device["ip"],i["version"]))
+ ssh.disconnect()
+def main():
+ for i in devices:
+ proc=Process(target=check_ver,args=(i,))
+ proc.start()
+if __name__ == "__main__":
+ main()
\ No newline at end of file
From ee2c5b81957ce8e387b60d73b2d5d0cea9c9d602 Mon Sep 17 00:00:00 2001
From: hotuanhoanh8 <55940179+hotuanhoanh8@users.noreply.github.com>
Date: Mon, 20 Jul 2020 17:06:45 +0700
Subject: [PATCH 43/44] Update pgpd.py
---
Network Controller( APIC-EM)/pgpd.py | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/Network Controller( APIC-EM)/pgpd.py b/Network Controller( APIC-EM)/pgpd.py
index 4353861..3347253 100644
--- a/Network Controller( APIC-EM)/pgpd.py
+++ b/Network Controller( APIC-EM)/pgpd.py
@@ -49,6 +49,19 @@ def get(ip=controller.APICEM_IP,ver=controller.VERSION,uname=controller.USERNAME
print("Something wrong",api)
sys.exit()
+def post(ip=controller.APICEM_IP, ver=controller.VERSION, uname=controller.USERNAME, pword=controller.PASSWORD, api='', params=''):
+ token = get_auth_token(ip,ver,uname,pword)
+ headers = {"content-type" : "application/json","X-Auth-Token": token}
+ url = "https://"+ip+"/api/"+ver+"/"+api
+ print ("\nExecuting POST '%s'\n"%url)
+ try:
+ resp= requests.post(url,json.dumps(params),headers=headers,verify = False)
+ print ("POST '%s' Status: "%api,resp.status_code,'\n')
+ return(resp)
+ except:
+ print ("Something wrong with POST /",api)
+ sys.exit()
+
# Tạo hàm put chỉnh sửa thông tin
def put(ip=controller.APICEM_IP,ver=controller.VERSION,uname=controller.USERNAME,pword=controller.PASSWORD,api='',params=''):
ticket = get_auth_token(ip,ver,uname,pword)
From e692f66302a78163faadb7762a96f25ed0ce97c0 Mon Sep 17 00:00:00 2001
From: BlackDrag0n
Date: Mon, 27 Jul 2020 16:24:00 +0700
Subject: [PATCH 44/44] Them code scan IOS-XE tren APIC-EM
---
APIC-EM_Scan_Device/create_scan.py | 66 ++++++++++++++++++++++++++++++
APIC-EM_Scan_Device/device.py | 20 +++++++++
2 files changed, 86 insertions(+)
create mode 100644 APIC-EM_Scan_Device/create_scan.py
create mode 100644 APIC-EM_Scan_Device/device.py
diff --git a/APIC-EM_Scan_Device/create_scan.py b/APIC-EM_Scan_Device/create_scan.py
new file mode 100644
index 0000000..2e9cc6e
--- /dev/null
+++ b/APIC-EM_Scan_Device/create_scan.py
@@ -0,0 +1,66 @@
+from device import device_list
+import json
+import requests
+import sys
+import tabulate
+from pprint import pprint
+requests.packages.urllib3.disable_warnings()
+
+def get_auth_token(ip,user,passwd):
+#Tạo 1 jsonObject có 2 key username,password có value tương ứng là uname,pword
+ r_json = {
+ "username": user,
+ "password": passwd
+ }
+ post_url = "https://{}/api/v1/ticket".format(ip) #khai báo URL để post
+ headers = {"Content-Type" : "application/json"} #khai báo headers
+ r=requests.post(post_url,data = json.dumps(r_json),headers = headers,verify=False) #gửi requests đến server và gán response vào biến r
+ #post là tạo dữ liệu ,post_url là địa chỉ ta muốn gửi đến,
+ #json.dumps dùng để mã hóa username và password,
+ #verify=False để không xác thực SSL
+ r.raise_for_status() # Lấy mã trạng thái, 200 là thành công, 404 là not found
+ token = r.json()["response"]["serviceTicket"] #Lấy ticket từ r
+ # Trả về giá trị
+ return {
+ "token" : token
+ }
+def scan(ip,user,passwd,token):
+ ticket=token
+ headers = {"Content-type":"application/json","X-Auth-Token": ticket['token']}
+ url = "https://{}/api/v1/discovery".format(ip)
+ body= {
+ "name":"Scan CSR1000V",
+ "ipAddressList":"10.215.26.170-10.215.26.175",
+ "discoveryType":"Range",
+ "snmpROCommunity":"vnpro",
+ "snmpRWCommunity":"vnpro",
+ "userNameList":["admin"],
+ "passwordList":["vnpro@149"],
+ "protocolOrder": "ssh"
+}
+ try:
+ resp = requests.post(url,headers=headers,params='',data=json.dumps(body),verify=False)
+ print(resp) #In ra trạng thái
+ except:
+ print("Something wrong")
+ sys.exit()
+def show_scan(ip,user,passwd,token):
+ ticket=token
+ headers = {"Content-type":"application/json","X-Auth-Token": ticket['token']}
+ url = "https://{}/api/v1/discovery".format(ip)
+ resp = requests.get(url,headers=headers,params='',verify=False)
+ data=resp.json()["response"]
+ list_discover=[]
+ #pprint(resp.json()["response"])~
+ n=0
+ for i in data:
+ n+=1
+ list_discover.append([n,i["name"],i["ipAddressList"],i["id"]])
+ return list_discover
+ print(list_discover)
+ #print(tabulate(list_discover,headers = ['number','Name','IP Range','ID Job'], tablefmt="rst"))
+if __name__ == "__main__":
+ for i in device_list:
+ token=get_auth_token(**i)
+ scan(i['ip'],i['user'],i['passwd'],token)
+ #show_scan(i['ip'],i['user'],i['passwd'],token)
diff --git a/APIC-EM_Scan_Device/device.py b/APIC-EM_Scan_Device/device.py
new file mode 100644
index 0000000..96cd874
--- /dev/null
+++ b/APIC-EM_Scan_Device/device.py
@@ -0,0 +1,20 @@
+from getpass import getpass
+#passwd=getpass("Nhap passwrd: ")
+passwd="VnPro@149"
+ap_1 = {
+ "ip" : "10.215.26.120", #Địa chỉ IP của APIC-EM
+ "user" :"admin", # Tên đăng nhập trong APIC-EM
+ "passwd":passwd # Mật khẩu của tài khoản APIC-EM
+}
+ap_2 = {
+ "ip" : "10.215.26.121", #Địa chỉ IP của APIC-EM
+ "user" :"admin", # Tên đăng nhập trong APIC-EM
+ "passwd":passwd # Mật khẩu của tài khoản APIC-EM
+}
+ap_3 = {
+ "ip" : "10.215.26.122", #Địa chỉ IP của APIC-EM
+ "user" :"admin", # Tên đăng nhập trong APIC-EM
+ "passwd":passwd # Mật khẩu của tài khoản APIC-EM
+}
+
+device_list = [ap_1]
\ No newline at end of file