Example #1
0
 def from_iscsi_connection(id):
     for line in execute('iscsiadm', '-m', 'session').split('\n'):
         if re.search(id, line):
             conn = re.split('\s*', line)
             ip, port, _ = re.split(':|,', conn[2])
             print conn[3], ip, port
             return ISCSIDevice(conn[3], ip, port)
     raise RuntimeError("Unable to find iscsi connection for '%s'" % id)
Example #2
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)
Example #3
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)
Example #4
0
    def create_clone(self, volume_id, clone_id, iqn, iscsi_ip, iscsi_port,
                     callback=None, lock=None, cinder=None):
        volume = self.get(volume_id)
        size = volume['size'] / 1024 / 1024 / 1024
        logger.info("Cloning source '%s' to volume '%s'" %
                    (volume_id, clone_id))
        snapshot_name = uuid.uuid4()
        snapshot = self.create_snapshot(volume_id, snapshot_name,
                                        clone_id=clone_id, type_='clone')
        logger.info("Snapshot to clone id: '%s'" % snapshot['id'])
        try:
            new_volume = ISCSIDevice(iqn, iscsi_ip, iscsi_port)
            new_volume.connect()
        except (ISCSILoginFailed, ISCSINotConnected):
            msg = "Unable to open iscsi connection to %s:%s - %s" % \
                  (iscsi_ip, iscsi_port, iqn)
            logger.error(msg)
            self.delete(snapshot['id'])
            raise ServiceUnavailable(msg)

        spawn(lock, self._copy_clone, snapshot, clone_id, size, new_volume,
              cinder, callback=callback, skip_fork=self.skip_fork)
Example #5
0
    def create_clone(self, volume_id, clone_id, iqn, iscsi_ip, iscsi_port,
                     callback=None, lock=None, cinder=None):
        volume = self.get(volume_id)
        size = volume['size'] / 1024 / 1024 / 1024
        logger.info("Cloning source '%s' to volume '%s'" %
                    (volume_id, clone_id))
        snapshot_name = uuid.uuid4()
        snapshot = self.create_snapshot(volume_id, snapshot_name,
                                        clone_id=clone_id, type_='clone')
        logger.info("Snapshot to clone id: '%s'" % snapshot['id'])
        try:
            new_volume = ISCSIDevice(iqn, iscsi_ip, iscsi_port)
            new_volume.connect()
        except (ISCSILoginFailed, ISCSINotConnected):
            msg = "Unable to open iscsi connection to %s:%s - %s" % \
                  (iscsi_ip, iscsi_port, iqn)
            logger.error(msg)
            self.delete(snapshot['id'])
            raise ServiceUnavailable(msg)

        spawn(lock, self._copy_clone, snapshot, clone_id, size, new_volume,
              cinder, callback=callback, skip_fork=self.skip_fork)