Commit de6d928d authored by hardy's avatar hardy

fix remote access for LogRotation method

parent 65aa1305
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
#--------------------------------------------------------------------- #---------------------------------------------------------------------
#USAGE: #USAGE:
# log=Log_Mgt(IPAddress,Password,Path) # log=Log_Mgt(Username,IPAddress,Password,Path)
# log.LogRotation() # log.LogRotation()
...@@ -38,7 +38,8 @@ import math ...@@ -38,7 +38,8 @@ import math
class Log_Mgt: class Log_Mgt:
def __init__(self,IPAddress,Password,Path): def __init__(self,Username, IPAddress,Password,Path):
self.Username=Username
self.IPAddress=IPAddress self.IPAddress=IPAddress
self.Password=Password self.Password=Password
self.path=Path self.path=Path
...@@ -49,7 +50,7 @@ class Log_Mgt: ...@@ -49,7 +50,7 @@ class Log_Mgt:
def __CheckAvailSpace(self): def __CheckAvailSpace(self):
HOST=self.IPAddress HOST=self.Username+'@'+self.IPAddress
COMMAND="df "+ self.path COMMAND="df "+ self.path
ssh = subprocess.Popen(["ssh", "%s" % HOST, COMMAND],shell=False,stdout=subprocess.PIPE,stderr=subprocess.PIPE) ssh = subprocess.Popen(["ssh", "%s" % HOST, COMMAND],shell=False,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
result = ssh.stdout.readlines() result = ssh.stdout.readlines()
...@@ -58,7 +59,7 @@ class Log_Mgt: ...@@ -58,7 +59,7 @@ class Log_Mgt:
return tmp[3] #return avail space from the line return tmp[3] #return avail space from the line
def __GetOldestFile(self): def __GetOldestFile(self):
HOST=self.IPAddress HOST=self.Username+'@'+self.IPAddress
COMMAND="ls -rtl "+ self.path #-rtl will bring oldest file on top COMMAND="ls -rtl "+ self.path #-rtl will bring oldest file on top
ssh = subprocess.Popen(["ssh", "%s" % HOST, COMMAND],shell=False,stdout=subprocess.PIPE,stderr=subprocess.PIPE) ssh = subprocess.Popen(["ssh", "%s" % HOST, COMMAND],shell=False,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
result = ssh.stdout.readlines() result = ssh.stdout.readlines()
...@@ -68,7 +69,7 @@ class Log_Mgt: ...@@ -68,7 +69,7 @@ class Log_Mgt:
def __AvgSize(self): def __AvgSize(self):
HOST=self.IPAddress HOST=self.Username+'@'+self.IPAddress
COMMAND="ls -rtl "+ self.path COMMAND="ls -rtl "+ self.path
ssh = subprocess.Popen(["ssh", "%s" % HOST, COMMAND],shell=False,stdout=subprocess.PIPE,stderr=subprocess.PIPE) ssh = subprocess.Popen(["ssh", "%s" % HOST, COMMAND],shell=False,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
result = ssh.stdout.readlines() result = ssh.stdout.readlines()
...@@ -94,7 +95,7 @@ class Log_Mgt: ...@@ -94,7 +95,7 @@ class Log_Mgt:
logging.debug("Avail Space : " + str(avail_space) + " / Artifact Avg Size : " + str(avg_size)) logging.debug("Avail Space : " + str(avail_space) + " / Artifact Avg Size : " + str(avg_size))
if avail_space < 2*avg_size: #reserved space is 2x artifact file ; oldest file will be deleted if avail_space < 2*avg_size: #reserved space is 2x artifact file ; oldest file will be deleted
oldestfile=self.__GetOldestFile() oldestfile=self.__GetOldestFile()
HOST=self.IPAddress HOST=self.Username+'@'+self.IPAddress
COMMAND="echo " + self.Password + " | sudo -S rm "+ self.path + "/" + oldestfile COMMAND="echo " + self.Password + " | sudo -S rm "+ self.path + "/" + oldestfile
logging.debug(COMMAND) logging.debug(COMMAND)
ssh = subprocess.Popen(["ssh", "%s" % HOST, COMMAND],shell=False,stdout=subprocess.PIPE,stderr=subprocess.PIPE) ssh = subprocess.Popen(["ssh", "%s" % HOST, COMMAND],shell=False,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
......
...@@ -168,7 +168,7 @@ class Module_UE: ...@@ -168,7 +168,7 @@ class Module_UE:
mySSH.command('echo $USER; echo ' + self.HostPassword + ' | nohup sudo -S zip -r '+destination+' '+source+' &','\$', 10) mySSH.command('echo $USER; echo ' + self.HostPassword + ' | nohup sudo -S zip -r '+destination+' '+source+' &','\$', 10)
mySSH.close() mySSH.close()
#post action : log cleaning to make sure enough space is reserved for the next run #post action : log cleaning to make sure enough space is reserved for the next run
Log_Mgt=cls_log_mgt.Log_Mgt(self.HostIPAddress, self.HostPassword, self.LogStore) Log_Mgt=cls_log_mgt.Log_Mgt(self.HostUsername,self.HostIPAddress, self.HostPassword, self.LogStore)
Log_Mgt.LogRotation() Log_Mgt.LogRotation()
else: else:
destination="" destination=""
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment