Exemplo n.º 1
0
def create_lv(ns, vg, name, size):
    """
    Create new Logical Volume on given Volume Group.

    :type vg: LMIInstance/LMI_VGStoragePool or string
    :param vg: Volume Group to allocate the volume from.
    :type name: string
    :param name: Name of the logical volume.
    :type size: int
    :param size: Size of the logical volume in bytes.
    :rtype: LMIInstance/LMI_LVStorageExtent
    """
    vg = common.str2vg(ns, vg)
    service = ns.LMI_StorageConfigurationService.first_instance()
    (ret, outparams, err) = service.SyncCreateOrModifyLV(ElementName=name,
                                                         Size=size,
                                                         InPool=vg)
    if ret != 0:
        if err:
            raise LmiFailed("Cannot create the logical volume: %s." % err)
        values = service.CreateOrModifyLV.CreateOrModifyLVValues
        raise LmiFailed("Cannot create the logical volume: %s." %
                        (values.value_name(ret), ))

    lv = outparams['TheElement'].to_instance()
    LOG().info("Created logical volume %s", lv.Name)
    return lv
Exemplo n.º 2
0
def vg_show(ns, vg, human_friendly):
    """
    Print extended information about the Volume Group.

    :type vg: LMIInstance/LMI_VGStoragePool or string
    :param vg: Volume Group to show.
    """
    yield ("Type", "Volume Group")
    vg = common.str2vg(ns, vg)
    yield ("InstanceID", vg.InstanceID)
    yield ("ElementName", vg.ElementName)
    yield ("Extent Size", common.size2str(vg.ExtentSize, human_friendly))
    yield ("Total Size", common.size2str(vg.TotalManagedSpace, human_friendly))
    yield ("Total Extents", vg.TotalExtents)
    yield ("Free Space", common.size2str(vg.RemainingManagedSpace, human_friendly))
    yield ("Free Extents", vg.RemainingExtents)

    pvs = lvm.get_vg_pvs(ns, vg)
    pvnames = [pv.Name for pv in pvs]
    yield ("Physical Volumes", " ".join(pvnames))

    lvs = lvm.get_vg_lvs(ns, vg)
    lvnames = [lv.Name for lv in lvs]
    yield ("Logical Volumes", " ".join(lvnames))

    tps = lvm.get_vg_tps(ns, vg)
    tpnames = [tp.Name for tp in tps]
    yield ("Thin Pools", " ".join(tpnames))
Exemplo n.º 3
0
def get_lvs(ns, vgs=None):
    """
    Retrieve list of all logical volumes allocated from given volume groups.

    If no volume groups are provided, all logical volumes on the system
    are returned.

    :type vgs: list of LMIInstance/LMI_VGStoragePool or list of strings
    :param vgs: Volume Groups to examine.
    :rtype: list of LMIInstance/LMI_LVStorageExtent.
    """
    if vgs:
        for vg in vgs:
            vg = common.str2vg(ns, vg)
            LOG().debug("Getting LVs on %s", vg.ElementName)
            for lv in get_vg_lvs(ns, vg):
                yield lv
    else:
        # No vgs supplied, list all LVs
        for lv in ns.LMI_LVStorageExtent.instances():
            # XXX workaround for https://fedorahosted.org/openlmi/ticket/277
            supports_thin = 'ThinlyProvisioned' in lv.properties()
            if not supports_thin:
                yield lv
            elif supports_thin and not lv.ThinlyProvisioned:
                yield lv
Exemplo n.º 4
0
def get_lvs(ns, vgs=None):
    """
    Retrieve list of all logical volumes allocated from given volume groups.

    If no volume groups are provided, all logical volumes on the system
    are returned.

    :type vgs: list of LMIInstance/LMI_VGStoragePool or list of strings
    :param vgs: Volume Groups to examine.
    :rtype: list of LMIInstance/LMI_LVStorageExtent.
    """
    if vgs:
        for vg in vgs:
            vg = common.str2vg(ns, vg)
            LOG().debug("Getting LVs on %s", vg.ElementName)
            for lv in get_vg_lvs(ns, vg):
                yield lv
    else:
        # No vgs supplied, list all LVs
        for lv in ns.LMI_LVStorageExtent.instances():
            # XXX workaround for https://fedorahosted.org/openlmi/ticket/277
            supports_thin = 'ThinlyProvisioned' in lv.properties()
            if not supports_thin:
                yield lv
            elif supports_thin and not lv.ThinlyProvisioned:
                yield lv
