vfclcm upgrade from python2 to python3
[vfc/gvnfm/vnflcm.git] / lcm / lcm / pub / vimapi / api.py
index ba84442..857c3a9 100644 (file)
@@ -27,7 +27,7 @@ MUTEX_PORT = Lock()
 
 
 def call(vim_id, tenant_id, res, method, data=''):
-    if data and not isinstance(data, (str, unicode)):
+    if data and not isinstance(data, str):
         data = json.JSONEncoder().encode(data)
     url_fmt = "{base_url}/{vim_id}{tenant_id}/{res}"
     url = url_fmt.format(base_url=VIM_DRIVER_BASE_URL,
@@ -162,6 +162,25 @@ def list_vm(vim_id, tenant_id):
 def action_vm(vim_id, tenant_id, vm_id, data):
     return call(vim_id, tenant_id, "servers/%s/action" % vm_id, "POST", data)
 
+
+# List port interfaces, show port interface details of the given server.
+# Create a port interface and uses it to attach a port to the given server,
+# detach a port interface from the given server
+def list_vm_port(vim_id, tenant_id, vm_id):
+    return call(vim_id, tenant_id, "servers/%s/os-interface" % vm_id, "GET")
+
+
+def create_vm_port(vim_id, tenant_id, vm_id, data):
+    return call(vim_id, tenant_id, "servers/%s/os-interface" % vm_id, "POST", data)
+
+
+def get_vm_port(vim_id, tenant_id, vm_id, port_id):
+    return call(vim_id, tenant_id, "servers/%s/os-interface/%s" % (vm_id, port_id), "GET")
+
+
+def delete_vm_port(vim_id, tenant_id, vm_id, port_id):
+    return call(vim_id, tenant_id, "servers/%s/os-interface/%s" % (vm_id, port_id), "DELETE")
+
 ######################################################################