コード例 #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
ファイル: csvol.py プロジェクト: AnyBucket/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
コード例 #3
0
ファイル: test_coreutils.py プロジェクト: chenleji/scalarizr
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"
コード例 #4
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'