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 ...
随机推荐
- Kali 2017.3开启VNC远程桌面登录
通过启用屏幕共享来开启远程桌面登录,开启后需要关闭encryption,否则会出现无法连接的情况.关闭encryption可以使用系统配置工具dconf来完成.所以先安装dconf-editor. 更 ...
- Django展示第一个网页
展示一个网页需要三部分组成: urls.py -- 指定网址与对应的视图 views.py -- 创建试图以及指定对应的模板 template/*.html -- 对应的模板 一.urls.py ur ...
- centos 更换yum源 (解决下载慢的问题)
先看有没有安装wget wget -V 如果没有执行 yum -y install wget 进行安装 然后进行配置的备份 mv /etc/yum.repos.d/CentO ...
- (一) Docker in Docker
一. 背景介绍 工作中,要实现在docker中运行docker,实现镜像的拉取,创建,修改,上传等操作. 尝试过在docker中,安装docker.行不通,服务起不来. 而且直接在 docker 容 ...
- DROP DOMAIN - 删除一个用户定义的域
SYNOPSIS DROP DOMAIN name [, ...] [ CASCADE | RESTRICT ] DESCRIPTION 描述 DROP DOMAIN 将从系统表中删除一个用户域. 只 ...
- DROP DATABASE - 删除一个数据库
SYNOPSIS DROP DATABASE name DESCRIPTION 描述 DROP DATABASE 删除一个现存数据库的目录入口并且删除包含数据的目录. 只有数据库所有者能够执行这条命令 ...
- DECLARE - 定义一个游标
SYNOPSIS DECLARE name [ BINARY ] [ INSENSITIVE ] [ [ NO ] SCROLL ] CURSOR [ { WITH | WITHOUT } HOLD ...
- js hover 下拉框
<div class="box"> <div class="a f">111111</div> <div class= ...
- Openjudge-4110-圣诞老人的礼物
这一题是一道贪心的题目,但是它比较特殊的地方在于糖果可以分开拿,我们不必整箱拿,所以我们可以直接就把糖果按照价值比从大到小排序,然后整箱装不下的时候,剩余重量乘以它的价值比,这样就算出来了. 对于结构 ...
- PHP将数据库的数据转换成json格式
header('content-type:application/json;charset=utf8'); $results = array(); while ($row = mysql_f ...