go.ligato.io/vpp-agent/v3@v3.5.0/ansible/action_plugins/plugins/nat.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.nat.nat_pb2 import Nat44Global
    20  from action_plugins.pout.models.vpp.nat.nat_pb2 import DNat44
    21  
    22  
    23  def plugin_init(name, values, agent_name, ip, port):
    24      if name == 'nat':
    25          return NatValidation(values, agent_name)
    26      elif name == 'dnat':
    27          DNatValidation(values, agent_name)
    28      else:
    29          return False
    30  
    31  
    32  class NatValidation:
    33  
    34      def __init__(self, values, agent_name):
    35          self.values = values
    36          self.agent_name = agent_name
    37  
    38      def validate(self):
    39          nat = Nat44Global()
    40          Parse(json.dumps(self.values), nat)
    41          return MessageToJson(nat, preserving_proto_field_name=True, indent=None)
    42  
    43      def create_key(self):
    44          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'])