Exemplo n.º 5
0
def vg_show(ns, vg, human_friendly):
    """
    Print extended information about the Volume Group.

    :type vg: LMIInstance/LMI_VGStoragePool or string
    :param vg: Volume Group to show.
    """
    yield ("Type", "Volume Group")
    vg = common.str2vg(ns, vg)
    yield ("InstanceID", vg.InstanceID)
    yield ("ElementName", vg.ElementName)
    yield ("Extent Size", common.size2str(vg.ExtentSize, human_friendly))
    yield ("Total Size", common.size2str(vg.TotalManagedSpace, human_friendly))
    yield ("Total Extents", vg.TotalExtents)
    yield ("Free Space",
           common.size2str(vg.RemainingManagedSpace, human_friendly))
    yield ("Free Extents", vg.RemainingExtents)

    pvs = lvm.get_vg_pvs(ns, vg)
    pvnames = [pv.Name for pv in pvs]
    yield ("Physical Volumes", " ".join(pvnames))

    lvs = lvm.get_vg_lvs(ns, vg)
    lvnames = [lv.Name for lv in lvs]
    yield ("Logical Volumes", " ".join(lvnames))

    tps = lvm.get_vg_tps(ns, vg)
    tpnames = [tp.Name for tp in tps]
    yield ("Thin Pools", " ".join(tpnames))
Exemplo n.º 6
0
def create_lv(ns, vg, name, size):
    """
    Create new Logical Volume on given Volume Group.

    :type vg: LMIInstance/LMI_VGStoragePool or string
    :param vg: Volume Group to allocate the volume from.
    :type name: string
    :param name: Name of the logical volume.
    :type size: int
    :param size: Size of the logical volume in bytes.
    :rtype: LMIInstance/LMI_LVStorageExtent
    """
    vg = common.str2vg(ns, vg)
    service = ns.LMI_StorageConfigurationService.first_instance()
    (ret, outparams, err) = service.SyncCreateOrModifyLV(
            ElementName=name,
            Size=size,
            InPool=vg)
    if ret != 0:
        if err:
            raise LmiFailed("Cannot create the logical volume: %s." % err)
        values = service.CreateOrModifyLV.CreateOrModifyLVValues
        raise LmiFailed("Cannot create the logical volume: %s."
                % (values.value_name(ret),))
    return outparams['TheElement']
Exemplo n.º 7
0
def create_tlv(ns, tp, name, size):
    tp = common.str2vg(ns, tp)
    args = {'ElementName': name, 'ThinPool': tp, 'Size': size}
    service = ns.LMI_StorageConfigurationService.first_instance()
    (ret, outparams, err) = service.SyncCreateOrModifyThinLV(**args)
    if ret != 0:
        raise LmiFailed("Cannot create thin LV: %s." % (err if err else ret))
    return outparams['TheElement']
Exemplo n.º 8
0
def create_tp(ns, name, vg, size):
    vg = common.str2vg(ns, vg)
    args = {'InPool': vg, 'ElementName': name, 'Size': size}
    service = ns.LMI_StorageConfigurationService.first_instance()
    (ret, outparams, err) = service.SyncCreateOrModifyThinPool(**args)
    if ret != 0:
        raise LmiFailed("Cannot create thin pool: %s." % (err if err else ret))
    return outparams['Pool']
