示例#1
0
文件: csvol.py 项目: ck1981/scalarizr
    def _detach(self, force=False, **kwds):
        self._check_connection()
        volume_id = self.id or self._native_vol.id

        # Remove volume from SCSI host
        if self.device and \
            ((self._native_vol and self._native_vol.virtualmachineid == __cloudstack__['instance_id']) or \
                not self._native_vol):
            if linux.which('lsscsi'):
                scsi = coreutils.lsscsi().get(self.device)
                if scsi:
                    LOG.debug('Removing device from SCSI host')
                    name = '/sys/class/scsi_host/host{host}/device/target{host}:{bus}:{target}/{host}:{bus}:{target}:{lun}/delete'.format(**scsi)
                    with open(name, 'w') as fp:
                        fp.write('1')

        LOG.debug('Detaching volume %s', volume_id)
        try:
            self._conn.detachVolume(volume_id)
        except Exception, e:
            if 'not attached' in str(e) or \
                'Please specify a VM that is either running or stopped' in str(e):
                pass
            else:
                raise
示例#2
0
    def _detach(self, force=False, **kwds):
        self._check_connection()
        volume_id = self.id or self._native_vol.id

        # Remove volume from SCSI host
        if self.device and \
            ((self._native_vol and self._native_vol.virtualmachineid == __cloudstack__['instance_id']) or \
                not self._native_vol):
            if linux.which('lsscsi'):
                scsi = coreutils.lsscsi().get(self.device)
                if scsi:
                    LOG.debug('Removing device from SCSI host')
                    name = '/sys/class/scsi_host/host{host}/device/target{host}:{bus}:{target}/{host}:{bus}:{target}:{lun}/delete'.format(**scsi)
                    with open(name, 'w') as fp:
                        fp.write('1')

        LOG.debug('Detaching volume %s', volume_id)
        try:
            self._conn.detachVolume(volume_id)
        except Exception, e:
            if 'not attached' in str(e) or \
                'Please specify a VM that is either running or stopped' in str(e):
                pass
            else:
                raise
示例#3
0
def test_lsscsi():
    out_filename = os.path.abspath(__file__ + "/../../../fixtures/linux/lsscsi.out")
    m = mock.Mock(return_value=[open(out_filename).read()])
    with mock.patch("scalarizr.linux.system", m):
        ret = coreutils.lsscsi()
        assert set(ret.keys()) == set(["/dev/sr0", "/dev/sda", "/dev/sdb"])
        sdb = ret["/dev/sdb"]
        assert sdb["host"] == "2"
        assert sdb["bus"] == "0"
        assert sdb["target"] == "0"
        assert sdb["lun"] == "0"

        sda = ret["/dev/sda"]
        assert sda["target"] == "1"
        assert sda["host"] == "0"
def test_lsscsi():
    out_filename = os.path.abspath(__file__ +
                                   '/../../../fixtures/linux/lsscsi.out')
    m = mock.Mock(return_value=[open(out_filename).read()])
    with mock.patch('scalarizr.linux.system', m):
        ret = coreutils.lsscsi()
        assert set(ret.keys()) == set(['/dev/sr0', '/dev/sda', '/dev/sdb'])
        sdb = ret['/dev/sdb']
        assert sdb['host'] == '2'
        assert sdb['bus'] == '0'
        assert sdb['target'] == '0'
        assert sdb['lun'] == '0'

        sda = ret['/dev/sda']
        assert sda['target'] == '1'
        assert sda['host'] == '0'