# Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# generated using file ./gen/model/dent/network/bridge/bridge.yaml
#
# DONOT EDIT - generated by diligent bots

import pytest
from dent_os_testbed.lib.bridge.linux.linux_bridge_link_impl import LinuxBridgeLinkImpl
from dent_os_testbed.lib.test_lib_object import TestLibObject


class BridgeLink(TestLibObject):
    """
    - bridge [ OPTIONS ] OBJECT { COMMAND | help }
    - bridge link [ show ] [ dev DEV ]

    """

    async def _run_command(api, *argv, **kwarg):
        devices = kwarg["input_data"]
        result = list()
        for device in devices:
            for device_name in device:
                device_result = {device_name: dict()}
                # device lookup
                if "device_obj" in kwarg:
                    device_obj = kwarg.get("device_obj", None)[device_name]
                else:
                    if device_name not in pytest.testbed.devices_dict:
                        device_result[device_name] = "No matching device " + device_name
                        result.append(device_result)
                        return result
                    device_obj = pytest.testbed.devices_dict[device_name]
                commands = ""
                if device_obj.os in ["dentos", "cumulus"]:
                    impl_obj = LinuxBridgeLinkImpl()
                    for command in device[device_name]:
                        commands += impl_obj.format_command(command=api, params=command)
                        commands += "&& "
                    commands = commands[:-3]

                else:
                    device_result[device_name]["rc"] = -1
                    device_result[device_name]["result"] = "No matching device OS " + device_obj.os
                    result.append(device_result)
                    return result
                device_result[device_name]["command"] = commands
                try:
                    rc, output = await device_obj.run_cmd(
                        ("sudo " if device_obj.ssh_conn_params.pssh else "") + commands
                    )
                    device_result[device_name]["rc"] = rc
                    device_result[device_name]["result"] = output
                    if "parse_output" in kwarg:
                        parse_output = impl_obj.parse_output(
                            command=api, output=output, commands=commands
                        )
                        device_result[device_name]["parsed_output"] = parse_output
                except Exception as e:
                    device_result[device_name]["rc"] = -1
                    device_result[device_name]["result"] = str(e)
                result.append(device_result)
        return result

    async def set(*argv, **kwarg):
        """
        Platforms: ['dentos', 'cumulus']
        Usage:
        BridgeLink.set(
            input_data = [{
                # device 1
                'dev1' : [{
                    # command 1
                        'dev':'string',
                        'cost':'string',
                        'priority':'int',
                        'state':'int',
                        'guard':'bool',
                        'hairpin':'bool',
                        'fastleave':'bool',
                        'root_block':'bool',
                        'learning':'bool',
                        'learning_sync':'bool',
                        'flood':'bool',
                        'hwmode':'string',
                        'mcast_flood':'bool',
                        'mcast_to_unicast':'bool',
                        'neigh_suppress':'bool',
                        'vlan_tunnel':'bool',
                        'vlan_tunnel':'bool',
                        'isolated':'bool',
                        'backup_port':'string',
                        'nobackup_port':'bool',
                        'self':'bool',
                        'master':'bool',
                        'options':'string',
                }],
            }],
        )
        Description:
        bridge link set dev DEV [ cost COST ] [ priority PRIO ] [ state STATE ] [ guard { on | off } ]
          [ hairpin { on | off } ] [ fastleave { on | off } ] [ root_block { on | off } ]
          [ learning { on | off } ] [ learning_sync { on | off } ] [ flood { on | off } ]
          [ hwmode { vepa | veb } ] [ mcast_flood { on | off } ] [ mcast_to_unicast { on | off } ]
          [ neigh_suppress { on | off } ] [ vlan_tunnel { on | off } ] [ isolated { on | off } ]
          [ backup_port DEVICE ] [ nobackup_port ] [ self ] [ master ]

        """
        return await BridgeLink._run_command("set", *argv, **kwarg)

    async def show(*argv, **kwarg):
        """
        Platforms: ['dentos', 'cumulus']
        Usage:
        BridgeLink.show(
            input_data = [{
                # device 1
                'dev1' : [{
                    # command 1
                        'dev':'string',
                        'options':'string',
                }],
            }],
        )
        Description:
        bridge link [ show ] [ dev DEV ]

        """
        return await BridgeLink._run_command("show", *argv, **kwarg)