Exemplo n.º 9
0
def get_tlvs(ns, tps=None):
    if tps:
        for tp in tps:
            tp = common.str2vg(ns, tp)
            for tlv in get_vg_lvs(ns, tp):
                yield tlv
    else:
        for tlv in ns.LMI_LVStorageExtent.instances():
            if tlv.ThinlyProvisioned:
                yield tlv
Exemplo n.º 10
0
def create_tp(ns, name, vg, size):
    vg = common.str2vg(ns, vg)
    args = {'InPool':vg,
            'ElementName':name,
            'Size':size}
    service = ns.LMI_StorageConfigurationService.first_instance()
    (ret, outparams, err) = service.SyncCreateOrModifyThinPool(**args)
    if ret != 0:
        raise LmiFailed("Cannot create thin pool: %s." % (err if err else ret))
    return outparams['Pool']
Exemplo n.º 11
0
def create_tlv(ns, tp, name, size):
    tp = common.str2vg(ns, tp)
    args = {'ElementName':name,
            'ThinPool':tp,
            'Size':size}
    service = ns.LMI_StorageConfigurationService.first_instance()
    (ret, outparams, err) = service.SyncCreateOrModifyThinLV(**args)
    if ret != 0:
        raise LmiFailed("Cannot create thin LV: %s." % (err if err else ret))
    return outparams['TheElement']
Exemplo n.º 12
0
def get_tlvs(ns, tps=None):
    if tps:
        for tp in tps:
            tp = common.str2vg(ns, tp)
            for tlv in get_vg_lvs(ns, tp):
                yield tlv
    else:
        for tlv in ns.LMI_LVStorageExtent.instances():
            if tlv.ThinlyProvisioned:
                yield tlv
Exemplo n.º 13
0
def get_vg_lvs(ns, vg):
    """
    Return list of Logical Volumes on given Volume Group.

    :type vg: LMIInstance/LMI_VGStoragePool or string
    :param vg: Volume Group to examine.
    :rtype: list of LMIInstance/LMI_LVStorageExtent
    """
    vg = common.str2vg(ns, vg)
    return vg.associators(AssocClass="LMI_LVAllocatedFromStoragePool")
Exemplo n.º 14
0
def get_vg_pvs(ns, vg):
    """
    Return Physical Volumes of given Volume Group.

    :type vg: LMIInstance/LMI_VGStoragePool or string
    :param vg: Volume Group to examine.
    :rtype: list of LMIInstance/CIM_StorageExtent
    """
    vg = common.str2vg(ns, vg)
    return vg.associators(AssocClass="LMI_VGAssociatedComponentExtent")
Exemplo n.º 15
0
def get_vg_pvs(ns, vg):
    """
    Return Physical Volumes of given Volume Group.

    :type vg: LMIInstance/LMI_VGStoragePool or string
    :param vg: Volume Group to examine.
    :rtype: list of LMIInstance/CIM_StorageExtent
    """
    vg = common.str2vg(ns, vg)
    return vg.associators(AssocClass="LMI_VGAssociatedComponentExtent")
Exemplo n.º 16
0
def get_vg_lvs(ns, vg):
    """
    Return list of Logical Volumes on given Volume Group.

    :type vg: LMIInstance/LMI_VGStoragePool or string
    :param vg: Volume Group to examine.
    :rtype: list of LMIInstance/LMI_LVStorageExtent
    """
    vg = common.str2vg(ns, vg)
    return vg.associators(AssocClass="LMI_LVAllocatedFromStoragePool")
Exemplo n.º 17
0
def create_tp(ns, name, vg, size):
    vg = common.str2vg(ns, vg)
    args = {"InPool": vg, "ElementName": name, "Size": size}
    service = ns.LMI_StorageConfigurationService.first_instance()
    (ret, outparams, err) = service.SyncCreateOrModifyThinPool(**args)
    if ret != 0:
        raise LmiFailed("Cannot create thin pool: %s." % (err if err else ret))

    pool = outparams["Pool"].to_instance()
    LOG().info("Created thin volume group %s", pool.Name)
    return pool
