def attach_volume(vol_id, connection_info): """ Attach volume with os-brick. """ if os_brick is None: raise se.ManagedVolumeNotSupported("Cannot import os_brick.initiator") db = managedvolumedb.open() with closing(db): _add_volume(db, vol_id, connection_info) log.debug("Starting attach volume %s connection_info=%s", vol_id, connection_info) try: attachment = run_helper("attach", connection_info) try: path = _resolve_path(vol_id, connection_info, attachment) db.update_volume(vol_id, path=path, attachment=attachment, multipath_id=attachment.get("multipath_id")) _invalidate_lvm_filter(attachment) except: _silent_detach(connection_info, attachment) raise except: _silent_remove(db, vol_id) raise log.debug("Attached volume %s attachment=%s", vol_id, attachment) return {"result": {'attachment': attachment, 'path': path}}
def connector_info(): """ Get connector information from os-brick. If not running as root, use supervdsm to invoke this function as root. """ if os_brick is None: raise se.ManagedVolumeNotSupported("Cannot import os_brick.initiator") log.debug("Starting get connector_info") return run_helper("connector_info")
def detach_volume(vol_id): """ Detach volume with os-brick. """ if os_brick is None: raise se.ManagedVolumeNotSupported("Cannot import os_brick.initiator") db = managedvolumedb.open() with closing(db): try: vol_info = db.get_volume(vol_id) except managedvolumedb.NotFound: return log.debug("Starting detach volume %s vol_info=%s", vol_id, vol_info) if "path" in vol_info and os.path.exists(vol_info["path"]): run_helper("detach", vol_info) db.remove_volume(vol_id)
def wrapper(*args, **kwargs): if os_brick is None: raise se.ManagedVolumeNotSupported("Cannot import os_brick") return func(*args, **kwargs)