How to write the plug-in of openstack neutron (1)

Source: Internet
Author: User

Since those who don't know about neutron won't read this article, and those who know it don't need me to worry about what neutron is, I decided to skip the introduction of neutron and open the news directly.

First, introduce my development environment. Instead of using devstack, I directly installed three virtual boxes on my computer and deployed an Environment: A control node according to the openstack Ubuntu Installation Guide, one Network Node and one computing node. Next, I will directly modify the files under <your path>/neutron/on the control node, and then update my modifications by restarting various services of neutron. If devstack is used, it is estimated that it is not much different from me.

The complete path of my neutron after installation is/usr/lib/python2.7/dist-packages/neutron. The file structure in neutron is as follows:

- neutron/  - agent/  - api/  - cmd/  - common/  - db/  - debug/  - extensions/  - locale/  - notifiers/  - openstack/  - plugins/  - scheduler/  - server/  - services/  - manager.py  - neutron_plugin_base_v2.py  - service.py  - wsgi.py  - ...

The self-written in will be placed under plugins/, while neutron_plugin_base_v2.py defines the minimum API set that should be implemented by plugin. Other files under extensions/and DB/are also important and will be mentioned in the following articles. Finally, I omitted some files that are not used at present.

If you are interested in how neutron loads plugin, you can add some breakpoints in manager. py to debug with PDB. It contains a class called neutronmanager. During the initialization process, a statement loads Plugin: plugin_provider = cfg. conf. core_plugin. The specific debug method can refer to a PPT of Yong sheng gong, link here: http://www.slideshare.net/gongys2004/inside-neutron-2

Well, now we are about to implement our own plugin.

The first step is to create your own folders and some files under plugins:

- neutron  - plugins    - myplugin      - __init__.py      - plugin.py

The above two files are the most basic, of course, plugin. py can also use different names. However, the name of _ init _. py cannot be changed. This tells Python myplugin that it can be regarded as a module. In plug-in. py, You can first define a class with a basic null value called myplugin, although this plug-in is useless.

from neutron.db import db_base_plugin_v2from neutron.openstack.common import logLOG = log.getLogger(__name__)class MyPlugin(db_base_plugin_v2.NeutronDbPluginV2):    def __init__(self):        LOG.info("MyPlugin is started.")

The neutron. DB and neutron. openstack. Common appearing in the code will be mentioned in subsequent chapters. You don't need to worry about them now.

Step 2: After completing the plug-in. py, you need to find a way to register this plug-in neutron, so that neutron will know this plug-in and know how to load it at startup. In this case, an entry_points.txt file is found. It is not in the neutron large folder we mentioned earlier, but in a parallel neutron egg info folder. In my environment:

- neutron- neutron-2014.1.egg-info  - entry_points.txt

In this file, there is an option [Neutron. core_plugins], and all registered core_plugins are in it. In this example, we can add one line by ourselves:

Myplugin = Neutron. plugins. myplugin. Plugin: myplugin

Then, in/etc/neutron/neturon. conf, there is an option [Default], and one line below it is used to set the core Plugin:

Core_plugin = myplugin

If the entry_points.txt file is not found, it is said that another method is to directly specify this plugin in neutron. conf:

Core_plugin = Neutron. plugins. myplugin. plugin. myplugin

However, I have not tried this method.

After completing these two steps, restart neutron to complete the work. Take a look at/var/log/neutron/server. log. If our line of log information appears, it means that neutron has loaded the plug-in that we can't do anything.

 

Then how is the plug-in implemented? See the next decomposition.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.