If you want to get understanding about Neutron ML2 Plugin, you can check the below link:

https://wiki.openstack.org/wiki/Neutron/ML2

In this post I will show you how to write a ML2 mechanism driver. What I am going to do is write a driver called mech_vietstack, then create a network. You will see the implementation of mech_vietstack in network creating. In addition, you can extend other functions such as network update, delete or subnet create, etc.

 

One of the key objectives of ML2 is to support multiple mechanism drivers under one plugin. It was previously not possible with a monolithic plugin. Hence if you see in ML2 plugin.py file, it calmly receives the request how any other plugin does. It then performs all the internal operations that it needs to do like updating database entries, setting up the internal services, etc. After doing all that it dispatches the request to all the mechanism drivers you have registered in /etc/neutron/plugins/ml2/ml2_conf.ini in the following section:

/neutron/plugins/ml2/plugin.py

Screenshot from 2015-09-01 13:09:03

(Source: http://control-that-vm.blogspot.hu/2014/08/writing-your-own-mechanism-driver-for.html)

/neutron/plugins/ml2/driver_api:

Includes the definitions of all the methods used in ML2 mechanism drivers. In this file, there are methods that will called the specific methods defined in each ML2 mechanism driver, for example, the method create_network() in driver_api will refer to create_network_precommit(), create_network_commit() methods. The way those methods are defined is specified in each mechanism driver. See the example of mech_vietstack as an easy definition of those methods.

 

*********************

/etc/neutron/plugins/ml2/ml2_conf.ini

[ml2]

mechanism_drivers = openvswitch,linuxbridge,vietstack

**********************

/opt/stack/neutron/neutron.egg-info/entry_points.txt

[neutron.ml2.mechanism_drivers]

vietstack = neutron.plugins.ml2.drivers.mech_vietstack:VietstackMechanismDriver

The name “vietstack” here will be passed to the mechanism_drivers in ml2_conf and it specifies the path to the mentioned mechanism driver. VietstackMechanismDriver is the class inside the mech_vietstack mechanism driver.

******************

Screenshot from 2015-09-01 13:07:54

*****************

Now, restart neutron-server then boot a network called “vietstack1”

**************

See the logs below to see how “mech_vietstack” is implemented.

25573 INFO neutron.plugins.ml2.managers [-] Configured mechanism driver names: ['openvswitch', 'linuxbridge', 'vietstack']

INFO neutron.plugins.ml2.managers [-] Loaded mechanism driver names: ['openvswitch', 'linuxbridge', 'vietstack']

INFO neutron.plugins.ml2.managers [-] Registered mechanism drivers: ['openvswitch', 'linuxbridge', 'vietstack']

INFO neutron.plugins.ml2.drivers.mech_vietstack [-] Initializing

INFO neutron.plugins.ml2.drivers.mech_vietstack [req-537b93a0-f369-40f1-8f38-5462c5555f3f admin admin] Create Network Precommits with network_id: 89a7527b-b0a6-4428-8e7e-fd52afbd7319, tenant_id: f7f97372bd184eab8588d822ad5b5e18, segment: [{'segmentation_id': 1054L, 'physical_network': None, 'id': u'd27252cb-c0e7-454f-ae55-d7fb021f4b84', 'network_type': u'vxlan'}]

INFO neutron.plugins.ml2.drivers.mech_vietstack [req-537b93a0-f369-40f1-8f38-5462c5555f3f admin admin] Create Network Postcommits with network_id: 89a7527b-b0a6-4428-8e7e-fd52afbd7319, tenant_id: f7f97372bd184eab8588d822ad5b5e18

1/9/2015

VietStack Team