diff options
author | IWASE Yusuke <iwase.yusuke0@gmail.com> | 2016-10-20 16:48:12 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2016-10-25 16:22:07 +0900 |
commit | d19e7a321375a6716905893dcc041b58a6135da3 (patch) | |
tree | 9664e22562a45e120b6d28f29bdd2887f3d1cffe | |
parent | fe83cfd66d86da4bd791660d098b9e7b3629340f (diff) |
ovs: Add API corresponding to ovs-vsctl add-bond command
Signed-off-by: IWASE Yusuke <iwase.yusuke0@gmail.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r-- | ryu/lib/ovs/bridge.py | 22 | ||||
-rw-r--r-- | ryu/lib/ovs/vsctl.py | 28 |
2 files changed, 49 insertions, 1 deletions
diff --git a/ryu/lib/ovs/bridge.py b/ryu/lib/ovs/bridge.py index 79185841..2e16ee7a 100644 --- a/ryu/lib/ovs/bridge.py +++ b/ryu/lib/ovs/bridge.py @@ -172,6 +172,28 @@ class OVSBridge(object): self.run_command([command]) return command.result + def add_bond(self, name, ifaces, bond_mode=None, lacp=None): + """ + Creates a bonded port. + + :param name: Port name to be created + :param ifaces: List of interfaces containing at least 2 interfaces + :param bond_mode: Bonding mode (active-backup, balance-tcp + or balance-slb) + :param lacp: LACP mode (active, passive or off) + """ + assert len(ifaces) >= 2 + + options = '' + if bond_mode: + options += 'bond_mode=%(bond_mode)s' % locals() + if lacp: + options += 'lacp=%(lacp)s' % locals() + + command_add = ovs_vsctl.VSCtlCommand( + 'add-bond', (self.br_name, name, ifaces), options) + self.run_command([command_add]) + def add_tunnel_port(self, name, tunnel_type, remote_ip, local_ip=None, key=None, ofport=None): options = 'remote_ip=%(remote_ip)s' % locals() diff --git a/ryu/lib/ovs/vsctl.py b/ryu/lib/ovs/vsctl.py index 833f8d28..8235be25 100644 --- a/ryu/lib/ovs/vsctl.py +++ b/ryu/lib/ovs/vsctl.py @@ -1063,7 +1063,7 @@ class VSCtl(object): # Port. commands 'list-ports': (self._pre_get_info, self._cmd_list_ports), 'add-port': (self._pre_cmd_add_port, self._cmd_add_port), - # 'add-bond': + 'add-bond': (self._pre_cmd_add_bond, self._cmd_add_bond), 'del-port': (self._pre_get_info, self._cmd_del_port), # 'port-to-br': @@ -1338,6 +1338,18 @@ class VSCtl(object): self._pre_add_port(ctx, columns) + def _pre_cmd_add_bond(self, ctx, command): + self._pre_get_info(ctx, command) + + if len(command.args) < 3: + vsctl_fatal('this command requires at least 3 arguments') + + columns = [ + ctx.parse_column_key_value( + self.schema.tables[vswitch_idl.OVSREC_TABLE_PORT], + setting)[0] for setting in command.args[3:]] + self._pre_add_port(ctx, columns) + def _cmd_add_port(self, ctx, command): may_exist = command.has_option('--may_exist') @@ -1352,6 +1364,20 @@ class VSCtl(object): ctx.add_port(br_name, port_name, may_exist, False, iface_names, settings) + def _cmd_add_bond(self, ctx, command): + may_exist = command.has_option('--may_exist') + fake_iface = command.has_option('--fake-iface') + + br_name = command.args[0] + port_name = command.args[1] + iface_names = list(command.args[2]) + settings = [ + ctx.parse_column_key_value( + self.schema.tables[vswitch_idl.OVSREC_TABLE_PORT], + setting) for setting in command.args[3:]] + ctx.add_port(br_name, port_name, may_exist, fake_iface, + iface_names, settings) + def _del_port(self, ctx, br_name=None, target=None, must_exist=False, with_iface=False): assert target is not None |