# coding: utf-8

from qingcloud.cli.iaas_client.actions.base import BaseAction

class JoinRouterAction(BaseAction):

    action = 'JoinRouter'
    command = 'join-router'
    usage = '%(prog)s -r <router_id>] -v <vxnet_id> -n <ip_network> [-f <features>] [options] [-f <conf_file>]'

    @classmethod
    def add_ext_arguments(cls, parser):
        parser.add_argument('-r', '--router', dest='router',
                action='store', type=str, default='',
                help='ID of the router which vxnet will join.')

        parser.add_argument('-v', '--vxnet', dest='vxnet',
                action='store', type=str, default='',
                help='the id of the vxnet that will join the router.')

        parser.add_argument('-F', '--features', dest='features',
                action='store', type=int, default=1,
                help='''
                the integer value of the bit mask that represent the selected features.
                Masking Bit:
                1 - dhcp server
                ''')

        parser.add_argument('-n', '--ip_network', dest='ip_network',
                action='store', type=str, default='',
                help='the ip_network, e.g. `192.168.x.0/24` ')

    @classmethod
    def build_directive(cls, options):
        required_params = {
                'router': options.router,
                'vxnet': options.vxnet,
                'ip_netword': options.ip_network,
                }
        for param in required_params:
            if required_params[param] is None or required_params[param] == '':
                print 'error: [%s] should be specified' % param
                return None

        return {
                'router': options.router,
                'vxnet': options.vxnet,
                'features': options.features,
                'ip_network': options.ip_network,
                }

@@ -200,17 +200,16 @@
 uter_id%3E
-%5D
  -v %3Cvxn
@@ -245,16 +245,66 @@
 eatures%3E
+ -m %3Cmanager_ip%3E -S %3Cdyn_ip_start%3E -E %3Cdyn_ip_end%3E
 %5D %5Boptio
@@ -744,24 +744,209 @@
  router.')%0A%0A
+        parser.add_argument('-n', '--ip_network', dest='ip_network',%0A                action='store', type=str, default='',%0A                help='ip for vxnet, e.g. %60192.168.x.0/24%60 ')%0A%0A
         pars
@@ -1281,44 +1281,298 @@
 t('-
-n
+m
 ', '--
-ip_network', dest='ip_network
+manager_ip', dest='manager_ip',%0A                action='store', type=str, default=None,%0A                help='the manager ip, this can be used as default gateway within the private network, e.g. %22192.168.x.2%22.')%0A%0A        parser.add_argument('-S', '--dyn_ip_start', dest='dyn_ip_start
 ',%0A 
@@ -1612,34 +1612,36 @@
 pe=str, default=
-''
+None
 ,%0A              
@@ -1652,30 +1652,262 @@
 lp='
-the ip_network
+starting ip allocated from DHCP server, e.g. %22192.168.x.2%22.')%0A%0A        parser.add_argument('-E', '--dyn_ip_end', dest='dyn_ip_end',%0A                action='store', type=str, default=None,%0A                help='ending ip allocated from DHCP server
 , e.g. 
-%60
+%22
 192.
@@ -1904,38 +1904,37 @@
 e.g. %22192.168.x.
-0/24%60 
+254%22.
 ')%0A%0A    @classme
@@ -2510,16 +2510,16 @@
 atures,%0A
-
         
@@ -2552,32 +2552,186 @@
 ons.ip_network,%0A
+                'manager_ip': options.manager_ip,%0A                'dyn_ip_start': options.dyn_ip_start,%0A                'dyn_ip_end': options.dyn_ip_end,%0A
                 

Add more params to join-router