some minor fixes
[osm/NBI.git] / osm_nbi / nbi.py
index c2cb1af..fefb3e9 100644 (file)
@@ -59,7 +59,7 @@ URL: /osm                                                       GET     POST
             /ns_instances_content                               O       O
                 /<nsInstanceId>                                 O                       O
             /ns_instances                                       5       5
-                /<nsInstanceId>                                 5                       5
+                /<nsInstanceId>                                 O5                      O5
                     instantiate                                         O5
                     terminate                                           O5
                     action                                              O
@@ -158,13 +158,13 @@ class Server(object):
                                  "<ID>": {"METHODS": ("GET", "DELETE")}
                                  },
                     "vims": {"METHODS": ("GET", "POST"),
-                             "<ID>": {"METHODS": ("GET", "DELETE")}
+                             "<ID>": {"METHODS": ("GET", "DELETE", "PATCH", "PUT")}
                              },
                     "vim_accounts": {"METHODS": ("GET", "POST"),
-                                     "<ID>": {"METHODS": ("GET", "DELETE", "PATCH")}
+                                     "<ID>": {"METHODS": ("GET", "DELETE", "PATCH", "PUT")}
                                      },
                     "sdns": {"METHODS": ("GET", "POST"),
-                             "<ID>": {"METHODS": ("GET", "DELETE", "PATCH")}
+                             "<ID>": {"METHODS": ("GET", "DELETE", "PATCH", "PUT")}
                              },
                 }
             },
@@ -215,7 +215,7 @@ class Server(object):
                                              "<ID>": {"METHODS": ("GET", "DELETE")}
                                              },
                     "ns_instances": {"METHODS": ("GET", "POST"),
-                                     "<ID>": {"TODO": ("GET", "DELETE"),
+                                     "<ID>": {"METHODS": ("GET", "DELETE"),
                                               "scale": {"TODO": "POST"},
                                               "terminate": {"METHODS": "POST"},
                                               "instantiate": {"METHODS": "POST"},
@@ -257,7 +257,7 @@ class Server(object):
                     try:
                         user_passwd = standard_b64decode(user_passwd64).decode()
                         user, _, passwd = user_passwd.partition(":")
-                    except:
+                    except Exception:
                         pass
                     outdata = self.engine.new_token(None, {"username": user, "password": passwd})
                     token = outdata["id"]
@@ -323,15 +323,15 @@ class Server(object):
                     elif format_yaml:
                         try:
                             kwargs[k] = yaml.load(v)
-                        except:
+                        except Exception:
                             pass
                     elif k.endswith(".gt") or k.endswith(".lt") or k.endswith(".gte") or k.endswith(".lte"):
                         try:
                             kwargs[k] = int(v)
-                        except:
+                        except Exception:
                             try:
                                 kwargs[k] = float(v)
-                            except:
+                            except Exception:
                                 pass
                     elif v.find(",") > 0:
                         kwargs[k] = v.split(",")
@@ -342,7 +342,7 @@ class Server(object):
                         elif format_yaml:
                             try:
                                 v[index] = yaml.load(v[index])
-                            except:
+                            except Exception:
                                 pass
 
             return indata
@@ -449,7 +449,7 @@ class Server(object):
             elif method == "POST":
                 try:
                     session = self._authorization()
-                except:
+                except Exception:
                     session = None
                 if kwargs:
                     indata.update(kwargs)
@@ -488,7 +488,7 @@ class Server(object):
         thread_info = None
         if args and args[0] == "help":
             return "<html><pre>\ninit\nfile/<name>  download file\ndb-clear/table\nprune\nlogin\nlogin2\n"\
-                    "sleep/<time>\nmessage/topic\n</pre></html>"
+                   "sleep/<time>\nmessage/topic\n</pre></html>"
 
         elif args and args[0] == "init":
             try:
@@ -726,11 +726,11 @@ class Server(object):
                 if engine_item in ("vim_accounts", "sdns"):
                     cherrypy.response.status = HTTPStatus.ACCEPTED.value
 
-            elif method == "PUT":
+            elif method in ("PUT", "PATCH"):
                 if not indata and not kwargs:
                     raise NbiException("Nothing to update. Provide payload and/or query string",
                                        HTTPStatus.BAD_REQUEST)
-                if item2 in ("nsd_content", "package_content"):
+                if item2 in ("nsd_content", "package_content") and method == "PUT":
                     completed = self.engine.upload_content(session, engine_item, _id, indata, kwargs,
                                                            cherrypy.request.headers)
                     if not completed:
@@ -739,11 +739,6 @@ class Server(object):
                     outdata = None
                 else:
                     outdata = {"id": self.engine.edit_item(session, engine_item, _id, indata, kwargs, force=force)}
-            elif method == "PATCH":
-                if not indata and not kwargs:
-                    raise NbiException("Nothing to update. Provide payload and/or query string",
-                                       HTTPStatus.BAD_REQUEST)
-                outdata = {"id": self.engine.edit_item(session, engine_item, _id, indata, kwargs, force=force)}
             else:
                 raise NbiException("Method {} not allowed".format(method), HTTPStatus.METHOD_NOT_ALLOWED)
             return self._format_out(outdata, session, _format)
@@ -792,7 +787,7 @@ def _start_service():
     for k, v in environ.items():
         if not k.startswith("OSMNBI_"):
             continue
-        k1, _,  k2 = k[7:].lower().partition("_")
+        k1, _, k2 = k[7:].lower().partition("_")
         if not k2:
             continue
         try: