# coding: utf-8

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

class ModifySecurityGroupRuleAttributesAction(BaseAction):

    action = 'ModifySecurityGroupRuleAttributes'
    command = 'modify-security-group-rule-attributes'
    usage = '%(prog)s -r <security_group_rule_id> -p <priority> [-f <conf_file>]'

    @classmethod
    def add_ext_arguments(cls, parser):
        parser.add_argument('-r', '--security_group_rule', dest='security_group_rule',
                action='store', type=str, default='',
                help='ID of security group rule whose attributes you want to update.')

        parser.add_argument('-n', '--name', dest='name',
                action='store', type=str, default=None,
                help='name of the rule. ')

        parser.add_argument('-p', '--priority', dest='priority',
                action='store', type=int, default=None,
                help='priority of the rule. ')

    @classmethod
    def build_directive(cls, options):
        required_params = {
                'security_group_rule': options.security_group_rule,
                'priority': options.priority,
                }
        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 {
                'security_group_rule': options.security_group_rule,
                'priority': options.priority,
                'security_group_rule_name': options.name,
                }

@@ -635,17 +635,17 @@
 ument('-
-n
+N
 ', '--na
@@ -749,33 +749,32 @@
 ame of the rule.
- 
 ')%0A%0A        pars
@@ -928,345 +928,1673 @@
 rule
-. ')%0A%0A    @classmethod%0A    def build_directive(cls, options):%0A        required_params = %7B%0A                'security_group_rule': options.security_group_rule,%0A                'priority': options.priority,%0A                %7D%0A        for param in require
+, from 0 to 100.')%0A%0A        parser.add_argument('-P', '--protocol', dest='protocol',%0A                action='store', type=str, default=None,%0A                help='protocol of the rule.')%0A%0A        parser.add_argument('-a', '--rule_action', dest='rule_action',%0A                action='store', type=str, default=None,%0A                help='action of the rule: %22accept%22 or %22drop%22.')%0A%0A        parser.add_argument('-d', '--direction', dest='direction',%0A                action='store', type=int, default=None,%0A                help='direction of the rule: 0 for inbound, 1 for outbound.')%0A%0A        parser.add_argument('--val1', dest='val1',%0A                action='store', type=str, default=None,%0A                help='''for %22icmp%22, this field is icmp type;%0A                        for %22tcp/udp%22, it is start port(empty means all).''')%0A%0A        parser.add_argument('--val2', dest='val2',%0A                action='store', type=str, default=None,%0A                help='''for %22icmp%22, this field is icmp code;%0A                        for %22tcp/udp%22, it is end port(empty means all).''')%0A%0A        parser.ad
 d_
-p
 ar
-ams:%0A            if required_params%5Bparam%5D is None or required_params%5Bparam%5D == ''
+gument('--val3', dest='val3',%0A                action='store', type=str, default=None,%0A                help='ip network, e.g %221.2.3.0/24%22')%0A%0A    @classmethod%0A    def build_directive(cls, options):%0A        if not options.security_group_rule:%0A            print 'error: %5Bsecurity_group_rule%5D should be specified'%0A            return None%0A%0A        if options.rule_action or options.direction or options.protocol:%0A            if not options.priority:%0A                print 'error: %5Bpriority%5D should be specified'%0A                return None%0A%0A            if not options.protocol
 :%0A  
@@ -2626,10 +2626,16 @@
 r: %5B
-%25s
+protocol
 %5D sh
@@ -2656,16 +2656,8 @@
 ied'
- %25 param
 %0A   
@@ -2681,20 +2681,16 @@
 rn None%0A
-    
 %0A       
@@ -2871,16 +2871,276 @@
 s.name,%0A
+                'protocol': options.protocol,%0A                'direction': options.direction,%0A                'rule_action': options.rule_action,%0A                'val1': options.val1,%0A                'val2': options.val2,%0A                'val3': options.val3,%0A
         

Add more options to modify-security-group-rule-attributes