3214a74928ed0d35147126c9e9a0a661e3cb5ef6
<mask token>

<mask token>


class BridgeLink(TestLibObject):
    <mask token>

    async def _run_command(api, *argv, **kwarg):
        devices = kwarg['input_data']
        result = list()
        for device in devices:
            for device_name in device:
                device_result = {device_name: dict()}
                if 'device_obj' in kwarg:
                    device_obj = kwarg.get('device_obj', None)[device_name]
                else:
                    if device_name not in pytest.testbed.devices_dict:
                        device_result[device_name
                            ] = 'No matching device ' + device_name
                        result.append(device_result)
                        return result
                    device_obj = pytest.testbed.devices_dict[device_name]
                commands = ''
                if device_obj.os in ['dentos', 'cumulus']:
                    impl_obj = LinuxBridgeLinkImpl()
                    for command in device[device_name]:
                        commands += impl_obj.format_command(command=api,
                            params=command)
                        commands += '&& '
                    commands = commands[:-3]
                else:
                    device_result[device_name]['rc'] = -1
                    device_result[device_name]['result'
                        ] = 'No matching device OS ' + device_obj.os
                    result.append(device_result)
                    return result
                device_result[device_name]['command'] = commands
                try:
                    rc, output = await device_obj.run_cmd(('sudo ' if
                        device_obj.ssh_conn_params.pssh else '') + commands)
                    device_result[device_name]['rc'] = rc
                    device_result[device_name]['result'] = output
                    if 'parse_output' in kwarg:
                        parse_output = impl_obj.parse_output(command=api,
                            output=output, commands=commands)
                        device_result[device_name]['parsed_output'
                            ] = parse_output
                except Exception as e:
                    device_result[device_name]['rc'] = -1
                    device_result[device_name]['result'] = str(e)
                result.append(device_result)
        return result

    async def set(*argv, **kwarg):
        """
        Platforms: ['dentos', 'cumulus']
        Usage:
        BridgeLink.set(
            input_data = [{
                # device 1
                'dev1' : [{
                    # command 1
                        'dev':'string',
                        'cost':'string',
                        'priority':'int',
                        'state':'int',
                        'guard':'bool',
                        'hairpin':'bool',
                        'fastleave':'bool',
                        'root_block':'bool',
                        'learning':'bool',
                        'learning_sync':'bool',
                        'flood':'bool',
                        'hwmode':'string',
                        'mcast_flood':'bool',
                        'mcast_to_unicast':'bool',
                        'neigh_suppress':'bool',
                        'vlan_tunnel':'bool',
                        'vlan_tunnel':'bool',
                        'isolated':'bool',
                        'backup_port':'string',
                        'nobackup_port':'bool',
                        'self':'bool',
                        'master':'bool',
                        'options':'string',
                }],
            }],
        )
        Description:
        bridge link set dev DEV [ cost COST ] [ priority PRIO ] [ state STATE ] [ guard { on | off } ]
          [ hairpin { on | off } ] [ fastleave { on | off } ] [ root_block { on | off } ]
          [ learning { on | off } ] [ learning_sync { on | off } ] [ flood { on | off } ]
          [ hwmode { vepa | veb } ] [ mcast_flood { on | off } ] [ mcast_to_unicast { on | off } ]
          [ neigh_suppress { on | off } ] [ vlan_tunnel { on | off } ] [ isolated { on | off } ]
          [ backup_port DEVICE ] [ nobackup_port ] [ self ] [ master ]

        """
        return await BridgeLink._run_command('set', *argv, **kwarg)

    async def show(*argv, **kwarg):
        """
        Platforms: ['dentos', 'cumulus']
        Usage:
        BridgeLink.show(
            input_data = [{
                # device 1
                'dev1' : [{
                    # command 1
                        'dev':'string',
                        'options':'string',
                }],
            }],
        )
        Description:
        bridge link [ show ] [ dev DEV ]

        """
        return await BridgeLink._run_command('show', *argv, **kwarg)

<mask token>


