Skip to content

Commit

Permalink
WIP - add plumb_dataport_method
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewdmcleod committed Sep 24, 2019
1 parent eec4334 commit 19306d6
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
11 changes: 11 additions & 0 deletions zaza/openstack/configure/network.py
Expand Up @@ -219,6 +219,17 @@ def setup_gateway_ext_port(network_config, keystone_session=None):
dvr_mode=network_config.get("dvr_enabled", False),
net_id=net_id)

current_release = openstack_utils.get_os_release()
bionic_queens = openstack_utils.get_os_release('bionic_queens')
if current_release >= bionic_queens:
logging.warn("Adding second interface for dataport to guest netplan, \
for bionic-queens and later")
openstack_utils.plumb_guest_nic(
nova_client,
neutron_client,
dvr_mode=network_config.get("dvr_enabled", False),
net_id=net_id)


def run_from_cli(**kwargs):
"""Run network configurations from CLI.
Expand Down
55 changes: 55 additions & 0 deletions zaza/openstack/utilities/openstack.py
Expand Up @@ -55,6 +55,7 @@
import tempfile
import tenacity
import urllib
import textwrap

from zaza import model
from zaza.openstack.utilities import (
Expand Down Expand Up @@ -483,6 +484,60 @@ def get_admin_net(neutron_client):
return net


def plumb_guest_nic(novaclient, neutronclient,
dvr_mode=None, net_id=None):

"""Add port associated with net_id to netplan
:type net_id: string
"""

if dvr_mode:
uuids = get_ovs_uuids()
else:
uuids = get_gateway_uuids()

for uuid in uuids:
server = novaclient.servers.get(uuid)
ext_port_name = "{}_ext-port".format(server.name)
for port in neutronclient.list_ports(device_id=server.id)['ports']:
if port['name'] == ext_port_name:
logging.info('Adding second port to netplan in guest:\
{}'.format(port['name']))
mac_address = port['mac_address']
if dvr_mode:
application_name = 'neutron-openvswitch'
else:
application_name = 'neutron-gateway'
unit_name = juju_utils.get_unit_name_from_ip_address(
server.ip, application_name)
interface = model.async_run_on_unit(
unit_name, "ip addr|grep\
{}".format(
mac_address)).split("\n")[0].split(" ")[2]
body_value = textwrap.dedent("""\
network:
ethernets:
{}:
dhcp4: false
dhcp6: true
optional: true
match:
macaddress: {}
set-name: {}
\n
version: 2
""".format(interface, mac_address, interface))
netplan_file = open("60-dataport.yaml", "w")
netplan_file.write(body_value)
netplan_file.close()
model.async_scp_to_unit(unit_name, './60-dataport.yaml',
'/etc/netplan/', user="root")
subprocess.call("rm 60-dataport.yaml")
model.async_run_on_unit(unit_name, "netplan apply",
user="root")


def configure_gateway_ext_port(novaclient, neutronclient,
dvr_mode=None, net_id=None):
"""Configure the neturong-gateway external port.
Expand Down

0 comments on commit 19306d6

Please sign in to comment.