Skip to content

Commit 0f29a05

Browse files
committed
Add a new open vswitch plugin
This plugin allows to add, delete and dump openflow rules for a given bridge. Signed-off-by: Guillaume <[email protected]>
1 parent 7b661ff commit 0f29a05

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

Diff for: README.md

+26
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,32 @@ Restart a service only if it is already running.
338338
$ xe host-call-plugin host-uuid<uuid> plugin=service.py fn=try_restart_service args:service=<service>
339339
```
340340

341+
342+
### `open-vswitch`
343+
344+
Add, delete and dump openflow rules.
345+
346+
347+
```
348+
$ xe host-call-plugin host-uuid<uuid> plugin=open-vswitch.py \
349+
fn=add-flow \
350+
args:bridge=xenbr0 \
351+
args:rule="ip,in_port=1,dl_src=5e:f3:5b:e6:7b:f3,nw_dst=10.10.10.0/24 actions=drop"
352+
```
353+
354+
```
355+
$ xe host-call-plugin host-uuid<uuid> plugin=open-vswitch.py \
356+
fn=del-flows \
357+
args:bridge=xenbr0 \
358+
args:rule="ip,in_port=1,dl_src=5e:f3:5b:e6:7b:f3,nw_dst=10.10.10.0/24"
359+
```
360+
361+
```
362+
$ xe host-call-plugin host-uuid<uuid> plugin=open-vswitch.py \
363+
fn=dump-flows \
364+
args:bridge=xenbr0
365+
```
366+
341367
## Tests
342368

343369
To run the plugins' unit tests you'll need to install `pytest`, `pyfakefs` and `mock`.

Diff for: SOURCES/etc/xapi.d/plugins/open-vswitch.py

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
import json
5+
6+
import XenAPIPlugin
7+
8+
from xcpngutils import configure_logging, error_wrapped
9+
10+
11+
@error_wrapped
12+
def add_flow(_session, args):
13+
_LOGGER.info("Calling add_flow with args {}".format(args))
14+
return json.dumps(True)
15+
16+
17+
@error_wrapped
18+
def del_flows(_session, args):
19+
_LOGGER.info("Calling del_flows with args {}".format(args))
20+
return json.dumps(True)
21+
22+
23+
@error_wrapped
24+
def dump_flows(session, args):
25+
_LOGGER.info("Calling check with args {}".format(args))
26+
return json.dumps(True)
27+
28+
29+
_LOGGER = configure_logging("ovs")
30+
if __name__ == "__main__":
31+
XenAPIPlugin.dispatch(
32+
{
33+
"add-flow": add_flow,
34+
"del-flows": del_flows,
35+
"dump-flows": dump_flows,
36+
}
37+
)

0 commit comments

Comments
 (0)