how to read openstack code: request extension
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
how to read openstack code: request extension的更多相关文章
- how to read openstack code: action extension
之前我们看过了core plugin, service plugin 还有resource extension. resource extension的作用是定义新的资源.而我们说过还有两种exten ...
- how to read openstack code: Core plugin and resource extension
本章我们将写一个自己的core plugin 和一个resource extension来加深理解.(阅读本文的前提是你已经理解了restful以及stevedore等内容) 什么是 core plu ...
- how to read openstack code: loading process
之前我们了解了neutron的结构,plugin 和 extension等信息.这一章我们看一下neutron如何加载这些plugin和extension.也就是neutron的启动过程.本文涉及的代 ...
- how to read openstack code: service plugin
We have learned core plugin, service plugin and extension in last post. Now let`s review: Core Plugi ...
- how to read openstack code
本文的目的不是介绍openstack.我们这里假设你已经知道了openstack是什么,能够做什么.所以目的是介绍如何阅读openstack的代码.通过读代码来进一步学习openstack. 转载要求 ...
- 怎样写 OpenStack Neutron 的 Extension (一)
前两篇文章讨论了怎么写一个 Neutron 的插件.但是最基本的插件只包括 Network, Port,和 Subnet 三种资源.如果需要引入新的资源,比如一个二层的 gateway 的话,就需要在 ...
- how to read openstack code: Neutron architecture
今天这一章节非常重要.我们知道neutron是一个非常复杂的系统,由很多组件构成.研究这样一个复杂的系统,正确的顺序应该是现在宏观上对其整体结构有所了解,然后再由针对性的对其组件进行深入了解.本章要做 ...
- how to read openstack code : routes
When coding a web system, you have to think about an important problem, how to map urls to logic. Op ...
- how to read openstack code : wsgi
要读懂本篇,你至少得写过一个python的web程序,并且把它部署到web服务器上过. 什么是wsgi 假设你写了一个python的web程序,并部署到了nginx上,那么一个http request ...
随机推荐
- docker 新手入门 (web项目的部署)
web项目的部署 1.首先我们下载centos镜像.docker pull centos 2.下载完成之后,我们首先要安装的是java环境 tomcat 和jdk 3.将下载好的软件放入到nmt目录 ...
- js 字符串截取 substring() 方法、 substr() 方法、slice() 方法、split() 、join();
三种 js 截取字符串的方法: substring() 方法: substr() 方法: slice() 方法: 1.:substring() 方法:string.substring(from, to ...
- 常用的-->查找算法与排序算法
顺序查找 从列表第一个元素开始,顺序进行搜索,直到找到为止. 二分查找 从有序列表的候选区data[0:n]开始,通过对待查找的值与候选区中间值的比较,可以使候选区减少一半. li = [1, 2, ...
- nginx 1.15.10 前端代理转发 将多个地址,代理转发到一个地址和端口 多系统公用一个cookie 统一token
nginx 1.15.10 前端代理转发 将多个地址,代理转发到一个地址和端口 多系统公用一个cookie 统一token 注意: proxy_pass http://192.168.40.54:22 ...
- hard fault 学习记录
使用 segger 的 hard fault 的源文件后,当调试时,发生硬件错误的时候,可以查看 HardFaultRegs 中的内容,并对比 segger_HardFaultHandler.c 中的 ...
- webpack、node、npm之间的关系
webpack能够把.vue后缀名的文件打包成浏览器能够识别的js 而这个.vue文件装换需要打包器vue-loader 这个vue-loader打包器是可以从npm上面下载(npm上面有很多资源包) ...
- 【lua实战摸索】在b.lua调用a.lua的函数
需要掌握知识: lua table的使用(创建自己函数的表作为函数库) 普通函数的调用:tab.func(tab,参数) 等效于表中函数的调用tab:func(参数) 基本思路: 1.在相同目录下创建 ...
- Linux内核网络数据包处理流程
Linux内核网络数据包处理流程 from kernel-4.9: 0. Linux内核网络数据包处理流程 - 网络硬件 网卡工作在物理层和数据链路层,主要由PHY/MAC芯片.Tx/Rx FIFO. ...
- jquery实现密码强度检测
jquery实现密码强度验证 jquery实现密码强度验证 JS代码: $('#pass').keyup(function(e) { var strongRegex = new RegExp( ...
- docker使用阿里云镜像仓库docker
1:阿里云docker仓库 https://dev.aliyun.com/search.html 2:进去注册帐号后,点击自己的管理中心. 3:在管理中心点击加速器,右边面板会有你的加速地址,右边面板 ...