Skip to main content

EXCEL TO GCP


 FROM EXCEL TO GOOGLE CLOUD PLATFORM

 

Introduction: 

    Tools are those which help us to ease our work. It can no more be called a great tool if the process of using it becomes harder or complicated. Since LANPAR (created in 1969), spreadsheets have been very useful to stack data and compute it easily. They became so popular that, now, apparently, it is a must! 

    It would turn out more interesting, if we used this simpler method of data acquisition to build infrastructure on GCP. Every cloud provider for that matter has an end left free for open-source developers to build tools in the form of REST-API. Python has a great capability of handling dictionaries and hence, JSON types. This can be exploited more to make it work for our easy use. 

    So, here is how I tried to make one such bundle of a package to create my VPC Networks, Subnets and Instances in it and also add Firewall rules to manage the traffic! 

 

Why python and how? 

    There is not a particular reason why I chose python, maybe because I know it well and I felt that it is capable of handling the JSON dictionaries. There are libraries for Python, R, Go, Ruby and many languages provided by GCP itself and here's what you need to know about it.

Python guide to GCP 

 

  

 We also have an option to read excel files/spreadsheets in Python using a library called pandas. This library (pandas) lets us read the spreadsheet and converts the whole document into something called a data-frame, in simpler words, makes it a table and every column can be treated as a list, hence giving us a dictionary, whose key is the head and value comprised of list of underneath values.

 

 

 

 

You can program it in such a way that, you can extract each value, and pass it on to API, and GCP with python will do rest of the work for you.


What does it take?

     Going through the python library provided by GCP, we get cleared of one thing. The library uses Google Cloud SDK for authorization and authentication. It is a must install CLI app in the system that work on, apart from Python itself. Click here to know how to install Google Cloud SDK in your PC. 

    Once the SDK gets installed, run

 'gcloud auth application-default login' 

command to initialize and set up credentials of your account inside the SDK, which will be then saved to be used later. It automatically updates the API request calls with the credentials. Later, you need not keep providing your credentials, every time you make your requests.

     After SDK, comes the Python libraries. You need to install google-api-client-library, in simpler words, run,

pip install --upgrade google-api-python-client
 in the terminal and 'pip' will do the work for you and get your job done! once installed. Then, one is capable of using the tool but, before, you need to enable the needed API. This can be done in console itself (the easy way). Open the tab of the resources that is desired to be used and click on Enable API is available. If you cannot find it, that means the API is already enabled.

 

 KEYS:     

     In the library google-api-python-client we use a subclass called discovery. First and foremost step, whenever we start, is to import this class. This class need to initialized in the following way.

  
 
Once this is done, the object compute now contains all the functions that can be used to create, change, list, delete any resources under that category. In GCP, we have several categories of APIs - namely, Compute Engine, Storage, Kubernetes etc.. Compute Engine can cover vast variety of subcategories such as Instances, Networks, Firewalls, etc.. (more can be seen here)

  

    Once our 'compute' carries all the methods, we can now build things over that. I would be writing a blog explaining each and every concepts about how to use such methods, for now you can click here for the documentation from GCP for creating instances using this client.

 

 

 Excel to Python:

 

    Till now we saw, how to get things to work from Python to GCP, now comes the other half from Excel (Spreadsheet) to Python. Once you have your Excel sheet ready, then we a library called Pandas to handle this file. Pandas takes the data from the file and converts it into a object called Dataframe. Making it a list of dictionaries, with the keys as the name of columns and the values being the enlisted data below. We shall use this feature to break down our requirements that will be given to functions as parameters.

 

 

Comments