Esempio n. 1
0
def unpack_value(tt):
    """Find VALUE or VALUE.ARRAY under TT and convert to a Python value.

    Looks at the TYPE of the node to work out how to decode it.
    Handles nodes with no value (e.g. in CLASS.)
    """
    ## TODO: Handle VALUE.REFERENCE, VALUE.REFARRAY

    valtype = attrs(tt)['TYPE']

    raw_val = list_of_matching(tt, ['VALUE', 'VALUE.ARRAY'])
    if len(raw_val) == 0:
        return None
    elif len(raw_val) > 1:
        raise ParseError('more than one VALUE or VALUE.ARRAY under %s' %
                         name(tt))

    raw_val = raw_val[0]

    if isinstance(raw_val, list):
        return [cim_obj.tocimobj(valtype, x) for x in raw_val]
    elif len(raw_val) == 0 and valtype != 'string':
        return None
    else:
        return cim_obj.tocimobj(valtype, raw_val)
Esempio n. 2
0
    def InvokeMethod(self, MethodName, ObjectName, **params):

        # Convert string to CIMClassName

        obj = ObjectName

        if isinstance(obj, StringTypes):
            obj = CIMClassName(obj, namespace = self.default_namespace)

        if isinstance(obj, CIMInstanceName) and obj.namespace is None:
            obj = ObjectName.copy()
            obj.namespace = self.default_namespace

        # Make the method call

        result = self.methodcall(MethodName, obj, **params)

        # Convert optional RETURNVALUE into a Python object

        returnvalue = None

        if len(result) > 0 and result[0][0] == 'RETURNVALUE':

            returnvalue = cim_obj.tocimobj(result[0][1]['PARAMTYPE'],
                                           result[0][2])
            result = result[1:]

        # Convert zero or more PARAMVALUE elements into dictionary

        output_params = {}

        for p in result:
            if p[1] == 'reference':
                output_params[p[0]] = p[2]
            else:
                output_params[p[0]] = cim_obj.tocimobj(p[1], p[2])

        return returnvalue, output_params
Esempio n. 3
0
def unpack_value(tt):
    """Find VALUE or VALUE.ARRAY under TT and convert to a Python value.

    Looks at the TYPE of the node to work out how to decode it.
    Handles nodes with no value (e.g. in CLASS.)
    """
    ## TODO: Handle VALUE.REFERENCE, VALUE.REFARRAY

    valtype = attrs(tt)['TYPE']

    raw_val = list_of_matching(tt, ['VALUE', 'VALUE.ARRAY'])
    if len(raw_val) == 0:
        return None
    elif len(raw_val) > 1:
        raise ParseError('more than one VALUE or VALUE.ARRAY under %s' % name(tt))

    raw_val = raw_val[0]
    
    if isinstance(raw_val, list):
        return [cim_obj.tocimobj(valtype, x) for x in raw_val]
    elif len(raw_val) == 0 and valtype != 'string':
        return None
    else:
        return cim_obj.tocimobj(valtype, raw_val)
Esempio n. 4
0
def parse_qualifier_declaration(tt):
    ## <!ELEMENT QUALIFIER.DECLARATION (SCOPE?, (VALUE | VALUE.ARRAY)?)>
    ## <!ATTLIST QUALIFIER.DECLARATION 
    ##     %CIMName;               
    ##     %CIMType;               #REQUIRED
    ##     ISARRAY    (true|false) #IMPLIED
    ##     %ArraySize;
    ##     %QualifierFlavor;>

    check_node(tt, 'QUALIFIER.DECLARATION',
               ['NAME', 'TYPE'],
               ['ISARRAY', 'ARRAYSIZE', 'OVERRIDABLE', 'TOSUBCLASS',
                'TOINSTANCE', 'TRANSLATABLE'],
               ['SCOPE', 'VALUE', 'VALUE.ARRAY'])

    a = attrs(tt)
    qname = a['NAME']
    type = a['TYPE']
    try:
        is_array = a['ISARRAY'].lower() == 'true'
    except KeyError:
        is_array = False
    try:
        array_size = int(a['ARRAYSIZE'])
    except KeyError:
        array_size = None

    flavors = {}
    for f in ['OVERRIDABLE', 'TOSUBCLASS', 'TOINSTANCE', 'TRANSLATABLE']:
        try:
            flavors[f.lower()] = a[f].lower() == 'true'
        except KeyError:
            pass

    scopes = None
    value = None
    for child in kids(tt):
        if name(child) == 'SCOPE':
            if scopes is not None:
                raise ParseError("Multiple SCOPE tags encountered")
            scopes = parse_any(child)
        else:
            if value is not None:
                raise ParseError("Multiple VALUE/VALUE.ARRAY tags encountered")
            value = cim_obj.tocimobj(type, parse_any(child))
            
    return cim_obj.CIMQualifierDeclaration(qname, type, value, is_array,
                 array_size, scopes, **flavors)
def parse_qualifier_declaration(tt):
    ## <!ELEMENT QUALIFIER.DECLARATION (SCOPE?, (VALUE | VALUE.ARRAY)?)>
    ## <!ATTLIST QUALIFIER.DECLARATION 
    ##     %CIMName;               
    ##     %CIMType;               #REQUIRED
    ##     ISARRAY    (true|false) #IMPLIED
    ##     %ArraySize;
    ##     %QualifierFlavor;>

    check_node(tt, 'QUALIFIER.DECLARATION',
               ['NAME', 'TYPE'],
               ['ISARRAY', 'ARRAYSIZE', 'OVERRIDABLE', 'TOSUBCLASS',
                'TOINSTANCE', 'TRANSLATABLE'],
               ['SCOPE', 'VALUE', 'VALUE.ARRAY'])

    a = attrs(tt)
    qname = a['NAME']
    type = a['TYPE']
    try:
        is_array = a['ISARRAY'].lower() == 'true'
    except KeyError:
        is_array = False
    try:
        array_size = int(a['ARRAYSIZE'])
    except KeyError:
        array_size = None

    flavors = {}
    for f in ['OVERRIDABLE', 'TOSUBCLASS', 'TOINSTANCE', 'TRANSLATABLE']:
        try:
            flavors[f.lower()] = a[f].lower() == 'true'
        except KeyError:
            pass

    scopes = None
    value = None
    for child in kids(tt):
        if name(child) == 'SCOPE':
            if scopes is not None:
                raise ParseError("Multiple SCOPE tags encountered")
            scopes = parse_any(child)
        else:
            if value is not None:
                raise ParseError("Multiple VALUE/VALUE.ARRAY tags encountered")
            value = cim_obj.tocimobj(type, parse_any(child))
            
    return cim_obj.CIMQualifierDeclaration(qname, type, value, is_array,
                 array_size, scopes, **flavors)