コード例 #1
0
ファイル: device.py プロジェクト: anoother/wry
    def dump(self, as_json=True):
        '''
        Print all of the known information about the device.

        :returns: WryDict or json.
        '''
        output = WryDict()
        impossible = []
        for name, methods in RESOURCE_METHODS.items():
            try:
                if 'get' in methods:
                    resource = self.get_resource(name)
                elif 'enumerate' in methods:
                    resource = self.enumerate_resource(name)
                else:
                    raise exceptions.NoSupportedMethods('The resource %r does not define a supported method for this action.' % name)
            except exceptions.WSManFault:
                impossible.append(name)
            else:
                output.update(resource)
        messages = ['# Could not dump %s' % name for name in impossible]
        if as_json:
            return '\n'.join(messages) + '\n' + output.as_json()
        else:
            print '\n'.join(messages)
            return output
コード例 #2
0
ファイル: common.py プロジェクト: mikebryant/wry
def invoke_method(client, method, input_dict, options=None):
    resource_name = input_dict.keys()[0]
    input_dict = WryDict(input_dict).with_namespaces()
    data = input_dict[resource_name]
    uri = data.pop(u'@xmlns')
    data.values()[0][u'@xmlns'] = uri
    xml = xmltodict.unparse(data, full_document=False, pretty=True)
    doc = wsman_invoke(client, RESOURCE_URIs[resource_name], method, xml, options=options)
    returned = WryDict(doc)
    return_value = returned[returned.keys()[0]]['ReturnValue']
    if return_value != 0:
        raise exceptions.NonZeroReturn(return_value)
    return returned
コード例 #3
0
ファイル: common.py プロジェクト: anoother/wry
def enumerate_resource(client, resource_name, wsman_filter=None, options=None):
    '''
    class.
    '''
    uri = RESOURCE_URIs[resource_name]
    doc = wsman_enumerate(client, uri, options=options) # Add in relevant kwargs... filter?
    doc = WryDict(doc)
    context = doc['EnumerateResponse']['EnumerationContext']
    ended = False
    output = {resource_name: []}
    while ended is False:
        doc = wsman_pull(client, uri, context=str(context), options=options)
        response = WryDict(doc)['PullResponse']
        ended = response.pop('EndOfSequence', False)
        output[resource_name].append(response['Items'][resource_name])
    return output