diff options
| author | Justin Santa Barbara <justin@fathomdb.com> | 2011-02-23 22:50:33 +0000 |
|---|---|---|
| committer | Tarmac <> | 2011-02-23 22:50:33 +0000 |
| commit | cd301d67506bcb6d67d921492435e9d7d56aafb1 (patch) | |
| tree | 77667bd9ef0841c3622670ed97d0a63c18e8e7d6 /nova/api | |
| parent | ed9bdfc8b61470bbe3f61ef7bf3f3044f8483b8a (diff) | |
| parent | 8c007b56b586257d048b6db4ecfbed8f502381fd (diff) | |
| download | nova-cd301d67506bcb6d67d921492435e9d7d56aafb1.tar.gz nova-cd301d67506bcb6d67d921492435e9d7d56aafb1.tar.xz nova-cd301d67506bcb6d67d921492435e9d7d56aafb1.zip | |
Helper function that supports XPath style selectors to traverse an object tree e.g.
inst = {'fixed_ip': {'floating_ips': [{'address': '1.2.3.4'}], 'address': '192.168.0.3'}, 'hostname': ''}
private_ips = get_from_path(inst, 'fixed_ip/address')
public_ips = get_from_path(inst, 'fixed_ip/floating_ips/address')
Avoids messy [.get() / if / for]* nested code
Diffstat (limited to 'nova/api')
| -rw-r--r-- | nova/api/openstack/servers.py | 15 |
1 files changed, 4 insertions, 11 deletions
diff --git a/nova/api/openstack/servers.py b/nova/api/openstack/servers.py index 53eb9fcf1..63e047b39 100644 --- a/nova/api/openstack/servers.py +++ b/nova/api/openstack/servers.py @@ -63,19 +63,12 @@ def _translate_detail_keys(inst): inst_dict['addresses'] = dict(public=[], private=[]) # grab single private fixed ip - try: - private_ip = inst['fixed_ip']['address'] - if private_ip: - inst_dict['addresses']['private'].append(private_ip) - except KeyError: - LOG.debug(_("Failed to read private ip")) + private_ips = utils.get_from_path(inst, 'fixed_ip/address') + inst_dict['addresses']['private'] = private_ips # grab all public floating ips - try: - for floating in inst['fixed_ip']['floating_ips']: - inst_dict['addresses']['public'].append(floating['address']) - except KeyError: - LOG.debug(_("Failed to read public ip(s)")) + public_ips = utils.get_from_path(inst, 'fixed_ip/floating_ips/address') + inst_dict['addresses']['public'] = public_ips inst_dict['hostId'] = '' |
