go.ligato.io/vpp-agent/v3@v3.5.0/ansible/action_plugins/plugins/linuxInterface.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 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'])