Exemple #1
0
def cim_pools_of_cim_sys_path(smis_common, cim_sys_path, property_list=None):
    """
    Use this association to get a list of CIM_StoragePool:
            CIM_ComputerSystem
                 |
                 | (CIM_HostedStoragePool)
                 |
                 v
            CIM_StoragePool
    As 'Block Services Package' is mandatory for 'Array' profile which already
    checked by plugin_register(), we don't do any profile check here.
    Primordial pool will be eliminated from return list.
    These pools will be eliminated also:
        * Spare pool with CIM_StoragePool['Usage'] == dmtf.POOL_USAGE_SPARE
        * IBM ArrayPool(IBMTSDS_ArrayPool)
        * IBM ArraySitePool(IBMTSDS_ArraySitePool)
    """
    cim_pools = []

    if property_list is None:
        property_list = ['Primordial', 'Usage']
    else:
        property_list = merge_list(property_list, ['Primordial', 'Usage'])

    cim_pools = smis_common.Associators(
        cim_sys_path,
        AssocClass='CIM_HostedStoragePool',
        ResultClass='CIM_StoragePool',
        PropertyList=property_list)

    rc = []
    for cim_pool in cim_pools:
        if 'Primordial' in cim_pool and cim_pool['Primordial']:
            continue
        if 'Usage' in cim_pool and cim_pool['Usage'] == dmtf.POOL_USAGE_SPARE:
            continue
        # Skip IBM ArrayPool and ArraySitePool
        # ArrayPool is holding RAID info.
        # ArraySitePool is holding 8 disks. Predefined by array.
        # ArraySite --(1to1 map) --> Array --(1to1 map)--> Rank

        # By design when user get a ELEMENT_TYPE_POOL only pool,
        # user can assume he/she can allocate spaces from that pool
        # to create a new pool with ELEMENT_TYPE_VOLUME or
        # ELEMENT_TYPE_FS ability.

        # If we expose them out, we will have two kind of pools
        # (ArrayPool and ArraySitePool) having element_type &
        # ELEMENT_TYPE_POOL, but none of them can create a
        # ELEMENT_TYPE_VOLUME pool.
        # Only RankPool can create a ELEMENT_TYPE_VOLUME pool.

        # We are trying to hide the detail to provide a simple
        # abstraction.
        if cim_pool.classname == 'IBMTSDS_ArrayPool' or \
           cim_pool.classname == 'IBMTSDS_ArraySitePool':
            continue
        rc.append(cim_pool)

    return rc
Exemple #2
0
def cim_pools_of_cim_sys_path(smis_common, cim_sys_path, property_list=None):
    """
    Use this association to get a list of CIM_StoragePool:
            CIM_ComputerSystem
                 |
                 | (CIM_HostedStoragePool)
                 |
                 v
            CIM_StoragePool
    As 'Block Services Package' is mandatory for 'Array' profile which already
    checked by plugin_register(), we don't do any profile check here.
    Primordial pool will be eliminated from return list.
    These pools will be eliminated also:
        * Spare pool with CIM_StoragePool['Usage'] == dmtf.POOL_USAGE_SPARE
        * IBM ArrayPool(IBMTSDS_ArrayPool)
        * IBM ArraySitePool(IBMTSDS_ArraySitePool)
    """
    cim_pools = []

    if property_list is None:
        property_list = ['Primordial', 'Usage']
    else:
        property_list = merge_list(property_list, ['Primordial', 'Usage'])

    cim_pools = smis_common.Associators(
        cim_sys_path,
        AssocClass='CIM_HostedStoragePool',
        ResultClass='CIM_StoragePool',
        PropertyList=property_list)

    rc = []
    for cim_pool in cim_pools:
        if 'Primordial' in cim_pool and cim_pool['Primordial']:
            continue
        if 'Usage' in cim_pool and cim_pool['Usage'] == dmtf.POOL_USAGE_SPARE:
            continue
        # Skip IBM ArrayPool and ArraySitePool
        # ArrayPool is holding RAID info.
        # ArraySitePool is holding 8 disks. Predefined by array.
        # ArraySite --(1to1 map) --> Array --(1to1 map)--> Rank

        # By design when user get a ELEMENT_TYPE_POOL only pool,
        # user can assume he/she can allocate spaces from that pool
        # to create a new pool with ELEMENT_TYPE_VOLUME or
        # ELEMENT_TYPE_FS ability.

        # If we expose them out, we will have two kind of pools
        # (ArrayPool and ArraySitePool) having element_type &
        # ELEMENT_TYPE_POOL, but none of them can create a
        # ELEMENT_TYPE_VOLUME pool.
        # Only RankPool can create a ELEMENT_TYPE_VOLUME pool.

        # We are trying to hide the detail to provide a simple
        # abstraction.
        if cim_pool.classname == 'IBMTSDS_ArrayPool' or \
           cim_pool.classname == 'IBMTSDS_ArraySitePool':
            continue
        rc.append(cim_pool)

    return rc
