Skip to content
This repository was archived by the owner on Nov 16, 2022. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 65 additions & 56 deletions 01-Arth-Team-Task-automation-using-python.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,32 @@ def Rechoice():
service()
elif(reChoice == 'E'):
print("\n\tyou have choosen to withdraw \n \t\tHAPPY CODING")

else:
print("\t\t\t !!! EXITING !!!!!!!")
exit()


#-------------------------->>>>>>>>>>>>>> dockerHostWebServer() <<<<<<--------------------

def dockerHostWebServer():
print("\n\tYou have chosen option 5\n")
osName = input("\n\tEnter the name of the os \t ---> ")

os.system("docker start {}".format(osName))
os.system("docker ps --latest")
print("\n \n")
# print("\n\t\t -->>Enter [ctrl+d] to exit the command line<<---\n")
# os.system()
print("\n The ip of the os is \t --->\t ")
var = os.system("docker container inspect --format \"{{.NetworkSettings.IPAddress}}\" {}".format(osName))
os.system("docker exec -it {} yum install httpd".format(osName))
# print("\n\t\twrite the codes for the server to deploy\n")
# os.system("")
webFileName = input("\n\tEnter the name of the html file that needs to be launched\t--->\t")
os.system("docker cp {} {}:/var/www/html".format(webFileName,osName))
print("\n\t\t--->>> LAUNCHING {} FILE ON WEB SERVER on {} <<<-----\t\n".format(webFileName,osName))
os.system("docker exec -it {} /usr/bin/httpd".format(osName))


#----------->>>>>>>>>> SERVICE() <<<<<<<<-__----------------
Expand All @@ -41,33 +63,33 @@ def service():
print("\n\t \t Starting Docker \t\t\n")
os.system("systemctl start docker")
dockerStart = 1
print("\n\tdocker is running")
print("\n\tdocker is running")
elif(ch == "2"):
print("\n\tstopping docker")
os.system("systemctl stop docker")
print("\n\tThe docker is stoped")
dockerStart = 0
elif(ch == "3"):
print("\n\t\tpresenting docker Details\n")
print("\n\t\tpresenting docker Details\n")
# os.system("systemctl status docker")
showDockerDetails(dockerStart)
showDockerDetails(dockerStart)
elif(ch == "4"):

# ==========>>>>>>> here we will ask the user details about the image it wants to run
configDockerImage(dockerStart)
elif(ch == "5"):
dockerHostWebServer(dockerStart)
dockerHostWebServer()
elif(ch == "x"):
print("\n\t\tYou have chosen To exit")
exit()
print("\n !!!! \t\tt\t\t\t\ EXITING THE SYSTEM \t\t\tt\t !!!!")
else:
print("You have entered wrong choice")

# exitStatus = input("Enter y to Return to main menu \nEnter n to exit [y/n] \n\t------>>\t")





def configDockerImage(dockerStart):
print("\t\t\t Welcome to docker configuration \n")
if(dockerStart == 1):
Expand All @@ -87,80 +109,80 @@ def configDockerImage(dockerStart):
if(choice == "E"):
print("\n\t\tReturning to main menu\n")
return

else:
print("\n\tUnable to perofrm action , Docker is closed\n")
print("\t \t Starting Docker \t\t\n")
os.system("systemctl start docker")
dockerStart = 1


# --------------------->>>>>>>>> showDockerDetails()<<<<<<<<<<<<____
def showDockerDetails(dockerStart):
con = "Y"
while(dockerStart != 1):
print("\n\tUnable to perofrm action , Docker is closed\n")
print("\n\t\t Starting Docker \t\t\n")
os.system("systemctl start docker")
dockerStart = 1

dockerStart = 1
while(con !="E"):
print("\n \t\t\t Below are the option")
os.system("docker ps --help")
option = input("\n\n\t Enter details \t--->>\t")
os.system("docker ps {}".format(option))
con = input("\n\n\t\tEnter Y to return to option 3\n \t\tEnter E to go to Docker menu\n\t\t--------->>>>" )

print("\n \t\t\t Exiting option Docker Details\n ")

# ==================>>>>>>>>Here we will ask the user details about the image it wants to pull

def dockerRunImage(dockerStart):
def dockerRunImage(dockerStart):
if(dockerStart == 1):

os.system("docker ps -a")

imgPull = input("\n\nEnter the name of the image you want to run\t -------> \t")
os.system("docker search {}".format(imgPull))
imgChoicePull = input("\nEnter the version of the image you want to run\t ---->> \t")
choiceDesiredName = input("\n\tDo you want to give a name to your image [y/n]\t -------->>\t")

