YANG Explained and Explored | Pyang | DevNet | CCNP

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
this may be one of the toughest videos I ever record but by the end of it we'll know what yang really is and explore it let's go [Music] welcome back to my channel if this is your first time visiting and you're interested in growing your IT career or your IT skills you're in the right place just make sure you hit that subscribe button and little bill so that you get notified when a new release comes out alright yang everybody yang Chun tonight yang is really really a massive topic and it's really just a piece in the puzzle it's not like a whole big thing that does all this stuff for you it's just a piece so what is yang it's so hard to summarize it but here's the definition yang is a data modeling language so we already got to take a step back what is a data model well think about it if you ask for information from someone or some thing maybe you're typing a CLI command and you type show you expect the information to be presented to you in a format that you can understand it has to be formatted in a specific way and structured or organized in a way that you can quickly find the info that you need and a data model does just that the data model says the structure of our data should follow this hierarchy for instance we may have a switch with 48 interface interfaces on it right so we might structure our data on those interfaces such as we'll have a tier called interfaces and then beneath that tier we'll have each interface and then within that interface we'll have the name of the interface and the status of the interface and so on so in order to find the status of say interface gig 0:38 we'll start with our interfaces tier and then work our way down into interface and then gig 0:38 or are you following if there's a certain structure that we have to have in the data now this is all well and good for us as humans we can kind of like figure things out on our own for the most part but computers can't computers are literal so if our computer is trying to connect to a network device and request data off of it they have to agree on what the structure of that date is going to be so that our computer knows what to do with the data in the first place our computer needs to know how the data's been organized in order for it to make decisions or actions on that data so let's take a look at what the ietf the people who standardized yang have to say about this here's what it really looks like in action we have interfaces the interface name then the name the description the type enabled link so on and so forth so if my computer is over here and I'm trying to connect into a network switch and I want my computer to maybe print a list of all of the interfaces whose enabled is set to false my computer and the network device need to agree on what the structure of the data needs to look like when it gets sent back and forth and here's the kicker we're not talking about just XML or JSON that is the data serialization no what we're really talking about here is the order or the hierarchy that the data needs to be sent in whether it's XML or JSON where does this really come into play this really comes into play when we talk about the industry standard network automation protocols net comp and rest cough if you're going for the cisco dev net exam you're going to see Netcom from rest comp particularly in the iOS XE section iOS XE devices are programmable because they implement net comp and rest calm whereas a lot of other network devices have their own api's like nexus now that doesn't mean that Nexus devices don't have yang data models it's just that net confident rest comp rely almost exclusively on structuring their data based on a yang template now the actual yang template itself is bonkers hard to explain and it's covered in detail in the Cisco definite course on CBT Nuggets but I actually want to show you how you can get the yang template off of a network device and then parse it into a tree structure like the one that we have right here on the screen let's go so I fired up vs code what I'm gonna do is I'm going to create a new file real quick we'll call this yang demo dot py for a PI file and what I'm gonna use is I'm gonna use this cisco dev net sandbox and leveraging iOS XE device that they have running in the sandbox I'm going to use the in C client library so that we can connect using net comp and grab the yang data models off of the network device using net comp I'm also going to use the XML Eitri element tree library so that we have the ability to work with XML data and parse out just the raw info that we need which is actually where the yang data model is going to be stored I'm gonna alias it as ET or element tree so that it's a little bit easier to work with now for this next part I'm just gonna paste in the connectivity details this is a little Python dictionary that has the info for the router that we're going to be connecting to this has the hostname the Netcom port that it's listening on is 10,000 username and password that's really all we need to get connected so with that being said let's get connected I'll use a with statement to call the with manager dot connect method and I'll aleus the connection as M you may be wondering why am i choosing to do it this way because what happens when we use the with manager dot connect as M Python will build the connection run all of the things that we need to run and then automatically tear down the connection and relieve the pressure off of memory it's just a cleaner way to handle connecting and disconnecting to network devices but of course we have to specify our connection parameters in the connect method so let's go ahead and specify those lucky for me the parameters that are used in the connect method all match up the key names here host port username and password so all I have to do is specify that they equal those keys in the router dictionary so I'll say host equals router host port equals router port username equals router username password equals router you know let's clean up the screen a little bit there router password and then lastly this is going to be issuing a self-generated keys so I'll say a host key verify equals false so that way we don't get any connectivity issues when we try to connect ok so now the connection is in place it's stored in a variable called M let's use that connection to grab a yang data model called IETF I pee I'm gonna call this variable IP schema and I will say with my M connection I will run the method get' schema and specify I want the ietf IP schema what this is really doing is it is getting the yang data model for how IP addresses are structured by the IETF this is then being stored in an IP schema variable so we're gonna need to parse out the XML from that variable and then parse that XML to get the actual yang data model here's how that looks the first thing I'm gonna do is turn this into an XML element and I'll store it in a variable called route because it will store in the route XML element I'll use the et elias alias mentioned from above and we'll use the from string method because that's exactly what's happening here is this is coming from string in the IP schema variable so I'll say IP schema and use the XML value if that came back as part of that IP schema so by the time this method is done it's gonna grab the XML value from IP schema and use the from string method to store it as an actual route XML element now what I need to do is parse that XML element to find the actual yang tree or the yang template that's actually completely outlined and built by the IETF so I'll store the results in a variable called yang tree and the first thing I'm gonna do is I'm going to convert that route object that we just got back for as an XML object into a list the very first item in that list we're gonna use the index of zero is what contains the raw data that we're looking for and we're gonna grab the text values that come back from that so at this point the yang tree variable should have the actual schema the actual yang data model schema for ietf IP in order to explore the schema we have to write this out to a file so I'll create a file variable I'll use the open command and I'll specify a file name of IETF IP dot yang it's going to have the yang extension I'm gonna hit comma and make sure I also use the W parameter to specify that we're going to be writing to this file I'll then use that variable to write the yang tree to that file and then I'll close the file if I've done everything right we should be able to debug the script and it will write the ietf IP yang file to my local machine let's go okay no errors let's go to the file browser scroll to the bottom look at that IETF IP yang if I click on it look at that that is a yang data model and all of these things that you're seeing here all of these like leaf container modules enums types all of this stuff is explained in the cisco definite course on CBT Nuggets so that's great but how do we get it into a tree like view so that we can quickly see how the structure of ietf IP yang works well the first thing is I can see that it imports other yang models too in fact 3 yang models ietf interfaces IETF high net types and IETF yang types so what I'm gonna do right now is I'm going to copy and paste each one of these and run the script one more time for each of these to make sure I download those models too so let's do that I'll paste it in and get schema and paste it in right here before the dot yang then I'll run the script we got to save it first we run the script and I'll repeat the same steps for the other two okay so checking the file browser now I see I have all of these yang files here and if we want to explore ietf IP yang in a tree-like structure that we originally saw on that website here's how we can do that using the get CLI I will make sure I you install a Python library called pi yang py ang let's give pip install pi yang all right already meets the command and I'm in the folder that has those yang data models let's give it an LS and you can see there they are right there so the command to see ietf IP yang in a tree like structure let me clear the screen will say pi yang f4 function tree and then specify the file name IETF IP dot yang there it is there is the tree like structure I can see there's an ipv4 and an ipv6 I see there's status items like MTU forwarding enabled as well as the address info the prefix length even neighbor info and ipv6 specific things like how it was Auto configured so what you need to imagine now is that my computer is going to be over here connecting to a network device and I may want again IP address information from that network device I'm going to say hey mister switch used the IETF IP model that way I know exactly the structure of the data that's going to be coming back to me and I can build my scripts to correctly parse out just say the IP address info if that's what I'm looking for whether it's net con for s conf it doesn't really matter net comp is going to be using XML but rest comps can use XML or JSON the key is that whatever serialization is being used we know where to go to get the data that we need because it's been modeled ahead of time so do you see what I mean yang is kind of a huge topic I mean we go a lot deeper on the Cisco definite course on CBT Nuggets because yang determines how our data is supposed to be sent and received it determines what the order or hierarchy of the data is and what yang does is it provides a template or a way to write how the data is supposed to be modeled yang isn't just a definite topic yang is on the CC and P to understanding the benefits of Yang and how to even interpret a yang data model is going to be a big deal especially if you're diving into network automation so yeah summarizing that in a few minutes pretty tough job but we now know what data models are what yang specifically does for Network Devices we now know how to pull off data models from a network device and parse it out in a tree-like structure using pi yang so that's been yang explained and explored thanks for stopping by y'all I'll see you in the next one
Info
Channel: Data Knox
Views: 7,623
Rating: 4.8947368 out of 5
Keywords: Technology, Networking, Cisco, PowerBI, Training, Certification, Engineer, Network, tips, troubleshoot, Azure, cisco certifications, cisco devnet, cisco devnet associate, cisco devnet associate certification, cisco devnet associate book, cisco devnet exam breakdown, cisco devnet associate exam breakdown, cbt nuggets, ccna training, devasc 200-901, netdevops certification, python certification, cisco python certification, pyang, yang python, devnet yang, cisco devnet yang, yang data model
Id: kESU4Y8DJ2A
Channel Id: undefined
Length: 13min 35sec (815 seconds)
Published: Thu Jan 16 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.