Files
compute-hyperv/hyperv/nova/ovsutils.py
Adelina Tuvenie ff76f3774e Adds Hyper-V OVS ViF driver
This branch adds a new ViF driver to the Nova Hyper-V compute driver.
It's responsible for creating the OVS port and the related association
with the Hyper-V virtual switch port. Aside from the openvswitch binaries
it has no other dependencies. Flow rules are added by an external agent
such as OpenDaylight or by a Neutron OVS agent.

Change-Id: I4cee52f65968fa503f2c8a2c9a206489719fb15a
Implements: blueprint hyper-v-ovs-vif
2015-05-12 14:39:36 -07:00

71 lines
2.4 KiB
Python

# Copyright 2014 Cloudbase Solutions Srl
# All Rights Reserved.
#
# 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.
"""
Implements necessary OVS helper functions. These functions are similar
to the linux_net ones but have linux specific options, such as run_as_root
and delete_net_dev, removed.
This also allows us the flexibility to adapt to any future platform
specific differences.
"""
import os
from nova import exception
from nova import utils
from oslo_config import cfg
from oslo_log import log as logging
from hyperv.i18n import _LE
LOG = logging.getLogger(__name__)
net_cfg = [
cfg.IntOpt('ovs_vsctl_timeout',
default=120,
help='Amount of time, in seconds, that ovs_vsctl should wait '
'for a response from the database. 0 is to wait forever.'),
]
CONF = cfg.CONF
CONF.register_opts(net_cfg)
def _ovs_vsctl(args):
full_args = ['ovs-vsctl', '--timeout=%s' % CONF.ovs_vsctl_timeout] + args
try:
return utils.execute(*full_args)
except Exception as e:
LOG.error(_LE("Unable to execute %(cmd)s. Exception: %(exception)s"),
{'cmd': full_args, 'exception': e})
raise exception.AgentError(method=full_args)
def create_ovs_vif_port(bridge, dev, iface_id, mac, instance_id):
_ovs_vsctl(['--', '--if-exists', 'del-port', dev, '--',
'add-port', bridge, dev,
'--', 'set', 'Interface', dev,
'external-ids:iface-id=%s' % iface_id,
'external-ids:iface-status=active',
'external-ids:attached-mac=%s' % mac,
'external-ids:vm-uuid=%s' % instance_id])
def delete_ovs_vif_port(bridge, dev):
_ovs_vsctl(['--', '--if-exists', 'del-port', bridge, dev])
def check_bridge_has_dev(bridge, dev, run_as_root=True):
ports = _ovs_vsctl(['--', 'list-ports', bridge])[0]
return dev in ports.split(os.linesep)