zoukankan      html  css  js  c++  java
  • 怎样写 OpenStack Neutron 的 Plugin (二)

    其实上一篇博文中的内容已经涵盖了大部分写Neutron插件的技术问题,这里主要还遗留了一些有关插件的具体实现的问题。

    首先,Neutron对最基本的三个资源:Network, Port 和 Subnet 的基本调用都已经定义好了API接口。如果你的插件也需要用到这些资源,最好直接实现它们的接口。API接口的定义可以再 neutron/neutron_plugin_base_v2.py 这个文件中找到,其中每个参数的作用也有比较详细的介绍。对于用不着的资源,直接放任不管就好了,最多下次不小心调用了会发出“该接口没有被实现”的错误,不会有其他影响。这里是一个 Network API 实现的范例,其实它什么也没有做,但是确实是一个有效的接口实现:

    from neutron import neutron_plugin_base_v2
    class MyPlugin(neutron_plugin_base_v2.NeutronPluginBaseV2):
        def __init__(self):
            pass
    
        def create_network(self, context, network):
            # Create a network by using data from network dictionary
            # Send back a dictionary to display created network's info
            return network
    
        def update_network(self, context, id, network):
            # Update a created network matched by id with
            # data in the network dictionary. Send back a
            # dictionary to display the network's updated info
            return network
    
        def get_network(self, context, id, fields=None):
            network = {}
            # List information of a specific network matched by id
            # and return it in a form of dictionary
            return network
    def get_networks(self, context, filters=None, fields=None): network = {} # List all networks that are active return network def delete_network(self, context, id): # Delete a specific network matched by id # return back the id of the network. return id

    如果在具体实现这些接口的过程中,你有什么不太清楚的地方,有两个地方非常值得参考:一个是 neutron/db/db_base_plugin_v2.py,这个是neutron官方给出的一个基于数据库的实现。它只是操作数据库中的内容,模拟各个资源的创建、修改、删除等操作,但没有在物理机器上做任何改变。第二个地方就是 neutron/plugins 里面收纳的各个公司的插件实现,你可以从中学习到其他公司是怎么写插件的。

    在写插件的过程中,通常还会遇到两种问题:一、我想要实现的 Network 还有一些额外的属性,但是现在的模型中不存在,怎么办? 二、我还想实现一些其他的资源,例如Gateway,Router,Firewall 等,怎么办?

    这两种问题需要更加复杂的解决方案,属于 Neutron Extension 的范畴,我会在稍后的文章中进行介绍。

    ----------------------------------------------------------------
    作者:好大一片云
    博客地址:http://www.cnblogs.com/zhutianshi/
    转载声明:可以转载, 但必须以超链接形式标明文章原始出处和作者信息及版权声明,谢谢合作!
    Creative Commons License
    This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.
  • 相关阅读:
    定义全局时间过滤器
    vue局部过滤器和全局过滤器
    vue-ref指令
    vue进行代码排序
    vue-通过name进行数据过滤
    将vue文档下载到本地预览
    由于vue的for循环id并不严谨,提高id严谨性
    vue指令v-for报错:Elements in iteration expect to have 'v-bind:key' directives.eslint-plugin-vue
    FlowPortal BPM历史版本升级说明
    102从 Outlook 中将电子邮件、联系人和日历导出到 .pst 文件
  • 原文地址:https://www.cnblogs.com/zhutianshi/p/3898491.html
Copyright © 2011-2022 走看看