zoukankan      html  css  js  c++  java
  • neutron ml2

    版权声明:本文为博主原创文章,未经博主同意不得转载。 https://blog.csdn.net/zhoumingbo532/article/details/27964675

    在介绍ml2之前,先介绍下以往的core-plugin,它基本的工作是与数据库打交道。真正起作用的是agent。然而对于每种core-plugin来说他们绝大部代码是反复的。在实际的网络部署中。想用linuxbridge就不能用openvswitch,想用vlan就不能用greMl2插件就能够非常好解决这样的问题,在复杂的二层网络中能够灵活地部署网络。

    Ml2插件是一种同意OpenStack网络同一时候地利用多种二层网络技术的框架。眼下与openswitchlinuxbridgehyperv L2 agent协同工作。ml2框架对简化新增L2网络技术的做了非常好支持。比起以往新添加的核心插件,ML2框架须要更少的初期以及后期维护工作。

     

    ML2驱动包含类型驱动和机制驱动,分别实现了网络类型和网络机制的可扩展性。

    1类型驱动(TypeDriver):

        类型驱动能够管理多种网络类型,眼下支持local, flat, vlan, gre, vxlan等。

    2机制驱动(MechanismDriver

        机制驱动处理由类型驱动建立的信息。而且确保能够用于指定的网络机制。

    机制驱动接口支持网络、子网、端口的创建、更新、删除操作。对每一个资源,机制驱动暴露出两种方法ACTION_RESOURCE_precommit,和ACTION_RESOURCE_postcommit。

    这样的precommit方法用于验证action是否有效和维护机制驱动的私有的数据库。而且这样的方法不能被堵塞。postcommit主要负责操作资源。

    举个样例,看下ciscoupdate_port机制驱动的两个方法,你能够自己跟踪一下。 update_port_precommit维护自己私有的数据库,update_port_postcommit配置物理交换机。

        def update_port_precommit(self, context):

            port = context.current

            if self._is_deviceowner_compute(port) and self._is_status_active(port):

                self._port_action(context, self._configure_nxos_db)

     

    def update_port_postcommit(self, context):

        port = context.current

            if self._is_deviceowner_compute(port) and self._is_status_active(port):

                self._port_action(context, self._configure_switch_entry)

     

    Ml2工作机制:

      在ml2框架中实现了两个ManagerTypeManagerMechanismManager,分别管理类型驱动和网络驱动。TypeManager能够依据用户创建的网络类型调用相应的类型驱动,MechanismManager是依据计算节点的部署环境和neuron配置文件决定调用哪种机制驱动。

    1)类型驱动:

    不同的类型驱动都有自己的ml2_*TYPE*_allocations表。类型驱动主要工作维护自己的数据库表:

    ml2_gre_allocations;

    +-----------+------------+------+-----+---------+-------+

    | Field     | Type       | Null | Key | Default | Extra |

    +-----------+------------+------+-----+---------+-------+

    | gre_id    | int(11)    | NO   | PRI | NULL    |       |

    | allocated | tinyint(1) | NO   |     | NULL    |       |

    +-----------+------------+------+-----+---------+-------+

     ml2_vlan_allocations;

    +------------------+-------------+------+-----+---------+-------+

    | Field            | Type        | Null | Key | Default | Extra |

    +------------------+-------------+------+-----+---------+-------+

    | physical_network | varchar(64) | NO   | PRI | NULL    |       |

    | vlan_id          | int(11)     | NO   | PRI | NULL    |       |

    | allocated        | tinyint(1)  | NO   |     | NULL    |       |

    +------------------+-------------+------+-----+---------+-------+

    2)机制驱动

    机制驱动能够在openstack环境中同一时候使用不同的网络机制。那么他是怎样工作的呢?假如我的计算节点Ac-a)。部署了neutron-openvswitch-agent服务,当启动虚拟机时(指定网络id)。nova-scheduler把虚拟机调度到c-a节点上,c-anova-compute服务会调用neutroncreate_port接口,当中create_port中会使用一个非常重要的方法:bind_portMechanismManager),MechanismManager.bind_port会循环调用全部支持的网络机制的bind_port方法进行端口与agent绑定,绑定成功则返回。

    openvswitch机制驱动bind_port主要依据调度到c-a的主机名和机制驱动的agent_type去数据库agents表中找相应的agent服务的信息(每种机制驱动都有自己的agent_typevif_typec-a的主机名是通过create_port携带的binding:host_id获得),再推断openvswitch是否支持端口所在的网络类型。

    经过上面的处理就把端口和openvswitch这样的网络机制绑定起来。

    详细操作例如以下:

    MechanismManager

        def bind_port(self, context):

            binding = context._binding

            for driver in self.ordered_mech_drivers:#循环顺序调用

                try:

                    driver.obj.bind_port(context)#调用机制驱动的bind_port

                    if binding.segment:

                        binding.driver = driver.name              

                        return#绑定上则返回

                except Exception:

                    LOG.exception(_("Mechanism driver %s failed in "

                                    "bind_port"),

                                  driver.name)

            binding.vif_type = portbindings.VIF_TYPE_BINDING_FAILED

     

     

    MechanismDriver

        def bind_port(self, context):

            vnic_type = context.current.get(portbindings.VNIC_TYPE,

                                            portbindings.VNIC_NORMAL)

            if vnic_type not in self.supported_vnic_types:

                return   

            for agent in context.host_agents(self.agent_type):#依据agent_typebind_host从数据库表agents获去

                if agent['alive']:

                    for segment in context.network.network_segments:

                        if self.try_to_bind_segment_for_agent(context, segment,

                                                              agent):#检測网络机制是否支持port所在网络的网络类型

                            return#绑定上则返回

                else:

                    LOG.warning(_("Attempting to bind with dead agent: %s"),

                                agent)

     

    绑定完毕会在数据库中记录绑定的信息

    ml2_port_bindings;

    +--------------------------------------+--------+----------+-------------+--------------------------------------+-----------+------------------------------------------------+---------+

    | port_id                              | host   | vif_type | driver      | segment                              | vnic_type | vif_details                                    | profile |

    +--------------------------------------+--------+----------+-------------+--------------------------------------+-----------+------------------------------------------------+---------+

    | 54259db7-68f2-4b33-a37c-8f134100f3fc | ubuntu | ovs      | openvswitch | 884cc396-ccec-4e56-9dc8-e6ccd3e7c9ea | normal    | {"port_filter": true, "ovs_hybrid_plug": true} |         |

    | 5e1c574a-e345-4c65-889f-59bff79fa31d | ubuntu | ovs      | openvswitch | 884cc396-ccec-4e56-9dc8-e6ccd3e7c9ea | normal    | {"port_filter": true, "ovs_hybrid_plug": true} | {}      |

    +--------------------------------------+--------+----------+-------------+--------------------------------------+-----------+------------------------------------------------+---------+

    Nova端会依据vif_type使用不同的网络机制。

查看全文
  • 相关阅读:
    centos6.8添加crontab定时启动任务
    centos7用户最大进程限制导致的问题排查
    centos ftp 服务器搭建
    centos6.8的坑
    华为云centos服务器挂载云硬盘
    华为云windows开启特定端口
    华为云centos上命令
    排查机器服务无法使用步骤
    高(0.10.X以上版本)低(0.10.X以下版本)版本kafka如何共存
    PHP array_column重新构建二维数组
  • 原文地址:https://www.cnblogs.com/ldxsuanfa/p/10707025.html
  • Copyright © 2011-2022 走看看