|
18 | 18 | @target_factory.reg_driver |
19 | 19 | @attr.s(eq=False) |
20 | 20 | class RawNetworkInterfaceDriver(Driver): |
| 21 | + """RawNetworkInterface - Manage a network interface and interact with it at a low level |
| 22 | + RawNetworkInterface binds to a NetworkInterface, RemoteNetworkInterface, or USBNetworkInterface |
| 23 | +
|
| 24 | + Args: |
| 25 | + manage_interface (bool): optional, if True this driver will |
| 26 | + setup/teardown the interface on activate/deactivate. Set this to |
| 27 | + False if you are managing the interface externally. |
| 28 | + """ |
| 29 | + |
21 | 30 | bindings = { |
22 | 31 | "iface": {"NetworkInterface", "RemoteNetworkInterface", "USBNetworkInterface"}, |
23 | 32 | } |
| 33 | + manage_interface = attr.ib(default=True, validator=attr.validators.instance_of(bool)) |
24 | 34 |
|
25 | 35 | def __attrs_post_init__(self): |
26 | 36 | super().__attrs_post_init__() |
27 | 37 | self._record_handle = None |
28 | 38 | self._replay_handle = None |
29 | 39 |
|
30 | 40 | def on_activate(self): |
31 | | - self._set_interface("up") |
32 | | - self._wait_state("up") |
| 41 | + if self.manage_inteface: |
| 42 | + self._set_interface("up") |
| 43 | + self._wait_state("up") |
33 | 44 |
|
34 | 45 | def on_deactivate(self): |
35 | | - self._set_interface("down") |
36 | | - self._wait_state("down") |
| 46 | + if self.manage_interface: |
| 47 | + self._set_interface("down") |
| 48 | + self._wait_state("down") |
37 | 49 |
|
38 | 50 | def _wrap_command(self, args): |
39 | 51 | wrapper = ["sudo", "labgrid-raw-interface"] |
|
0 commit comments