go.ligato.io/vpp-agent/v3@v3.5.0/ansible/action_plugins/plugins/route.py (about) 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 17 from google.protobuf.json_format import MessageToJson, Parse 18 19 from action_plugins.pout.models.vpp.l3.route_pb2 import Route 20 21 22 def plugin_init(name, values, agent_name, ip, port): 23 if name == 'route': 24 return RouteValidation(values, agent_name) 25 else: 26 return False 27 28 29 class RouteValidation: 30 31 def __init__(self, values, agent_name): 32 self.values = values 33 self.agent_name = agent_name 34 35 def validate(self): 36 route = Route() 37 Parse(json.dumps(self.values), route) 38 return MessageToJson(route, preserving_proto_field_name=True, indent=None) 39 40 def create_key(self): 41 return "/vnf-agent/{}/config/vpp/v2/route/vrf/{}/dst/{}/gw/{}".format(self.agent_name, 42 self.values.get('name', 0), 43 self.values['dst_network'], 44 self.values.get('next_hop_addr', ''))