Skip to content

Commit

Permalink
Squashed commits
Browse files Browse the repository at this point in the history
 - use a single bridge instead of list of ovs bridges
 - create python scripts to wiring machines
  • Loading branch information
root committed Jul 23, 2018
1 parent 08522f8 commit 77425a3
Show file tree
Hide file tree
Showing 8 changed files with 226 additions and 18 deletions.
6 changes: 3 additions & 3 deletions plugin.spec
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ subparsers:
type: Bool
help: Whether nested virtualization should be enabled on this host.
default: False
ovs_bridges:
ovs_bridge:
type: Value
help: List of OVS bridges to set up.
default: dunno how to make a list
help: OVS bridges that connects nodes with virtual switch.
default: br-vqfx
4 changes: 1 addition & 3 deletions roles/vqfx/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,4 @@
use_nested: no
vagrant_working_dir: /home/anet-vagrant
vagrant_box_source: http://10.8.125.119/vagrant
ovs_bridges:
- br-controller
- br-baremetal
ovs_bridge: br-vqfx
12 changes: 4 additions & 8 deletions roles/vqfx/tasks/setup.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
---
#- name: Create working directory
# file:
# path: "{{ working_dir }}"
# state: directory
# become: yes
#
# install vagrant and dependencies
- name: Install vagrant
yum:
name: https://releases.hashicorp.com/vagrant/2.1.1/vagrant_2.1.1_x86_64.rpm
Expand All @@ -28,9 +21,12 @@
- libxml2-devel
- libvirt-devel
- libguestfs-tools-c
- python-ovsdbapp
- python-lxml
- libvirt-python
become: yes

# expect ansible requires a newer version
# expect ansible requires a newer version
- name: Install pexpect from pip
pip:
name: pexpect
Expand Down
3 changes: 1 addition & 2 deletions roles/vqfx/tasks/vagrant-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@
state: started

- openvswitch_bridge:
bridge: "{{ item }}"
bridge: "{{ ovs_bridge }}"
state: present
with_items: "{{ ovs_bridges }}"

- name: Find virtual switch
shell: "vagrant status vqfx-pfe | grep vqfx-pfe | grep running"
Expand Down
4 changes: 2 additions & 2 deletions roles/vqfx/templates/Vagrantfile.j2
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,14 @@ Vagrant.configure(2) do |config|
vqfx.vm.network "public_network",
:auto_config => false,
:type => "bridge",
:dev => "{{ ovs_bridges[0] }}",
:dev => "{{ ovs_bridge }}",
:ovs => true

# overcloud baremetal - xe-0/0/1
vqfx.vm.network "public_network",
:auto_config => false,
:type => "bridge",
:dev => "{{ ovs_bridges[1] }}",
:dev => "{{ ovs_bridge }}",
:ovs => true
end

Expand Down
126 changes: 126 additions & 0 deletions utils/libvirtwrap.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
# Copyright 2018 Red Hat, Inc.
#
# 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.


import libvirt
from lxml import etree

LIBVIRT_CONN = None
SUPPORTED_NETWORKS = ('network', 'bridge')


class NotFound(Exception):
pass


class DomainDict(dict):
def __init__(self):
self.update({
'undercloud': [],
'controller': [],
'compute': [],
'anet': [],
})

def add(self, value):
try:
self[value.type].append(value)
except KeyError:
print("Unknown domain %s, ignoring ..." % value.type)


class Domain(object):
def __init__(self, domain):
self.domain = domain
self.name = domain.name()
self.type = self.name.split('-')[0]
self.domxml = None
self.interfaces = []

def load_xml_definition(self):
self.domxml = etree.fromstring(self.domain.XMLDesc())
self.interfaces = [
interface_factory(iface)
for iface in self.domxml.findall('./devices/interface')
if iface.attrib['type'] in SUPPORTED_NETWORKS]

def get_interface_by_network(self, network_name):
for iface in self.interfaces:
if iface.network == network_name:
return iface
raise NotFound("Network %s was not found")

def __repr__(self):
return "<%s %s: %s>" % (self.type ,self.name, self.interfaces)


class Interface(object):
def __init__(self, interface):
self.mac = interface.find('./mac').attrib['address']
self.device = interface.find('./target').attrib['dev']

def __repr__(self):
return "<interface %s %s>" % (self.device, self.mac)

__str__ = __repr__


class BridgeInterface(Interface):
def __init__(self, interface):
super(BridgeInterface, self).__init__(interface)
self.bridge = interface.find('./source').attrib['bridge']

def __repr__(self):
return "<bridge %s %s %s>" % (
self.bridge, self.mac, self.device)


class NetworkInterface(Interface):
def __init__(self, interface):
super(NetworkInterface, self).__init__(interface)
self.network = interface.find('./source').attrib['network']
self.bridge = interface.find('./source').attrib['bridge']

def __repr__(self):
return "<network %s %s %s %s>" % (
self.network, self.mac, self.bridge, self.device)


TYPE_TO_IFACE = {
"network": NetworkInterface,
"bridge": BridgeInterface,
}


def interface_factory(interface):
return TYPE_TO_IFACE[interface.attrib['type']](interface)


def get_libvirt_connetion():
global LIBVIRT_CONN

if LIBVIRT_CONN is None:
LIBVIRT_CONN = libvirt.openReadOnly()
return LIBVIRT_CONN


def get_domains():
domains = DomainDict()
conn = get_libvirt_connetion()
for libv_domain in conn.listAllDomains():
domain = Domain(libv_domain)
domains.add(domain)
domain.load_xml_definition()

return domains
50 changes: 50 additions & 0 deletions utils/ovsdb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Copyright 2018 Red Hat, Inc.
#
# 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.

import functools

from ovs.db import idl
from ovsdbapp.backend.ovs_idl import connection
from ovsdbapp.backend.ovs_idl import idlutils
from ovsdbapp.schema.open_vswitch import helpers
from ovsdbapp.schema.open_vswitch import impl_idl

_idl = None
OVSDB_CONNECTION = 'tcp:127.0.0.1:6640'


enable_connection_uri = functools.partial(
helpers.enable_connection_uri, OVSDB_CONNECTION)


def idl_factory(conn, schema):
helper = idlutils.get_schema_helper(conn, schema)
helper.register_all()

return idl.Idl(conn, helper)


def get_idl_singleton():
global _idl

conn = OVSDB_CONNECTION
schema = "Open_vSwitch"

if _idl is None:
_connection = connection.Connection(
idl=idl_factory(conn, schema),
timeout=10)
_idl = impl_idl.OvsdbIdl(_connection)

return _idl
39 changes: 39 additions & 0 deletions utils/wire_net.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Copyright 2018 Red Hat, Inc.
#
# 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.

import argparse

import libvirtwrap
import ovsdb


def parse_args():
parser = argparse.ArgumentParser()

return parser.parse_args()


def main():
args = parse_args()
domains = libvirtwrap.get_domains()
try:
idl = ovsdb.get_idl_singleton()
except Exception:
ovsdb.enable_connection_uri()
idl = ovsdb.get_idl_singleton()


if __name__ == "__main__":
main()

0 comments on commit 77425a3

Please sign in to comment.