if(choiceDesiredName == "y"):
print("\n\tRunning Docker image\t---->> {}".format(imgChoicePull))
configImageName(imgChoicePull)

configImageName(imgChoicePull)
else:
print("\nENTER -->>> exit <<----- to exit the image or press [ctrl+c] to exit")
os.system("docker run -i -t {}".format(imgChoicePull))
os.system("docker run -i -t {}".format(imgChoicePull))
print("\n\t!!!!\tEXITING\t!!!!!!\n")

else:
print("\n\t\t The docker has stooped\n")

# --------------------->>>>>>>>>> configImageName() <<<<<<<<<<<<<------------------------

def configImageName(imgChoicePull):
desiredImageName = input("\n\tEnter the name \t\n \t------> ")
os.system("docker run -it --name {} {}".format(desiredImageName,imgChoicePull))

#-------------------------->>>>>>>>>>>>>> deleteAllPullImage() <<<<<<--------------------

def dockerPullImage(dockerStart):
def dockerPullImage(dockerStart):
if(dockerStart == 1):
imgStart = input("\n\tEnter the name of the image you want to Pull\t ------>\t")
os.system("docker search {}".format(imgStart))
imgChoicePull = input("\n\tEnter the version of the image you want to Pull\t ---->> \t")
print("\n \t\t\t\t !!!! PULLING IMAGE {} !!!!\n".format(imgChoicePull))
os.system("docker pull {}".format(imgChoicePull))
os.system("docker pull {}".format(imgChoicePull))
else:
print("\n\tThe docker has stooped")
return

return


#-------------------------->>>>>>>>>>>>>> deleteDockerImage() <<<<<<--------------------


def deleteDockerImage():
# deleteImageName = ""
chooseExit = "c"
Expand All @@ -174,21 +196,21 @@ def deleteDockerImage():
deleteAllFlag = 1
print("\n\tDeleting all docker Image\n")
deleteAllDockerImage()

elif(deleteDockerImageChoice == "1"):
print("\n\tDeleting single IMAGE\n")
deleteDockerImageChoiceFunction()

elif(deleteDockerImageChoice == "2"):
deleteAllRunningDockerImage()

else:
print("\n\t\t WRONG OPTION\n")
chooseExit = input("\n\tENTER c to continue\n\tENTER e to exit\n")
if(chooseExit == "e"):
return
# here I'm having trouble exiting the code if wrong ImageName is given

# 💥 here I'm having trouble exiting the code if wrong ImageName is given
print("\n\tYou have entered wrong option ")
choice = input("Enter C to continue and E to exit\t------------>\t")
if(choice != "c" and deleteAllFlag == 1):
Expand All @@ -199,51 +221,38 @@ def deleteDockerImage():
# ------------------>>>>>>deleteAllDockerImage()<<<_------------------
def deleteAllDockerImage():
print("\n\tDeleting all docker Images")
os.system("docker rm `docker ps -a -q`")

os.system("docker rm `docker ps -a -q`")
#-------------------------->>>>>>>>>>>>>> deleteDockerImage() <<<<<<--------------------


def deleteDockerImageChoiceFunction():
imageName = input("\n\tEnter the name of the image you want to remove")
print("\n\t\t\t REMOVING {}\n".format(imageName))
os.system("docker rm {}".format(imageName))

#-------------------------->>>>>>>>>>>>>> deleteAllDockerImage() <<<<<<--------------------
def deleteAllDockerImage():
print("\n\tDeleting all docker Images")
os.system("docker rm `docker ps -a -q`")
os.system("docker rm `docker ps -a -q`")

#-------------------------->>>>>>>>>>>>>> deleteAllRunningDockerImage() <<<<<<--------------------

def deleteAllRunningDockerImage():
print("\n\tDeleting all running images")
os.system("docker rm `docker ps -q`")

#-------------------------->>>>>>>>>>>>>> dockerHostWebServer() <<<<<<--------------------

def dockerHostWebServer(dockerStart):
print("\n\tYou have chosen option 5")
if(dockerStart == 1):
print("\n\tHosting Web Server")
os.system("docker pull httpd")
os.system("docker run httpd")
print("\n\t\t you have successfully started the web server")

else:
print("\n\tUnable to perform action Docker is shut")



#-------------------------->>>>>>>>>>>>>> docker() <<<<<<--------------------

def docker():
os.system("clear")
print("\n\t Welcome to dockers below are the list of options to use docker \t!!")

service()
Rechoice()

# ---------------->>>>>>>>>>>>>>>>>> Here only by calling docker function the whole program will run


Expand Down