We have learned resource extension and action extension. This post we will write a request extension

First see two API call

curl -X POST http://liberty-controller01:9696/v2.0/networks.json -H "Content-Type: application/json" -H "Accept: application/json" -H "X-Auth-Token: $token" -d '{"network": {"name": "net3", "admin_state_up": true}}'

{"network": {"status": "ACTIVE", "subnets": [], "name": "net3", "provider:physical_network": "physnet1", "admin_state_up": true, "tenant_id": "8c5f13ee6a404759839e48537bdf69ac", "mtu": 0, "router:external": false, "shared": false, "port_security_enabled": true, "provider:network_type": "vlan", "id": "95c955ac-c963-4f53-ab4a-d721fa0cda51", "provider:segmentation_id": 490}}

It run successful. Nothing to say. Then this one

curl -X POST http://liberty-controller01:9696/v2.0/networks.json -H "Content-Type: application/json" -H "Accept: application/json" -H "X-Auth-Token: $token" -d '{"network": {"name": "net3", "admin_state_up": true, "some_attr":"some_value"}}'

{"NeutronError": {"message": "Unrecognized attribute(s) 'some_attr'", "type": "HTTPBadRequest", "detail": ""}}[root@liberty-controller01 myPluginPKG]#

This one is bad request. But the only difference is the POST body. Neutron think the some_attr is not a attribute of network and it is right. Because this is a core resource and the attribute map of this resource do not have some_attr

To solve this we need an request extension which actually update the resource attribute map of network. Below are the code

from neutron.api import extensions

EXTENDED_ATTRIBUTES_2_0 = {
'networks': {
'some_attr': {'allow_post': True,
'allow_put': False,
'is_visible': True,
'default': ''}
}
} class Myreq(extensions.ExtensionDescriptor):
@classmethod
def get_name(cls):
return "myreq" @classmethod
def get_alias(cls):
return 'myreq' @classmethod
def get_description(cls):
return "myreq" @classmethod
def get_updated(cls):
return "2017-02-08T10:00:00-00:00" def get_extended_resources(self, *args, **kwargs):
return EXTENDED_ATTRIBUTES_2_0

You can see we defined a dict in the extension and return it with method get_extended_resources.

So to implement an request extension is very easy. Define a method called get_extended_resources and return some attributes that you want to added to the original reosurce

最新文章

  1. Data对象
  2. C#各种文件操作的代码与注释
  3. 计算机视觉入门 Intorduction To Computer Vision
  4. CPU与外设传送数据方式
  5. BZOJ 1006 神奇的国度
  6. 彻底解决TAP(点透)提升移动端点击响应速度
  7. php 极简框架ES发布(代码总和不到 400 行)
  8. Linux netfilter 学习笔记
  9. Docker技术应用场景(转载)
  10. 使用bat脚本部署hexo到coding和github
  11. 集腋成裘-06-angularJS -angular_02
  12. Jmeter(二十八)_Docker+Jmeter+Gitlab+Jenkins+Ant(容器化的接口自动化持续集成平台)
  13. Android - 序列化与反序列化
  14. 【Jmeter】Jmeter 5.0新特性
  15. [Java学习] 再谈Java包
  16. fast协议解读
  17. c语言中static、extern、void的重载
  18. python-redis集合模式
  19. #运算符、不同的指针类型、数组和指针、指针运算、堆、栈、静态区、只读区、下标VS指针
  20. Linux远程管理器xshell和xftp使用教程,以及遇到关闭Xshell后项目也停止的解决方法

热门文章

  1. 【C++】cerr,cout,clog
  2. c++调用com口操作autocad
  3. 最短路 || Codeforces 938D Buy a Ticket
  4. HTML基础(一)
  5. 任务一:零基础HTML编码
  6. 使用iframe引入公共模块
  7. (7) 将tomcat HTTP连接器启动在80端口(jsvc使用详解)
  8. 笔记本无法从DHCP服务器获取地址怎么解决?
  9. 在cmd 命令中 用cd E:\ 进入不了E盘 问题
  10. .NET Core 文件的上传与下载