opendaylight:API响应不一致

时间:2018-07-06 12:17:40

标签: opendaylight

我已经启用并运行了Opendaylight,但是当我尝试通过REST API对其进行配置时,

执行完全相同的请求,第一次是我收到异常,第二次是我收到错误消息,表明配置已经存在。

请参见下面的示例,该示例两次发出相同的请求。 一个导致异常,另一个返回响应

我想问你:

  1. 我在哪里可以解决此问题?
  2. 我正在尝试查找一些诊断信息 用于Opendaylight BGP配置的restful GET命令,用于 例;向我显示BGP会话/组/邻居的所有BGP属性。 我在哪里可以找到?

    In [9]: cmd = """  <neighbor xmlns="urn:opendaylight:params:xml:ns:yang:bgp:openconfig-extensions">
       ...:     <neighbor-address>10.20.14.1</neighbor-address>
       ...:     <afi-safis>
       ...:         <afi-safi>
       ...:             <afi-safi-name>LINKSTATE</afi-safi-name>
       ...:         </afi-safi>
       ...:     </afi-safis>
       ...: </neighbor>
       ...: """
    
    In [10]: url = "/restconf/config/openconfig-network-instance:network-instances/network-instance/global-bgp/openconfig-network-instance:protocols/protocol/openconfig-policy-types:BGP/bgp-example/bgp/ne
        ...: ighbors"
    
    In [11]: 
    
    In [11]: requests.post('http://{}:{}{}'.format(odl['api']['ipaddr'],odl['api']['port'],url), auth=auth, headers=headers, data=cmd).json()
    ---------------------------------------------------------------------------
    JSONDecodeError                           Traceback (most recent call last)
    <ipython-input-11-6c5beab7d9fb> in <module>()
    ----> 1 requests.post('http://{}:{}{}'.format(odl['api']['ipaddr'],odl['api']['port'],url), auth=auth, headers=headers, data=cmd).json()
    
    /usr/lib/python3.6/site-packages/requests/models.py in json(self, **kwargs)
        894                     # used.
        895                     pass
    --> 896         return complexjson.loads(self.text, **kwargs)
        897 
        898     @property
    
    /usr/lib64/python3.6/json/__init__.py in loads(s, encoding, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
        352             parse_int is None and parse_float is None and
        353             parse_constant is None and object_pairs_hook is None and not kw):
    --> 354         return _default_decoder.decode(s)
        355     if cls is None:
        356         cls = JSONDecoder
    
    /usr/lib64/python3.6/json/decoder.py in decode(self, s, _w)
        337 
        338         """
    --> 339         obj, end = self.raw_decode(s, idx=_w(s, 0).end())
        340         end = _w(s, end).end()
        341         if end != len(s):
    
    /usr/lib64/python3.6/json/decoder.py in raw_decode(self, s, idx)
        355             obj, end = self.scan_once(s, idx)
        356         except StopIteration as err:
    --> 357             raise JSONDecodeError("Expecting value", s, err.value) from None
        358         return obj, end
    
    JSONDecodeError: Expecting value: line 1 column 1 (char 0)
    
    In [12]: requests.post('http://{}:{}{}'.format(odl['api']['ipaddr'],odl['api']['port'],url), auth=auth, headers=headers, data=cmd).json()
    Out[12]: 
    {'errors': {'error': [{'error-type': 'protocol',
        'error-tag': 'data-exists',
        'error-message': 'Data already exists for path: /(http://openconfig.net/yang/network-instance?revision=2015-10-18)network-instances/network-instance/network-instance[{(http://openconfig.net/yang/network-instance?revision=2015-10-18)name=global-bgp}]/protocols/protocol/protocol[{(http://openconfig.net/yang/network-instance?revision=2015-10-18)identifier=(http://openconfig.net/yang/policy-types?revision=2015-10-09)BGP, (http://openconfig.net/yang/network-instance?revision=2015-10-18)name=bgp-example}]/AugmentationIdentifier{childNames=[(urn:opendaylight:params:xml:ns:yang:bgp:openconfig-extensions?revision=2017-12-07)bgp]}/(urn:opendaylight:params:xml:ns:yang:bgp:openconfig-extensions?revision=2017-12-07)bgp/neighbors/neighbor/neighbor[{(urn:opendaylight:params:xml:ns:yang:bgp:openconfig-extensions?revision=2017-12-07)neighbor-address=10.20.14.1}]'}]}}
    

1 个答案:

答案 0 :(得分:0)

您正在使用POST,这意味着如果不存在则创建,因此第二个请求正确返回了RESTCONF RFC中指定的“数据已存在”错误。