【问题标题】:Creating SOAP request via Zeep with variable number of XML tags通过 Zeep 使用可变数量的 XML 标签创建 SOAP 请求
【发布时间】:2019-01-11 00:15:20
【问题描述】:

所有,我正在使用 Zeep 连接到 CUCM 以执行批量 AXL 事务。我需要修改的一些对象接受可变数量的 XML 标记。例如:

我想添加一个实体(调用搜索空间),它可以有可变数量的与之关联的分区。根据 WSDL:


    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://www.cisco.com/AXL/API/11.5">
       <soapenv:Header/>
       <soapenv:Body>
          <ns:addCss sequence="?">
             <css>
                <!--Optional:-->
                <description>?</description>
                <!--Optional:-->
                <members>
                   <!--Zero or more repetitions:--> <------------------------------------------
                   <member>
                      <routePartitionName uuid="?">?</routePartitionName>
                      <index>?</index>
                   </member>
                </members>
                <!--Optional:-->
                <partitionUsage>General</partitionUsage>
                <name>?</name>
             </css>
          </ns:addCss>
       </soapenv:Body>
    </soapenv:Envelope>

我可以轻松编写固定数量的成员:


    result = service.addCss({
        'name': 'SampleCSS',
        'description': 'Sample CSS Description',
        'members': {
            'member': [
                {'routePartitionName':{
                    '_value_1':None, 'uuid':'{07614566-ADC4-1ABB-3EB3-C08650E11CBE}'},
                    'index':1},
                {'routePartitionName': 'Auto Register','index': 2},
                {'routePartitionName': 'DNS External', 'index':3},
                {'routePartitionName':{
                    '_value_1':'On Cluster', 'uuid':'{F7FF933E-2B63-25DB-11AF-1DDDC8F9A52E}'},
                    'index':4},
            ]}
         })
    print (result)
    print(type(result))
    res = result['return']
    print("\n\n", res)

但是,我很难为可变数量的成员编写脚本

我将我的成员存储在字典中:


    CSSes = {
        'Test1': ['Test1','Test1','07614566-ADC4-1ABB-3EB3-C08650E11CBE','Staging',1],
        'Test2': ['Test2','Test2','F7FF933E-2B63-25DB-11AF-1DDDC8F9A52E', 'On Cluster',1]
    }

如果我要添加多个 CSS,并且每个 CSS 有不同数量的分区(成员),我该怎么做?

我只能想出一个办法,即每个 CSS 都分配了相同数量的分区:

for css in CSSes:
    result = service.addCss({
        'name': CSSes[css][0],
        'description': CSSes[css][1],
        'members': {
            'member': [
                {'routePartitionName':{
                        '_value_1':CSSes[css][3], 'uuid':CSSes[css][1]},
                        'index':CSSes[css][4]}
        ]}
    })

【问题讨论】:

    标签: python-3.x zeep cucm cisco-axl


    【解决方案1】:

    我不能 100% 确定我了解您的情况(主要基于提供的 sn-ps),但鉴于此数据集,其中要创建的一个 CSS 有 2 个分区,另一个有 3 个:

    CSSs = [
        {
            'name': 'CSS1',
            'description': 'CSS1 description',
            'members': [
                {
                    'name': 'Partition1',
                    'index': 1
                },
                {
                    'name': 'Partition2',
                    'index': 2
                }
            ]
        },
        {
            'name': 'CSS2',
            'description': 'CSS2 description',
            'members': [
                {
                    'name': 'Partition1',
                    'index': 1
                },
                {
                    'name': 'Partition2',
                    'index': 2
                },
                {
                    'name': 'Partition3',
                    'index': 3
                }
            ]
        }
    ]
    

    我能够通过动态附加成员来完成这项工作,如下所示:

    for css in CSSs:
        css_data = {
            'name': css['name'],
            'description': css['description'],
            'members': {
                'member': []
            }
        }
        for memb in css['members']:
            css_data['members']['member'].append(
                {
                    'routePartitionName': memb['name'],
                    'index': memb['index']
                }
            )
        css_resp = service.addCss(css_data)
    

    【讨论】:

      猜你喜欢
      • 2019-02-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-31
      • 1970-01-01
      相关资源
      最近更新 更多