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 ...
随机推荐
- Java从入门到放弃18---Map集合/HashMap/LinkedHashMap/TreeMap/集合嵌套/Collections工具类常用方法
Java从入门到放弃18—Map集合/HashMap/LinkedHashMap/TreeMap/集合嵌套/Collections工具类常用方法01 Map集合Map集合处理键值映射关系的数据为了方便 ...
- DROP TRIGGER - 删除一个触发器定义
SYNOPSIS DROP TRIGGER name ON table [ CASCADE | RESTRICT ] DESCRIPTION 描述 DROP TRIGGER 将删除所有对一个现存触发器 ...
- Image Is Everything LA2995
白书第一章例题6 构造.思维.几何. 分别从几个角度去看,有矛盾就删掉,最后遍历一下统计个数 方法证明:第一个方块肯定要删除.假设前k个必须删除,第k+1个矛盾出现,假如不删掉,矛盾将持续存在,故必须 ...
- JS 中的事件绑定、事件监听、事件委托是什么?
在JavaScript的学习中,我们经常会遇到JavaScript的事件机制,例如,事件绑定.事件监听.事件委托(事件代理)等.这些名词是什么意思呢,有什么作用呢? 事件绑定 要想让 JavaScri ...
- git命令(使用visual studio)
拉取,提取,合并 提交到本地 切换分支 创建分支 推送到远端 删除本地分支 删除远程分支
- 在已有的mysql表中添加自增字段
现有数据表xiami,建表的时候忘记添加自增字段,现需要添加自增字段 第一步:添加字段 alter table xiami add id int; 第二步:修改字段 alter tabel xiami ...
- [JOYOI] 1061 Mobile Service
题目限制 时间限制 内存限制 评测方式 题目来源 1000ms 131072KiB 标准比较器 Local 题目描述 一个公司有三个移动服务员.如果某个地方有一个请求,某个员工必须赶到那个地方去(那个 ...
- (二十二)python 3 sort()与sorted()
Python list内置sort()方法用来排序,也可以用python内置的全局sorted()方法来对可迭代的序列排序生成新的序列 一,最简单的排序 1.使用sort排序 my_list = [3 ...
- Python中 模块、包、库
模块:就是.py文件,里面定义了一些函数和变量,需要的时候就可以导入这些模块. 包:在模块之上的概念,为了方便管理而将文件进行打包.包目录下第一个文件便是 __init__.py,然后是一些模块文件和 ...
- Linux使用yum命令安装软件时,连接不了网路报错:ERROR 6 - "Couldn't resolve host 'mirrorlist.centos.org'"
错误: 解决方案: 在/etc/sysconfig/network-scripts/ifcfg-eth0文件中配置DNS信息: vim /etc/sysconfig/network-scripts/i ...