From d85f6dbe027d3f5627a04476f12ff77ff75ef1b3 Mon Sep 17 00:00:00 2001 From: Brian Curtin Date: Wed, 11 Mar 2015 21:21:12 -0500 Subject: [PATCH] Get the ID of a single sub-resource We currently have the ability to loop through all attributes on a resource and get values which are safe to send in a request body, such as converting the IDs of subresources. However, it would be helpful in several cases to be able to get the ID of just one specific attribute when overriding Resource methods. A lot of the Resources that have paths like /images/%(image_id)/tag that need an override also need to get the ID of the image.Image that it's set as. Change-Id: I8d2c79ebaceb4135ab605510d009432d7d5307f3 --- openstack/resource.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/openstack/resource.py b/openstack/resource.py index ac4c24673..ce8e67741 100644 --- a/openstack/resource.py +++ b/openstack/resource.py @@ -455,6 +455,14 @@ class Resource(collections.MutableMapping): # CRUD OPERATIONS ## + @staticmethod + def _get_id(value): + """If a value is a Resource, return the canonical ID.""" + if isinstance(value, Resource): + return value.id + else: + return value + @staticmethod def _convert_ids(attrs): """Return an attribute dictionary suitable for create/update