Exemplo n.º 18
0
def create_tlv(ns, tp, name, size):
    tp = common.str2vg(ns, tp)
    args = {"ElementName": name, "ThinPool": tp, "Size": size}
    service = ns.LMI_StorageConfigurationService.first_instance()
    (ret, outparams, err) = service.SyncCreateOrModifyThinLV(**args)
    if ret != 0:
        raise LmiFailed("Cannot create thin LV: %s." % (err if err else ret))

    tlv = outparams["TheElement"].to_instance()
    LOG().info("Created thin logical volume %s", tlv.Name)
    return tlv
Exemplo n.º 19
0
 def execute(self, ns, vgs=None):
     """
     Implementation of 'vg show' command.
     """
     if not vgs:
         vgs = lvm.get_vgs(ns)
     for vg in vgs:
         vg = str2vg(ns, vg)
         cmd = fcmd.NewTableCommand(title=vg.InstanceID)
         yield cmd
         for line in show.vg_show(ns, vg, self.app.config.human_friendly):
             yield line
Exemplo n.º 20
0
 def execute(self, ns, tps=None):
     """
     Implementation of 'thinpool show' command.
     """
     if not tps:
         tps = lvm.get_tps(ns)
     for tp in tps:
         tp = str2vg(ns, tp)
         cmd = fcmd.NewTableCommand(title=tp.InstanceID)
         yield cmd
         for line in show.tp_show(ns, tp, self.app.config.human_friendly):
             yield line
Exemplo n.º 21
0
 def execute(self, ns, vgs=None):
     """
     Implementation of 'vg show' command.
     """
     if not vgs:
         vgs = lvm.get_vgs(ns)
     for vg in vgs:
         vg = str2vg(ns, vg)
         cmd = fcmd.NewTableCommand(title=vg.InstanceID)
         yield cmd
         for line in show.vg_show(ns, vg, self.app.config.human_friendly):
             yield line
Exemplo n.º 22
0
def get_vg_tps(ns, vg):
    """
    Return Thin Pools of given Volume Group.

    :type vg: LMIInstance/LMI_VGStoragePool or string
    :param vg: Volume Group to examine.
    :rtype: list of LMIInstance/CIM_StoragePool
    """
    # XXX workaround for https://fedorahosted.org/openlmi/ticket/276
    assoc_class = "LMI_VGAllocatedFromStoragePool"
    if not assoc_class in ns.classes():
        return []

    vg = common.str2vg(ns, vg)
    return vg.associators(AssocClass=assoc_class)
Exemplo n.º 23
0
def get_vg_tps(ns, vg):
    """
    Return Thin Pools of given Volume Group.

    :type vg: LMIInstance/LMI_VGStoragePool or string
    :param vg: Volume Group to examine.
    :rtype: list of LMIInstance/CIM_StoragePool
    """
    # XXX workaround for https://fedorahosted.org/openlmi/ticket/276
    assoc_class = "LMI_VGAllocatedFromStoragePool"
    if not assoc_class in ns.classes():
        return []

    vg = common.str2vg(ns, vg)
    return vg.associators(AssocClass=assoc_class)
Exemplo n.º 24
0
def delete_vg(ns, vg):
    """
    Destroy given Volume Group.

    :type vg: LMIInstance/LMI_VGStoragePool or string
    :param vg: Volume Group to delete.
    """
    vg = common.str2vg(ns, vg)
    service = ns.LMI_StorageConfigurationService.first_instance()
    (ret, _outparams, err) = service.SyncDeleteVG(Pool=vg)
    if ret != 0:
        if err:
            raise LmiFailed("Cannot delete the VG: %s." % err)
        raise LmiFailed("Cannot delete the VG: %s."
                % (service.DeleteVG.DeleteVGValues.value_name(ret),))
