Fixed some aync return responses. Change vims to vim_accounts
Change-Id: If2879409d1978b213353a4b8445188451635aba6
Signed-off-by: tierno <alfonso.tiernosepulveda@telefonica.com>
diff --git a/osm_nbi/engine.py b/osm_nbi/engine.py
index 16d2834..209d9f6 100644
--- a/osm_nbi/engine.py
+++ b/osm_nbi/engine.py
@@ -277,7 +277,7 @@
elif item == "nsrs":
pass
- elif item == "vims" or item == "sdns":
+ elif item == "vim_accounts" or item == "sdns":
if self.db.get_one(item, {"name": indata.get("name")}, fail_on_empty=False, fail_on_more=False):
raise EngineException("name '{}' already exist for {}".format(indata["name"], item),
HTTPStatus.CONFLICT)
@@ -309,7 +309,7 @@
indata["_admin"]["usageSate"] = "NOT_IN_USE"
if item == "nsrs":
indata["_admin"]["nsState"] = "NOT_INSTANTIATED"
- if item in ("vims", "sdns"):
+ if item in ("vim_accounts", "sdns"):
indata["_admin"]["operationalState"] = "PROCESSING"
def upload_content(self, session, item, _id, indata, kwargs, headers):
@@ -540,7 +540,7 @@
Creates a new entry into database. For nsds and vnfds it creates an almost empty DISABLED entry,
that must be completed with a call to method upload_content
:param session: contains the used login username and working project
- :param item: it can be: users, projects, vims, sdns, nsrs, nsds, vnfds
+ :param item: it can be: users, projects, vim_accounts, sdns, nsrs, nsds, vnfds
:param indata: data to be inserted
:param kwargs: used to override the indata descriptor
:param headers: http request headers
@@ -573,7 +573,7 @@
if item == "nsrs":
pass
# self.msg.write("ns", "created", _id) # sending just for information.
- elif item == "vims":
+ elif item == "vim_accounts":
msg_data = self.db.get_one(item, {"_id": _id})
msg_data.pop("_admin", None)
self.msg.write("vim_account", "create", msg_data)
@@ -770,7 +770,7 @@
:param item: it can be: users, projects, vnfds, nsds, ...
:param _id: server id of the item
:param force: indicates if deletion must be forced in case of conflict
- :return: dictionary, raise exception if not found.
+ :return: dictionary with deleted item _id. It raises exception if not found.
"""
# TODO add admin to filter, validate rights
# data = self.get_item(item, _id)
@@ -787,11 +787,11 @@
self.db.del_list("nslcmops", {"nsInstanceId": _id})
self.msg.write("ns", "deleted", {"_id": _id})
return v
- if item in ("vims", "sdns"):
+ if item in ("vim_accounts", "sdns"):
desc = self.db.get_one(item, filter)
desc["_admin"]["to_delete"] = True
self.db.replace(item, _id, desc) # TODO change to set_one
- if item == "vims":
+ if item == "vim_accounts":
self.msg.write("vim_account", "delete", {"_id": _id})
elif item == "sdns":
self.msg.write("sdn", "delete", {"_id": _id})
@@ -891,10 +891,10 @@
self._validate_new_data(session, item, content, id)
# self._format_new_data(session, item, content)
self.db.replace(item, id, content)
- if item in ("vims", "sdns"):
+ if item in ("vim_accounts", "sdns"):
indata.pop("_admin", None)
indata["_id"] = id
- if item == "vims":
+ if item == "vim_accounts":
self.msg.write("vim_account", "edit", indata)
elif item == "sdns":
self.msg.write("sdn", "edit", indata)
diff --git a/osm_nbi/nbi.py b/osm_nbi/nbi.py
index c4c61ad..a72fa58 100644
--- a/osm_nbi/nbi.py
+++ b/osm_nbi/nbi.py
@@ -76,7 +76,7 @@
/<id> O O
/projects O O
/<id> O O
- /vims O O
+ /vims_accounts (also vims for compatibility) O O
/<id> O O O
/sdns O O
/<id> O O O
@@ -149,6 +149,9 @@
"vims": {"METHODS": ("GET", "POST"),
"<ID>": {"METHODS": ("GET", "DELETE")}
},
+ "vim_accounts": {"METHODS": ("GET", "POST"),
+ "<ID>": {"METHODS": ("GET", "DELETE")}
+ },
"sdns": {"METHODS": ("GET", "POST"),
"<ID>": {"METHODS": ("GET", "DELETE")}
},
@@ -349,7 +352,7 @@
if data is None:
if accept and "text/html" in accept:
return html.format(data, cherrypy.request, cherrypy.response, session)
- cherrypy.response.status = HTTPStatus.NO_CONTENT.value
+ # cherrypy.response.status = HTTPStatus.NO_CONTENT.value
return
elif hasattr(data, "read"): # file object
if _format:
@@ -635,6 +638,8 @@
engine_item = "nsrs"
if item == "ns_lcm_op_occs":
engine_item = "nslcmops"
+ if engine_item == "vims": # TODO this is for backward compatibility, it will remove in the future
+ engine_item = "vim_accounts"
if method == "GET":
if item2 in ("nsd_content", "package_content", "artifacts", "vnfd", "nsd"):
@@ -680,17 +685,22 @@
outdata = {"id": _id}
# TODO form NsdInfo when item in ("ns_descriptors", "vnf_packages")
cherrypy.response.status = HTTPStatus.CREATED.value
+
elif method == "DELETE":
if not _id:
outdata = self.engine.del_item_list(session, engine_item, kwargs)
+ cherrypy.response.status = HTTPStatus.OK.value
else: # len(args) > 1
if item == "ns_instances_content":
self.engine.ns_action(session, _id, "terminate", {"autoremove": True}, None)
+ cherrypy.response.status = HTTPStatus.ACCEPTED.value
else:
force = kwargs.get("FORCE")
self.engine.del_item(session, engine_item, _id, force)
- # TODO return 202 ACCEPTED for nsrs vims
- outdata = None
+ cherrypy.response.status = HTTPStatus.NO_CONTENT.value
+ if engine_item in ("vim_accounts", "sdns"):
+ cherrypy.response.status = HTTPStatus.ACCEPTED.value
+
elif method == "PUT":
if not indata and not kwargs:
raise NbiException("Nothing to update. Provide payload and/or query string",
@@ -699,6 +709,7 @@
completed = self.engine.upload_content(session, engine_item, _id, indata, kwargs, cherrypy.request.headers)
if not completed:
cherrypy.response.headers["Transaction-Id"] = id
+ cherrypy.response.status = HTTPStatus.NO_CONTENT.value
outdata = None
else:
outdata = {"id": self.engine.edit_item(session, engine_item, args[1], indata, kwargs)}
diff --git a/osm_nbi/test/test.py b/osm_nbi/test/test.py
index 004da02..979af44 100755
--- a/osm_nbi/test/test.py
+++ b/osm_nbi/test/test.py
@@ -83,12 +83,12 @@
vim_bad.pop("name")
test_admin_list1 = (
- ("VIM1", "Create VIM", "POST", "/admin/v1/vims", headers_json, vim, (201, 204), {"Location": "/admin/v1/vims/", "Content-Type": "application/json"}, "json"),
- ("VIM2", "Create VIM bad schema", "POST", "/admin/v1/vims", headers_json, vim_bad, 422, None, headers_json),
- ("VIM2", "Create VIM name repeated", "POST", "/admin/v1/vims", headers_json, vim, 409, None, headers_json),
- ("VIM4", "Show VIMs", "GET", "/admin/v1/vims", headers_yaml, None, 200, r_header_yaml, "yaml"),
- ("VIM5", "Show VIM", "GET", "/admin/v1/vims/{VIM1}", headers_yaml, None, 200, r_header_yaml, "yaml"),
- ("VIM6", "Delete VIM", "DELETE", "/admin/v1/vims/{VIM1}", headers_yaml, None, 204, None, 0),
+ ("VIM1", "Create VIM", "POST", "/admin/v1/vim_accounts", headers_json, vim, (201, 204), {"Location": "/admin/v1/vim_accounts/", "Content-Type": "application/json"}, "json"),
+ ("VIM2", "Create VIM bad schema", "POST", "/admin/v1/vim_accounts", headers_json, vim_bad, 422, None, headers_json),
+ ("VIM2", "Create VIM name repeated", "POST", "/admin/v1/vim_accounts", headers_json, vim, 409, None, headers_json),
+ ("VIM4", "Show VIMs", "GET", "/admin/v1/vim_accounts", headers_yaml, None, 200, r_header_yaml, "yaml"),
+ ("VIM5", "Show VIM", "GET", "/admin/v1/vim_accounts/{VIM1}", headers_yaml, None, 200, r_header_yaml, "yaml"),
+ ("VIM6", "Delete VIM", "DELETE", "/admin/v1/vim_accounts/{VIM1}", headers_yaml, None, 202, None, 0),
)
class TestException(Exception):
diff --git a/osm_nbi/validation.py b/osm_nbi/validation.py
index 5a2fbdc..c1141f1 100644
--- a/osm_nbi/validation.py
+++ b/osm_nbi/validation.py
@@ -65,10 +65,30 @@
schema_version = {"type": "string", "enum": ["1.0"]}
+vim_account_edit_schema = {
+ "title": "vim_account edit input schema",
+ "$schema": "http://json-schema.org/draft-04/schema#",
+ "type": "object",
+ "properties": {
+ "name": name_schema,
+ "description": description_schema,
+ "type": nameshort_schema, # currently "openvim" or "openstack", can be enlarged with plugins
+ "vim": name_schema,
+ "datacenter": name_schema,
+ "vim_url": description_schema,
+ "vim_url_admin": description_schema,
+ "vim_tenant": name_schema,
+ "vim_tenant_name": name_schema,
+ "vim_username": nameshort_schema,
+ "vim_password": nameshort_schema,
+ "config": {"type": "object"}
+ },
+ "additionalProperties": False
+}
schema_type = {"type": "string"}
-vim_new_schema = {
- "title": "vims new user input schema",
+vim_account_new_schema = {
+ "title": "vim_account creation input schema",
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
@@ -76,6 +96,8 @@
"schema_type": schema_type,
"name": name_schema,
"description": description_schema,
+ "vim": name_schema,
+ "datacenter": name_schema,
"vim_type": {"enum": ["openstack", "openvim", "vmware", "opennebula", "aws"]},
"vim_url": description_schema,
# "vim_url_admin": description_schema,
@@ -88,24 +110,6 @@
"required": ["name", "vim_url", "vim_type", "vim_user", "vim_password", "vim_tenant_name"],
"additionalProperties": False
}
-vim_edit_schema = {
- "title": "datacenter edit nformation schema",
- "$schema": "http://json-schema.org/draft-04/schema#",
- "type": "object",
- "properties": {
- "name": name_schema,
- "description": description_schema,
- "type": nameshort_schema, # currently "openvim" or "openstack", can be enlarged with plugins
- "vim_url": description_schema,
- "vim_url_admin": description_schema,
- "vim_tenant": name_schema,
- "vim_tenant_name": name_schema,
- "vim_username": nameshort_schema,
- "vim_password": nameshort_schema,
- "config": {"type": "object"}
- },
- "additionalProperties": False
-}
sdn_properties = {
@@ -172,14 +176,14 @@
nbi_new_input_schemas = {
- "vims": vim_new_schema,
+ "vim_accounts": vim_account_new_schema,
"sdns": sdn_new_schema,
"ns_instantiate": ns_instantiate,
"ns_action": ns_action,
}
nbi_edit_input_schemas = {
- "vims": vim_edit_schema,
+ "vim_accounts": vim_account_edit_schema,
"sdns": sdn_edit_schema
}