X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=lcm%2Flcm%2Fpub%2Fvimapi%2Fapi.py;h=857c3a94b150bb4a9a8e11028fab45c38c8c0a64;hb=46ad7c172411214c5432ed93fda4271288077447;hp=b46bbf4b4c392e1c7b0a465591df94f2559c73b0;hpb=962b48bfee74f301000b2afae937dcb45ab9ec1c;p=vfc%2Fgvnfm%2Fvnflcm.git diff --git a/lcm/lcm/pub/vimapi/api.py b/lcm/lcm/pub/vimapi/api.py index b46bbf4b..857c3a94 100644 --- a/lcm/lcm/pub/vimapi/api.py +++ b/lcm/lcm/pub/vimapi/api.py @@ -23,10 +23,11 @@ from .exceptions import VimException VIM_DRIVER_BASE_URL = "api/multicloud/v0" MUTEX_NET = Lock() MUTEX_SUBNET = Lock() +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, @@ -102,7 +103,8 @@ def list_subnet(vim_id, tenant_id): def create_port(vim_id, tenant_id, data): - return call(vim_id, tenant_id, "ports", "POST", data) + with MUTEX_PORT: + return call(vim_id, tenant_id, "ports", "POST", data) def delete_port(vim_id, tenant_id, port_id): @@ -160,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") + ######################################################################