Exemplo n.º 25
0
def delete_vg(ns, vg):
    """
    Destroy given Volume Group.

    :type vg: LMIInstance/LMI_VGStoragePool or string
    :param vg: Volume Group to delete.
    """
    vg = common.str2vg(ns, vg)
    service = ns.LMI_StorageConfigurationService.first_instance()
    (ret, _outparams, err) = service.SyncDeleteVG(Pool=vg)
    if ret != 0:
        if err:
            raise LmiFailed("Cannot delete the VG: %s." % err)
        raise LmiFailed("Cannot delete the VG: %s." %
                        (service.DeleteVG.DeleteVGValues.value_name(ret), ))
Exemplo n.º 26
0
def tp_show(ns, tp, human_friendly):
    yield ("Type", "Thin Pool")
    tp = common.str2vg(ns, tp)
    yield ("InstanceID", tp.InstanceID)
    yield ("ElementName", tp.ElementName)
    yield ("Extent Size", common.size2str(tp.ExtentSize, human_friendly))
    yield ("Total Size", common.size2str(tp.TotalManagedSpace, human_friendly))
    yield ("Total Extents", tp.TotalExtents)
    yield ("Free Space", common.size2str(tp.RemainingManagedSpace, human_friendly))
    yield ("Free Extents", tp.RemainingExtents)

    vgs = lvm.get_tp_vgs(ns, tp)
    vgnames = [vg.Name for vg in vgs]
    yield ("Volume Group", " ".join(vgnames))

    lvs = lvm.get_vg_lvs(ns, tp)
    lvnames = [lv.Name for lv in lvs]
    yield ("Logical Volumes", " ".join(lvnames))
Exemplo n.º 27
0
def tp_show(ns, tp, human_friendly):
    yield ("Type", "Thin Pool")
    tp = common.str2vg(ns, tp)
    yield ("InstanceID", tp.InstanceID)
    yield ("ElementName", tp.ElementName)
    yield ("Extent Size", common.size2str(tp.ExtentSize, human_friendly))
    yield ("Total Size", common.size2str(tp.TotalManagedSpace, human_friendly))
    yield ("Total Extents", tp.TotalExtents)
    yield ("Free Space",
           common.size2str(tp.RemainingManagedSpace, human_friendly))
    yield ("Free Extents", tp.RemainingExtents)

    vgs = lvm.get_tp_vgs(ns, tp)
    vgnames = [vg.Name for vg in vgs]
    yield ("Volume Group", " ".join(vgnames))

    lvs = lvm.get_vg_lvs(ns, tp)
    lvnames = [lv.Name for lv in lvs]
    yield ("Logical Volumes", " ".join(lvnames))
Exemplo n.º 28
0
def get_lvs(ns, vgs=None):
    """
    Retrieve list of all logical volumes allocated from given volume groups.

    If no volume groups are provided, all logical volumes on the system
    are returned.

    :type vgs: list of LMIInstance/LMI_VGStoragePool or list of strings
    :param vgs: Volume Groups to examine.
    :rtype: list of LMIInstance/LMI_LVStorageExtent.
    """
    if vgs:
        for vg in vgs:
            vg = common.str2vg(ns, vg)
            LOG().debug("Getting LVs on %s", vg.ElementName)
            for lv in get_vg_lvs(ns, vg):
                yield lv
    else:
        # No vgs supplied, list all LVs
        for lv in ns.LMI_LVStorageExtent.instances():
            yield lv
Exemplo n.º 29
0
def get_lvs(ns, vgs=None):
    """
    Retrieve list of all logical volumes allocated from given volume groups.

    If no volume groups are provided, all logical volumes on the system
    are returned.

    :type vgs: list of LMIInstance/LMI_VGStoragePool or list of strings
    :param vgs: Volume Groups to examine.
    :rtype: list of LMIInstance/LMI_LVStorageExtent.
    """
    if vgs:
        for vg in vgs:
            vg = common.str2vg(ns, vg)
            LOG().debug("Getting LVs on %s", vg.ElementName)
            for lv in get_vg_lvs(ns, vg):
                yield lv
    else:
        # No vgs supplied, list all LVs
        for lv in ns.LMI_LVStorageExtent.instances():
            yield lv
