Advertisement
Guest User

Untitled

a guest
Dec 3rd, 2018
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.39 KB | None | 0 0
  1. def install_package(dss, package_name):
  2.     print("Installing package: {}".format(package_name))
  3.     with paramiko.SSHClient() as ssh:
  4.         ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  5.         ssh.connect(hostname=dss.host, username=dss.username, password=dss.password)
  6.         channel = ssh.invoke_shell()
  7.         LogInAsRoot(channel, dss)
  8.         commands = ('opkg update', 'opkg install {}'.format(package_name))
  9.         for command in commands:
  10.             send_command_with_confirmation(channel=channel, command=command, delay=20, print_response=True)
  11.         print("Package {} installed properly".format(package_name))
  12.  
  13. def checkIfPackageIsInstalled(dss, package_name):
  14.     print("Checking if package {} is installed".format(package_name))
  15.     with paramiko.SSHClient() as ssh:
  16.         ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  17.         ssh.connect(hostname=dss.host, username=dss.username, password=dss.password)
  18.         channel = ssh.invoke_shell()
  19.         LogInAsRoot(channel, dss)
  20.         command = 'opkg list-installed | grep {}\n'.format(package_name)
  21.         try:
  22.             '''
  23.            exit code 0 - package is installed
  24.            exit code 1 - package not installed
  25.            '''
  26.             send_command_with_confirmation(channel, command)
  27.         except ProblemOccuredWhileExecutingCommand:
  28.             return False
  29.         return True
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement