Source: channelfutures.com

Creating a menu based program using the Python : ‘Automating Different Technologies using the Python’

Anurag Sharma

--

Automating Technologies using Linux (Source: medium.com)

In this article we gonna learn what awesome technologies we can automate with the help of the python language and we gonna use loc.py python menu file created by me and my team 😎

So the first question is :

Why Python for Automation ?

Python is an easy-to-learn programming language that allows organizations to script custom automation and reap the time-savings.

As we all know python is a versatile, easy to use and fast to develop. We have so many libraries in python that make our task easy and fast.

The best way to learn any language is to make a project and whenever the new use cases comes then learn the new concept of programming language

We will add our new functionalities as we learn as a new menu which will make our code more readable and easily accessible

For now we’re adding this functionalities in our program , we can upgrade it by the time we know more technologies :

  1. BASIC LINUX COMMANDS
  2. HADOOP SERVICES with LVM SERVICE
  3. WEB SERVICES
  4. DOCKER WORLD
  5. LVM SERVICES
  6. AWS SERVICES

Let’s see -

📌 BASIC LINUX COMMANDS

🔷 Following are the redhat commands we will run using python

  • Calendar
  • Date
  • Calculator
  • Creating a New User
  • Deleting User
  • To login in another user
  • For For Checking System IP
  • For Ping
  • For Deleting Directory
  • For Making Directory
  • For reading a file content
  • For creating a file
  • For View all Disk Partitions in Linux
  • For View Specific Disk Partition in Linux
  • For Checking File System Disk Space Usage
  • For Installing Software Using yum
  • For Uninstalling Software Using yum
  • For Finding Path Of Software Installed In Linux
  • For Running Python Interpreter
  • To Open Browser

Here are some screenshot of commands :

Executing Calendar command
Calendar command Output
Executing Firefox command
Viewing all Disk partitions
Output of fdisk -l
Checking System IP
All the IP’s of my VM

Isn’t it fascinating how we can run one OS command from another OS

Python make it happen, The OS module in python provides functions for interacting with the operating system. This module provides a portable way of using operating system dependent functionality.

📌 HADOOP SERVICES with LVM SERVICE

Let’s first take some brief about what is Hadoop cluster

A Hadoop cluster is a collection of computers, known as nodes, that are networked together to perform these kinds of parallel computations on big data sets.

🔷Let’s see how can we configure Hadoop cluster using python, we are providing following functionalities for Hadoop cluster setup:

  • Starting Datanode Services
  • Starting Namenode Services
  • For Client Services
  • To Check Cluster Report
  • To Stop Datanode
  • To Stop Namenode

Here are some screenshot of output :

Starting Name node
Seeing Cluster Report
Checking the number of data node we have using the Cluster Report

📌 WEB SERVICES

A web server is a computer that runs websites. It’s a computer program that distributes web pages as they are requisitioned. The basic objective of the web server is to store, process and deliver web pages to the users. This intercommunication is done using Hypertext Transfer Protocol (HTTP).

🔷Let’s automate web server configuration…

Here are some screenshot of Outputs & practical :

Installing necessary files for configuring repos and httpd
Installing HTTPD in progress
Output of the command

In this command python will automatically configure the yum repos for us and install the httpd software form Apache and using systemctl run and activate it

📌 DOCKER WORLD

What is docker?

Docker is an open platform for developing, shipping, and running applications. Docker enables you to separate your applications from your infrastructure so you can deliver software quickly. With Docker, you can manage your infrastructure in the same ways you manage your applications.

A container is a standard unit of software that packages up code and all its dependencies so the application runs quickly and reliably from one computing environment to another. A Docker container image is a lightweight, standalone, executable package of software that includes everything needed to run an application: code, runtime, system tools, system libraries and settings.

🔷Here are some functionalities for docker using python:

  • Installing Docker
  • Starting docker Service
  • Launch Container
  • Start Container
  • Stop Container
  • Status Of Containers
  • Delete Containers
  • Delete Image
  • Stop docker service
  • Status docker service

Here are some screenshot of practical :

Installing Docker
Docker Completely installed on system
Starting the Docker Service
Docker Service Successfully Started
Launching the Container
Status of Container
For Starting Container
Centos Opened

📌 LVM SERVICES

What is LVM ?

LVM allows for very flexible disk space management. It provides features like the ability to add disk space to a logical volume and its filesystem while that filesystem is mounted and active and it allows for the collection of multiple physical hard drives and partitions into a single volume group which can then be divided into logical volumes.

🔷Following are the LVM commands that we are going to use :

  • Static To Dynamic
  • Extend Your LVM Size
  • Reduce Your LVM Size
  • Extend Your Volume Group Size
  • Remove LVM
  • Remove Volume Group
  • Remove Physical Volume

Here are some screenshot of practical :

Selecting the LVM Service by the User
Converting the Static volume to the Dynamic one
Conversion of Static to Dynamic Volume Completed
Extending disk size using LVM
Extending the Size using LVM
Removing LVM
LVM Removed

📌 AWS SERVICES

The AWS Command Line Interface (CLI) is a unified tool to manage your AWS services. With just one tool to download and configure, you can control multiple AWS services from the command line and automate them through scripts.

🔷Following are the functionalities of aws-cli using Python :

  • To Install AWS CLI
  • To Login into AWS CLI
  • To Create Key Pair
  • To Create Security Group
  • To Launch a instance
  • To Start a Instance
  • To Stop a Instance
  • To Describe All Instances
  • To Create a Volume
  • To Attach volume with instance
  • For Partitioning the attached volume
  • To configure Web Server
  • To Format Partition
  • To Mount the Web Server to Volume
  • To Detach Volume
  • To Launch S3 Services
  • To create Cloud Front Distributions
  • To Create Snapshot

Here are some screenshot of practical :

Starting a Instance from our VM using AWS CLI
Instance Details
Stopping a instance using AWS CLI
Describing all the instance using AWS CLI
Creating a Volume inside a Instance

CONCLUSION :

In this program we integrated python with different technologies like AWS, Docker, Hadoop, SSH and many more….

Call us python freak but integrating different technologies with python is such a fun thing to do, you get to learn a lot and you can truly see the power of python

This is just the start let’s keep exploring

Here is the descriptive video for your better understanding :

Github Code link :

https://github.com/pranay1603/Linux-Automation.git

Thank you for Reading 😊

--

--