def distribute_pubkey(self, confs=[]): for x in confs: port = 22 url, password = x[0], x[1] if ':' in url: url, port = url.split(':') sh.sshpass('-p', password, 'ssh-copy-id', '-i', self.pubkey_path, url, '-p', port, '-o', 'StrictHostKeyChecking no')
def syncbackups(self, cluster): backupdirpattern = "{}{}".format(LOCAL_BACKUP_PATH, cluster.get("cluster")) r = sshpass( "-p", cluster.get("password"), "rsync", "-avz", '{}@{}:{}'.format(cluster.get("login"), cluster.get("host"), BACKUP_PATH), backupdirpattern) print(r)
def copy_utils(self): """ a """ r = sshpass("-p", self.ssh_pass, "rsync","-avz", "./fabric_common/templates/rpi3-arch/local-scripts", 'deploy@{}:~/Developer'.format(self.ssh_host) ) logi(title="envoie scriptes",msg=r) self.bash.sudo("cp -r ~/Developer/local-scripts/* {}/ || /bin/true".format(self.image_path)) self.bash.sudo("chmod +x {}/clean-img.sh".format(self.image_path))
def setup_template(self): """ """ r = sshpass("-p", self.ssh_passwd, "rsync", "-avz", "./fabric_common/templates/posbox/", 'deploy@{}:{}'.format(self.host, self.appDir)) logi(title="envoie via ssh des templates", msg=r) if not exists(self.cnx, self.appDir + '/odoo_src'): path_release = _pull_release(release=self.ODOO_POS_VERSION) r = sshpass("-p", self.ssh_passwd, "rsync", "-avz", path_release, 'deploy@{}:{}'.format(self.host, self.appDir)) logi(title="envoie via ssh de l'instance des sources odoo", msg=r) self.cnx.run( 'cd {} && unzip {}.zip && mkdir odoo_src && mv odoo-{}/* odoo_src && rm -rf odoo-{} && rm {}.zip' .format(self.appDir, self.ODOO_POS_VERSION, self.ODOO_POS_VERSION, self.ODOO_POS_VERSION, self.ODOO_POS_VERSION))
def process_torrents(): client_connected = False try: yield client.connect(host=deluge_host, username=deluge_username, password=deluge_password) client_connected = True log.info("Connected to deluge") torrents = yield client.core.get_torrents_status({}, ['name','label','progress','save_path','state','files']) downloads = [{ 'id' : id, 'location' : torrent['save_path'] + '/' + torrent['name'], 'label' : torrent['label'] } for id, torrent in torrents.iteritems() if torrent['progress'] == 100 and torrent['label'].startswith('download')] log.info('List of torrents to download: %s', downloads) for torrent in downloads: log.info('Downloading torrent: %s', torrent) remote_location = torrent['location'].replace(' ', '\ ').replace('(', '\(').replace(')', '\)').replace('&', '\&').replace('[', '\[').replace(']', '\]').replace('\'', '\\\'') save_location = complete_dir + '/' + torrent['label'] log.info('Remote location: %s', remote_location) log.info('Save location: %s', save_location) source = rsync_username + "@" + deluge_host + ":" + remote_location result = sshpass("-p", rsync_password, "rsync", "-hre", "ssh -o StrictHostKeyChecking=no", "-T", partial_dir, "--partial", "--progress", source, save_location) log.info('Got rsync result: %s', result) if (result.exit_code == 0): log.info('Remove label from torrent: %s', torrent) yield client.label.set_torrent(torrent['id'], 'No Label') except Exception as err: log.exception("Error downloading torrent") finally: if client_connected: log.info('Disconnecting deluge client') yield client.disconnect() log.info('Stopping reactor') reactor.stop()
def common_config(self): self.chroot(path=self.image_path, cmd ="mkdir -p /root/Developer") r = sshpass("-p", self.ssh_pass, "rsync","-avz", "./fabric_common/templates/rpi3-arch", 'deploy@{}:~/Developer'.format(self.ssh_host) ) logi(title="envoie template",msg=r) self.bash.sudo("cp -r ~/Developer/rpi3-arch {}/mnt/root/Developer || /bin/true".format(self.image_path)) self.chroot(path=self.image_path, cmd ="cp -a /root/Developer/rpi3-arch/etc/. /etc/") self.chroot(path=self.image_path, cmd ="chmod +x /root/Developer/rpi3-arch/remoted-scripts/setup.sh") # corromp kernel """
from sh import mkdir from sh import sshpass parser = argparse.ArgumentParser(description='Process gateway logs.') parser.add_argument('-g', '--gateway', help='SSH style path to gateway logs (e.g. swarmgateway.local:/media/sdcard)') parser.add_argument('-p', '--password', help='gateway login password') args = parser.parse_args() with tempfile.TemporaryDirectory() as tmpdirname: print('Copy all gateway logs to this computer') sshpass('-p', args.password, 'scp', '-o', 'PreferredAuthentications=keyboard-interactive,password', '-o', 'PubkeyAuthentication=no', 'debian@{}/gateway.log*'.format(args.gateway), '{}/'.format(tmpdirname)) print('Done copying, start parsing') devices = {} logs = glob.glob(tmpdirname + '/gateway.log*') for log in logs: name, ext = os.path.splitext(log) print('Handling {}'.format(log)) # Uncompress this log file if needed if ext == '.gz': print('Have to uncompress first') gzip('-d', log)
parser = argparse.ArgumentParser(description='Process gateway logs.') parser.add_argument( '-g', '--gateway', help= 'SSH style path to gateway logs (e.g. swarmgateway.local:/media/sdcard)') parser.add_argument('-p', '--password', help='gateway login password') args = parser.parse_args() with tempfile.TemporaryDirectory() as tmpdirname: print('Copy all gateway logs to this computer') sshpass('-p', args.password, 'scp', '-o', 'PreferredAuthentications=keyboard-interactive,password', '-o', 'PubkeyAuthentication=no', 'debian@{}/gateway.log*'.format(args.gateway), '{}/'.format(tmpdirname)) print('Done copying, start parsing') devices = {} logs = glob.glob(tmpdirname + '/gateway.log*') for log in logs: name, ext = os.path.splitext(log) print('Handling {}'.format(log)) # Uncompress this log file if needed if ext == '.gz': print('Have to uncompress first')