Exemple #3
0
def cim_sys_of_sys_id(smis_common, sys_id, property_list=None):
    """
    Find out the CIM_ComputerSystem for given lsm.System.id using
    root_cim_sys()
    """
    id_pros = cim_sys_id_pros()
    if property_list is None:
        property_list = id_pros
    else:
        property_list = merge_list(property_list, id_pros)

    cim_syss = root_cim_sys(smis_common, property_list)
    for cim_sys in cim_syss:
        if sys_id_of_cim_sys(cim_sys) == sys_id:
            return cim_sys
    raise LsmError(ErrorNumber.NOT_FOUND_SYSTEM, "Not found System")
Exemple #4
0
def cim_sys_of_sys_id(smis_common, sys_id, property_list=None):
    """
    Find out the CIM_ComputerSystem for given lsm.System.id using
    root_cim_sys()
    """
    id_pros = cim_sys_id_pros()
    if property_list is None:
        property_list = id_pros
    else:
        property_list = merge_list(property_list, id_pros)

    cim_syss = root_cim_sys(smis_common, property_list)
    for cim_sys in cim_syss:
        if sys_id_of_cim_sys(cim_sys) == sys_id:
            return cim_sys
    raise LsmError(ErrorNumber.NOT_FOUND_SYSTEM, "Not found System")
    def cim_job_of_job_id(self, job_id, property_list=None):
        """
        Return CIM_ConcreteJob for given job_id.
        """
        if property_list is None:
            property_list = SmisCommon.cim_job_pros()
        else:
            property_list = merge_list(property_list,
                                       SmisCommon.cim_job_pros())

        cim_jobs = self.EnumerateInstances('CIM_ConcreteJob',
                                           PropertyList=property_list)
        real_job_id = SmisCommon.parse_job_id(job_id)[0]
        for cim_job in cim_jobs:
            if md5(cim_job['InstanceID']) == real_job_id:
                return cim_job

        raise LsmError(ErrorNumber.NOT_FOUND_JOB, "Job %s not found" % job_id)
Exemple #6
0
def root_cim_sys(smis_common, property_list=None):
    """
    Use this association to find out the root CIM_ComputerSystem:
        CIM_RegisteredProfile       # Root Profile('Array') in interop
                 |
                 | CIM_ElementConformsToProfile
                 v
        CIM_ComputerSystem          # vendor namespace
    """
    id_pros = cim_sys_id_pros()
    if property_list is None:
        property_list = id_pros
    else:
        property_list = merge_list(property_list, id_pros)

    cim_syss = []
    if smis_common.is_megaraid():
        cim_syss = smis_common.EnumerateInstances("CIM_ComputerSystem", PropertyList=property_list)
    else:
        cim_syss = smis_common.Associators(
            smis_common.root_blk_cim_rp.path,
            ResultClass="CIM_ComputerSystem",
            AssocClass="CIM_ElementConformsToProfile",
            PropertyList=property_list,
        )

        if len(cim_syss) == 0:
            raise LsmError(
                ErrorNumber.NO_SUPPORT,
                "Current SMI-S provider does not provide "
                "the root CIM_ComputerSystem associated "
                "to 'Array' CIM_RegisteredProfile.",
            )

    # System URI Filtering
    if smis_common.system_list:
        needed_cim_syss = []
        for cim_sys in cim_syss:
            if sys_id_of_cim_sys(cim_sys) in smis_common.system_list:
                needed_cim_syss.extend([cim_sys])
        return needed_cim_syss
    else:
        return cim_syss
