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