class BridgeLink(TestLibObject):
    """
    - bridge [ OPTIONS ] OBJECT { COMMAND | help }
    - bridge link [ show ] [ dev DEV ]

    """

    async def _run_command(api, *argv, **kwarg):
        devices = kwarg['input_data']
        result = list()
        for device in devices:
            for device_name in device:
                device_result = {device_name: dict()}
                if 'device_obj' in kwarg:
                    device_obj = kwarg.get('device_obj', None)[device_name]
                else:
                    if device_name not in pytest.testbed.devices_dict:
                        device_result[device_name
                            ] = 'No matching device ' + device_name
                        result.append(device_result)
                        return result
                    device_obj = pytest.testbed.devices_dict[device_name]
                commands = ''
                if device_obj.os in ['dentos', 'cumulus']:
                    impl_obj = LinuxBridgeLinkImpl()
                    for command in device[device_name]:
                        commands += impl_obj.format_command(command=api,
                            params=command)
                        commands += '&& '
                    commands = commands[:-3]
                else:
                    device_result[device_name]['rc'] = -1
                    device_result[device_name]['result'
                        ] = 'No matching device OS ' + device_obj.os
                    result.append(device_result)
                    return result
                device_result[device_name]['command'] = commands
                try:
                    rc, output = await device_obj.run_cmd(('sudo ' if
                        device_obj.ssh_conn_params.pssh else '') + commands)
                    device_result[device_name]['rc'] = rc
                    device_result[device_name]['result'] = output
                    if 'parse_output' in kwarg:
                        parse_output = impl_obj.parse_output(command=api,
                            output=output, commands=commands)
                        device_result[device_name]['parsed_output'
                            ] = parse_output
                except Exception as e:
                    device_result[device_name]['rc'] = -1
                    device_result[device_name]['result'] = str(e)
                result.append(device_result)
        return result

    async def set(*argv, **kwarg):
        """
        Platforms: ['dentos', 'cumulus']
        Usage:
        BridgeLink.set(
            input_data = [{
                # device 1
                'dev1' : [{
                    # command 1
                        'dev':'string',
                        'cost':'string',
                        'priority':'int',
                        'state':'int',
                        'guard':'bool',
                        'hairpin':'bool',
                        'fastleave':'bool',
                        'root_block':'bool',
                        'learning':'bool',
                        'learning_sync':'bool',
                        'flood':'bool',
                        'hwmode':'string',
                        'mcast_flood':'bool',
                        'mcast_to_unicast':'bool',
                        'neigh_suppress':'bool',
                        'vlan_tunnel':'bool',
                        'vlan_tunnel':'bool',
                        'isolated':'bool',
                        'backup_port':'string',
                        'nobackup_port':'bool',
                        'self':'bool',
                        'master':'bool',
                        'options':'string',
                }],
            }],
        )
        Description:
        bridge link set dev DEV [ cost COST ] [ priority PRIO ] [ state STATE ] [ guard { on | off } ]
          [ hairpin { on | off } ] [ fastleave { on | off } ] [ root_block { on | off } ]
          [ learning { on | off } ] [ learning_sync { on | off } ] [ flood { on | off } ]
          [ hwmode { vepa | veb } ] [ mcast_flood { on | off } ] [ mcast_to_unicast { on | off } ]
          [ neigh_suppress { on | off } ] [ vlan_tunnel { on | off } ] [ isolated { on | off } ]
          [ backup_port DEVICE ] [ nobackup_port ] [ self ] [ master ]

        """
        return await BridgeLink._run_command('set', *argv, **kwarg)

    async def show(*argv, **kwarg):
        """
        Platforms: ['dentos', 'cumulus']
        Usage:
        BridgeLink.show(
            input_data = [{
                # device 1
                'dev1' : [{
                    # command 1
                        'dev':'string',
                        'options':'string',
                }],
            }],
        )
        Description:
        bridge link [ show ] [ dev DEV ]

        """
        return await BridgeLink._run_command('show', *argv, **kwarg)

import pytest
from dent_os_testbed.lib.bridge.linux.linux_bridge_link_impl import LinuxBridgeLinkImpl
from dent_os_testbed.lib.test_lib_object import TestLibObject


