Using The Linode API | Getting Started Guide

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello and welcome back to linode in today's video we are going to take a look at the lenod api which is very powerful we can use it for all kinds of things even setting up our very own linux instance right from the command line so let's go ahead and dive right in and see some examples of the lynnode api in action so the first thing that we'll need to do to get started is to create an api token that we will use to authenticate with our lynnode account to do that we will click up here where our username is if we drop that down we can go down to profile and then here closer to the middle we have an api tokens tab then once you click on that you will get a list of any personal access tokens you may already have in this case i don't have any and it will also give you the opportunity to create a personal access token if you don't already have one or if you need to create a new one for a separate purpose so to create a new one we could go ahead and click on add a personal access token right here and then on this section right here that just popped out we can configure the permissions for what this key is allowed to do and you definitely want to pay very special attention to that because you definitely don't want to give it more permission than it needs because if this key were to ever leak out whoever gets a hold of it can do anything that this key is configured to do first and foremost we need to give it a name so for mine i'll just call it test and then right here we have an option for expiry if we want this token to expire in a certain amount of time if you drop this down you can make the token never expire you can make it expire in one month three months or six months i'm going to leave that as its default for now and then down here in this area we have the most important section of the entire process and i've already mentioned that you should give this key only the permissions that it needs for security purposes but whether or not this key is able to be useful for its intended purpose all comes down to whether or not you actually set the right permissions so for example if you set account to read and write it can make actual account changes but maybe read only is good enough if you are going to use the api for a purpose that involves reading the domain names you can simply set this to read only if you don't have any intention of actually having that make changes to your domains perhaps read only is good enough then you could go straight down and then determine which permissions the key will need to have and that all comes down to your intended purpose perhaps you are writing a program a script or you simply want to do some curl statements to interact with your account which is actually what we're going to do in this video now in my case i'm going to make everything read only so with this key there won't be any changes allowed but it will be able to read all of the account details which would be more than enough for me to show you some examples of interacting with the api so i will click create token and then we have the token right here and make sure you jot this down because it will never be displayed again if i click ok right now and i didn't copy that down then i have permanently lost my ability to see what the key is and i'll have to revoke it and then create a new one so in my case i'm just going to copy this to the clipboard and that should be good enough for me but again make sure you make a note of this in a very secure area now i really shouldn't be showing this key in a video that is going to be watched by a lot of people however it is just a test and i want to make sure you guys see generally what keys look like it's just a bunch of random characters as you see here but do as i say not as i do definitely keep this key safe and don't let anyone see it unless they really really need to see it so i'll click ok and then we should be good to go to go ahead and use it so i'm going to go down here to a terminal what i'm going to do is create a variable and that variable is going to contain the api token for future use so to set up a variable for this i can simply type token then the equal sign and then i will paste in the token right here and there it is so i'll press enter and just to make sure that it was saved properly i could simply type echo dollar sign and then the name of the variable and sure enough we see that the variable does indeed contain the actual api token before we get started with the examples there's a few commands that we'll need to have available first and the second one is json underscore pp in order to find out if you already have that on your system just simply type which before the command and that'll tell you whether or not you have that available in this case i don't have this command right here it's basically telling me that it wasn't found similarly we also need curl so i can do the same thing with curl now this one is installed we can see the output user bin curl the which command if it's successful will show you where that particular binary for that command is located and if it's found on your system it will give you the full path to that particular binary so in this case on my system i do have curl but i am missing json underscore pp on your end if you are missing one or both of these commands you'll need to get those installed so in my case on this fedora system i can simply run sudo dnf install and i'll paste the name of the package that i need at least on fedora right here which is this package right here it's actually part of perl so for you you would just consult the documentation for your distribution or operating system so i'll press enter so it's going to install a total of three packages to facilitate the installation of this command that's fine let's go ahead and do it and that was pretty quick so let's go ahead and see an example the first example will actually fetch a list of images that are available on the lynnode platform so in order to do that we will type curl then https api.lynode.com slash v4 and then slash images slash and then we are going to pipe that into json underscore pp just like that so i'll press enter and see what happens and we get quite a bit of output here so i'll scroll up to the top and there's definitely a lot of detail here so here we get a list of images as we would expect we get the name of the image so for example we have the alpine 3.10 image right here scrolling down you see some different versions of alpine now we have centos 8 w9 fedora and so on so that's pretty cool now we can fetch a list of images and that's especially useful if you want to be able to interact with lenode on the command line to the point where you actually create your own instances it's good to know which images are available to serve as the base of your lynnote instances if you want to do full automation so for the next example we can actually get a list of all the instance types available on the lynnode platform so if i press the up arrow here then i can simply change images to lynode then add types to the end and then press enter and as you can see we have quite a few now note the id so we get the id of the instance type right here and we get some specs for example how much memory does that instance type contain what is the actual label which will give you some additional clues for what actually makes that instance type different from others the number of gpus disk and so on so as you scroll through this list you'll see that there's quite a bit of information here so if you want to basically just find out some information on the types that are available for creating a lynnode then you get that from this list right here and we were able to do that right from the command line by simply using curl with our api token so for the next example i will again recall the previous command i'll just simplify this right here we don't need linode for this you could change types to regions because we are able to create linux in various regions around the globe so it's a good idea to get a list of the regions that are available so that way you could choose the one that is closest to you or closest to the customers that you intend to serve so i'll press enter and again we get quite a bit of information here as you can see so we have europe central we have europe west you can get the ipv4 ranges as well which is pretty cool here's us east and we also get a list of capabilities which is important if you want to deploy a linux or some other feature that lenode gives you access to in a particular region it's important to know what the capabilities are of that region it does vary a bit so make sure you pay attention to that but again we were able to get this information right from the command line without even having to google it or go through all the documentation to find it it was actually pretty easy to get that information as you see right here in our terminal now here's where it all comes together because what i'm going to show you how to do right now is actually create a lynnode instance right from the command line in order to do this though we will need to have different permissions for our api token because if you recall we set everything to read only so if i attempted to create a lynode with the api token that we currently have it's going to fail because we didn't give it any privileges at all whatsoever that allow it to actually make changes so back on the dashboard we have our test key right here and again if we view the scopes we can see that it is indeed read only we can't change it so what i'm going to do is actually revoke this key and that'll get rid of it and what i'm going to do now is create a brand new one so i'll call my new key test 2 i'm going to have it default to read only and then when it comes to lynn nodes i'm going to set that to read and write and i think that should be good enough so click create token and here we have the token so i'll copy that again and back down here on the terminal i'm going to replace the token variable that we've created earlier with the new key so the example curl command that we will use to create our linode instance is fairly long so what i'm going to do is paste it in right here to save some time and there it is so what i'm going to do is explain what's going on here so of course you know that we are using curl and we want to post because we don't want to just read information we want to actually send changes over to the api endpoint and the api endpoint that we are going to send changes to is this one right here as you can see it's using the version 4 linode api it's api.lynode.com and then we want to interact with lynnodes and specifically we want to interact with instances now what we're going to do is set the authorization to the token that we have saved as a variable so we have that right here and then we're going to send content type of json as you see in this section we need to set the type to the linode g5 standard two you can replace this with any instance type that you want to create just keep in mind that when you do create a lynn node billing for that linode starts immediately so if this is just a test on your end make sure you delete that linode when we're done otherwise you will receive a bill for it just keep that in mind anyway continuing we want to set the region and in this case we are setting it to us east the image that we are going to use is lynnode w9 as you see right here and then we have root pass and we have it set to root underscore password from the documentation so what i'm going to do is change that to super secret pass and that should be fine and then the label which is what the lynnode will be called is set to prod hyphen one so let's press enter and see what happens and we get some output here but what's exactly happening so let's return to the dashboard and see if anything is different so i'm going to click on linux and as you can see here we have a linode with a name of prod 1 it's debian 9 and this is indeed the one that we created with the api token via the command line so if i click on it let's just see what's going on with the console and we can actually see that it's all set and ready to go so i'll log in with root super secret pass and then enter and what do you know we were able to create our very own linode with only the command line via the api token that we've created which just goes to show you that the lynnode api is powerful and allows you to interact with your account without even having to leave your terminal so there you go those are some examples of using the lynnode api we were even able to use it to set up our very own lynnote instance which was awesome and in the documentation page that matches this article there's even more examples in there so definitely check that out as well but either way i hope you enjoyed this video the api is awesome and you could use it to fully automate pretty much everything you would want to do with the leno platform now as always click that like button if you like this video and also subscribe because we have some awesome things coming up very soon thanks for watching [Music] you
Info
Channel: Linode
Views: 1,622
Rating: undefined out of 5
Keywords: linode, cloud computing, api, linode api token, linode api documentation, linode api key, linode api dns, linode server setup, learn linux, cloud hosting, linode tutorial, open source, alternative cloud, linode cli, cloud computing tutorial for beginners, learn linux commands, cloud api, create linode api, using linode api, create vps with api, api vps tutorial, linux vps tutorial, create server with api, create linode through api, command line api tutorial, linux, terminal
Id: 3s9mm1qQh0A
Channel Id: undefined
Length: 15min 29sec (929 seconds)
Published: Wed Jan 13 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.