Пример #1
0
    def runWithClient(self, client, args):
        package_to_install = args[1]
        package_filename = os.path.basename(package_to_install)
        remote_filename = os.path.join('/tmp', package_filename)

        sftp_callback = MakeProgressFunc(package_filename, PROGRESS_WIDTH)
        sftp = client.openSftp()
        sftp.put(package_to_install, remote_filename, callback=sftp_callback)
        sftp.close()
        client.close()
        print()

        channel = client.shellExec("sudo /usr/sbin/mdt-install-package {0}; "
                                   "rm -f {0}".format(remote_filename),
                                   allocPty=True)
        cons = console.Console(channel, sys.stdin)
        return cons.run()
Пример #2
0
    def runWithClient(self, client, args):
        # Setup this session now, since once we remove the key from
        # authorized_keys, we won't be able to use execSession.
        channel = client.openChannel()

        sftp = client.openSftp()
        try:
            sftp.chdir('/home/mendel/.ssh')
        except FileNotFoundError as e:
            print('No keys were previously pushed to the board.')
        else:
            lines = []

            with sftp.open('/home/mendel/.ssh/authorized_keys', 'r') as fp:
                lines = fp.readlines()

            with sftp.open('/home/mendel/.ssh/authorized_keys', 'w') as fp:
                for line in lines:
                    if ' mdt' not in line:
                        print('wrote: {0}'.format(line))
                        fp.write(line)

        channel.exec_command("sudo systemctl restart mdt-keymaster")
        cons = console.Console(channel, sys.stdin)
        try:
            cons.run()
        except console.ConnectionClosedError as e:
            if e.exit_code:
                print('`systemctl restart mdt-keymaster` exited with code {0}'.
                      format(e.exit_code))
                print(
                    'Your device may be in an inconsistent state. Verify using'
                )
                print('the serial console.')
            else:
                print('Successfully reset {0}'.format(self.device))
            return e.exit_code
Пример #3
0
 def runWithClient(self, client, args):
     channel = client.openShell()
     cons = console.Console(channel, sys.stdin)
     return cons.run()
Пример #4
0
 def runWithClient(self, client, args):
     channel = client.shellExec("sudo reboot-bootloader", allocPty=True)
     cons = console.Console(channel, sys.stdin)
     return cons.run()
Пример #5
0
 def runWithClient(self, client, args):
     channel = client.shellExec(' '.join(args[1:]), allocPty=True)
     cons = console.Console(channel, sys.stdin)
     return cons.run()