class BridgeLink(TestLibObject):
    """
    - bridge [ OPTIONS ] OBJECT { COMMAND | help }
    - bridge link [ show ] [ dev DEV ]

    """

    async def _run_command(api, *argv, **kwarg):
        devices = kwarg['input_data']
        result = list()
        for device in devices:
            for device_name in device:
                device_result = {device_name: dict()}
                if 'device_obj' in kwarg:
                    device_obj = kwarg.get('device_obj', None)[device_name]
                else:
                    if device_name not in pytest.testbed.devices_dict:
                        device_result[device_name
                            ] = 'No matching device ' + device_name
                        result.append(device_result)
                        return result
                    device_obj = pytest.testbed.devices_dict[device_name]
                commands = ''
                if device_obj.os in ['dentos', 'cumulus']:
                    impl_obj = LinuxBridgeLinkImpl()
                    for command in device[device_name]:
                        commands += impl_obj.format_command(command=api,
                            params=command)
                        commands += '&& '
                    commands = commands[:-3]
                else:
                    device_result[device_name]['rc'] = -1
                    device_result[device_name]['result'
                        ] = 'No matching device OS ' + device_obj.os
                    result.append(device_result)
                    return result
                device_result[device_name]['command'] = commands
                try:
                    rc, output = await device_obj.run_cmd(('sudo ' if
                        device_obj.ssh_conn_params.pssh else '') + commands)
                    device_result[device_name]['rc'] = rc
                    device_result[device_name]['result'] = output
                    if 'parse_output' in kwarg:
                        parse_output = impl_obj.parse_output(command=api,
                            output=output, commands=commands)
                        device_result[device_name]['parsed_output'
                            ] = parse_output
                except Exception as e:
                    device_result[device_name]['rc'] = -1
                    device_result[device_name]['result'] = str(e)
                result.append(device_result)
        return result

    async def set(*argv, **kwarg):
        """
        Platforms: ['dentos', 'cumulus']
        Usage:
        BridgeLink.set(
            input_data = [{
                # device 1
                'dev1' : [{
                    # command 1
                        'dev':'string',
                        'cost':'string',
                        'priority':'int',
                        'state':'int',
                        'guard':'bool',
                        'hairpin':'bool',
                        'fastleave':'bool',
                        'root_block':'bool',
                        'learning':'bool',
                        'learning_sync':'bool',
                        'flood':'bool',
                        'hwmode':'string',
                        'mcast_flood':'bool',
                        'mcast_to_unicast':'bool',
                        'neigh_suppress':'bool',
                        'vlan_tunnel':'bool',
                        'vlan_tunnel':'bool',
                        'isolated':'bool',
                        'backup_port':'string',
                        'nobackup_port':'bool',
                        'self':'bool',
                        'master':'bool',
                        'options':'string',
                }],
            }],
        )
        Description:
        bridge link set dev DEV [ cost COST ] [ priority PRIO ] [ state STATE ] [ guard { on | off } ]
          [ hairpin { on | off } ] [ fastleave { on | off } ] [ root_block { on | off } ]
          [ learning { on | off } ] [ learning_sync { on | off } ] [ flood { on | off } ]
          [ hwmode { vepa | veb } ] [ mcast_flood { on | off } ] [ mcast_to_unicast { on | off } ]
          [ neigh_suppress { on | off } ] [ vlan_tunnel { on | off } ] [ isolated { on | off } ]
          [ backup_port DEVICE ] [ nobackup_port ] [ self ] [ master ]

        """
        return await BridgeLink._run_command('set', *argv, **kwarg)

    async def show(*argv, **kwarg):
        """
        Platforms: ['dentos', 'cumulus']
        Usage:
        BridgeLink.show(
            input_data = [{
                # device 1
                'dev1' : [{
                    # command 1
                        'dev':'string',
                        'options':'string',
                }],
            }],
        )
        Description:
        bridge link [ show ] [ dev DEV ]

        """
        return await BridgeLink._run_command('show', *argv, **kwarg)

# Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# generated using file ./gen/model/dent/network/bridge/bridge.yaml
#
# DONOT EDIT - generated by diligent bots

