diff --git a/neutronclient/neutron/v2_0/floatingip.py b/neutronclient/neutron/v2_0/floatingip.py index 15aa69a85..c6b3345f5 100644 --- a/neutronclient/neutron/v2_0/floatingip.py +++ b/neutronclient/neutron/v2_0/floatingip.py @@ -64,6 +64,10 @@ class CreateFloatingIP(neutronV20.CreateCommand): parser.add_argument( '--floating-ip-address', help=_('IP address of the floating IP')) + parser.add_argument( + '--subnet', + dest='subnet_id', + help=_('Subnet ID on which you want to create the floating IP.')) def args2body(self, parsed_args): _network_id = neutronV20.find_resourceid_by_name_or_id( @@ -72,7 +76,7 @@ class CreateFloatingIP(neutronV20.CreateCommand): neutronV20.update_dict(parsed_args, body, ['port_id', 'tenant_id', 'fixed_ip_address', - 'floating_ip_address']) + 'floating_ip_address', 'subnet_id']) return {self.resource: body} diff --git a/neutronclient/tests/unit/test_cli20_floatingips.py b/neutronclient/tests/unit/test_cli20_floatingips.py index 92f527a4b..4f09856b1 100644 --- a/neutronclient/tests/unit/test_cli20_floatingips.py +++ b/neutronclient/tests/unit/test_cli20_floatingips.py @@ -85,6 +85,35 @@ class CLITestV20FloatingIpsJSON(test_cli20.CLITestV20Base): self._test_create_resource(resource, cmd, name, myid, args, position_names, position_values) + def test_create_floatingip_with_subnet_id(self): + """Create floatingip: fip1 on a given subnet id.""" + resource = 'floatingip' + cmd = fip.CreateFloatingIP(test_cli20.MyApp(sys.stdout), None) + name = 'fip1' + myid = 'myid' + subnet_id = 'mysubnetid' + + args = [name, '--subnet', subnet_id] + position_values = [name, subnet_id] + position_names = ['floating_network_id', 'subnet_id'] + self._test_create_resource(resource, cmd, name, myid, args, + position_names, position_values) + + def test_create_floatingip_with_subnet_id_and_port(self): + """Create floatingip: fip1 on a given subnet id and port.""" + resource = 'floatingip' + cmd = fip.CreateFloatingIP(test_cli20.MyApp(sys.stdout), None) + name = 'fip1' + myid = 'myid' + pid = 'mypid' + subnet_id = 'mysubnetid' + + args = [name, '--subnet', subnet_id, '--port-id', pid] + position_values = [name, subnet_id, pid] + position_names = ['floating_network_id', 'subnet_id', 'port_id'] + self._test_create_resource(resource, cmd, name, myid, args, + position_names, position_values) + def test_list_floatingips(self): """list floatingips: -D.""" resources = 'floatingips'