Exemple #7
0
def root_cim_sys(smis_common, property_list=None):
    """
    Use this association to find out the root CIM_ComputerSystem:
        CIM_RegisteredProfile       # Root Profile('Array') in interop
                 |
                 | CIM_ElementConformsToProfile
                 v
        CIM_ComputerSystem          # vendor namespace
    """
    id_pros = cim_sys_id_pros()
    if property_list is None:
        property_list = id_pros
    else:
        property_list = merge_list(property_list, id_pros)

    cim_syss = []
    if smis_common.is_megaraid():
        cim_syss = smis_common.EnumerateInstances('CIM_ComputerSystem',
                                                  PropertyList=property_list)
    else:
        cim_syss = smis_common.Associators(
            smis_common.root_blk_cim_rp.path,
            ResultClass='CIM_ComputerSystem',
            AssocClass='CIM_ElementConformsToProfile',
            PropertyList=property_list)

        if len(cim_syss) == 0:
            raise LsmError(
                ErrorNumber.NO_SUPPORT,
                "Current SMI-S provider does not provide "
                "the root CIM_ComputerSystem associated "
                "to 'Array' CIM_RegisteredProfile.")

    # System URI Filtering
    if smis_common.system_list:
        needed_cim_syss = []
        for cim_sys in cim_syss:
            if sys_id_of_cim_sys(cim_sys) in smis_common.system_list:
                needed_cim_syss.extend([cim_sys])
        return needed_cim_syss
    else:
        return cim_syss
def _pri_cim_ext_of_cim_disk(smis_common, cim_disk_path, property_list=None):
    """
    Usage:
        Find out the Primordial CIM_StorageExtent of CIM_DiskDrive
        In SNIA SMI-S 1.4 rev.6 Block book, section 11.1.1 'Base Model'
        quote:
        A disk drive is modeled as a single MediaAccessDevice (DiskDrive)
        That shall be linked to a single StorageExtent (representing the
        storage in the drive) by a MediaPresent association. The
        StorageExtent class represents the storage of the drive and
        contains its size.
    Parameter:
        cim_disk_path   # CIM_InstanceName of CIM_DiskDrive
        property_list   # a List of properties needed on returned
                        # CIM_StorageExtent
    Returns:
        cim_pri_ext     # The CIM_Instance of Primordial CIM_StorageExtent
    Exceptions:
        LsmError
            ErrorNumber.LSM_PLUGIN_BUG  # Failed to find out pri cim_ext
    """
    if property_list is None:
        property_list = ['Primordial']
    else:
        property_list = merge_list(property_list, ['Primordial'])

    cim_exts = smis_common.Associators(
        cim_disk_path,
        AssocClass='CIM_MediaPresent',
        ResultClass='CIM_StorageExtent',
        PropertyList=property_list)
    cim_exts = [p for p in cim_exts if p["Primordial"]]
    if len(cim_exts) == 1:
        # As SNIA commanded, only _ONE_ Primordial CIM_StorageExtent for
        # each CIM_DiskDrive
        return cim_exts[0]
    else:
        raise LsmError(ErrorNumber.PLUGIN_BUG,
                       "_pri_cim_ext_of_cim_disk(): "
                       "Got unexpected count of Primordial " +
                       "CIM_StorageExtent for CIM_DiskDrive: %s, %s " %
                       (cim_disk_path, cim_exts))
