Skip to content

Commit

Permalink
Implements: #719
Browse files Browse the repository at this point in the history
  • Loading branch information
micafer committed Nov 21, 2018
1 parent 20f0c4a commit 164c391
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
12 changes: 12 additions & 0 deletions IM/REST.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 3 additions & 2 deletions doc/source/REST.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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``. |
+-------------+-----------------------------------------------------+----------------------------------------------------+

+-------------+-----------------------------------------------+------------------------------------------------+
Expand Down Expand Up @@ -147,7 +147,8 @@ GET ``http://imserver.com/infrastructures/<infId>/<property_name>``
:``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).
Expand Down
4 changes: 4 additions & 0 deletions test/unit/REST.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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.")
Expand Down

0 comments on commit 164c391

Please sign in to comment.