代码之家  ›  专栏  ›  技术社区  ›  nskalis

OpenDaylight:API响应不一致

  •  0
  • nskalis  · 技术社区  · 6 年前

    我已经启动并运行了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 回复  |  直到 6 年前
        1
  •  0
  •   Tom Pantelis    6 年前

    您正在使用POST,这意味着如果不存在,那么第二个请求正确返回RESCONFRFC中指定的“数据存在”错误。