Exemple #9
0
def _pri_cim_ext_of_cim_disk(smis_common, cim_disk_path, property_list=None):
    """
    Usage:
        Find out the Primordial CIM_StorageExtent of CIM_DiskDrive
        In SNIA SMI-S 1.4 rev.6 Block book, section 11.1.1 'Base Model'
        quote:
        A disk drive is modeled as a single MediaAccessDevice (DiskDrive)
        That shall be linked to a single StorageExtent (representing the
        storage in the drive) by a MediaPresent association. The
        StorageExtent class represents the storage of the drive and
        contains its size.
    Parameter:
        cim_disk_path   # CIM_InstanceName of CIM_DiskDrive
        property_list   # a List of properties needed on returned
                        # CIM_StorageExtent
    Returns:
        cim_pri_ext     # The CIM_Instance of Primordial CIM_StorageExtent
    Exceptions:
        LsmError
            ErrorNumber.LSM_PLUGIN_BUG  # Failed to find out pri cim_ext
    """
    if property_list is None:
        property_list = ['Primordial']
    else:
        property_list = merge_list(property_list, ['Primordial'])

    cim_exts = smis_common.Associators(cim_disk_path,
                                       AssocClass='CIM_MediaPresent',
                                       ResultClass='CIM_StorageExtent',
                                       PropertyList=property_list)
    cim_exts = [p for p in cim_exts if p["Primordial"]]
    if len(cim_exts) == 1:
        # As SNIA commanded, only _ONE_ Primordial CIM_StorageExtent for
        # each CIM_DiskDrive
        return cim_exts[0]
    else:
        raise LsmError(
            ErrorNumber.PLUGIN_BUG, "_pri_cim_ext_of_cim_disk(): "
            "Got unexpected count of Primordial " +
            "CIM_StorageExtent for CIM_DiskDrive: %s, %s " %
            (cim_disk_path, cim_exts))
    def cim_job_of_job_id(self, job_id, property_list=None):
        """
        Return CIM_ConcreteJob for given job_id.
        """
        if property_list is None:
            property_list = SmisCommon.cim_job_pros()
        else:
            property_list = merge_list(
                property_list, SmisCommon.cim_job_pros())

        cim_jobs = self.EnumerateInstances(
            'CIM_ConcreteJob',
            PropertyList=property_list)
        real_job_id = SmisCommon.parse_job_id(job_id)[0]
        for cim_job in cim_jobs:
            if md5(cim_job['InstanceID']) == real_job_id:
                return cim_job

        raise LsmError(
            ErrorNumber.NOT_FOUND_JOB,
            "Job %s not found" % job_id)
Exemple #11
0
def Draw_2(G, df):
    '''

    :param G:
    :param df:
    :return:
    '''

    key_nodes = args.key_nodes  #画出的跟结点
    if len(key_nodes) != 0:
        nodes = []
        for item in key_nodes:
            nodes.append(get_children(item))
        all_nodes = merge_list(nodes) + key_nodes
        del (nodes)

        # all_nodes = merge_list2(nodes[0],nodes[1])

        # (all_nodes)
        print(len(all_nodes))
        sub_g = G.subgraph(all_nodes)
        G = nx.MultiDiGraph(sub_g)
    else:
        pass

    in_deg = [item for item in G.in_degree]
    in_deg = dict(in_deg)
    out_deg = [item for item in G.out_degree]
    out_deg = dict(out_deg)

    # REMOVE NODES
    Gnodes = list(G.nodes)  # deep copy
    if args.show_leaf == False:
        for node in Gnodes:
            if node[:2] == '.0' and in_deg[node] < draw_th:
                G.remove_node(node)
        print('AFTER REMOVE')
    else:
        print('SHOW LEAF')

    print(len(G.nodes))
    print(len(G.edges))

    # define key edges
    key_edges = []
    for (o, i, j) in G.edges:
        if is_leaf(i) == False:  # 如果边的入结点不是叶子, 那边就是干
            key_edges.append((o, i, j))

    # with labels, 显示中文结点名字
    words = {}
    for idx, row in df.iterrows():
        pass
        words[row['id']] = row['word']
    labels = {}
    for id in G.nodes:
        #        labels[id] = id  # named as id
        labels[id] = words[id]  # df['id'].at(node)

    # 1. node color size
    node_color = []
    node_size = []
    for node in G.nodes():
        ns = in_deg[node]
        node_size.append(ns)
        c = cnt_sub_nodes(node)
        node_color.append(c)
    node_size = np.array(node_size) * 200 + 200
    node_color = np.array(node_color)

    # edge color size
    edge_width = []
    edge_color = []
    for (x, y, i) in G.edges:
        c = cnt_sub_nodes(y)
        edge_width.append(c)
        if is_leaf(y):
            edge_color.append('lightskyblue')
        else:
            edge_color.append('red')

    edge_width = np.array(edge_width)

    min = edge_width.min()
    max = edge_width.max()
    if min != max:
        edge_width = (edge_width - min) / (max - min)
    else:
        pass
    edge_width = 2 * edge_width + 1

    if len(key_nodes) == 1:
        edge_width = 1
    # draw
    # pos = nx.spring_layout(G)
    pos = graphviz_layout(G, prog='sfdp')
    # pos = nx.spectral_layout(sub_g)
    # print(edge_width)
    # print(edge_color)
    # print(node_color)
    # print(node_size)
    nx.draw(
        G,
        pos,
        cmap=plt.get_cmap('Wistia'),
        node_color=node_color,  # same size with nodes
        node_size=node_size,
        # edge
        edge_color=edge_color,
        # edge_cmap=plt.get_cmap('Blues'),
        width=edge_width,
        # label_color='white',
        labels=labels,
        encoding='utf-8',
        with_labels=True)
    plt.axis('off')
    plt.show()
