Esempio n. 1
0
    def save(self,
             backup_id=None,
             src=None,
             timestamp=None,
             force=None,
             scrub=None):
        """
        Create a new backup for a given volume or snapshot

        If you provide a valid --src and backup_id, a snapshot can
        be created for you.

        If can also omit --src if you provide the backup_id of a
        valid snapshot.  The `--timestamp` option is ignored if in this
        case.

        You can specify `--scrub` to wipe the snapshot volume,
        otherwise you will be prompted to simply remove it (you can
        bypass prompts with `--force`)

        WARNING: running this command does not LOCK the volume while
        the save is in progress
        """
        helper = self.load_conf(self.config)
        helper.volumes.skip_fork = True

        volume = helper.volumes.get(src or backup_id)
        if not src and not volume['origin']:
            print "--src is required if backup_id isn't a snapshot"
            return 1

        # The id passed was NOT a snapshot id
        if not volume['origin']:
            if not confirm("Create new snapshot of '%s' for backup '%s'" %
                           (volume['id'], backup_id),
                           force=force):
                return
            # Create a new snapshot
            volume = helper.volumes.create_snapshot(volume['id'],
                                                    backup_id,
                                                    timestamp=timestamp)
        else:
            # snapshot id was passed
            backup_id = volume['backup_id']

        # Start the backup job
        helper.backups.save(volume, backup_id)
        if scrub:
            helper.volumes.delete(volume)
        elif confirm('Remove snapshot', force=force):
            helper.volumes.remove(volume['path'])
Esempio n. 2
0
    def deploy(self, id=None, all=None):
        """ Mark a PENDING node(s) ACTIVE  """
        if not all and not id:
            return self._parser.print_help()

        if all:
            nodes = self.request('/nodes')
            nodes = [n for n in nodes if n['status'] == 'PENDING']
        else:
            node = self.request('/nodes/%s' % id)
            if node['status'] != 'PENDING':
                if not confirm("Node '%s' status is '%s' set to 'ACTIVE'" %
                               (node['id'], node['status'])):
                    return 1
            nodes = [node]

        results = []
        for node in nodes:
            resp = self.request('/nodes/%s' % node['id'],
                                method='POST',
                                params={'status': 'ACTIVE'})
            results.append(resp)

        if results:
            self.display(results, ['id', 'status'])
            return 0
        print "No nodes in 'PENDING' status"
Esempio n. 3
0
    def deploy(self, id=None, all=None):
        """ Mark a PENDING node(s) ACTIVE  """
        if not all and not id:
            return self._parser.print_help()

        if all:
            nodes = self.request('/nodes')
            nodes = [n for n in nodes if n['status'] == 'PENDING']
        else:
            node = self.request('/nodes/%s' % id)
            if node['status'] != 'PENDING':
                if not confirm("Node '%s' status is '%s' set to 'ACTIVE'"
                               % (node['id'], node['status'])):
                    return 1
            nodes = [node]

        results = []
        for node in nodes:
            resp = self.request('/nodes/%s' % node['id'], method='POST',
                                params={'status': 'ACTIVE'})
            results.append(resp)

        if results:
            self.display(results, ['id', 'status'])
            return 0
        print "No nodes in 'PENDING' status"
Esempio n. 4
0
    def save(self, backup_id=None, src=None, timestamp=None,
             force=None, scrub=None):
        """
        Create a new backup for a given volume or snapshot

        If you provide a valid --src and backup_id, a snapshot can
        be created for you.

        If can also omit --src if you provide the backup_id of a
        valid snapshot.  The `--timestamp` option is ignored if in this
        case.

        You can specify `--scrub` to wipe the snapshot volume,
        otherwise you will be prompted to simply remove it (you can
        bypass prompts with `--force`)

        WARNING: running this command does not LOCK the volume while
        the save is in progress
        """
        helper = self.load_conf(self.config)
        helper.volumes.skip_fork = True

        volume = helper.volumes.get(src or backup_id)
        if not src and not volume['origin']:
            print "--src is required if backup_id isn't a snapshot"
            return 1

        # The id passed was NOT a snapshot id
        if not volume['origin']:
            if not confirm("Create new snapshot of '%s' for backup '%s'"
                           % (volume['id'], backup_id), force=force):
                return
            # Create a new snapshot
            volume = helper.volumes.create_snapshot(volume['id'],
                                                    backup_id,
                                                    timestamp=timestamp)
        else:
            # snapshot id was passed
            backup_id = volume['backup_id']

        # Start the backup job
        helper.backups.save(volume, backup_id)
        if scrub:
            helper.volumes.delete(volume)
        elif confirm('Remove snapshot', force=force):
            helper.volumes.remove(volume['path'])
Esempio n. 5
0
    def scrub(self, volume=None, byte=None):
        """
        Scrub a volume with 0x03:
            > lunr-storage-admin tools scrub -b 03 -v \
                /dev/lunr-volume/8275d343-365b-4966-a652-43271adbe9e5
        """
        byte = byte.decode('hex')
        if byte != '\x00':
            if not confirm('write %s to disk' % repr(byte)):
                return

        helper = self.load_conf(self.config)
        if os.path.exists(volume):
            path = volume
        else:
            path = helper.volumes.get(volume)['path']
        helper.volumes.scrub.scrub_volume(path, byte=byte)
Esempio n. 6
0
    def scrub(self, volume=None, byte=None):
        """
        Scrub a volume with 0x03:
            > lunr-storage-admin tools scrub -b 03 -v \
                /dev/lunr-volume/8275d343-365b-4966-a652-43271adbe9e5
        """
        byte = byte.decode('hex')
        if byte != '\x00':
            if not confirm('write %s to disk' % repr(byte)):
                return

        helper = self.load_conf(self.config)
        if os.path.exists(volume):
            path = volume
        else:
            path = helper.volumes.get(volume)['path']
        helper.volumes.scrub.scrub_volume(path, byte=byte)
Esempio n. 7
0
    def copy(self, src, dest):
        """
        Copy all data from one volume to another
            > lunr-storage-admin tools copy \
                /dev/lunr-volume/8275d343-365b-4966-a652-43271adbe9e5 \
                /dev/lunr-volume/b206deda-df9f-473c-8a72-b3df09dd3b1d
        """
        helper = self.load_conf(self.config)

        if not os.path.exists(src):
            src = helper.volumes.get(src)['path']

        if not os.path.exists(dest):
            dest = helper.volumes.get(dest)['path']

        if not confirm("Copy from '%s' to '%s'" % (src, dest)):
            return

        ISCSIDevice.copy_volume(src, dest)
Esempio n. 8
0
    def copy(self, src, dest):
        """
        Copy all data from one volume to another
            > lunr-storage-admin tools copy \
                /dev/lunr-volume/8275d343-365b-4966-a652-43271adbe9e5 \
                /dev/lunr-volume/b206deda-df9f-473c-8a72-b3df09dd3b1d
        """
        helper = self.load_conf(self.config)

        if not os.path.exists(src):
            src = helper.volumes.get(src)['path']

        if not os.path.exists(dest):
            dest = helper.volumes.get(dest)['path']

        if not confirm("Copy from '%s' to '%s'" % (src, dest)):
            return

        ISCSIDevice.copy_volume(src, dest)