diff options
Diffstat (limited to 'deploy/adapters')
-rw-r--r-- | deploy/adapters/ansible/roles/setup-network/files/setup_networks/setup_networks.py | 33 | ||||
-rw-r--r-- | deploy/adapters/ansible/roles/setup-network/templates/network.cfg | 1 |
2 files changed, 15 insertions, 19 deletions
diff --git a/deploy/adapters/ansible/roles/setup-network/files/setup_networks/setup_networks.py b/deploy/adapters/ansible/roles/setup-network/files/setup_networks/setup_networks.py index bf784bb3..e58d6c72 100644 --- a/deploy/adapters/ansible/roles/setup-network/files/setup_networks/setup_networks.py +++ b/deploy/adapters/ansible/roles/setup-network/files/setup_networks/setup_networks.py @@ -5,43 +5,40 @@ import log as logging LOG = logging.getLogger("net-init") config_path = os.path.join(os.path.dirname(__file__), "network.cfg") -#from socket import AF_INET -#from pyroute2 import IPRoute -#from pyroute2 import IPRouteRequest -#ip = IPRoute() def setup_bondings(bond_mappings): print bond_mappings def add_vlan_link(interface, ifname, vlan_id): LOG.info("add_vlan_link enter") - #idx = ip.link_lookup(ifname=interface)[0] - #ip.link_create(ifname=ifname, - # kind="vlan", - # vlan_id=vlan_id, - # link=idx) cmd = "ip link add link %s name %s type vlan id %s; " % (ifname, interface, vlan_id) cmd += "ip link set %s up; ip link set %s up" % (interface, ifname) LOG.info("add_vlan_link: cmd=%s" % cmd) os.system(cmd) -def add_ovs_port(ovs_br, ifname, vlan_id=None): +def add_ovs_port(ovs_br, ifname, uplink, vlan_id=None): LOG.info("add_ovs_port enter") cmd = "ovs-vsctl --may-exist add-port %s %s" % (ovs_br, ifname) if vlan_id: cmd += " tag=%s" % vlan_id cmd += " -- set Interface %s type=internal;" % ifname + cmd += "ip link set dev %s address `ip link show %s |awk '/link\/ether/{print $2}'`;" \ + % (ifname, uplink) cmd += "ip link set %s up;" % ifname LOG.info("add_ovs_port: cmd=%s" % cmd) os.system(cmd) -def setup_intfs(sys_intf_mappings): +def setup_intfs(sys_intf_mappings, uplink_map): LOG.info("setup_intfs enter") for intf_name, intf_info in sys_intf_mappings.items(): if intf_info["type"] == "vlan": add_vlan_link(intf_name, intf_info["interface"], intf_info["vlan_tag"]) elif intf_info["type"] == "ovs": - add_ovs_port(intf_info["interface"], intf_name, vlan_id=intf_info.get("vlan_tag")) + add_ovs_port( + intf_info["interface"], + intf_name, + uplink_map[intf_info["interface"]], + vlan_id=intf_info.get("vlan_tag")) else: pass @@ -60,16 +57,14 @@ def setup_ips(ip_settings, sys_intf_mappings): cmd += "ip route add default via %s dev %s" % (intf_info["gw"], intf_name) LOG.info("setup_ips: cmd=%s" % cmd) os.system(cmd) - #idx = ip.link_lookup(ifname=intf_name)[0] - #ip.addr('add', - # index=idx, - # address=intf_info["ip"], - # broadcast=str(network.broadcast), - # prefixlen=intf_info["netmask"]) def main(config): + uplink_map = {} setup_bondings(config["bond_mappings"]) - setup_intfs(config["sys_intf_mappings"]) + for provider_net in config["provider_net_mappings"]: + uplink_map[provider_net['name']] = provider_net['interface'] + + setup_intfs(config["sys_intf_mappings"], uplink_map) setup_ips(config["ip_settings"], config["sys_intf_mappings"]) if __name__ == "__main__": diff --git a/deploy/adapters/ansible/roles/setup-network/templates/network.cfg b/deploy/adapters/ansible/roles/setup-network/templates/network.cfg index 230d10a9..75ba90cb 100644 --- a/deploy/adapters/ansible/roles/setup-network/templates/network.cfg +++ b/deploy/adapters/ansible/roles/setup-network/templates/network.cfg @@ -1,4 +1,5 @@ bond_mappings: {{ network_cfg["bond_mappings"] }} ip_settings: {{ ip_settings[inventory_hostname] }} sys_intf_mappings: {{ sys_intf_mappings }} +provider_net_mappings: {{ network_cfg["provider_net_mappings"] }} |