API extension扩展是标准的为Neutron项目引入新功能的方式,它允许插件决定是否要支持此新功能。
示例 Examples
演示API扩展如何书写的最简单方法是学习一个现有的API扩展,并解释不同的层级。
… toctree::
:maxdepth: 1
security_group_api
Extensions for Resources with standard attributes
从HasStandardAttributes DB类继承的资源可以自动的获得为标准属性编写的扩展(例如时间戳、修订号等),通过在其模型上定义’api_collections’来扩充资源。扩展使用它们为标准属性资源生成扩展资源地图。
向标准属性集合中添加资源必须附带新的扩展,以确保可以通过API发现它。如果它是一个全新的资源,那么一个描述资源的扩展就足够了。如果它是一个在前一个周期释放过的现有资源,第一次添加标准属性,则需要添加一个dummy扩展,指示资源现在有了标准属性。这确保了API调用程序当属性可用时,能够发现属性。
例如,如果将Flavors迁移为包含标准属性,那么需要新的’flavor-standardattr’扩展。然后作为一个API调用者,我会通过检查’flavor-standardattr’
和 ‘timestamps’,了解Flavor将具有时间戳属性。
当前被标准属性扩展支持的API资源如下:
- subnets: neutron.db.models_v2.Subnet
- trunks: neutron.services.trunk.models.Trunk
- routers: neutron.db.l3_db.Router
- segments: neutron.db.segments_db.NetworkSegment
- security_group_rules: neutron.db.models.securitygroup.SecurityGroupRule
- networks: neutron.db.models_v2.Network
- policies: neutron.db.qos.models.QosPolicy
- subnetpools: neutron.db.models_v2.SubnetPool
- ports: neutron.db.models_v2.Port
- security_groups: neutron.db.models.securitygroup.SecurityGroup
- floatingips: neutron.db.l3_db.FloatingIP