summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorxinhuili <lxinhui@vmware.com>2017-03-14 19:59:31 -0700
committerxinhuili <lxinhui@vmware.com>2017-03-15 02:15:09 -0700
commit2403901f33bbbf71960be27c1717fea4660dc510 (patch)
tree7054d1a8d23d34a4be5918cd58456e15ab4fd46f
parentac6ad9ed76acb52fa3358d8e62387d01e6c78d68 (diff)
Merge small fixes
This patch is to merge several small fixes. Change-Id: Ifd84ddf4e8f6273ac9a582bcd4bb07989004048d Issue-ids: MULTIVIM-36 Signed-off-by: xinhuili <lxinhui@vmware.com>
-rw-r--r--vio/vio/pub/exceptions.py6
-rw-r--r--vio/vio/pub/msapi/extsys.py4
-rw-r--r--vio/vio/pub/vim/drivers/vimsdk/compute.py10
-rw-r--r--vio/vio/pub/vim/drivers/vimsdk/image_v2.py6
-rw-r--r--vio/vio/pub/vim/drivers/vimsdk/keystone_v3.py4
-rw-r--r--vio/vio/pub/vim/vimapi/glance/OperateImage.py5
-rw-r--r--vio/vio/pub/vim/vimapi/keystone/OperateTenant.py4
-rw-r--r--vio/vio/pub/vim/vimapi/network/OperateNetwork.py17
-rw-r--r--vio/vio/pub/vim/vimapi/network/OperatePort.py10
-rw-r--r--vio/vio/pub/vim/vimapi/network/OperateSubnet.py10
-rw-r--r--vio/vio/pub/vim/vimapi/nova/OperateFlavors.py6
-rw-r--r--vio/vio/pub/vim/vimapi/nova/OperateServers.py4
-rw-r--r--vio/vio/swagger/image_utils.py12
-rw-r--r--vio/vio/swagger/nova_utils.py9
-rw-r--r--vio/vio/swagger/views/flavor/views.py30
-rw-r--r--vio/vio/swagger/views/hypervisor/views.py7
-rw-r--r--vio/vio/swagger/views/image/views.py26
-rw-r--r--vio/vio/swagger/views/limits/views.py8
-rw-r--r--vio/vio/swagger/views/network/views.py3
-rw-r--r--vio/vio/swagger/views/port/views.py5
-rw-r--r--vio/vio/swagger/views/server/views.py33
-rw-r--r--vio/vio/swagger/views/service/views.py8
-rw-r--r--vio/vio/swagger/views/subnet/views.py5
-rw-r--r--vio/vio/swagger/views/tenant/views.py10
-rw-r--r--vio/vio/swagger/views/volume/views.py36
-rw-r--r--vio/vio/swagger/volume_utils.py8
26 files changed, 202 insertions, 84 deletions
diff --git a/vio/vio/pub/exceptions.py b/vio/vio/pub/exceptions.py
index 394685a..077b72d 100644
--- a/vio/vio/pub/exceptions.py
+++ b/vio/vio/pub/exceptions.py
@@ -12,4 +12,8 @@
class VimDriverVioException(Exception):
- pass
+ def __init__(self, message, status_code="", content=""):
+ super(VimDriverVioException, self).__init__(message)
+ self.status_code = status_code
+ self.content = content
+ pass
diff --git a/vio/vio/pub/msapi/extsys.py b/vio/vio/pub/msapi/extsys.py
index 002f3ad..5410c58 100644
--- a/vio/vio/pub/msapi/extsys.py
+++ b/vio/vio/pub/msapi/extsys.py
@@ -13,6 +13,7 @@
import json
import logging
+from rest_framework import status
from vio.pub.exceptions import VimDriverVioException
from vio.pub.utils.restcall import req_by_msb
@@ -31,5 +32,6 @@ def get_vim_by_id(vim_id):
ret = req_by_msb("/openoapi/extsys/v1/vims/%s" % vim_id, "GET")
if ret[0] != 0:
logger.error("Status code is %s, detail is %s.", ret[2], ret[1])
- raise VimDriverVioException("Failed to query VIM with id (%s) from extsys." % vim_id)
+ raise VimDriverVioException("Failed to query VIM with id (%s) from extsys." % vim_id,
+ status.HTTP_404_NOT_FOUND)
return json.JSONDecoder().decode(ret[1])
diff --git a/vio/vio/pub/vim/drivers/vimsdk/compute.py b/vio/vio/pub/vim/drivers/vimsdk/compute.py
index 9e774a0..1ed4b25 100644
--- a/vio/vio/pub/vim/drivers/vimsdk/compute.py
+++ b/vio/vio/pub/vim/drivers/vimsdk/compute.py
@@ -52,8 +52,8 @@ class ComputeClient(base.DriverBase):
return server
@sdk.translate_exception
- def list_servers(self):
- servers = self.conn.compute.servers()
+ def list_servers(self, **query):
+ servers = self.conn.compute.servers(**query)
return servers
@sdk.translate_exception
@@ -78,7 +78,7 @@ class ComputeClient(base.DriverBase):
@sdk.translate_exception
def list_flavors(self, **query):
- flavors = self.conn.compute.flavors()
+ flavors = self.conn.compute.flavors(**query)
return flavors
@sdk.translate_exception
@@ -123,5 +123,5 @@ class ComputeClient(base.DriverBase):
return self.conn.compute.services()
@sdk.translate_exception
- def get_hypervisor(self, hypervisor, **kwargs):
- return self.conn.compute.get_hypervisor(hypervisor=hypervisor)
+ def get_hypervisor(self, hypervisor, **query):
+ return self.conn.compute.get_hypervisor(hypervisor=hypervisor, **query)
diff --git a/vio/vio/pub/vim/drivers/vimsdk/image_v2.py b/vio/vio/pub/vim/drivers/vimsdk/image_v2.py
index 88babba..a9342cf 100644
--- a/vio/vio/pub/vim/drivers/vimsdk/image_v2.py
+++ b/vio/vio/pub/vim/drivers/vimsdk/image_v2.py
@@ -39,6 +39,12 @@ class GlanceClient(base.DriverBase):
image = self._proxy.get_image(imageid)
return image
+
+ @sdk.translate_exception
+ def find_image(self, name_or_id):
+ image = self._proxy.find_image(name_or_id, ignore_missing=False)
+ return image
+
@sdk.translate_exception
def delete_image(self, imageid):
self._proxy.delete_image(imageid)
diff --git a/vio/vio/pub/vim/drivers/vimsdk/keystone_v3.py b/vio/vio/pub/vim/drivers/vimsdk/keystone_v3.py
index aff2d6f..1dc7fac 100644
--- a/vio/vio/pub/vim/drivers/vimsdk/keystone_v3.py
+++ b/vio/vio/pub/vim/drivers/vimsdk/keystone_v3.py
@@ -27,6 +27,6 @@ class KeystoneClient(base.DriverBase):
self.session = self.conn.session
@sdk.translate_exception
- def project_list(self):
- projects = self.conn.identity.projects()
+ def project_list(self, **query):
+ projects = self.conn.identity.projects(**query)
return projects
diff --git a/vio/vio/pub/vim/vimapi/glance/OperateImage.py b/vio/vio/pub/vim/vimapi/glance/OperateImage.py
index f93441b..2b08359 100644
--- a/vio/vio/pub/vim/vimapi/glance/OperateImage.py
+++ b/vio/vio/pub/vim/vimapi/glance/OperateImage.py
@@ -74,6 +74,11 @@ class OperateImage(baseclient):
image = self.glance(self.param).get_image(imageid)
return image
+ def find_vim_image(self, name_or_id):
+
+ image = self.glance(self.param).find_image(name_or_id)
+ return image
+
def delete_vim_image(self, imageid):
image = self.glance(self.param).delete_image(imageid)
diff --git a/vio/vio/pub/vim/vimapi/keystone/OperateTenant.py b/vio/vio/pub/vim/vimapi/keystone/OperateTenant.py
index 7781be7..0d8a3c5 100644
--- a/vio/vio/pub/vim/vimapi/keystone/OperateTenant.py
+++ b/vio/vio/pub/vim/vimapi/keystone/OperateTenant.py
@@ -23,7 +23,7 @@ logger = logging.getLogger(__name__)
class OperateTenant(baseclient):
- def get_projects(self, data):
+ def get_projects(self, data, **query):
param = {}
param['username'] = data['username']
param['user_domain_name'] = 'default'
@@ -31,6 +31,6 @@ class OperateTenant(baseclient):
param['password'] = data['password']
param['auth_url'] = data['url']
param['project_name'] = data['project_name']
- projects = self.identity(param).project_list()
+ projects = self.identity(param).project_list(**query)
return projects
diff --git a/vio/vio/pub/vim/vimapi/network/OperateNetwork.py b/vio/vio/pub/vim/vimapi/network/OperateNetwork.py
index 3b67053..dd49f48 100644
--- a/vio/vio/pub/vim/vimapi/network/OperateNetwork.py
+++ b/vio/vio/pub/vim/vimapi/network/OperateNetwork.py
@@ -12,9 +12,11 @@
import logging
+from rest_framework import status
+
from vio.pub.msapi.extsys import get_vim_by_id
from vio.pub.vim.drivers.vimsdk import neutron_v2_0
-
+from vio.pub.exceptions import VimDriverVioException
logger = logging.getLogger(__name__)
@@ -33,7 +35,12 @@ def translate(mapping, data, revert=True):
class BaseNet(object):
def get_vim_info(self, vimid):
- return get_vim_by_id(vimid)
+ try:
+ vim_info = get_vim_by_id(vimid)
+ except VimDriverVioException as e:
+ raise VimDriverVioException("Failed to query VIM with id (%s) from extsys." % vimid,
+ status.HTTP_404_NOT_FOUND)
+ return vim_info
def auth(self, vim_info):
param = {}
@@ -101,11 +108,11 @@ class OperateNetwork(BaseNet):
network = self.auth(vim_info)
return network.network_delete(networkid)
- def list_networks(self, vimid, tenantid):
+ def list_networks(self, vimid, tenantid, **query):
vim_info = self.get_vim_info(vimid)
network = self.auth(vim_info)
- tenant = {"project_id": tenantid}
- resp = network.networks_get(**tenant)
+ query.update({"project_id": tenantid})
+ resp = network.networks_get(**query)
vim_dict = {"vimName": vim_info['name'], "vimId": vim_info['vimId']}
networks = {'networks': []}
if resp:
diff --git a/vio/vio/pub/vim/vimapi/network/OperatePort.py b/vio/vio/pub/vim/vimapi/network/OperatePort.py
index 4363f51..3e9e4eb 100644
--- a/vio/vio/pub/vim/vimapi/network/OperatePort.py
+++ b/vio/vio/pub/vim/vimapi/network/OperatePort.py
@@ -55,10 +55,10 @@ class OperatePort(BaseNet):
resp.update(vim_dict)
return resp
- def list_port(self, vimid, tenantid, portid):
+ def list_port(self, vimid, tenantid, portid, ignore_missing=False):
vim_info = self.get_vim_info(vimid)
network = self.auth(vim_info)
- port = network.port_find(portid)
+ port = network.port_find(portid, ignore_missing=ignore_missing)
if port is None:
return port
vim_dict = {"vimName": vim_info['name'], "vimId": vim_info['vimId']}
@@ -71,11 +71,11 @@ class OperatePort(BaseNet):
network = self.auth(vim_info)
return network.port_delete(portid)
- def list_ports(self, vimid, tenantid):
+ def list_ports(self, vimid, tenantid, **query):
vim_info = self.get_vim_info(vimid)
network = self.auth(vim_info)
- tenant = {"project_id": tenantid}
- resp = network.ports_get(**tenant)
+ query.update({"project_id": tenantid})
+ resp = network.ports_get(**query)
vim_dict = {"vimName": vim_info['name'], "vimId": vim_info['vimId']}
ports = {'ports': []}
if resp:
diff --git a/vio/vio/pub/vim/vimapi/network/OperateSubnet.py b/vio/vio/pub/vim/vimapi/network/OperateSubnet.py
index b28383d..8d2895f 100644
--- a/vio/vio/pub/vim/vimapi/network/OperateSubnet.py
+++ b/vio/vio/pub/vim/vimapi/network/OperateSubnet.py
@@ -59,10 +59,10 @@ class OperateSubnet(BaseNet):
resp.update(vim_dict)
return resp
- def list_subnet(self, vimid, tenantid, subnetid):
+ def list_subnet(self, vimid, tenantid, subnetid, ignore_missing=False):
vim_info = self.get_vim_info(vimid)
network = self.auth(vim_info)
- subnet = network.subnet_get(subnetid)
+ subnet = network.subnet_get(subnetid, ignore_missing=ignore_missing)
if subnet is None:
return subnet
vim_dict = {"vimName": vim_info['name'], "vimId": vim_info['vimId'], "tenantId": tenantid}
@@ -75,11 +75,11 @@ class OperateSubnet(BaseNet):
network = self.auth(vim_info)
return network.subnet_delete(subnetid)
- def list_subnets(self, vimid, tenantid):
+ def list_subnets(self, vimid, tenantid, **query):
vim_info = self.get_vim_info(vimid)
network = self.auth(vim_info)
- tenant = {"project_id": tenantid}
- resp = network.subnets_get(**tenant)
+ query.update({"project_id": tenantid})
+ resp = network.subnets_get(**query)
vim_dict = {"vimName": vim_info['name'], "vimId": vim_info['vimId'], "tenantId": tenantid}
subnets = {'subnets': []}
if resp:
diff --git a/vio/vio/pub/vim/vimapi/nova/OperateFlavors.py b/vio/vio/pub/vim/vimapi/nova/OperateFlavors.py
index 50303b2..8d09624 100644
--- a/vio/vio/pub/vim/vimapi/nova/OperateFlavors.py
+++ b/vio/vio/pub/vim/vimapi/nova/OperateFlavors.py
@@ -39,7 +39,7 @@ class OperateFlavors(OperateNova):
project_id=project_id, **req)
extra_specs_spec = {l['keyName']: l['value']
for l in create_req.get('extraSpecs', [])}
- extra_specs = {}
+ extra_specs = None
if extra_specs_spec:
extra_specs = self.request('create_flavor_extra_specs', data,
project_id=project_id,
@@ -47,8 +47,8 @@ class OperateFlavors(OperateNova):
extra_specs=extra_specs_spec)
return flavor, extra_specs
- def list_flavors(self, data, project_id):
- flavors = self.request('list_flavors', data, project_id=project_id)
+ def list_flavors(self, data, project_id, **query):
+ flavors = self.request('list_flavors', data, project_id=project_id, **query)
flavors = list(flavors)
result = []
for flavor in flavors:
diff --git a/vio/vio/pub/vim/vimapi/nova/OperateServers.py b/vio/vio/pub/vim/vimapi/nova/OperateServers.py
index 6fad7a5..98a836b 100644
--- a/vio/vio/pub/vim/vimapi/nova/OperateServers.py
+++ b/vio/vio/pub/vim/vimapi/nova/OperateServers.py
@@ -65,14 +65,14 @@ class OperateServers(OperateNova):
volumes = create_req.get('volumeArray', [])
return cc.create_server(**req)
- def list_servers(self, data, project_id):
+ def list_servers(self, data, project_id, **query):
param = {'username': data['username'],
'user_domain_name': 'default',
'project_domain_name': 'default',
'password': data['password'],
'auth_url': data['url'],
'project_id': project_id}
- projects = self.compute(param).list_servers()
+ projects = self.compute(param).list_servers(**query)
return projects
def list_server_interfaces(self, data, project_id, server):
diff --git a/vio/vio/swagger/image_utils.py b/vio/vio/swagger/image_utils.py
index 48a2771..3073bd1 100644
--- a/vio/vio/swagger/image_utils.py
+++ b/vio/vio/swagger/image_utils.py
@@ -15,8 +15,11 @@ def image_formatter(image):
image = image.to_dict()
properties = {}
- properties['vmware_adaptertype'] = image.get("vmware_adaptertype")
- properties['vmware_ostype'] = image.get("vmware_ostype")
+ if image.get("vmware_adaptertype"):
+ properties['vmware_adaptertype'] = image.get("vmware_adaptertype")
+ if image.get("vmware_ostype"):
+ properties['vmware_ostype'] = image.get("vmware_ostype")
+
return {
'id' : image.get("id"),
'name' : image.get("name"),
@@ -57,6 +60,7 @@ def req_body_formatter(body):
param['container_format'] = body.get('containerFormat')
param['visibility'] = body.get('visibility')
param['imagePath'] = body.get('imagePath')
- param['vmware_adaptertype'] = body.get('properties').get('vmware_adaptertype')
- param['vmware_ostype'] = body.get('properties').get('vmware_ostype')
+ if body.get('properties'):
+ param['vmware_adaptertype'] = body.get('properties').get('vmware_adaptertype')
+ param['vmware_ostype'] = body.get('properties').get('vmware_ostype')
return param
diff --git a/vio/vio/swagger/nova_utils.py b/vio/vio/swagger/nova_utils.py
index bfc02f3..ac48ac9 100644
--- a/vio/vio/swagger/nova_utils.py
+++ b/vio/vio/swagger/nova_utils.py
@@ -54,7 +54,7 @@ def server_formatter(server, interfaces=[]):
def flavor_formatter(flavor, extra_specs):
- return {
+ r = {
"id": flavor.id,
"name": flavor.name,
"vcpu": flavor.vcpus,
@@ -62,9 +62,10 @@ def flavor_formatter(flavor, extra_specs):
"disk": flavor.disk,
"ephemeral": flavor.ephemeral,
"swap": flavor.swap,
- "isPublic": flavor.is_public,
- "extraSpecs": extra_specs_formatter(extra_specs)
- }
+ "isPublic": flavor.is_public}
+ if extra_specs:
+ r["extraSpecs"] = extra_specs_formatter(extra_specs)
+ return r
def extra_specs_formatter(extra_specs):
diff --git a/vio/vio/swagger/views/flavor/views.py b/vio/vio/swagger/views/flavor/views.py
index a926e98..cbecba4 100644
--- a/vio/vio/swagger/views/flavor/views.py
+++ b/vio/vio/swagger/views/flavor/views.py
@@ -18,7 +18,7 @@ from rest_framework.views import APIView
from vio.pub.msapi import extsys
from vio.pub.vim.vimapi.nova import OperateFlavors
from vio.swagger import nova_utils
-
+from vio.pub.exceptions import VimDriverVioException
class FlavorsView(APIView):
@@ -29,7 +29,11 @@ class FlavorsView(APIView):
return Response(data={'error': 'Fail to decode request body.'},
status=status.HTTP_500_INTERNAL_SERVER_ERROR)
- vim_info = extsys.get_vim_by_id(vimid)
+ try:
+ vim_info = extsys.get_vim_by_id(vimid)
+ except VimDriverVioException as e:
+ return Response(data={'error': str(e)}, status=e.status_code)
+
data = {'vimId': vim_info['vimId'],
'vimName': vim_info['name'],
'username': vim_info['userName'],
@@ -61,17 +65,21 @@ class FlavorsView(APIView):
return Response(data=rsp, status=status.HTTP_200_OK)
def get(self, request, vimid, tenantid):
- vim_info = extsys.get_vim_by_id(vimid)
+ try:
+ vim_info = extsys.get_vim_by_id(vimid)
+ except VimDriverVioException as e:
+ return Response(data={'error': str(e)}, status=e.status_code)
+
data = {'vimId': vim_info['vimId'],
'vimName': vim_info['name'],
'username': vim_info['userName'],
'password': vim_info['password'],
'url': vim_info['url'],
'project_name': vim_info['tenant']}
-
+ query = dict(request.query_params)
flavors_op = OperateFlavors.OperateFlavors()
try:
- flavors_result = flavors_op.list_flavors(data, tenantid)
+ flavors_result = flavors_op.list_flavors(data, tenantid, **query)
flavors_dict = [nova_utils.flavor_formatter(flavor, extra)
for flavor, extra in flavors_result]
except Exception as e:
@@ -89,7 +97,11 @@ class FlavorsView(APIView):
class FlavorView(APIView):
def get(self, request, vimid, tenantid, flavorid):
- vim_info = extsys.get_vim_by_id(vimid)
+ try:
+ vim_info = extsys.get_vim_by_id(vimid)
+ except VimDriverVioException as e:
+ return Response(data={'error': str(e)}, status=e.status_code)
+
data = {'vimId': vim_info['vimId'],
'vimName': vim_info['name'],
'username': vim_info['userName'],
@@ -112,7 +124,11 @@ class FlavorView(APIView):
return Response(data=rsp, status=status.HTTP_200_OK)
def delete(self, request, vimid, tenantid, flavorid):
- vim_info = extsys.get_vim_by_id(vimid)
+ try:
+ vim_info = extsys.get_vim_by_id(vimid)
+ except VimDriverVioException as e:
+ return Response(data={'error': str(e)}, status=e.status_code)
+
data = {'vimId': vim_info['vimId'],
'vimName': vim_info['name'],
'username': vim_info['userName'],
diff --git a/vio/vio/swagger/views/hypervisor/views.py b/vio/vio/swagger/views/hypervisor/views.py
index 7946420..e973503 100644
--- a/vio/vio/swagger/views/hypervisor/views.py
+++ b/vio/vio/swagger/views/hypervisor/views.py
@@ -16,6 +16,7 @@ from rest_framework.response import Response
from rest_framework.views import APIView
from vio.pub.msapi import extsys
+from vio.pub.exceptions import VimDriverVioException
from vio.pub.vim.vimapi.nova import OperateHypervisor
from vio.pub.vim.vimapi.nova import OperateServers
from vio.pub.vim.vimapi.nova import OperateService
@@ -26,7 +27,11 @@ from vio.swagger import nova_utils
class HostView(APIView):
def get(self, request, vimid, tenantid, hostname):
- vim_info = extsys.get_vim_by_id(vimid)
+ try:
+ vim_info = extsys.get_vim_by_id(vimid)
+ except VimDriverVioException as e:
+ return Response(data={'error': str(e)}, status=e.status_code)
+
data = {'vimid': vim_info['vimId'],
'vimName': vim_info['name'],
'username': vim_info['userName'],
diff --git a/vio/vio/swagger/views/image/views.py b/vio/vio/swagger/views/image/views.py
index 9f166d9..ff3b4d3 100644
--- a/vio/vio/swagger/views/image/views.py
+++ b/vio/vio/swagger/views/image/views.py
@@ -19,12 +19,16 @@ from rest_framework.views import APIView
from vio.pub.msapi import extsys
from vio.pub.vim.vimapi.glance import OperateImage
from vio.swagger import image_utils
-
+from vio.pub.exceptions import VimDriverVioException
class GetDeleteImageView(APIView):
def get(self, request, vimid, tenantid, imageid):
- vim_info = extsys.get_vim_by_id(vimid)
+ try:
+ vim_info = extsys.get_vim_by_id(vimid)
+ except VimDriverVioException as e:
+ return Response(data={'error': str(e)}, status=e.status_code)
+
image_op = OperateImage.OperateImage(vim_info)
try:
@@ -38,7 +42,11 @@ class GetDeleteImageView(APIView):
status=status.HTTP_500_INTERNAL_SERVER_ERROR)
def delete(self, request, vimid, tenantid, imageid):
- vim_info = extsys.get_vim_by_id(vimid)
+ try:
+ vim_info = extsys.get_vim_by_id(vimid)
+ except VimDriverVioException as e:
+ return Response(data={'error': str(e)}, status=e.status_code)
+
image_op = OperateImage.OperateImage(vim_info)
try:
@@ -51,7 +59,11 @@ class GetDeleteImageView(APIView):
class CreateListImagesView(APIView):
def get(self, request, vimid, tenantid):
- vim_info = extsys.get_vim_by_id(vimid)
+ try:
+ vim_info = extsys.get_vim_by_id(vimid)
+ except VimDriverVioException as e:
+ return Response(data={'error': str(e)}, status=e.status_code)
+
query_data = dict(request.query_params)
image_instance = OperateImage.OperateImage(vim_info)
@@ -69,7 +81,11 @@ class CreateListImagesView(APIView):
status=status.HTTP_500_INTERNAL_SERVER_ERROR)
def post(self, request, vimid, tenantid):
- vim_info = extsys.get_vim_by_id(vimid)
+ try:
+ vim_info = extsys.get_vim_by_id(vimid)
+ except VimDriverVioException as e:
+ return Response(data={'error': str(e)}, status=e.status_code)
+
try:
req_body = json.loads(request.body)
except Exception as e:
diff --git a/vio/vio/swagger/views/limits/views.py b/vio/vio/swagger/views/limits/views.py
index d3f0e2c..98c66ed 100644
--- a/vio/vio/swagger/views/limits/views.py
+++ b/vio/vio/swagger/views/limits/views.py
@@ -18,12 +18,16 @@ from rest_framework.views import APIView
from vio.pub.msapi import extsys
from vio.pub.vim.vimapi.nova import OperateLimits
from vio.swagger import nova_utils
-
+from vio.pub.exceptions import VimDriverVioException
class LimitsView(APIView):
def get(self, request, vimid, tenantid):
- vim_info = extsys.get_vim_by_id(vimid)
+ try:
+ vim_info = extsys.get_vim_by_id(vimid)
+ except VimDriverVioException as e:
+ return Response(data={'error': str(e)}, status=e.status_code)
+
data = {'vimId': vim_info['vimId'],
'vimName': vim_info['name'],
'username': vim_info['userName'],
diff --git a/vio/vio/swagger/views/network/views.py b/vio/vio/swagger/views/network/views.py
index 0427160..47a72b3 100644
--- a/vio/vio/swagger/views/network/views.py
+++ b/vio/vio/swagger/views/network/views.py
@@ -51,9 +51,10 @@ class CreateNetworkView(APIView):
def get(self, request, vimid, tenantid):
logger.info("Enter %s, method is %s, vim_id is %s",
syscomm.fun_name(), request.method, vimid)
+ query = dict(request.query_params)
net = OperateNetwork.OperateNetwork()
try:
- resp = net.list_networks(vimid, tenantid)
+ resp = net.list_networks(vimid, tenantid, **query)
return Response(data=resp, status=status.HTTP_202_ACCEPTED)
except Exception as e:
return Response(data={'error': str(e)},
diff --git a/vio/vio/swagger/views/port/views.py b/vio/vio/swagger/views/port/views.py
index 64b0fe7..907378c 100644
--- a/vio/vio/swagger/views/port/views.py
+++ b/vio/vio/swagger/views/port/views.py
@@ -37,7 +37,7 @@ class CreatePortView(APIView):
port_name = body.get('name')
port_id = body.get('id', None)
target = port_id or port_name
- resp = port.list_port(vimid, tenantid, target)
+ resp = port.list_port(vimid, tenantid, target, ignore_missing=True)
if resp:
resp['returnCode'] = 0
else:
@@ -51,9 +51,10 @@ class CreatePortView(APIView):
def get(self, request, vimid, tenantid):
logger.info("Enter %s, method is %s, vim_id is %s",
syscomm.fun_name(), request.method, vimid)
+ query = dict(request.query_params)
port = OperatePort.OperatePort()
try:
- resp = port.list_ports(vimid, tenantid)
+ resp = port.list_ports(vimid, tenantid, **query)
return Response(data=resp, status=status.HTTP_202_ACCEPTED)
except Exception as e:
return Response(data={'error': str(e)},
diff --git a/vio/vio/swagger/views/server/views.py b/vio/vio/swagger/views/server/views.py
index 211644b..d6345f8 100644
--- a/vio/vio/swagger/views/server/views.py
+++ b/vio/vio/swagger/views/server/views.py
@@ -19,6 +19,7 @@ from rest_framework.views import APIView
from vio.pub.msapi import extsys
from vio.pub.vim.vimapi.nova import OperateServers
from vio.swagger import nova_utils
+from vio.pub.exceptions import VimDriverVioException
logger = logging.getLogger(__name__)
@@ -32,7 +33,11 @@ class ListServersView(APIView):
return Response(data={'error': 'Fail to decode request body.'},
status=status.HTTP_500_INTERNAL_SERVER_ERROR)
- vim_info = extsys.get_vim_by_id(vimid)
+ try:
+ vim_info = extsys.get_vim_by_id(vimid)
+ except VimDriverVioException as e:
+ return Response(data={'error': str(e)}, status=e.status_code)
+
data = {'vimid': vim_info['vimId'],
'vimName': vim_info['name'],
'username': vim_info['userName'],
@@ -63,17 +68,21 @@ class ListServersView(APIView):
return Response(data=rsp, status=status.HTTP_200_OK)
def get(self, request, vimid, tenantid):
- vim_info = extsys.get_vim_by_id(vimid)
+ try:
+ vim_info = extsys.get_vim_by_id(vimid)
+ except VimDriverVioException as e:
+ return Response(data={'error': str(e)}, status=e.status_code)
+
data = {'vimid': vim_info['vimId'],
'vimName': vim_info['name'],
'username': vim_info['userName'],
'password': vim_info['password'],
'url': vim_info['url'],
'project_name': vim_info['tenant']}
-
+ query = dict(request.query_params)
servers_op = OperateServers.OperateServers()
try:
- servers = servers_op.list_servers(data, tenantid)
+ servers = servers_op.list_servers(data, tenantid, **query)
except Exception as e:
return Response(data={'error': str(e)},
status=status.HTTP_500_INTERNAL_SERVER_ERROR)
@@ -84,7 +93,7 @@ class ListServersView(APIView):
servers_resp.append(nova_utils.server_formatter(
server, interfaces=intfs))
- rsp = {'vimid': vim_info['vimId'],
+ rsp = {'vimId': vim_info['vimId'],
'vimName': vim_info['name'],
'servers': servers_resp}
@@ -94,7 +103,11 @@ class ListServersView(APIView):
class GetServerView(APIView):
def get(self, request, vimid, tenantid, serverid):
- vim_info = extsys.get_vim_by_id(vimid)
+ try:
+ vim_info = extsys.get_vim_by_id(vimid)
+ except VimDriverVioException as e:
+ return Response(data={'error': str(e)}, status=e.status_code)
+
data = {'vimid': vim_info['vimId'],
'vimName': vim_info['name'],
'username': vim_info['userName'],
@@ -111,7 +124,7 @@ class GetServerView(APIView):
return Response(data={'error': str(e)},
status=status.HTTP_500_INTERNAL_SERVER_ERROR)
- rsp = {'vimid': vim_info['vimId'],
+ rsp = {'vimId': vim_info['vimId'],
'vimName': vim_info['name'],
'tenantId': tenantid}
rsp.update(server_dict)
@@ -120,7 +133,11 @@ class GetServerView(APIView):
def delete(self, request, vimid, tenantid, serverid):
servers_op = OperateServers.OperateServers()
- vim_info = extsys.get_vim_by_id(vimid)
+ try:
+ vim_info = extsys.get_vim_by_id(vimid)
+ except VimDriverVioException as e:
+ return Response(data={'error': str(e)}, status=e.status_code)
+
data = {'vimid': vim_info['vimId'],
'vimName': vim_info['name'],
'username': vim_info['userName'],
diff --git a/vio/vio/swagger/views/service/views.py b/vio/vio/swagger/views/service/views.py
index 35dc4c9..cca1456 100644
--- a/vio/vio/swagger/views/service/views.py
+++ b/vio/vio/swagger/views/service/views.py
@@ -18,14 +18,18 @@ from rest_framework.views import APIView
from vio.pub.msapi import extsys
from vio.pub.vim.vimapi.nova import OperateServers
from vio.pub.vim.vimapi.nova import OperateService
-
+from vio.pub.exceptions import VimDriverVioException
from vio.swagger import nova_utils
class HostsView(APIView):
def get(self, request, vimid, tenantid):
- vim_info = extsys.get_vim_by_id(vimid)
+ try:
+ vim_info = extsys.get_vim_by_id(vimid)
+ except VimDriverVioException as e:
+ return Response(data={'error': str(e)}, status=e.status_code)
+
data = {'vimid': vim_info['vimId'],
'vimName': vim_info['name'],
'username': vim_info['userName'],
diff --git a/vio/vio/swagger/views/subnet/views.py b/vio/vio/swagger/views/subnet/views.py
index feb9512..f6d109a 100644
--- a/vio/vio/swagger/views/subnet/views.py
+++ b/vio/vio/swagger/views/subnet/views.py
@@ -37,7 +37,7 @@ class CreateSubnetView(APIView):
subnet_name = body.get('name')
subnet_id = body.get('id', None)
target = subnet_id or subnet_name
- resp = subnet.list_subnet(vimid, tenantid, target)
+ resp = subnet.list_subnet(vimid, tenantid, target, ignore_missing=True)
if resp:
resp['returnCode'] = 0
else:
@@ -51,9 +51,10 @@ class CreateSubnetView(APIView):
def get(self, request, vimid, tenantid):
logger.info("Enter %s, method is %s, vim_id is %s",
syscomm.fun_name(), request.method, vimid)
+ query = dict(request.query_params)
subnet = OperateSubnet.OperateSubnet()
try:
- resp = subnet.list_subnets(vimid, tenantid)
+ resp = subnet.list_subnets(vimid, tenantid, **query)
return Response(data=resp, status=status.HTTP_202_ACCEPTED)
except Exception as e:
return Response(data={'error': str(e)},
diff --git a/vio/vio/swagger/views/tenant/views.py b/vio/vio/swagger/views/tenant/views.py
index 7b1d432..3eff77f 100644
--- a/vio/vio/swagger/views/tenant/views.py
+++ b/vio/vio/swagger/views/tenant/views.py
@@ -19,13 +19,16 @@ from rest_framework.views import APIView
from vio.pub.msapi import extsys
from vio.pub.vim.vimapi.keystone import OperateTenant
-
+from vio.pub.exceptions import VimDriverVioException
logger = logging.getLogger(__name__)
class ListTenantsView(APIView):
def get(self, request, vimid):
- vim_info = extsys.get_vim_by_id(vimid)
+ try:
+ vim_info = extsys.get_vim_by_id(vimid)
+ except VimDriverVioException as e:
+ return Response(data={'error': str(e)}, status=e.status_code)
data = {}
data['vimId'] = vim_info['vimId']
@@ -35,9 +38,10 @@ class ListTenantsView(APIView):
data['url'] = vim_info['url']
data['project_name'] = vim_info['tenant']
+ query = dict(request.query_params)
tenant_instance = OperateTenant.OperateTenant()
try:
- projects = tenant_instance.get_projects(data)
+ projects = tenant_instance.get_projects(data, **query)
except Exception as e:
return Response(data={'error': str(e)},
status=status.HTTP_500_INTERNAL_SERVER_ERROR)
diff --git a/vio/vio/swagger/views/volume/views.py b/vio/vio/swagger/views/volume/views.py
index ce56de7..47c6903 100644
--- a/vio/vio/swagger/views/volume/views.py
+++ b/vio/vio/swagger/views/volume/views.py
@@ -20,7 +20,8 @@ from rest_framework.views import APIView
from vio.pub.msapi import extsys
from vio.pub.vim.vimapi.cinder import OperateVolume
-
+from vio.pub.vim.vimapi.glance import OperateImage
+from vio.pub.exceptions import VimDriverVioException
from vio.swagger import volume_utils
logger = logging.getLogger(__name__)
@@ -29,7 +30,11 @@ logger = logging.getLogger(__name__)
class GetDeleteVolumeView(APIView):
def get(self, request, vimid, tenantid, volumeid):
- vim_info = extsys.get_vim_by_id(vimid)
+ try:
+ vim_info = extsys.get_vim_by_id(vimid)
+ except VimDriverVioException as e:
+ return Response(data={'error': str(e)}, status=e.status_code)
+
volume_op = OperateVolume.OperateVolume(vim_info)
try:
@@ -43,7 +48,11 @@ class GetDeleteVolumeView(APIView):
status=status.HTTP_500_INTERNAL_SERVER_ERROR)
def delete(self, request, vimid, tenantid, volumeid):
- vim_info = extsys.get_vim_by_id(vimid)
+ try:
+ vim_info = extsys.get_vim_by_id(vimid)
+ except VimDriverVioException as e:
+ return Response(data={'error': str(e)}, status=e.status_code)
+
volume_op = OperateVolume.OperateVolume(vim_info)
try:
@@ -57,7 +66,11 @@ class GetDeleteVolumeView(APIView):
class CreateListVolumeView(APIView):
def get(self, request, vimid, tenantid):
- vim_info = extsys.get_vim_by_id(vimid)
+ try:
+ vim_info = extsys.get_vim_by_id(vimid)
+ except VimDriverVioException as e:
+ return Response(data={'error': str(e)}, status=e.status_code)
+
query_data = dict(request.query_params)
volume_op = OperateVolume.OperateVolume(vim_info)
@@ -79,10 +92,14 @@ class CreateListVolumeView(APIView):
def post(self, request, vimid, tenantid):
- vim_info = extsys.get_vim_by_id(vimid)
+ try:
+ vim_info = extsys.get_vim_by_id(vimid)
+ except VimDriverVioException as e:
+ return Response(data={'error': str(e)}, status=e.status_code)
+
volume_op = OperateVolume.OperateVolume(vim_info)
try:
- json_body = json.loads(request.body)
+ body = json.loads(request.body)
except Exception as e:
return Response(data={'error': 'Fail to decode request body.'},
status=status.HTTP_500_INTERNAL_SERVER_ERROR)
@@ -90,14 +107,15 @@ class CreateListVolumeView(APIView):
volumes_detail = volume_op.get_vim_volumes()
vim_rsp = volume_utils.vim_formatter(vim_info, tenantid)
for volume in volumes_detail:
- if volume.name == json_body.get('name'):
+ if volume.name == body.get('name'):
volume_info = volume_op.get_vim_volume(volume.id)
rsp = volume_utils.volume_formatter(volume_info)
rsp['returnCode'] = 0
rsp.update(vim_rsp)
return Response(data=rsp, status=status.HTTP_200_OK)
- param = volume_utils.req_body_formatter(json_body)
+ param = volume_utils.req_body_formatter(body)
+
volume_info = volume_op.create_vim_volume(**param)
rsp = volume_utils.volume_formatter(volume_info)
rsp['returnCode'] = 1
@@ -105,4 +123,4 @@ class CreateListVolumeView(APIView):
return Response(data=rsp, status=status.HTTP_202_ACCEPTED)
except Exception as e:
return Response(data={'error': str(e)},
- status=status.HTTP_500_INTERNAL_SERVER_ERROR) \ No newline at end of file
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR)
diff --git a/vio/vio/swagger/volume_utils.py b/vio/vio/swagger/volume_utils.py
index 88d811b..21c2732 100644
--- a/vio/vio/swagger/volume_utils.py
+++ b/vio/vio/swagger/volume_utils.py
@@ -61,8 +61,10 @@ def req_body_formatter(body):
param = {}
param['size'] = body.get('volumeSize')
- param['volume_type'] = body.get('volumeType')
+ if body.get('volumeType'):
+ param['volume_type'] = body.get('volumeType')
param['name'] = body.get('name')
- param['availability_zone'] = body.get('availabilityZone')
- param['image_id'] = body.get('imageName')
+ if body.get('availabilityZone'):
+ param['availability_zone'] = body.get('availabilityZone')
+ param['image_id'] = body.get('imageId')
return param