Support security group name for --src-group
Support security group name for the "--src-group" option on the "os security group rule create" command. Change-Id: Ic23d0671dad77566269c9a588644c8d774368733 Closes-Bug: #1540656
This commit is contained in:
		@@ -28,7 +28,7 @@ Create a new security group rule
 | 
			
		||||
 | 
			
		||||
.. option:: --src-group <group>
 | 
			
		||||
 | 
			
		||||
    Source security group (ID only)
 | 
			
		||||
    Source security group (name or ID)
 | 
			
		||||
 | 
			
		||||
.. option:: --dst-port <port-range>
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -69,7 +69,7 @@ class CreateSecurityGroupRule(common.NetworkAndComputeShowOne):
 | 
			
		||||
        source_group.add_argument(
 | 
			
		||||
            "--src-group",
 | 
			
		||||
            metavar="<group>",
 | 
			
		||||
            help="Source security group (ID only)",
 | 
			
		||||
            help="Source security group (name or ID)",
 | 
			
		||||
        )
 | 
			
		||||
        parser.add_argument(
 | 
			
		||||
            "--dst-port",
 | 
			
		||||
@@ -103,7 +103,10 @@ class CreateSecurityGroupRule(common.NetworkAndComputeShowOne):
 | 
			
		||||
            attrs['port_range_max'] = parsed_args.dst_port[1]
 | 
			
		||||
        attrs['protocol'] = parsed_args.proto
 | 
			
		||||
        if parsed_args.src_group is not None:
 | 
			
		||||
            attrs['remote_group_id'] = parsed_args.src_group
 | 
			
		||||
            attrs['remote_group_id'] = client.find_security_group(
 | 
			
		||||
                parsed_args.src_group,
 | 
			
		||||
                ignore_missing=False
 | 
			
		||||
            ).id
 | 
			
		||||
        else:
 | 
			
		||||
            attrs['remote_ip_prefix'] = parsed_args.src_ip
 | 
			
		||||
        attrs['security_group_id'] = security_group_id
 | 
			
		||||
@@ -123,6 +126,11 @@ class CreateSecurityGroupRule(common.NetworkAndComputeShowOne):
 | 
			
		||||
            from_port, to_port = -1, -1
 | 
			
		||||
        else:
 | 
			
		||||
            from_port, to_port = parsed_args.dst_port
 | 
			
		||||
        if parsed_args.src_group is not None:
 | 
			
		||||
            parsed_args.src_group = utils.find_resource(
 | 
			
		||||
                client.security_groups,
 | 
			
		||||
                parsed_args.src_group,
 | 
			
		||||
            ).id
 | 
			
		||||
        obj = client.security_group_rules.create(
 | 
			
		||||
            group.id,
 | 
			
		||||
            parsed_args.proto,
 | 
			
		||||
 
 | 
			
		||||
@@ -149,13 +149,13 @@ class TestCreateSecurityGroupRuleNetwork(TestSecurityGroupRuleNetwork):
 | 
			
		||||
        })
 | 
			
		||||
        arglist = [
 | 
			
		||||
            '--dst-port', str(self._security_group_rule.port_range_min),
 | 
			
		||||
            '--src-group', self._security_group.id,
 | 
			
		||||
            '--src-group', self._security_group.name,
 | 
			
		||||
            self._security_group.id,
 | 
			
		||||
        ]
 | 
			
		||||
        verifylist = [
 | 
			
		||||
            ('dst_port', (self._security_group_rule.port_range_min,
 | 
			
		||||
                          self._security_group_rule.port_range_max)),
 | 
			
		||||
            ('src_group', self._security_group.id),
 | 
			
		||||
            ('src_group', self._security_group.name),
 | 
			
		||||
            ('group', self._security_group.id),
 | 
			
		||||
        ]
 | 
			
		||||
        parsed_args = self.check_parser(self.cmd, arglist, verifylist)
 | 
			
		||||
@@ -289,17 +289,17 @@ class TestCreateSecurityGroupRuleCompute(TestSecurityGroupRuleCompute):
 | 
			
		||||
        expected_columns, expected_data = self._setup_security_group_rule({
 | 
			
		||||
            'from_port': 22,
 | 
			
		||||
            'to_port': 22,
 | 
			
		||||
            'group': {'name': self._security_group.id},
 | 
			
		||||
            'group': {'name': self._security_group.name},
 | 
			
		||||
        })
 | 
			
		||||
        arglist = [
 | 
			
		||||
            '--dst-port', str(self._security_group_rule.from_port),
 | 
			
		||||
            '--src-group', self._security_group.id,
 | 
			
		||||
            '--src-group', self._security_group.name,
 | 
			
		||||
            self._security_group.id,
 | 
			
		||||
        ]
 | 
			
		||||
        verifylist = [
 | 
			
		||||
            ('dst_port', (self._security_group_rule.from_port,
 | 
			
		||||
                          self._security_group_rule.to_port)),
 | 
			
		||||
            ('src_group', self._security_group.id),
 | 
			
		||||
            ('src_group', self._security_group.name),
 | 
			
		||||
            ('group', self._security_group.id),
 | 
			
		||||
        ]
 | 
			
		||||
        parsed_args = self.check_parser(self.cmd, arglist, verifylist)
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										5
									
								
								releasenotes/notes/bug-1540656-f7b7b7e3feef2440.yaml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								releasenotes/notes/bug-1540656-f7b7b7e3feef2440.yaml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,5 @@
 | 
			
		||||
---
 | 
			
		||||
features:
 | 
			
		||||
  - The ``security group rule create`` command now supports a security
 | 
			
		||||
    group name for the ``--src-group`` option.
 | 
			
		||||
    [Bug `1540656 <https://bugs.launchpad.net/bugs/1540656>`_]
 | 
			
		||||
		Reference in New Issue
	
	Block a user