def plug_ovs(self, instance, vif): if_local_name = 'tap%s' % vif['id'][:11] if_remote_name = 'ns%s' % vif['id'][:11] bridge = vif['network']['bridge'] # Device already exists so return. if linux_net.device_exists(if_local_name): return undo_mgr = utils.UndoManager() try: utils.execute('ip', 'link', 'add', 'name', if_local_name, 'type', 'veth', 'peer', 'name', if_remote_name, run_as_root=True) linux_net.create_ovs_vif_port(bridge, if_local_name, network.get_ovs_interfaceid(vif), vif['address'], instance['uuid']) utils.execute('ip', 'link', 'set', if_local_name, 'up', run_as_root=True) except Exception: LOG.exception("Failed to configure network") msg = _('Failed to setup the network, rolling back') undo_mgr.rollback_and_reraise(msg=msg, instance=instance)
def plug_midonet(self, instance, vif): """Plug into MidoNet's network port This accomplishes binding of the vif to a MidoNet virtual port """ if_local_name = 'tap%s' % vif['id'][:11] if_remote_name = 'ns%s' % vif['id'][:11] port_id = network.get_ovs_interfaceid(vif) # Device already exists so return. if linux_net.device_exists(if_local_name): return undo_mgr = utils.UndoManager() try: utils.execute('ip', 'link', 'add', 'name', if_local_name, 'type', 'veth', 'peer', 'name', if_remote_name, run_as_root=True) undo_mgr.undo_with(lambda: utils.execute( 'ip', 'link', 'delete', if_local_name, run_as_root=True)) utils.execute('ip', 'link', 'set', if_local_name, 'up', run_as_root=True) utils.execute('mm-ctl', '--bind-port', port_id, if_local_name, run_as_root=True) except Exception: LOG.exception("Failed to configure network") msg = _('Failed to setup the network, rolling back') undo_mgr.rollback_and_reraise(msg=msg, instance=instance)
def plug_midonet(self, instance, vif): """Plug into MidoNet's network port This accomplishes binding of the vif to a MidoNet virtual port """ LOG.info('2222') if_local_name = 'tap%s' % vif['id'][:11] if_remote_name = 'ns%s' % vif['id'][:11] port_id = network.get_ovs_interfaceid(vif) # Device already exists so return. if linux_net.device_exists(if_local_name): return undo_mgr = utils.UndoManager() try: utils.execute('ip', 'link', 'add', 'name', if_local_name, 'type', 'veth', 'peer', 'name', if_remote_name, run_as_root=True) undo_mgr.undo_with(lambda: utils.execute( 'ip', 'link', 'delete', if_local_name, run_as_root=True)) utils.execute('ip', 'link', 'set', if_local_name, 'up', run_as_root=True) utils.execute('mm-ctl', '--bind-port', port_id, if_local_name, run_as_root=True) except Exception: LOG.exception("Failed to configure network") msg = _('Failed to setup the network, rolling back') undo_mgr.rollback_and_reraise(msg=msg, instance=instance)
def plug_ovs(self, instance, vif): LOG.info('8888888888888') if_local_name = 'tap%s' % vif['id'][:11] if_remote_name = 'ns%s' % vif['id'][:11] bridge = vif['network']['bridge'] # Device already exists so return. if linux_net.device_exists(if_local_name): return undo_mgr = utils.UndoManager() try: LOG.info('7777777aaaa') LOG.info('ip', 'link', 'add', 'name', if_local_name, 'type', 'veth', 'peer', 'name', if_remote_name, run_as_root=True) utils.execute('ip', 'link', 'add', 'name', if_local_name, 'type', 'veth', 'peer', 'name', if_remote_name, run_as_root=True) linux_net.create_ovs_vif_port(bridge, if_local_name, network.get_ovs_interfaceid(vif), vif['address'], instance['uuid']) utils.execute('ip', 'link', 'set', if_local_name, 'up', run_as_root=True) except Exception: LOG.exception("Failed to configure network") msg = _('Failed to setup the network, rolling back') undo_mgr.rollback_and_reraise(msg=msg, instance=instance)
def unplug_midonet(self, instance, vif): """Unplug into MidoNet's network port This accomplishes unbinding of the vif from its MidoNet virtual port """ try: utils.execute('mm-ctl', '--unbind-port', network.get_ovs_interfaceid(vif), run_as_root=True) except processutils.ProcessExecutionError: LOG.exception(_("Failed while unplugging vif"), instance=instance)
def plug_ovs(self, instance, vif, container_id): if_local_name = 'tap%s' % vif['id'][:11] if_remote_name = 'ns%s' % vif['id'][:11] bridge = vif['network']['bridge'] gateway = network.find_gateway(instance, vif['network']) ip = network.find_fixed_ip(instance, vif['network']) # Device already exists so return. if linux_net.device_exists(if_local_name): return undo_mgr = utils.UndoManager() try: utils.execute('ip', 'link', 'add', 'name', if_local_name, 'type', 'veth', 'peer', 'name', if_remote_name, run_as_root=True) linux_net.create_ovs_vif_port(bridge, if_local_name, network.get_ovs_interfaceid(vif), vif['address'], instance['uuid']) utils.execute('ip', 'link', 'set', if_local_name, 'up', run_as_root=True) utils.execute('ip', 'link', 'set', if_remote_name, 'netns', container_id, run_as_root=True) utils.execute('ip', 'netns', 'exec', container_id, 'ip', 'link', 'set', if_remote_name, 'address', vif['address'], run_as_root=True) utils.execute('ip', 'netns', 'exec', container_id, 'ifconfig', if_remote_name, ip, run_as_root=True) utils.execute('ip', 'netns', 'exec', container_id, 'ip', 'route', 'replace', 'default', 'via', gateway, 'dev', if_remote_name, run_as_root=True) except Exception: LOG.exception("Failed to configure network") msg = _('Failed to setup the network, rolling back') undo_mgr.rollback_and_reraise(msg=msg, instance=instance)