Skip to content

Commit c7dfdd6

Browse files
miroslavKovacPantheonondrej-fabry
authored andcommitted
Add new python proto parsers (ligato#1391)
* Add new python proto paresers Signed-off-by: miroslav.kovac <[email protected]> * Add and update new plugins Signed-off-by: miroslav.kovac <[email protected]> * Change script back to executable Signed-off-by: miroslav.kovac <[email protected]>
1 parent e8fa2f9 commit c7dfdd6

17 files changed

+1158
-94
lines changed

ansible/action_plugins/plugins/bridgeDomain.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def __init__(self, values, agent_name):
4040
def validate(self):
4141
bridgeDomain = BridgeDomain()
4242
Parse(json.dumps(self.values), bridgeDomain)
43-
return MessageToJson(bridgeDomain, indent=None)
43+
return MessageToJson(bridgeDomain, preserving_proto_field_name=True, indent=None)
4444

4545
def create_key(self):
4646
return "/vnf-agent/{}/config/vpp/l2/v2/bridge-domain/{}".format(self.agent_name, self.values['name'])
@@ -69,7 +69,7 @@ def validate(self):
6969

7070
bridgeDomain = BridgeDomain()
7171
Parse(json.dumps(val), bridgeDomain)
72-
return MessageToJson(bridgeDomain, indent=None)
72+
return MessageToJson(bridgeDomain, preserving_proto_field_name=True, indent=None)
7373

7474
def create_key(self):
7575
return "/vnf-agent/{}/config/vpp/l2/v2/bridge-domain/{}".format(self.agent_name, self.values['name'])
@@ -94,7 +94,7 @@ def validate(self):
9494

9595
bridgeDomain = BridgeDomain()
9696
Parse(json.dumps(val), bridgeDomain)
97-
return MessageToJson(bridgeDomain, indent=None)
97+
return MessageToJson(bridgeDomain, preserving_proto_field_name=True, indent=None)
9898

9999
def create_key(self):
100100
return "/vnf-agent/{}/config/vpp/l2/v2/bridge-domain/{}".format(self.agent_name, self.values['name'])
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Copyright (c) 2019 PANTHEON.tech
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at:
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import json
16+
import ipaddress
17+
from google.protobuf.json_format import MessageToJson, Parse
18+
19+
from action_plugins.pout.models.vpp.l3.l3_pb2 import DHCPProxy
20+
21+
22+
def plugin_init(name, values, agent_name, ip, port):
23+
if name == 'dhcp-proxy':
24+
return DHCPProxyValidation(values, agent_name)
25+
else:
26+
return False
27+
28+
29+
class DHCPProxyValidation:
30+
31+
def __init__(self, values, agent_name):
32+
self.values = values
33+
self.agent_name =agent_name
34+
version = ipaddress.ip_address(self.values['source_ip_address']).version
35+
self.protocol = 'IPv{}'.format(version)
36+
37+
def validate(self):
38+
dhcp_proxy = DHCPProxy()
39+
Parse(json.dumps(self.values), dhcp_proxy)
40+
return MessageToJson(dhcp_proxy, preserving_proto_field_name=True, indent=None)
41+
42+
def create_key(self):
43+
return "/vnf-agent/{}/config/vpp/v2/dhcp-proxy/{}".format(self.agent_name,
44+
self.protocol)

ansible/action_plugins/plugins/interface.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def __init__(self, values, agent_name):
3535
def validate(self):
3636
interface = Interface()
3737
Parse(json.dumps(self.values), interface)
38-
return MessageToJson(interface, indent=None)
38+
return MessageToJson(interface, preserving_proto_field_name=True, indent=None)
3939

4040
def create_key(self):
4141
return "/vnf-agent/{}/config/vpp/v2/interfaces/{}".format(self.agent_name, self.values['name'])
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Copyright (c) 2019 PANTHEON.tech
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at:
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import json
16+
from google.protobuf.json_format import MessageToJson, Parse
17+
18+
from action_plugins.pout.models.linux.interfaces.interface_pb2 import Interface
19+
20+
21+
def plugin_init(name, values, agent_name, ip, port):
22+
if name == 'linuxInterface':
23+
return LinuxInterfaceValidation(values, agent_name)
24+
else:
25+
return False
26+
27+
28+
class LinuxInterfaceValidation:
29+
30+
def __init__(self, values, agent_name):
31+
self.values = values
32+
self.agent_name =agent_name
33+
34+
35+
def validate(self):
36+
dhcp_proxy = Interface()
37+
Parse(json.dumps(self.values), dhcp_proxy)
38+
return MessageToJson(dhcp_proxy, preserving_proto_field_name=True, indent=None)
39+
40+
def create_key(self):
41+
return "/vnf-agent/{}/config/linux/interfaces/v2/interface/{}".format(self.agent_name, self.values['name'])

ansible/action_plugins/plugins/nat.py

+20-2
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,14 @@
1717
from google.protobuf.json_format import MessageToJson, Parse
1818

1919
from action_plugins.pout.models.vpp.nat.nat_pb2 import Nat44Global
20+
from action_plugins.pout.models.vpp.nat.nat_pb2 import DNat44
2021

2122

2223
def plugin_init(name, values, agent_name, ip, port):
2324
if name == 'nat':
2425
return NatValidation(values, agent_name)
26+
elif name == 'dnat':
27+
DNatValidation(values, agent_name)
2528
else:
2629
return False
2730

@@ -30,12 +33,27 @@ class NatValidation:
3033

3134
def __init__(self, values, agent_name):
3235
self.values = values
33-
self.agent_name =agent_name
36+
self.agent_name = agent_name
3437

3538
def validate(self):
3639
nat = Nat44Global()
3740
Parse(json.dumps(self.values), nat)
38-
return MessageToJson(nat, indent=None)
41+
return MessageToJson(nat, preserving_proto_field_name=True, indent=None)
3942

4043
def create_key(self):
4144
return "/vnf-agent/{}/config/vpp/nat/v2/nat44-global".format(self.agent_name)
45+
46+
47+
class DNatValidation:
48+
49+
def __init__(self, values, agent_name):
50+
self.values = values
51+
self.agent_name = agent_name
52+
53+
def validate(self):
54+
nat = DNat44()
55+
Parse(json.dumps(self.values), nat)
56+
return MessageToJson(nat, preserving_proto_field_name=True, indent=None)
57+
58+
def create_key(self):
59+
return "/vnf-agent/{}/config/vpp/nat/v2/dnat44/{}".format(self.agent_name, self.values['label'])

ansible/action_plugins/plugins/route.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
# limitations under the License.
1414

1515
import json
16-
from enum import Enum
1716

1817
from google.protobuf.json_format import MessageToJson, Parse
1918

@@ -36,7 +35,7 @@ def __init__(self, values, agent_name):
3635
def validate(self):
3736
route = Route()
3837
Parse(json.dumps(self.values), route)
39-
return MessageToJson(route, indent=None)
38+
return MessageToJson(route, preserving_proto_field_name=True, indent=None)
4039

4140
def create_key(self):
4241
return "/vnf-agent/{}/config/vpp/v2/route/vrf/{}/dst/{}/gw/{}".format(self.agent_name,
+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Copyright (c) 2019 PANTHEON.tech
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at:
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import json
16+
from google.protobuf.json_format import MessageToJson, Parse
17+
18+
from action_plugins.pout.models.vpp.l2.xconnect_pb2 import XConnectPair
19+
20+
21+
def plugin_init(name, values, agent_name, ip, port):
22+
if name == 'xconnect':
23+
return XConnectValidation(values, agent_name)
24+
else:
25+
return False
26+
27+
28+
class XConnectValidation:
29+
30+
def __init__(self, values, agent_name):
31+
self.values = values
32+
self.agent_name =agent_name
33+
34+
35+
def validate(self):
36+
dhcp_proxy = XConnectPair()
37+
Parse(json.dumps(self.values), dhcp_proxy)
38+
return MessageToJson(dhcp_proxy, preserving_proto_field_name=True, indent=None)
39+
40+
def create_key(self):
41+
return "/vnf-agent/{}/config/vpp/l2/v2/xconnect/{}".format(self.agent_name,
42+
self.values['receive_interface'])
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Copyright (c) 2019 PANTHEON.tech
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at:
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Copyright (c) 2019 PANTHEON.tech
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at:
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.

0 commit comments

Comments
 (0)