From 48c7bacea84b05ccef5033711893144887c1eaf6 Mon Sep 17 00:00:00 2001 From: FisehaTessema4 <60725293+FisehaTessema4@users.noreply.github.com> Date: Mon, 29 Nov 2021 20:36:53 -0800 Subject: [PATCH 1/4] Added some lines of code filled the missing code to make it work correctly --- Server.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/Server.py b/Server.py index cb8697c..68be930 100644 --- a/Server.py +++ b/Server.py @@ -1,10 +1,33 @@ + + +import os class Server: """ Server class for representing and manipulating servers. """ def __init__(self, server_ip): # TODO - self.server_ip = server_ip + self.ping() def ping(self): # TODO - Use os module to ping the server - return \ No newline at end of file + print("The Server IP is", self.server_ip) + #Get the location from where the Python script is run + filepath = os.path.dirname(os.path.abspath(__file__)) + #Set the working directory to the path where the python source code is + os.chdir(filepath) + #pingresult = os.path.join(filepath,"pingResults__.txt") + #Create a text file Name to store the Ping results + pingresult = "pingResults__.txt" + pingText = 'ping ' + (self.server_ip) + ' > ' + pingresult + print("Command sent to the OS system for the ping is: ", pingText) + response = os.system(pingText) + #A response of 0 is returned for a sucessfull server response + f = open(pingresult, "r") + if (response == 0): + print("Ping Successfull for the server", self.server_ip) + print(f.read()) + else: + print("Check the server - Unsuccessfull ping response for ", self.server_ip) + print(f.read()) + return From efcf774a786a283090876de7aebb5531f51464e8 Mon Sep 17 00:00:00 2001 From: FisehaTessema4 <60725293+FisehaTessema4@users.noreply.github.com> Date: Mon, 29 Nov 2021 20:38:58 -0800 Subject: [PATCH 2/4] Added some lines of code Filled the missing codes --- main.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index 2fb474f..bd8f41f 100644 --- a/main.py +++ b/main.py @@ -1,13 +1,15 @@ # This is the template code for the CNA337 Final Project # Zachary Rubin, zrubin@rtc.edu # CNA 337 Fall 2020 - +import Server def print_program_info(): # TODO - Change your name - print("Server Automator v0.1 by Your Name") + print("Fiseha Tessema") # This is the entry point to our program if __name__ == '__main__': print_program_info() # TODO - Create a Server object - # TODO - Call Ping method and print the results \ No newline at end of file + # TODO - Call Ping method and print the results + #The IP address is passed as a string to the Server class in the server.py module + ec2Server = Server.Server("52.41.99.1") From c67e56358044be406c1a31363b79789ade91a410 Mon Sep 17 00:00:00 2001 From: FisehaTessema4 <60725293+FisehaTessema4@users.noreply.github.com> Date: Tue, 30 Nov 2021 22:54:42 -0800 Subject: [PATCH 3/4] Added paramiko module --- Server.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Server.py b/Server.py index 68be930..0b979c7 100644 --- a/Server.py +++ b/Server.py @@ -1,5 +1,5 @@ - +import paramiko import os class Server: """ Server class for representing and manipulating servers. """ From 152c19eb9da73148713757751a9520014849f1e2 Mon Sep 17 00:00:00 2001 From: FisehaTessema4 <60725293+FisehaTessema4@users.noreply.github.com> Date: Tue, 30 Nov 2021 22:56:52 -0800 Subject: [PATCH 4/4] Added lines of code 16&17 --- main.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/main.py b/main.py index bd8f41f..53bbcda 100644 --- a/main.py +++ b/main.py @@ -13,3 +13,5 @@ def print_program_info(): # TODO - Call Ping method and print the results #The IP address is passed as a string to the Server class in the server.py module ec2Server = Server.Server("52.41.99.1") + print(server.ping()) + server.SSh_and_updated()