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

如何通过az cli在TrafficManager上设置属性预期状态代码范围

  •  0
  • bramvdk  · 技术社区  · 5 年前

    我无法通过az cli为Traffic Manager配置文件设置预期的代码范围。

    我得到一个错误:

    Unable to build a model: Cannot deserialize as [MonitorConfigExpectedStatusCodeRangesItem] an object of type , DeserializationError: Cannot deserialize as [MonitorConfigExpectedStatusCodeRangesItem] an object of type 
    Traceback (most recent call last):
      File "/opt/az/lib/python3.6/site-packages/msrest/serialization.py", line 573, in body
        data = deserializer._deserialize(data_type, data)
      File "/opt/az/lib/python3.6/site-packages/msrest/serialization.py", line 1260, in _deserialize
        self._deserialize(local_type, value)
      File "/opt/az/lib/python3.6/site-packages/msrest/serialization.py", line 1260, in _deserialize
        self._deserialize(local_type, value)
      File "/opt/az/lib/python3.6/site-packages/msrest/serialization.py", line 1269, in _deserialize
        return self.deserialize_data(data, response)
      File "/opt/az/lib/python3.6/site-packages/msrest/serialization.py", line 1445, in deserialize_data
        return self.deserialize_type[iter_type](data, data_type[1:-1])
      File "/opt/az/lib/python3.6/site-packages/msrest/serialization.py", line 1474, in deserialize_iter
        type(attr)
    msrest.exceptions.DeserializationError: Cannot deserialize as [MonitorConfigExpectedStatusCodeRangesItem] an object of type 
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "/opt/az/lib/python3.6/site-packages/knack/cli.py", line 197, in invoke
        cmd_result = self.invocation.execute(args)
      File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/__init__.py", line 373, in execute
        six.reraise(*sys.exc_info())
      File "/opt/az/lib/python3.6/site-packages/six.py", line 693, in reraise
        raise value
      File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/__init__.py", line 347, in execute
        result = cmd(params)
      File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/__init__.py", line 182, in __call__
        return self.handler(*args, **kwargs)
      File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/arm.py", line 512, in handler
        result = setter(**setterargs)
      File "/opt/az/lib/python3.6/site-packages/azure/mgmt/trafficmanager/operations/profiles_operations.py", line 347, in create_or_update
        body_content = self._serialize.body(parameters, 'Profile')
      File "/opt/az/lib/python3.6/site-packages/msrest/serialization.py", line 576, in body
        SerializationError, "Unable to build a model: "+str(err), err)
      File "/opt/az/lib/python3.6/site-packages/msrest/exceptions.py", line 54, in raise_with_traceback
        raise error.with_traceback(exc_traceback)
      File "/opt/az/lib/python3.6/site-packages/msrest/serialization.py", line 573, in body
        data = deserializer._deserialize(data_type, data)
      File "/opt/az/lib/python3.6/site-packages/msrest/serialization.py", line 1260, in _deserialize
        self._deserialize(local_type, value)
      File "/opt/az/lib/python3.6/site-packages/msrest/serialization.py", line 1260, in _deserialize
        self._deserialize(local_type, value)
      File "/opt/az/lib/python3.6/site-packages/msrest/serialization.py", line 1269, in _deserialize
        return self.deserialize_data(data, response)
      File "/opt/az/lib/python3.6/site-packages/msrest/serialization.py", line 1445, in deserialize_data
        return self.deserialize_type[iter_type](data, data_type[1:-1])
      File "/opt/az/lib/python3.6/site-packages/msrest/serialization.py", line 1474, in deserialize_iter
        type(attr)
    msrest.exceptions.SerializationError: Unable to build a model: Cannot deserialize as [MonitorConfigExpectedStatusCodeRangesItem] an object of type , DeserializationError: Cannot deserialize as [MonitorConfigExpectedStatusCodeRangesItem] an object of type 
    

    我已经在Azure中设置了TrafficManager配置文件,现在我想用预期的状态代码范围更新该配置文件。在创建过程中无法设置此选项。

    我使用的命令是:

    az network traffic-manager profile update --resource-group RG20BRAM-DEV --name test --set monitorConfig.expectedStatusCodeRanges='200'
    

    致以亲切的问候, 布拉姆

    1 回复  |  直到 5 年前
        1
  •  1
  •   Charles Xu    5 年前

    您可以使用CLI命令更新Azure Traffic Manager配置文件,如下所示:

    az network traffic-manager profile update -g groupName -n trafficName --set monitorConfig.expectedStatusCodeRanges[0].max=301
    

    az network traffic-manager profile update -g groupName -n trafficName --set monitorConfig.expectedStatusCodeRanges[0].min=301
    

    看看 Traffic Manager

    使现代化

    更新的屏幕截图:

    enter image description here

    创建配置文件时,不设置属性monitorConfig.expectedStatusCodeRanges。您可以首先使用CLI命令进行设置:

    az network traffic-manager profile update -g charles -n charlesTrafficManager --set monitorConfig.expectedStatusCodeRanges='[{"min":200,"max":299}]'
    

    执行命令的屏幕截图:

    enter image description here