несколько фильтров WS-I в SOAP NNMi 10.20 - PullRequest
0 голосов
/ 20 ноября 2018

Я хотел бы применить несколько фильтров WS-I к SOAP NNMi 10.20, я использую библиотеку Zeep Python:

from requests.auth import HTTPBasicAuth  # or HTTPDigestAuth, or OAuth1
from requests import Session
from zeep import Client
from zeep.transports import Transport

user = 'admin'
password = 'secret'
url = 'http://domaine.fr/NodeBeanService/NodeBean?wsdl'
node_id= "144077343434" 

session = Session()
session.auth = HTTPBasicAuth(user, password)
client = Client(url, transport=Transport(session=session))


factory = client.type_factory('ns3')
constraint = factory.constraint(name="includeCustomAttributes", value=1)
condition = factory.condition(name="id", operator="EQ", value=node_id)
filterr = factory.expression(operator="AND", subFilters=[constraint, condition])
node_infos = client.service.getNodes(filterr)

Я получаю эту ошибку:

Fault: java.lang.IllegalArgumentException: prefix ns1 is not bound to a namespace

Что такоеРешение пожалуйста.

заранее спасибо.

1 Ответ

0 голосов
/ 26 ноября 2018

это запрос в XML, я использовал SOAPUI для его отправки

  <env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
    <env:Body>
        <ns1:getNodes xmlns:ns1="http://node.sdk.nms.ov.hp.com/">
            <arg0 xsi:type="ns3:expression" xmlns:ns3="http://filter.sdk.nms.ov.hp.com/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
               <operator>AND</operator>
               <subFilters xsi:type="ns3:condition">
                   <name>id</name>
                   <operator>EQ</operator>
                   <value>34345454656</value>
               </subFilters>
               <subFilters xsi:type="ns3:constraint">
                   <name>includeCustomAttributes</name>
                       <value>true</value>
               </subFilters>
            </arg0>
        </ns1:getNodes>
    </env:Body>
</env:Envelope>

вы можете использовать для этого запросы

from lxml import etree
import requests 

from config import config, urls

def prepare_xml_request(deviceId, includeCustomAttributes="true"):

    return """   
        <env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
            etc ......
                           <name>id</name>
                           <operator>EQ</operator>
                           <value>{0}</value>
                       </subFilters>
                       <subFilters xsi:type="ns3:constraint">
                           <name>includeCustomAttributes</name>
                               <value>{1}</value>
                       </subFilters>

        </env:Envelope>
        """.format(deviceId, includeCustomAttributes)

def parse_response(resp_file):
    tree = etree.parse(resp_file)
    root = tree.getroot()
    customAttributes = {}
    hostname = ""
    for customAttribut in root.iter("customAttributes"):
        att = []
        for element in customAttribut.iter("*"):
            if element.tag != 'customAttributes':
                att.append(element.text)

        customAttributes[att[0]] = att[1]

    for longName in root.iter("longName"):
        hostname = longName.text

    return (hostname, customAttributes)

def get_infos_node(node_id):
    xml_req = prepare_xml_request(node_id)

    resp = requests.post(urls.get('Node'), data=xml_req, auth=(config.get('username'), config.get('password'))).text

    f = open('node_resp.xml', mode='w', encoding='utf-8')
    f.write(resp)
    f.close()

    # parser le resp et recuper le hostname et les customattributes
    (hostname, customAttributes) = parse_response('node_resp.xml')

    # return hostname, customAttributes
    return (hostname, customAttributes)
...