Exemple #12
0
def Draw_1(G, df):
    '''

    :param G:
    :param df:
    :return:
    '''
    plt.style.use('dark_background')

    #key_nodes=['.1.01','.1.00','.1.03','.1.05']
    #key_nodes=['.1.01','.1.00','.1.03','.1.05']# doc6 病原学特点, 流行病学特点,诊断标准
    #key_nodes=['.1.01','.1.00']

    nodes = []
    for item in key_nodes:
        nodes.append(get_children(item))
    all_nodes = merge_list(nodes) + key_nodes
    del (nodes)

    #all_nodes = merge_list2(nodes[0],nodes[1])

    #(all_nodes)
    sub_g = G.subgraph(all_nodes)
    sub_g = nx.MultiDiGraph(sub_g)

    in_deg = [item for item in sub_g.in_degree]
    in_deg = dict(in_deg)

    out_deg = [item for item in sub_g.out_degree]
    out_deg = dict(out_deg)

    nodes = list(sub_g.nodes())
    for node in nodes:
        if node[:2] == '.0' and in_deg[node] < 2:
            sub_g.remove_node(node)
    print('sub graph')
    print(len(sub_g.nodes))
    print(len(sub_g.edges))

    # define key edges
    key_edges = []
    for (o, i, j) in sub_g.edges:
        if is_leaf(i) == False:  # 如果边的入结点不是叶子, 那边就是干
            key_edges.append((o, i, j))
    print(key_edges)

    #with labels

    labels = {}
    for node in sub_g.nodes:
        labels[node] = node  # df['id'].at(node)
#1. node color
    node_color = []
    for node in sub_g.nodes:
        node_color.append(in_deg[node])
#        if is_leaf(node) == False:
#            node_color.append('red')
#            with_labels.append(True)
#        else:
#            node_color.append('yellow')
#            with_labels.append(False)
#2. node size
    base_size = 350
    k = 200
    node_size = []
    for item in sub_g.nodes:
        #        if is_leaf(item) ==True:
        node_size.append(cnt_sub_nodes(item))
        #            node_size.append(base_size)
        node_size = normalize(node_size)
#edge color, width

# for edge in sub_g.edges:
#     if edge in key_edges:
#         edge_width.append(4)
#         edge_color.append('blue')

#     else:
#         edge_width.append(0.5)
#         edge_color.append('gray')

    edge_width = []
    edge_color = []
    base_width = 1
    base_edge_color = 1
    for (x, y, i) in sub_g.edges:
        c = cnt_sub_nodes(y)
        edge_width.append(c)
        if is_leaf(y):
            edge_color.append('lightskyblue')
        else:
            edge_color.append('deepskyblue')
        #edge_width.append(c*base_width+base_width)


#edge_width
#edge_color = recolor(edge_color)

    pos = graphviz_layout(sub_g, prog='fdp')
    #pos = nx.spectral_layout(sub_g)
    nx.draw(
        sub_g,
        pos,
        cmap=plt.get_cmap('Wistia'),
        node_color=node_color,  # same size with nodes
        node_size=node_size,
        #edge
        edge_color=edge_color,
        #edge_cmap=plt.get_cmap('Blues'),
        width=edge_width)
    #label_color='white',
    #labels = labels,
    #with_labels=True)
    plt.axis('off')
    plt.show()