cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
999
Views
2
Helpful
3
Replies

Expressway Upgrade from CLI?

jmorton1
Level 1
Level 1

Is there a way to upgrade expressway via CLI? The web interface is not working.

3 Replies 3

Yes that is possible. We just completed a MVP of a script (Python) run from Ansible for upgrades of our Expressway systems. I don’t have the commands at hand, but I can look it up a little later in the script.



Response Signature


This is a snippet of the script I mentioned before. I'm not the one that have developed the script, so I don't have any deep or first hand information on how it works, but hopefully you'll be of some help with it anyway.

import paramiko
import subprocess

import time
import os

from paramiko import ssh_exception
from scp import SCPClient
from distutils.version import StrictVersion



from src.utils.logger import *

# Initializing logger
console_logs = Logger(__name__).write_log()

class SshConnection:

    def __init__(self, server, username, password, imagePath, imageVersion):

        self.server = server
        self.username = username
        self.password = password
        self.imagePath = imagePath
        self.imageVersion = imageVersion


    def open_ssh_connection(self):

        if self.check_availability():
            try:
                console_logs.info(f'Connecting with {self.server}')
                self.client = paramiko.client.SSHClient()
                self.client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
                self.client.connect(self.server, username=self.username, password=self.password)
                self.scp = SCPClient(self.client.get_transport())
                return self.client, f"Successfully connected with {self.server}"

            except TimeoutError:
                console_logs.exception(f"{self.server} seems to be offline.")
                logging.exception(TimeoutError)
                return False, "Time out error, server seems to be offline."

            except ssh_exception.AuthenticationException:
                console_logs.exception(f"{self.server} failed connection. Authentication exception.")
                return False, "Unable to authenticate with provided credentials, please check Password State root credentials."

            except ssh_exception.NoValidConnectionsError:
                console_logs.exception(f"{self.server} failed connection. Authentication exception.")
                logging.exception(ssh_exception.NoValidConnectionsError)
                return False, "Multiple connection attempts were made and none succeeded."            
  
        else:
            return False, f"Server seems to be offline."



    def close_connections(self):

        try:
            self.client.close()
            self.scp.close()
            console_logs.info("SSH and SCP connections have been closed successfully.")

        except Exception as e:
            console_logs.info("Unable to close SSH and SCP connections. Check logs for further information.")
            console_logs.exception(e)


        
    def update_server(self, serverInstallPath):
        console_logs.info("Transferring upgrade image to server. This may take several minutes...")
        self.scp.put(self.imagePath, serverInstallPath)

        sleeptime, waittime = 60, 6000
        starttime = time.time()

        console_logs.info("Checking if installation has been successfull, please wait...")
        while time.time() - starttime < waittime:
            stdin, stdout,stderr = self.client.exec_command("ls -l /tmp/install*")
            response = stdout.read().decode()
            if 'No such file or directory' in response:
                console_logs.error('Installation has failed.')
                console_logs.error('FAILED: {}\n{}'.format(self.server,response))
                return False
            if 'install-ok' in response:
                console_logs.info('Successful installation on server {}'.format(self.server))
                return True
            console_logs.info(f"Installation still in progress, script will sleep for {sleeptime} seconds and allow installation progress to finish.")
            time.sleep(sleeptime)
            console_logs.info("Script has awaken and will check installation progress once again...")

        console_logs.error('Installation has failed. Please check error logs for further details.')
        console_logs.error('TIMEOUT: {}\n{}'.format(self.server,response))
        return False


 



Response Signature


For more information have a look at this link to Git and this presentation (BRKCOC-2996) from Cisco Live.



Response Signature