Ejemplo n.º 1
0
    def download_snapshot(
        self,
        zpool,
        zvol,
        remotehost,
        ):
        params = {
            'user': self.imgUser,
            'zpool': zpool,
            'zvol': zvol,
            'snap_name': self.snapname(),
            'remotehost': remotehost,
            'remotehost_zpool': self.get_node_zpool(remotehost),
            'local_last_snapshot': self.find_last_snapshot(zpool,
                    zvol),
            }

        download_speed = imgstorage.get_attribute('img_download_speed',
                remotehost, self.logger)
        params['throttle'] = (' | pv -L %s -q '
                              % download_speed if download_speed else ''
                              )

        runCommand(['su', self.imgUser, '-c',
                   '/usr/bin/ssh %(remotehost)s "/sbin/zfs snap %(remotehost_zpool)s/%(zvol)s@%(snap_name)s"'
                    % params])
        runCommand(['su %(user)s -c \'/usr/bin/ssh %(remotehost)s "/sbin/zfs send -i %(remotehost_zpool)s/%(zvol)s@%(local_last_snapshot)s %(remotehost_zpool)s/%(zvol)s@%(snap_name)s"\' %(throttle)s | zfs receive -F %(zpool)s/%(zvol)s'
                    % params], shell=True)

        def destroy_local_snapshot(snapshot):
            runCommand(['/sbin/zfs', 'destroy', snapshot])

        out = runCommand([
            '/sbin/zfs',
            'list',
            '-Hpr',
            '-t',
            'snapshot',
            '-o',
            'name',
            '-s',
            'creation',
            '%s/%s' % (zpool, zvol),
            ])
	## Find only the snapshots that we have created
	out = filter(lambda x : x.find(self.prefix) >= 0, out)
        map(destroy_local_snapshot, out[:-2])
Ejemplo n.º 2
0
    def upload_snapshot(
        self,
        zpool,
        zvol,
        remotehost,
        ):
        params = {
            'user': self.imgUser,
            'zpool': zpool,
            'zvol': zvol,
            'snap_name': self.snapname(),
            'remotehost': remotehost,
            'remotehost_zpool': self.get_node_zpool(remotehost),
            }

        upload_speed = imgstorage.get_attribute('img_upload_speed',
                remotehost, self.logger)
        params['throttle'] = (' | pv -L %s -q '
                              % upload_speed if upload_speed else '')

        runCommand(['zfs', 'snap', '%(zpool)s/%(zvol)s@%(snap_name)s'
                   % params])
        runCommand(['zfs send %(zpool)s/%(zvol)s@%(snap_name)s %(throttle)s | su %(user)s -c \'ssh %(remotehost)s "/sbin/zfs receive -F %(remotehost_zpool)s/%(zvol)s"\''
                    % params], shell=True)
Ejemplo n.º 3
0
 def get_node_zpool(self, remotehost):
     return imgstorage.get_attribute('vm_container_zpool',
             remotehost, self.logger)
Ejemplo n.º 4
0
    def is_sync_node(self, remotehost):
        """ Get information from attributes if image sync is enabled for the
        node"""

        return rocks.util.str2bool(imgstorage.get_attribute('img_sync', remotehost,
                self.logger))