Esempio n. 1
0
def _createMo(node, parentMo):
    """Create a managed object.

    Use the XML node and parentMo to create a Mo.

    Args:
      node (xml.etree.cElementTree.Element): The node in the XML that should
        be used to create the Mo.
      parentMo (str or cobra.mit.mo.Mo): The parent Mo for this Mo either as
        a Mo or as a Dn string.

    Returns:
      cobra.mit.mo.Mo: The managed object represented by node.
    """
    pkgName, className = parseMoClassName(node.tag)
    fqClassName = "cobra.model." + pkgName + "." + className
    pyClass = ClassLoader.loadClass(fqClassName)
    parentDnStr = None
    moProps = {}
    for attr, val in list(node.attrib.items()):
        if (attr != 'dn' and attr != 'rn' and attr != 'instanceId'
                and attr != 'status'):
            moProps[attr] = str(val)
        elif attr == 'dn':
            # Set the dn of this MO from the data returned by server
            parentDnStr = getParentDn(str(val))

    mo = buildMo(pyClass, moProps, parentMo, parentDnStr)

    for childNode in node:
        _createMo(childNode, mo)

    return mo
Esempio n. 2
0
def _createMo(node, parentMo):
    """Create a managed object.

    Use the XML node and parentMo to create a Mo.

    Args:
      node (xml.etree.cElementTree.Element): The node in the XML that should
        be used to create the Mo.
      parentMo (str or cobra.mit.mo.Mo): The parent Mo for this Mo either as
        a Mo or as a Dn string.

    Returns:
      cobra.mit.mo.Mo: The managed object represented by node.
    """
    pkgName, className = parseMoClassName(node.tag)
    fqClassName = "cobra.model." + pkgName + "." + className
    pyClass = ClassLoader.loadClass(fqClassName)
    parentDnStr = None
    moProps = {}
    for attr, val in list(node.attrib.items()):
        if attr != "dn" and attr != "rn" and attr != "instanceId" and attr != "status":
            moProps[attr] = str(val)
        elif attr == "dn":
            # Set the dn of this MO from the data returned by server
            parentDnStr = getParentDn(str(val))

    mo = buildMo(pyClass, moProps, parentMo, parentDnStr)

    for childNode in node:
        _createMo(childNode, mo)

    return mo
Esempio n. 3
0
def _createMo(moClassName, moData, parentMo):
    """Create a Mo given a class name, some data and a parent Mo.

    Args:
      moClassName (str): The Mo class name in packageClass form.
      moData (dict): The Mo as a python dictionary.
      parentMo (str or cobra.mit.mo.Mo): The parent Mo as a Dn string or
        a Mo.

    Returns:
      cobra.mit.mo.Mo: The Mo from moClass and moData.
    """
    pkgName, className = parseMoClassName(moClassName)
    fqClassName = "cobra.model." + pkgName + "." + className
    pyClass = ClassLoader.loadClass(fqClassName)
    parentDnStr = None
    moProps = moData['attributes']
    if 'dn' in moProps:
        parentDnStr = getParentDn(moProps['dn'])
        del moProps['dn']
    if 'rn' in moProps:
        del moProps['rn']
    if 'instanceId' in moProps:
        del moProps['instanceId']
    if 'status' in moProps:
        del moProps['status']

    mo = buildMo(pyClass, moProps, parentMo, parentDnStr)

    children = moData.get('children', [])
    for childNode in children:
        className = list(childNode.keys())[0]
        moData = childNode[className]
        _createMo(className, moData, mo)

    return mo
Esempio n. 4
0
def _createMo(moClassName, moData, parentMo):
    """Create a Mo given a class name, some data and a parent Mo.

    Args:
      moClassName (str): The Mo class name in packageClass form.
      moData (dict): The Mo as a python dictionary.
      parentMo (str or cobra.mit.mo.Mo): The parent Mo as a Dn string or
        a Mo.

    Returns:
      cobra.mit.mo.Mo: The Mo from moClass and moData.
    """
    pkgName, className = parseMoClassName(moClassName)
    fqClassName = "cobra.model." + pkgName + "." + className
    pyClass = ClassLoader.loadClass(fqClassName)
    parentDnStr = None
    moProps = moData['attributes']
    if 'dn' in moProps:
        parentDnStr = getParentDn(moProps['dn'])
        del moProps['dn']
    if 'rn' in moProps:
        del moProps['rn']
    if 'instanceId' in moProps:
        del moProps['instanceId']
    if 'status' in moProps:
        del moProps['status']

    mo = buildMo(pyClass, moProps, parentMo, parentDnStr)

    children = moData.get('children', [])
    for childNode in children:
        className = list(childNode.keys())[0]
        moData = childNode[className]
        _createMo(className, moData, mo)

    return mo