Skip to content
Open
Show file tree
Hide file tree
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
25 changes: 24 additions & 1 deletion Server.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,33 @@

import paramiko
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
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
10 changes: 7 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
# 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
# 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()