how openstacksdk get_port just through ip_address

306 views Asked by At

How to get the special port information which only dependent on the ip-address field by openstacksdk API, like the result as the openstack-client tool show:

# openstack port list --fixed-ip ip-address=1.1.1.1
+-----+------+-------------+---------------------------------------+--------+
| ID  | Name | MAC Address | Fixed IP Addresses                    | Status |
+-----+------+-------------+---------------------------------------+--------+
| f23 |      | fa:*****:ad | ip_address='1.1.1.1', subnet_id='821' | ACTIVE |
+-----+------+-------------+---------------------------------------+--------+

I had try these methods, none work:

  • port = conn.network.get_port(openstack.network.v2.port.Port(fixed_ips=[{'subnet_id'" '821', 'ip_address': '1.1.1.1'}]))
  • err: openstack.exceptions.InvalidRequest: Request requires an ID but none was found

  • port = conn.network.ports(fixed_ips=[{'ip_address': '1.1.1.1'}])
  • err: openstack.exceptions.BadRequestException: BadRequestException: 400: Client Error for url: domain:9696/v2.0/ports?fixed_ips=ip_address, Invalid input for operation: 'ip_address' is not of the form <key>=[value].

  • port = conn.network.ports(fixed_ips=['1.1.1.1'])
  • err: penstack.exceptions.BadRequestException: BadRequestException: 400: Client Error for url: domain:9696/v2.0/ports?fixed_ips=1.1.1.1, Invalid input for operation: '1.1.1.1' is not of the form <key>=[value].

  • port = conn.network.ports(ip_address='1.1.1.1')
  • err: openstack.exceptions.BadRequestException: BadRequestException: 400: Client Error for url: https://gzi-ost.2980.com:9696/v2.0/ports?ip_address=1.1.1.1, ['ip_address'] is invalid attribute for filtering

Refer to these documentation: network.port-operations and openstack api list-ports-detail .

How could I achieve that? Thank you in advance.

One more thing, I couldn't know the port_id before, only know the fixed ip-address.

1

There are 1 answers

0
Victor Lee On

Obviously, my bad, the problem is that my request parameter has a wrong format data.

Solve it by import urllib to encode the request json data in Python 3.

or