diff --git a/IM/REST.py b/IM/REST.py index 742b1fac2..31af4708a 100644 --- a/IM/REST.py +++ b/IM/REST.py @@ -375,6 +375,18 @@ def RESTGetInfrastructureProperty(infid=None, prop=None): res = InfrastructureManager.GetInfrastructureContMsg(infid, auth, headeronly) elif prop == "radl": res = InfrastructureManager.GetInfrastructureRADL(infid, auth) + elif prop == "tosca": + accept = get_media_type('Accept') + if accept and "application/json" not in accept and "*/*" not in accept and "application/*" not in accept: + return return_error(415, "Unsupported Accept Media Types: %s" % accept) + bottle.response.content_type = "application/json" + auth = InfrastructureManager.check_auth_data(auth) + sel_inf = InfrastructureManager.get_infrastructure(infid, auth) + if "TOSCA" in sel_inf.extra_info: + res = sel_inf.extra_info["TOSCA"].serialize() + else: + bottle.abort( + 403, "'tosca' infrastructure property is not valid in this infrastructure") elif prop == "state": accept = get_media_type('Accept') if accept and "application/json" not in accept and "*/*" not in accept and "application/*" not in accept: diff --git a/doc/source/REST.rst b/doc/source/REST.rst index 43e86cfa5..5768fc9e2 100644 --- a/doc/source/REST.rst +++ b/doc/source/REST.rst @@ -40,7 +40,7 @@ Next tables summaries the resources and the HTTP methods available. | **GET** | | **Get** the specified property ``property_name`` | | **Get** the specified property ``property_name`` | | | | associated to the machine ``vmId`` in ``infId``. | | associated to the infrastructure ``infId``. | | | | It has one special property: ``contmsg``. | | It has five properties: ``contmsg``, ``radl``, | -| | | | ``state``, ``outputs`` and ``data``. | +| | | | ``state``, ``outputs``, ``tosca`` and ``data``. | +-------------+-----------------------------------------------------+----------------------------------------------------+ +-------------+-----------------------------------------------+------------------------------------------------+ @@ -147,7 +147,8 @@ GET ``http://imserver.com/infrastructures//`` :``contmsg``: a string with the contextualization message. In case of ``headeronly`` flag is set to 'yes', 'true' or '1' only the initial part of the infrastructure contextualization log will be returned (without any VM contextualization log). - :``radl``: a string with the original specified RADL of the infrastructure. + :``radl``: a string with the original specified RADL of the infrastructure. + :``tosca``: a string with the TOSCA representation of the infrastructure. :``data``: a string with the JSOMN serialized data of the infrastructure. In case of ``delete`` flag is set to 'yes', 'true' or '1' the data not only will be exported but also the infrastructure will be set deleted (the virtual infrastructure will not be modified). diff --git a/test/unit/REST.py b/test/unit/REST.py index a6f8ab1db..6efe0ecaf 100755 --- a/test/unit/REST.py +++ b/test/unit/REST.py @@ -159,6 +159,7 @@ def test_GetInfrastructureProperty(self, bottle_request, get_infrastructure, Get tosca = MagicMock() inf.extra_info = {"TOSCA": tosca} tosca.get_outputs.return_value = "outputs" + tosca.serialize.return_value = "tosca" res = RESTGetInfrastructureProperty("1", "state") self.assertEqual(json.loads(res)["state"]["state"], "running") @@ -177,6 +178,9 @@ def test_GetInfrastructureProperty(self, bottle_request, get_infrastructure, Get res = RESTGetInfrastructureProperty("1", "radl") self.assertEqual(res, "radl") + res = RESTGetInfrastructureProperty("1", "tosca") + self.assertEqual(res, "tosca") + GetInfrastructureRADL.side_effect = DeletedInfrastructureException() res = RESTGetInfrastructureProperty("1", "radl") self.assertEqual(res, "Error Getting Inf. prop: Deleted infrastructure.")