當前位置: 首頁>>代碼示例>>Python>>正文


Python VolumeOps.create_volume_for_sm方法代碼示例

本文整理匯總了Python中nova.virt.xenapi.volumeops.VolumeOps.create_volume_for_sm方法的典型用法代碼示例。如果您正苦於以下問題:Python VolumeOps.create_volume_for_sm方法的具體用法?Python VolumeOps.create_volume_for_sm怎麽用?Python VolumeOps.create_volume_for_sm使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在nova.virt.xenapi.volumeops.VolumeOps的用法示例。


在下文中一共展示了VolumeOps.create_volume_for_sm方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: XenSMDriver

# 需要導入模塊: from nova.virt.xenapi.volumeops import VolumeOps [as 別名]
# 或者: from nova.virt.xenapi.volumeops.VolumeOps import create_volume_for_sm [as 別名]

#.........這裏部分代碼省略.........
            session = XenAPISession(url, username, password)
            self._volumeops = VolumeOps(session)
        except Exception as ex:
            LOG.exception(ex)
            raise exception.Error(_("Failed to initiate session"))

        super(XenSMDriver, self).__init__(execute=utils.execute,
                                          sync_exec=utils.execute,
                                          *args, **kwargs)

    def do_setup(self, ctxt):
        """Setup includes creating or introducing storage repos
           existing in the database and destroying deleted ones."""

        # TODO purge storage repos
        self.ctxt = ctxt
        self._create_storage_repos(ctxt)

    def create_volume(self, volume):
        """Creates a logical volume. Can optionally return a Dictionary of
        changes to the volume object to be persisted."""

        # For now the scheduling logic will be to try to fit the volume in
        # the first available backend.
        # TODO better scheduling once APIs are in place
        sm_vol_rec = None
        backends = self.db.sm_backend_conf_get_all(self.ctxt)
        for backend in backends:
            # Ensure that storage repo exists, if not create.
            # This needs to be done because if nova compute and
            # volume are both running on this host, then, as a
            # part of detach_volume, compute could potentially forget SR
            self._create_storage_repo(self.ctxt, backend)
            sm_vol_rec = self._volumeops.create_volume_for_sm(volume,
                                                  backend['sr_uuid'])
            if sm_vol_rec:
                LOG.debug(_('Volume will be created in backend - %d')
                          % backend['id'])
                break

        if sm_vol_rec:
            # Update db
            sm_vol_rec['id'] = volume['id']
            sm_vol_rec['backend_id'] = backend['id']
            try:
                self.db.sm_volume_create(self.ctxt, sm_vol_rec)
            except Exception as ex:
                LOG.exception(ex)
                raise exception.Error(_("Failed to update volume in db"))

        else:
            raise exception.Error(_('Unable to create volume'))

    def delete_volume(self, volume):

        vol_rec = self.db.sm_volume_get(self.ctxt, volume['id'])

        try:
            # If compute runs on this node, detach could have disconnected SR
            backend_ref = self.db.sm_backend_conf_get(self.ctxt,
                                                      vol_rec['backend_id'])
            self._create_storage_repo(self.ctxt, backend_ref)
            self._volumeops.delete_volume_for_sm(vol_rec['vdi_uuid'])
        except Exception as ex:
            LOG.exception(ex)
            raise exception.Error(_("Failed to delete vdi"))
開發者ID:baz-reddwarf,項目名稱:nova,代碼行數:70,代碼來源:xensm.py


注:本文中的nova.virt.xenapi.volumeops.VolumeOps.create_volume_for_sm方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。