Exemplo n.º 30
0
def modify_vg(ns, vg, add_pvs=None, remove_pvs=None):
    """
    Modify given Volume Group.

    Add 'add_pvs' devices as Physical Volumes of the group.
    Remove 'remove_pvs' devices from the Volume Group.

    :type vg: LMIInstance/LMI_VGStoragePool or string
    :param vg: Volume Group to delete.
    :type add_pvs: List of LMIInstances/LMI_VGStoragePools or strings
    :param add_pvs: List of new devices to be added as Physical Volumes of the
                    VG.
    :type remove_pvs: List of LMIInstances/LMI_VGStoragePools or strings
    :param remove_pvs: List of Physical Volume to be removed from the VG.
    """
    vg = common.str2vg(ns, vg)
    service = ns.LMI_StorageConfigurationService.first_instance()

    # get list of current PVs
    pvs = get_vg_pvs(ns, vg)

    for device in add_pvs:
        device = common.str2device(ns, device)
        if device not in pvs:
            pvs.append(device)

    for device in remove_pvs:
        device = common.str2device(ns, device)
        # don't report error when removing device that is not a PV
        if device in pvs:
            pvs.remove(device)

    (ret, _outparams, err) = service.SyncCreateOrModifyVG(Pool=vg, InExtents = list(pvs))
    if ret != 0:
        if err:
            raise LmiFailed("Cannot modify the VG: %s." % err)
        raise LmiFailed("Cannot modify the VG: %s."
                % (service.CreateOrModifyVG.CreateOrModifyVG.value_name(ret),))
    LOG().info("Modified volume group %s", vg.Name)
Exemplo n.º 31
0
def modify_vg(ns, vg, add_pvs=None, remove_pvs=None):
    """
    Modify given Volume Group.

    Add 'add_pvs' devices as Physical Volumes of the group.
    Remove 'remove_pvs' devices from the Volume Group.

    :type vg: LMIInstance/LMI_VGStoragePool or string
    :param vg: Volume Group to delete.
    :type add_pvs: List of LMIInstances/LMI_VGStoragePools or strings
    :param add_pvs: List of new devices to be added as Physical Volumes of the
                    VG.
    :type remove_pvs: List of LMIInstances/LMI_VGStoragePools or strings
    :param remove_pvs: List of Physical Volume to be removed from the VG.
    """
    vg = common.str2vg(ns, vg)
    service = ns.LMI_StorageConfigurationService.first_instance()

    # get list of current PVs
    pvs = get_vg_pvs(ns, vg)

    for device in add_pvs:
        device = common.str2device(ns, device)
        if device not in pvs:
            pvs.append(device)

    for device in remove_pvs:
        device = common.str2device(ns, device)
        # don't report error when removing device that is not a PV
        if device in pvs:
            pvs.remove(device)

    (ret, _outparams, err) = service.SyncCreateOrModifyVG(Pool=vg, InExtents=list(pvs))
    if ret != 0:
        if err:
            raise LmiFailed("Cannot modify the VG: %s." % err)
        raise LmiFailed("Cannot modify the VG: %s." % (service.CreateOrModifyVG.CreateOrModifyVG.value_name(ret),))
    LOG().info("Modified volume group %s", vg.Name)
Exemplo n.º 32
0
 def execute(self, ns, vg, name, size):
     """
     Implementation of 'lv create' command.
     """
     vg = str2vg(ns, vg[0])
     lvm.create_lv(ns, vg, name, str2size(size, vg.ExtentSize, 'E'))
Exemplo n.º 33
0
 def execute(self, ns, tp, name, size):
     """
     Implementation of 'thinlv create' command.
     """
     tp = str2vg(ns, tp[0])
     lvm.create_tlv(ns, tp, name, str2size(size))
Exemplo n.º 34
0
 def execute(self, ns, vg, name, size):
     """
     Implementation of 'lv create' command.
     """
     vg = str2vg(ns, vg[0])
     lvm.create_lv(ns, vg, name, str2size(size, vg.ExtentSize, 'E'))