命令:neutron.list_ports()["ports"]
(Python)为我提供了我机器上的所有IP地址。
例如:
[{u'status': u'ACTIVE',
u'name': u'',
u'allowed_address_pairs': [],
u'admin_state_up': True,
u'network_id': u'7da####81c2##79e2',
u'dns_name': u'',
u'extra_dhcp_opts': [],
u'dns_assignment': [{u'hostname': u'host-193-164-#5-##',
u'ip_address': u'193.164.#5.##',
u'fqdn': u'host-193-164-#5-##.openstacklocal.'}],
u'binding:vnic_type': u'normal',
u'device_owner': u'compute:None',
u'tenant_id': u'155##748a###3895###8b890',
u'mac_address': u'fa:##:3e:##:##:cr',
u'port_security_enabled': True,
u'fixed_ips': [{u'subnet_id': u'66####e6-###-####-a7#f-4017###6d762',
u'ip_address': u'193.164.#5.##'}],
u'id': u'170##4c7d-571f-###-a089-5c4###97d29',
u'security_groups': [u'ba6d##2-bd#58-40#c2-a5c#2-9###92a4##e'],
u'device_id': u'da##5d-###-4d6f-b##b-c3###8435'},
{u'status': u'DOWN',
u'name': u'',
u'allowed_address_pairs': [],
u'admin_state_up': True,
u'network_id': u'##',
u'dns_name': u'',
u'extra_dhcp_opts': [],
u'dns_assignment': [{u'hostname': u'host-##',
u'ip_address': u'##',
u'fqdn': u'host-##.openstacklocal.'}],
u'binding:vnic_type': u'normal',
u'device_owner': u'',
u'tenant_id': u'##',
u'mac_address': u'f##9:f7',
u'port_security_enabled': True,
u'fixed_ips': [{u'subnet_id': u'##62',
u'ip_address': u'####'}],
u'id': u'34f##b7c-######9138-##39##30e9',
u'security_groups': [u'ba##-bd58-40##5c2-9##92a4##'],
u'device_id': u''}]
我把“#”隐藏IP ......
我希望能够区分三种类型的IP:
答案 0 :(得分:0)
列表 - > num - >字典
a = [{'name': 'one'}, {'name': 'two'}]
a[0]['name']
访问元素
network = neutron.list_ports()["ports"]
for elem in network:
print a['status']
print a['network_id']
print a['ip_address']
print a['dns_assignment'][0]['ip_address']