From 5fb4ce9c3e41a8f91a8638dd9ea39f10688ceb09 Mon Sep 17 00:00:00 2001 From: Huan Xie Date: Fri, 10 Mar 2017 02:01:15 -0800 Subject: [PATCH] Create ovs port with other params together When create ovs port in nova, it will first create ovs port using one commnd and set other parameters using seperated commands, but this isn't the correct way, because once the ovs port is created, neutron ove agent will monitor the chagne immediately and deals with the new added port, however, at this time, the other params are not set in ovs, this patch is to make creating ovs port and setting corresponding params in one operation In this patch, we add new Dom0 plugin functions ovs_create_port() and wrapper file host_network.py for calling Dom0 plugin Change-Id: Ic7bab9fd3eeed8be3f1493716178189bcf048da1 Partial-Bug: #1649747 --- os_xenapi/client/host_network.py | 24 +++++++++++++++++++ os_xenapi/client/session.py | 2 +- .../etc/xapi.d/plugins/dom0_plugin_version.py | 3 ++- os_xenapi/dom0/etc/xapi.d/plugins/xenhost.py | 17 +++++++++++++ os_xenapi/tests/client/test_session.py | 2 +- 5 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 os_xenapi/client/host_network.py diff --git a/os_xenapi/client/host_network.py b/os_xenapi/client/host_network.py new file mode 100644 index 0000000..e43f782 --- /dev/null +++ b/os_xenapi/client/host_network.py @@ -0,0 +1,24 @@ +# Copyright 2013 OpenStack Foundation +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + + +def ovs_create_port(session, bridge, port, iface_id, mac, status): + args = {'cmd': 'ovs_create_port', + 'args': {'bridge': bridge, + 'port': port, + 'iface-id': iface_id, + 'mac': mac, + 'status': status} + } + session.call_plugin_serialized('xenhost.py', 'network_config', args) diff --git a/os_xenapi/client/session.py b/os_xenapi/client/session.py index dbc4356..91fb535 100644 --- a/os_xenapi/client/session.py +++ b/os_xenapi/client/session.py @@ -66,7 +66,7 @@ class XenAPISession(object): # changed in development environments. # MAJOR VERSION: Incompatible changes with the plugins # MINOR VERSION: Compatible changes, new plguins, etc - PLUGIN_REQUIRED_VERSION = '2.0' + PLUGIN_REQUIRED_VERSION = '2.1' def __init__(self, url, user, pw, originator="os-xenapi", timeout=10, concurrent=5): diff --git a/os_xenapi/dom0/etc/xapi.d/plugins/dom0_plugin_version.py b/os_xenapi/dom0/etc/xapi.d/plugins/dom0_plugin_version.py index 9a755d2..414a653 100644 --- a/os_xenapi/dom0/etc/xapi.d/plugins/dom0_plugin_version.py +++ b/os_xenapi/dom0/etc/xapi.d/plugins/dom0_plugin_version.py @@ -37,7 +37,8 @@ import utils # 1.7 - Add Partition utilities plugin # 1.8 - Add support for calling plug-ins with the .py suffix # 2.0 - Remove plugin files which don't have .py suffix -PLUGIN_VERSION = "2.0" +# 2.1 - Add interface ovs_create_port in xenhost.py +PLUGIN_VERSION = "2.1" def get_version(session): diff --git a/os_xenapi/dom0/etc/xapi.d/plugins/xenhost.py b/os_xenapi/dom0/etc/xapi.d/plugins/xenhost.py index 2af160a..23e9af5 100644 --- a/os_xenapi/dom0/etc/xapi.d/plugins/xenhost.py +++ b/os_xenapi/dom0/etc/xapi.d/plugins/xenhost.py @@ -260,6 +260,22 @@ def _ovs_add_port(args): return _run_command(cmd_args) +def _ovs_create_port(args): + bridge = pluginlib.exists(args, 'bridge') + port = pluginlib.exists(args, 'port') + iface_id = pluginlib.exists(args, 'iface-id') + mac = pluginlib.exists(args, 'mac') + status = pluginlib.exists(args, 'status') + cmd_args = ['ovs-vsctl', '--', '--if-exists', 'del-port', port, + '--', 'add-port', bridge, port, + '--', 'set', 'Interface', port, + 'external_ids:iface-id=%s' % iface_id, + 'external_ids:iface-status=%s' % status, + 'external_ids:attached-mac=%s' % mac, + 'external_ids:xs-vif-uuid=%s' % iface_id] + return _run_command(cmd_args) + + def _ip_link_get_dev(args): device_name = pluginlib.exists(args, 'device_name') cmd_args = ['ip', 'link', 'show', device_name] @@ -338,6 +354,7 @@ ALLOWED_NETWORK_CMDS = { # allowed cmds to config OVS bridge 'ovs_add_patch_port': _ovs_add_patch_port, 'ovs_add_port': _ovs_add_port, + 'ovs_create_port': _ovs_create_port, 'ovs_del_port': _ovs_del_port, 'ovs_del_br': _ovs_del_br, 'ovs_set_if_external_id': _ovs_set_if_external_id, diff --git a/os_xenapi/tests/client/test_session.py b/os_xenapi/tests/client/test_session.py index 4d0579b..d823693 100644 --- a/os_xenapi/tests/client/test_session.py +++ b/os_xenapi/tests/client/test_session.py @@ -35,7 +35,7 @@ class SessionTestCase(base.TestCase): mock_verify_plugin_version): concurrent = 2 originator = 'os-xenapi-nova' - version = '2.0' + version = '2.1' timeout = 10 sess = mock.Mock() mock_create_session.return_value = sess