Commit 5a24210b authored by hardy's avatar hardy

check if container is running

parent 7a505f75
...@@ -235,6 +235,11 @@ class EPCManagement(): ...@@ -235,6 +235,11 @@ class EPCManagement():
mySSH.command('mkdir -p ' + self.SourceCodePath + '/scripts', '\$', 5) mySSH.command('mkdir -p ' + self.SourceCodePath + '/scripts', '\$', 5)
mySSH.command('cd /opt/oai-cn5g-fed/docker-compose', '\$', 5) mySSH.command('cd /opt/oai-cn5g-fed/docker-compose', '\$', 5)
mySSH.command('./core-network.sh start nrf spgwu', '\$', 30) mySSH.command('./core-network.sh start nrf spgwu', '\$', 30)
#time.sleep(10)
#response = mySSH.command3('docker inspect --format=\'{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}\' oai-amf', 5)
#self.MmeIPAddress = str(response[0],'utf-8')
#self.MmeIPAddress.rstrip()
#logging.debug('AMF IP Address ' + self.MmeIPAddress)
else: else:
logging.error('This option should not occur!') logging.error('This option should not occur!')
mySSH.close() mySSH.close()
...@@ -251,9 +256,11 @@ class EPCManagement(): ...@@ -251,9 +256,11 @@ class EPCManagement():
elif re.match('OAICN5G', self.Type, re.IGNORECASE): elif re.match('OAICN5G', self.Type, re.IGNORECASE):
mySSH = SSH.SSHConnection() mySSH = SSH.SSHConnection()
mySSH.open(self.IPAddress, self.UserName, self.Password) mySSH.open(self.IPAddress, self.UserName, self.Password)
mySSH.command2('docker inspect --format=\'{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}\' oai-amf', 5) response=mySSH.command3('docker container ls -f name=oai-amf', 10)
self.MmeIPAddress = str(mySSH.cmd2Results[0],'utf-8') if len(response)>1:
self.MmeIPAddress.rstrip() response=mySSH.command3('docker inspect --format=\'{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}\' oai-amf', 10)
tmp = str(response[0],'utf-8')
self.MmeIPAddress = tmp.rstrip()
logging.debug('AMF IP Address ' + self.MmeIPAddress) logging.debug('AMF IP Address ' + self.MmeIPAddress)
mySSH.close() mySSH.close()
...@@ -459,7 +466,7 @@ class EPCManagement(): ...@@ -459,7 +466,7 @@ class EPCManagement():
self.LogCollectOAICN5G() self.LogCollectOAICN5G()
logging.debug('Terminating OAI CN5G') logging.debug('Terminating OAI CN5G')
mySSH.command('cd /opt/oai-cn5g-fed/docker-compose', '\$', 5) mySSH.command('cd /opt/oai-cn5g-fed/docker-compose', '\$', 5)
mySSH.command('./core-network.sh stop nrf spgwu', '\$', 5) mySSH.command('./core-network.sh stop nrf spgwu', '\$', 30)
else: else:
logging.error('This should not happen!') logging.error('This should not happen!')
mySSH.close() mySSH.close()
......
...@@ -163,6 +163,18 @@ class SSHConnection(): ...@@ -163,6 +163,18 @@ class SSHConnection():
lSsh = subprocess.Popen(["ssh", "%s" % myHost, commandline],shell=False,stdout=subprocess.PIPE,stderr=subprocess.PIPE) lSsh = subprocess.Popen(["ssh", "%s" % myHost, commandline],shell=False,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
self.cmd2Results = str(lSsh.stdout.readlines()) self.cmd2Results = str(lSsh.stdout.readlines())
def command3(self, commandline, timeout, silent=False):
if not silent:
logging.debug(commandline)
self.cmd2Results = ''
myHost = self.username + '@' + self.ipaddress
# CAUTION: THIS METHOD IMPLIES THAT THERE ARE VALID SSH KEYS
# BETWEEN THE PYTHON EXECUTOR NODE AND THE REMOTE HOST
# OTHERWISE IT WON'T WORK
lSsh = subprocess.Popen(["ssh", "%s" % myHost, commandline],shell=False,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
return lSsh.stdout.readlines()
def close(self): def close(self):
self.ssh.timeout = 5 self.ssh.timeout = 5
self.ssh.sendline('exit') self.ssh.sendline('exit')
......
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