from contrail_api_cli.command import Command, Arg, Option, expand_paths


class RPF(Command):
    """Simple command to enable or disable RPF (Reverse Path Forwarding) on a VN.

    To check if RPF is enabled or not run::

        contrail-api-cli rpf virtual-network/uuid

    To enable of disable RPF add ``--on`` or ``--off`` options.
    """
    description = 'enable/disable RPF on network'
    on = Option(action='store_true',
                help='Enable RPF')
    off = Option(action='store_true',
                 help='Disable RPF')
    paths = Arg(nargs='*',
                metavar='vn',
                help='List of VN')

    def __call__(self, paths=None, on=False, off=False):
        resources = expand_paths(paths,
                                 predicate=lambda r: r.type == 'virtual-network')
        for vn in resources:
            vn.fetch()
            if 'virtual_network_properties' not in vn:
                vn['virtual_network_properties'] = {
                    "allow_transit": None,
                    "forwarding_mode": None,
                    "network_id": vn.get('virtual_network_id', None),
                    "vxlan_network_identifier": None
                }
            if off:
                vn['virtual_network_properties']['rpf'] = 'disable'
                vn.save()
            elif on:
                vn['virtual_network_properties']['rpf'] = None
                vn.save()
            else:
                return 'on' if vn['virtual_network_properties'].get('rpf') is None else 'off'

@@ -1,75 +1,145 @@
-from contrail_api_cli.command import Command, Arg, Option, expand_paths
+# -*- coding: utf-8 -*-%0Afrom __future__ import unicode_literals%0A%0Afrom contrail_api_cli.command import Option%0A%0Afrom ..utils import PathCommand
 %0A%0A%0Ac
@@ -147,16 +147,20 @@
 ass RPF(
+Path
 Command)
@@ -613,99 +613,84 @@
 F')%0A
+%0A
     
-paths = Arg(nargs='*',%0A                metavar='vn',%0A                help='List of VN')
+@property%0A    def resource_type(self):%0A        return 'virtual-network'
 %0A%0A  
@@ -713,20 +713,8 @@
 elf,
- paths=None,
  on=
@@ -729,16 +729,26 @@
 ff=False
+, **kwargs
 ):%0A     
@@ -754,120 +754,42 @@
     
-resources = expand_paths(paths,%0A                                 predicate=lambda r: r.type == 'virtual-network'
+super(RPF, self).__call__(**kwargs
 )%0A  
@@ -804,16 +804,21 @@
 r vn in 
+self.
 resource

use PathCommand helper class