import pytest
from dent_os_testbed.lib.bridge.linux.linux_bridge_link_impl import LinuxBridgeLinkImpl
from dent_os_testbed.lib.test_lib_object import TestLibObject


class BridgeLink(TestLibObject):
    """
    - bridge [ OPTIONS ] OBJECT { COMMAND | help }
    - bridge link [ show ] [ dev DEV ]

    """

    async def _run_command(api, *argv, **kwarg):
        devices = kwarg["input_data"]
        result = list()
        for device in devices:
            for device_name in device:
                device_result = {device_name: dict()}
                # device lookup
                if "device_obj" in kwarg:
                    device_obj = kwarg.get("device_obj", None)[device_name]
                else:
                    if device_name not in pytest.testbed.devices_dict:
                        device_result[device_name] = "No matching device " + device_name
                        result.append(device_result)
                        return result
                    device_obj = pytest.testbed.devices_dict[device_name]
                commands = ""
                if device_obj.os in ["dentos", "cumulus"]:
                    impl_obj = LinuxBridgeLinkImpl()
                    for command in device[device_name]:
                        commands += impl_obj.format_command(command=api, params=command)
                        commands += "&& "
                    commands = commands[:-3]

                else:
                    device_result[device_name]["rc"] = -1
                    device_result[device_name]["result"] = "No matching device OS " + device_obj.os
                    result.append(device_result)
                    return result
                device_result[device_name]["command"] = commands
                try:
                    rc, output = await device_obj.run_cmd(
                        ("sudo " if device_obj.ssh_conn_params.pssh else "") + commands
                    )
                    device_result[device_name]["rc"] = rc
                    device_result[device_name]["result"] = output
                    if "parse_output" in kwarg:
                        parse_output = impl_obj.parse_output(
                            command=api, output=output, commands=commands
                        )
                        device_result[device_name]["parsed_output"] = parse_output
                except Exception as e:
                    device_result[device_name]["rc"] = -1
                    device_result[device_name]["result"] = str(e)
                result.append(device_result)
        return result

    async def set(*argv, **kwarg):
        """
        Platforms: ['dentos', 'cumulus']
        Usage:
        BridgeLink.set(
            input_data = [{
                # device 1
                'dev1' : [{
                    # command 1
                        'dev':'string',
                        'cost':'string',
                        'priority':'int',
                        'state':'int',
                        'guard':'bool',
                        'hairpin':'bool',
                        'fastleave':'bool',
                        'root_block':'bool',
                        'learning':'bool',
                        'learning_sync':'bool',
                        'flood':'bool',
                        'hwmode':'string',
                        'mcast_flood':'bool',
                        'mcast_to_unicast':'bool',
                        'neigh_suppress':'bool',
                        'vlan_tunnel':'bool',
                        'vlan_tunnel':'bool',
                        'isolated':'bool',
                        'backup_port':'string',
                        'nobackup_port':'bool',
                        'self':'bool',
                        'master':'bool',
                        'options':'string',
                }],
            }],
        )
        Description:
        bridge link set dev DEV [ cost COST ] [ priority PRIO ] [ state STATE ] [ guard { on | off } ]
          [ hairpin { on | off } ] [ fastleave { on | off } ] [ root_block { on | off } ]
          [ learning { on | off } ] [ learning_sync { on | off } ] [ flood { on | off } ]
          [ hwmode { vepa | veb } ] [ mcast_flood { on | off } ] [ mcast_to_unicast { on | off } ]
          [ neigh_suppress { on | off } ] [ vlan_tunnel { on | off } ] [ isolated { on | off } ]
          [ backup_port DEVICE ] [ nobackup_port ] [ self ] [ master ]

        """
        return await BridgeLink._run_command("set", *argv, **kwarg)

    async def show(*argv, **kwarg):
        """
        Platforms: ['dentos', 'cumulus']
        Usage:
        BridgeLink.show(
            input_data = [{
                # device 1
                'dev1' : [{
                    # command 1
                        'dev':'string',
                        'options':'string',
                }],
            }],
        )
        Description:
        bridge link [ show ] [ dev DEV ]

        """
        return await BridgeLink._run_command("show", *argv, **kwarg)
