def show(self, request, image): """Return a dictionary with image details.""" image_dict = { "id": image.get("id"), "name": image.get("name"), "minRam": int(image.get("min_ram") or 0), "minDisk": int(image.get("min_disk") or 0), "metadata": image.get("properties", {}), "created": self._format_date(image.get("created_at")), "updated": self._format_date(image.get("updated_at")), "status": self._get_status(image), "progress": self._get_progress(image), "links": self._get_links(request, image["id"]), } server_ref = image.get("properties", {}).get("instance_ref") if server_ref is not None: image_dict["server"] = { "id": common.get_id_from_href(server_ref), "links": [{ "rel": "self", "href": server_ref, }, { "rel": "bookmark", "href": common.remove_version_from_href(server_ref), }], } return dict(image=image_dict)
def _flavor_id_from_req_data(self, data): try: flavor_ref = data['server']['flavorRef'] except (TypeError, KeyError): msg = _("Missing flavorRef attribute") raise exc.HTTPBadRequest(explanation=msg) return common.get_id_from_href(flavor_ref)
def _get_image(self, request, instance): image_ref = instance["image_ref"] image_id = str(common.get_id_from_href(image_ref)) bookmark = self._image_builder._get_bookmark_link(request, image_id) return { "id": image_id, "links": [{ "rel": "bookmark", "href": bookmark, }], }
def _get_flavor(self, request, instance): flavor_id = instance["instance_type"]["flavorid"] flavor_ref = self._flavor_builder._get_href_link(request, flavor_id) flavor_bookmark = self._flavor_builder._get_bookmark_link(request, flavor_id) return { "id": str(common.get_id_from_href(flavor_ref)), "links": [{ "rel": "bookmark", "href": flavor_bookmark, }], }
def _get_flavor(self, request, instance): flavor_id = instance["instance_type"]["flavorid"] flavor_ref = self._flavor_builder._get_href_link(request, flavor_id) flavor_bookmark = self._flavor_builder._get_bookmark_link( request, flavor_id) return { "id": str(common.get_id_from_href(flavor_ref)), "links": [{ "rel": "bookmark", "href": flavor_bookmark, }], }
def test_get_id_from_href_with_uuid(self): fixture = 'abc123' actual = common.get_id_from_href(fixture) expected = 'abc123' self.assertEqual(actual, expected)
def test_get_id_from_href_with_uuid_url_query(self): fixture = 'http://www.testsite.com/dir/abc123?asdf=jkl' actual = common.get_id_from_href(fixture) expected = "abc123" self.assertEqual(actual, expected)
def test_get_id_from_href_with_int_url_query(self): fixture = 'http://www.testsite.com/dir/45?asdf=jkl' actual = common.get_id_from_href(fixture) expected = '45' self.assertEqual(actual, expected)
def test_get_id_from_href_with_int(self): fixture = '45' actual = common.get_id_from_href(fixture) expected = '45' self.assertEqual(actual, expected)
def test_get_id_from_href_with_uuid(self): fixture = "abc123" actual = common.get_id_from_href(fixture) expected = "abc123" self.assertEqual(actual, expected)
def test_get_id_from_href_with_uuid_url_query(self): fixture = "http://www.testsite.com/dir/abc123?asdf=jkl" actual = common.get_id_from_href(fixture) expected = "abc123" self.assertEqual(actual, expected)
def test_get_id_from_href_with_int(self): fixture = "45" actual = common.get_id_from_href(fixture) expected = "45" self.assertEqual(actual, expected)
def test_get_id_from_href_with_int_url(self): fixture = "http://www.testsite.com/dir/45" actual = common.get_id_from_href(fixture) expected = "45" self.assertEqual(actual, expected)