summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--vio/vio/pub/vim/vimapi/keystone/OperateTenant.py13
-rw-r--r--vio/vio/pub/vim/vimapi/network/OperateNetwork.py15
-rw-r--r--vio/vio/pub/vim/vimapi/network/OperatePort.py8
-rw-r--r--vio/vio/pub/vim/vimapi/network/OperateSubnet.py8
-rw-r--r--vio/vio/pub/vim/vimapi/nova/OperateFlavors.py4
-rw-r--r--vio/vio/pub/vim/vimapi/nova/OperateLimits.py2
-rw-r--r--vio/vio/pub/vim/vimapi/nova/OperateServers.py44
-rw-r--r--vio/vio/swagger/image_utils.py2
-rw-r--r--vio/vio/swagger/views/flavor/views.py47
-rw-r--r--vio/vio/swagger/views/hypervisor/views.py9
-rw-r--r--vio/vio/swagger/views/image/views.py32
-rw-r--r--vio/vio/swagger/views/limits/views.py10
-rw-r--r--vio/vio/swagger/views/network/views.py37
-rw-r--r--vio/vio/swagger/views/port/views.py37
-rw-r--r--vio/vio/swagger/views/server/views.py49
-rw-r--r--vio/vio/swagger/views/service/views.py10
-rw-r--r--vio/vio/swagger/views/subnet/views.py37
-rw-r--r--vio/vio/swagger/views/tenant/views.py7
-rw-r--r--vio/vio/swagger/views/volume/views.py32
-rw-r--r--vio/vio/swagger/volume_utils.py2
20 files changed, 276 insertions, 129 deletions
diff --git a/vio/vio/pub/vim/vimapi/keystone/OperateTenant.py b/vio/vio/pub/vim/vimapi/keystone/OperateTenant.py
index 0d8a3c5..382bbca 100644
--- a/vio/vio/pub/vim/vimapi/keystone/OperateTenant.py
+++ b/vio/vio/pub/vim/vimapi/keystone/OperateTenant.py
@@ -32,5 +32,16 @@ class OperateTenant(baseclient):
param['auth_url'] = data['url']
param['project_name'] = data['project_name']
projects = self.identity(param).project_list(**query)
- return projects
+ projects = list(projects)
+ # fix tenant filter
+ # only list tenants in 'default' domain
+ # query['name'] is a list here.
+ projs = []
+ for p in projects:
+ if p.domain_id != "default":
+ continue
+ if query.get("name") and p.name not in query['name']:
+ continue
+ projs.append(p)
+ return projs
diff --git a/vio/vio/pub/vim/vimapi/network/OperateNetwork.py b/vio/vio/pub/vim/vimapi/network/OperateNetwork.py
index dd49f48..325999b 100644
--- a/vio/vio/pub/vim/vimapi/network/OperateNetwork.py
+++ b/vio/vio/pub/vim/vimapi/network/OperateNetwork.py
@@ -42,14 +42,14 @@ class BaseNet(object):
status.HTTP_404_NOT_FOUND)
return vim_info
- def auth(self, vim_info):
+ def auth(self, vim_info, tenant_id):
param = {}
param['username'] = vim_info['userName']
param['user_domain_name'] = 'default'
param['project_domain_name'] = 'default'
param['password'] = vim_info['password']
param['auth_url'] = vim_info['url']
- param['project_name'] = vim_info['tenant']
+ param['project_id'] = tenant_id
return neutron_v2_0.NeutronClient(param)
@@ -66,7 +66,7 @@ class OperateNetwork(BaseNet):
}
def ___init__(self, params):
- super(Network, self).__init__(params)
+ super(OperateNetwork, self).__init__(params)
def _convert(self, network):
result = {}
@@ -84,7 +84,7 @@ class OperateNetwork(BaseNet):
def create_network(self, vimid, tenantid, body):
vim_info = self.get_vim_info(vimid)
- network = self.auth(vim_info)
+ network = self.auth(vim_info, tenantid)
body = translate(self.keys_mapping, body)
net = network.network_create(**body)
vim_dict = {"vimName": vim_info['name'], "vimId": vim_info['vimId']}
@@ -94,7 +94,7 @@ class OperateNetwork(BaseNet):
def list_network(self, vimid, tenantid, networkid):
vim_info = self.get_vim_info(vimid)
- network = self.auth(vim_info)
+ network = self.auth(vim_info, tenantid)
net = network.network_get(networkid)
if net is None:
return net
@@ -105,13 +105,12 @@ class OperateNetwork(BaseNet):
def delete_network(self, vimid, tenantid, networkid):
vim_info = self.get_vim_info(vimid)
- network = self.auth(vim_info)
+ network = self.auth(vim_info, tenantid)
return network.network_delete(networkid)
def list_networks(self, vimid, tenantid, **query):
vim_info = self.get_vim_info(vimid)
- network = self.auth(vim_info)
- query.update({"project_id": tenantid})
+ network = self.auth(vim_info, tenantid)
resp = network.networks_get(**query)
vim_dict = {"vimName": vim_info['name'], "vimId": vim_info['vimId']}
networks = {'networks': []}
diff --git a/vio/vio/pub/vim/vimapi/network/OperatePort.py b/vio/vio/pub/vim/vimapi/network/OperatePort.py
index 235498d..ac4f564 100644
--- a/vio/vio/pub/vim/vimapi/network/OperatePort.py
+++ b/vio/vio/pub/vim/vimapi/network/OperatePort.py
@@ -51,7 +51,7 @@ class OperatePort(BaseNet):
def create_port(self, vimid, tenantid, body):
vim_info = self.get_vim_info(vimid)
- network = self.auth(vim_info)
+ network = self.auth(vim_info, tenantid)
body = translate(self.keys_mapping, body)
if body.get('subnetId'):
body['fixed_ips'] = [{'subnet_id': body.pop('subnetId')}]
@@ -63,7 +63,7 @@ class OperatePort(BaseNet):
def list_port(self, vimid, tenantid, portid, ignore_missing=False):
vim_info = self.get_vim_info(vimid)
- network = self.auth(vim_info)
+ network = self.auth(vim_info, tenantid)
port = network.port_find(portid, ignore_missing=ignore_missing)
if port is None:
return port
@@ -74,12 +74,12 @@ class OperatePort(BaseNet):
def delete_port(self, vimid, tenantid, portid):
vim_info = self.get_vim_info(vimid)
- network = self.auth(vim_info)
+ network = self.auth(vim_info, tenantid)
return network.port_delete(portid)
def list_ports(self, vimid, tenantid, **query):
vim_info = self.get_vim_info(vimid)
- network = self.auth(vim_info)
+ network = self.auth(vim_info, tenantid)
query.update({"project_id": tenantid})
resp = network.ports_get(**query)
vim_dict = {"vimName": vim_info['name'], "vimId": vim_info['vimId']}
diff --git a/vio/vio/pub/vim/vimapi/network/OperateSubnet.py b/vio/vio/pub/vim/vimapi/network/OperateSubnet.py
index 8d2895f..598eefa 100644
--- a/vio/vio/pub/vim/vimapi/network/OperateSubnet.py
+++ b/vio/vio/pub/vim/vimapi/network/OperateSubnet.py
@@ -51,7 +51,7 @@ class OperateSubnet(BaseNet):
def create_subnet(self, vimid, tenantid, body):
vim_info = self.get_vim_info(vimid)
- network = self.auth(vim_info)
+ network = self.auth(vim_info, tenantid)
body = translate(self.keys_mapping, body)
subnet = network.subnet_create(**body)
vim_dict = {"vimName": vim_info['name'], "vimId": vim_info['vimId'], "tenantId": tenantid}
@@ -61,7 +61,7 @@ class OperateSubnet(BaseNet):
def list_subnet(self, vimid, tenantid, subnetid, ignore_missing=False):
vim_info = self.get_vim_info(vimid)
- network = self.auth(vim_info)
+ network = self.auth(vim_info, tenantid)
subnet = network.subnet_get(subnetid, ignore_missing=ignore_missing)
if subnet is None:
return subnet
@@ -72,12 +72,12 @@ class OperateSubnet(BaseNet):
def delete_subnet(self, vimid, tenantid, subnetid):
vim_info = self.get_vim_info(vimid)
- network = self.auth(vim_info)
+ network = self.auth(vim_info, tenantid)
return network.subnet_delete(subnetid)
def list_subnets(self, vimid, tenantid, **query):
vim_info = self.get_vim_info(vimid)
- network = self.auth(vim_info)
+ network = self.auth(vim_info, tenantid)
query.update({"project_id": tenantid})
resp = network.subnets_get(**query)
vim_dict = {"vimName": vim_info['name'], "vimId": vim_info['vimId'], "tenantId": tenantid}
diff --git a/vio/vio/pub/vim/vimapi/nova/OperateFlavors.py b/vio/vio/pub/vim/vimapi/nova/OperateFlavors.py
index 8d09624..569e333 100644
--- a/vio/vio/pub/vim/vimapi/nova/OperateFlavors.py
+++ b/vio/vio/pub/vim/vimapi/nova/OperateFlavors.py
@@ -52,6 +52,10 @@ class OperateFlavors(OperateNova):
flavors = list(flavors)
result = []
for flavor in flavors:
+ # Since flavor filter didn't work, need to manually do it.
+ # query['name'] is a list here.
+ if query.get('name') and flavor.name not in query['name']:
+ continue
extra_specs = self.request('get_flavor_extra_specs', data,
project_id=project_id, flavor_id=flavor.id)
result.append((flavor, extra_specs))
diff --git a/vio/vio/pub/vim/vimapi/nova/OperateLimits.py b/vio/vio/pub/vim/vimapi/nova/OperateLimits.py
index 34e0584..8c1e878 100644
--- a/vio/vio/pub/vim/vimapi/nova/OperateLimits.py
+++ b/vio/vio/pub/vim/vimapi/nova/OperateLimits.py
@@ -20,4 +20,4 @@ logger = logging.getLogger(__name__)
class OperateLimits(OperateNova):
def get_limits(self, data, project_id, **kwargs):
- return self.request('get_limits', data, **kwargs)
+ return self.request('get_limits', data, project_id=project_id, **kwargs)
diff --git a/vio/vio/pub/vim/vimapi/nova/OperateServers.py b/vio/vio/pub/vim/vimapi/nova/OperateServers.py
index a3f1bf4..f42c0dd 100644
--- a/vio/vio/pub/vim/vimapi/nova/OperateServers.py
+++ b/vio/vio/pub/vim/vimapi/nova/OperateServers.py
@@ -14,7 +14,9 @@ import base64
import logging
from openstack import exceptions
+from rest_framework import status
+from vio.pub.exceptions import VimDriverVioException
from vio.pub.vim.vimapi.nova.OperateNova import OperateNova
logger = logging.getLogger(__name__)
@@ -31,12 +33,12 @@ class OperateServers(OperateNova):
'project_id': project_id}
cc = self.compute(param)
req = {
- "name": create_req.get('name'),
- "flavorRef": cc.find_flavor(create_req.get('flavorId')).id
+ "name": create_req['name'],
+ "flavorRef": cc.find_flavor(create_req['flavorId']).id
}
- boot = create_req.get('boot')
- boot_type = boot.get('type')
- if boot_type == 1:
+ boot = create_req['boot']
+ boot_type = boot['type']
+ if int(boot_type) == 1:
# boot from vol
req['block_device_mapping_v2'] = [{
'boot_index': "0",
@@ -45,8 +47,12 @@ class OperateServers(OperateNova):
'destination_type': 'volume',
'delete_on_termination': False
}]
- elif boot_type == 2:
- req['imageRef'] = cc.find_image(boot.get('imageId')).id
+ elif int(boot_type) == 2:
+ req['imageRef'] = cc.find_image(boot['imageId']).id
+ else:
+ raise VimDriverVioException(
+ 'Boot type should be 1 or 2.',
+ status_code=status.HTTP_500_INTERNAL_SERVER_ERROR)
networks = create_req.get('nicArray', [])
if networks:
req['networks'] = [{'port': n['portId']} for n in networks]
@@ -66,6 +72,25 @@ class OperateServers(OperateNova):
req['security_groups'].append({'name':v})
# todo attach volumes after server created
volumes = create_req.get('volumeArray', [])
+ if volumes:
+ if not req.get('block_device_mapping_v2'):
+ req['block_device_mapping_v2'] = []
+ for vol in volumes:
+ req['block_device_mapping_v2'].append(
+ {
+ 'uuid': vol["volumeId"],
+ 'source_type': 'volume',
+ 'destination_type': 'volume',
+ 'delete_on_termination': False
+ }
+ )
+ inject_files = create_req.get('contextArray', [])
+ if inject_files:
+ req['personality'] = []
+ for i in inject_files:
+ req['personality'].append(
+ {"path": i["fileName"], "contents": i["fileData"]})
+
return cc.create_server(**req)
def list_servers(self, data, project_id, **query):
@@ -75,8 +100,9 @@ class OperateServers(OperateNova):
'password': data['password'],
'auth_url': data['url'],
'project_id': project_id}
- projects = self.compute(param).list_servers(**query)
- return projects
+ servers = self.compute(param).list_servers(**query)
+ servers = list(servers)
+ return servers
def list_server_interfaces(self, data, project_id, server):
param = {'username': data['username'],
diff --git a/vio/vio/swagger/image_utils.py b/vio/vio/swagger/image_utils.py
index a7302a8..9f96bc7 100644
--- a/vio/vio/swagger/image_utils.py
+++ b/vio/vio/swagger/image_utils.py
@@ -47,7 +47,7 @@ def sdk_param_formatter(data):
param['username'] = data.get('userName')
param['password'] = data.get('password')
param['auth_url'] = data.get('url')
- param['project_name'] = data.get('tenant')
+ param['project_id'] = data.get('tenant')
param['user_domain_name'] = 'default'
param['project_domain_name'] = 'default'
return param
diff --git a/vio/vio/swagger/views/flavor/views.py b/vio/vio/swagger/views/flavor/views.py
index cbecba4..c774f90 100644
--- a/vio/vio/swagger/views/flavor/views.py
+++ b/vio/vio/swagger/views/flavor/views.py
@@ -38,14 +38,14 @@ class FlavorsView(APIView):
'vimName': vim_info['name'],
'username': vim_info['userName'],
'password': vim_info['password'],
- 'url': vim_info['url'],
- 'project_name': vim_info['tenant']}
+ 'url': vim_info['url']}
rsp = {'vimId': vim_info['vimId'],
'vimName': vim_info['name'],
'tenantId': tenantid}
flavor_name = create_req.get('name', None)
flavor_id = create_req.get('id', None)
flavors_op = OperateFlavors.OperateFlavors()
+ exist = False
try:
target = flavor_id or flavor_name
flavor = flavors_op.find_flavor(data, tenantid, target)
@@ -53,16 +53,23 @@ class FlavorsView(APIView):
flavor, extra_specs = flavors_op.get_flavor(
data, tenantid, flavor.id)
rsp['returnCode'] = 0
+ exist = True
else:
rsp['returnCode'] = 1
flavor, extra_specs = flavors_op.create_flavor(
data, tenantid, create_req)
flavor_dict = nova_utils.flavor_formatter(flavor, extra_specs)
except Exception as e:
- return Response(data={'error': str(e)},
- status=status.HTTP_500_INTERNAL_SERVER_ERROR)
+ if hasattr(e, "http_status"):
+ return Response(data={'error': str(e)}, status=e.http_status)
+ else:
+ return Response(data={'error': str(e)},
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR)
rsp.update(flavor_dict)
- return Response(data=rsp, status=status.HTTP_200_OK)
+ if exist:
+ return Response(data=rsp, status=status.HTTP_200_OK)
+ else:
+ return Response(data=rsp, status=status.HTTP_202_ACCEPTED)
def get(self, request, vimid, tenantid):
try:
@@ -74,8 +81,7 @@ class FlavorsView(APIView):
'vimName': vim_info['name'],
'username': vim_info['userName'],
'password': vim_info['password'],
- 'url': vim_info['url'],
- 'project_name': vim_info['tenant']}
+ 'url': vim_info['url']}
query = dict(request.query_params)
flavors_op = OperateFlavors.OperateFlavors()
try:
@@ -83,8 +89,11 @@ class FlavorsView(APIView):
flavors_dict = [nova_utils.flavor_formatter(flavor, extra)
for flavor, extra in flavors_result]
except Exception as e:
- return Response(data={'error': str(e)},
- status=status.HTTP_500_INTERNAL_SERVER_ERROR)
+ if hasattr(e, "http_status"):
+ return Response(data={'error': str(e)}, status=e.http_status)
+ else:
+ return Response(data={'error': str(e)},
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR)
rsp = {'vimId': vim_info['vimId'],
'vimName': vim_info['name'],
@@ -106,16 +115,18 @@ class FlavorView(APIView):
'vimName': vim_info['name'],
'username': vim_info['userName'],
'password': vim_info['password'],
- 'url': vim_info['url'],
- 'project_name': vim_info['tenant']}
+ 'url': vim_info['url']}
flavors_op = OperateFlavors.OperateFlavors()
try:
flavor, extra_specs = flavors_op.get_flavor(data, tenantid, flavorid)
flavor_dict = nova_utils.flavor_formatter(flavor, extra_specs)
except Exception as e:
- return Response(data={'error': str(e)},
- status=status.HTTP_500_INTERNAL_SERVER_ERROR)
+ if hasattr(e, "http_status"):
+ return Response(data={'error': str(e)}, status=e.http_status)
+ else:
+ return Response(data={'error': str(e)},
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR)
rsp = {'vimId': vim_info['vimId'],
'vimName': vim_info['name'],
@@ -133,12 +144,14 @@ class FlavorView(APIView):
'vimName': vim_info['name'],
'username': vim_info['userName'],
'password': vim_info['password'],
- 'url': vim_info['url'],
- 'project_name': vim_info['tenant']}
+ 'url': vim_info['url']}
flavors_op = OperateFlavors.OperateFlavors()
try:
flavors_op.delete_flavor(data, tenantid, flavorid)
except Exception as e:
- return Response(data={'error': str(e)},
- status=status.HTTP_500_INTERNAL_SERVER_ERROR)
+ if hasattr(e, "http_status"):
+ return Response(data={'error': str(e)}, status=e.http_status)
+ else:
+ return Response(data={'error': str(e)},
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR)
return Response(status=status.HTTP_204_NO_CONTENT)
diff --git a/vio/vio/swagger/views/hypervisor/views.py b/vio/vio/swagger/views/hypervisor/views.py
index e973503..bada577 100644
--- a/vio/vio/swagger/views/hypervisor/views.py
+++ b/vio/vio/swagger/views/hypervisor/views.py
@@ -37,14 +37,17 @@ class HostView(APIView):
'username': vim_info['userName'],
'password': vim_info['password'],
'url': vim_info['url'],
- 'project_name': vim_info['tenant']}
+ 'project_id': tenantid}
hypervisor_op = OperateHypervisor.OperateHypervisor()
try:
hv = hypervisor_op.get_hypervisor(data, hypervisor=hostname)
except Exception as e:
- return Response(data={'error': str(e)},
- status=status.HTTP_500_INTERNAL_SERVER_ERROR)
+ if hasattr(e, "http_status"):
+ return Response(data={'error': str(e)}, status=e.http_status)
+ else:
+ return Response(data={'error': str(e)},
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR)
rsp = {'vimid': vim_info['vimId'],
'vimName': vim_info['name'],
diff --git a/vio/vio/swagger/views/image/views.py b/vio/vio/swagger/views/image/views.py
index 34877f0..fd8592d 100644
--- a/vio/vio/swagger/views/image/views.py
+++ b/vio/vio/swagger/views/image/views.py
@@ -26,6 +26,7 @@ class GetDeleteImageView(APIView):
def get(self, request, vimid, tenantid, imageid):
try:
vim_info = extsys.get_vim_by_id(vimid)
+ vim_info['tenant'] = tenantid
except VimDriverVioException as e:
return Response(data={'error': str(e)}, status=e.status_code)
@@ -38,12 +39,16 @@ class GetDeleteImageView(APIView):
rsp.update(vim_rsp)
return Response(data=rsp, status=status.HTTP_200_OK)
except Exception as e:
- return Response(data={'error': str(e)},
- status=status.HTTP_500_INTERNAL_SERVER_ERROR)
+ if hasattr(e, "http_status"):
+ return Response(data={'error': str(e)}, status=e.http_status)
+ else:
+ return Response(data={'error': str(e)},
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR)
def delete(self, request, vimid, tenantid, imageid):
try:
vim_info = extsys.get_vim_by_id(vimid)
+ vim_info['tenant'] = tenantid
except VimDriverVioException as e:
return Response(data={'error': str(e)}, status=e.status_code)
@@ -53,14 +58,18 @@ class GetDeleteImageView(APIView):
image_op.delete_vim_image(imageid)
return Response(status=status.HTTP_204_NO_CONTENT)
except Exception as e:
- return Response(data={'error': str(e)},
- status=status.HTTP_500_INTERNAL_SERVER_ERROR)
+ if hasattr(e, "http_status"):
+ return Response(data={'error': str(e)}, status=e.http_status)
+ else:
+ return Response(data={'error': str(e)},
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR)
class CreateListImagesView(APIView):
def get(self, request, vimid, tenantid):
try:
vim_info = extsys.get_vim_by_id(vimid)
+ vim_info['tenant'] = tenantid
except VimDriverVioException as e:
return Response(data={'error': str(e)}, status=e.status_code)
@@ -77,12 +86,16 @@ class CreateListImagesView(APIView):
rsp.update(vim_rsp)
return Response(data=rsp, status=status.HTTP_200_OK)
except Exception as e:
- return Response(data={'error': str(e)},
- status=status.HTTP_500_INTERNAL_SERVER_ERROR)
+ if hasattr(e, "http_status"):
+ return Response(data={'error': str(e)}, status=e.http_status)
+ else:
+ return Response(data={'error': str(e)},
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR)
def post(self, request, vimid, tenantid):
try:
vim_info = extsys.get_vim_by_id(vimid)
+ vim_info['tenant'] = tenantid
except VimDriverVioException as e:
return Response(data={'error': str(e)}, status=e.status_code)
@@ -114,5 +127,8 @@ class CreateListImagesView(APIView):
rsp['returnCode'] = '1'
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
+ if hasattr(e, "http_status"):
+ return Response(data={'error': str(e)}, status=e.http_status)
+ else:
+ return Response(data={'error': str(e)},
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR) \ No newline at end of file
diff --git a/vio/vio/swagger/views/limits/views.py b/vio/vio/swagger/views/limits/views.py
index 98c66ed..5232f66 100644
--- a/vio/vio/swagger/views/limits/views.py
+++ b/vio/vio/swagger/views/limits/views.py
@@ -32,15 +32,17 @@ class LimitsView(APIView):
'vimName': vim_info['name'],
'username': vim_info['userName'],
'password': vim_info['password'],
- 'url': vim_info['url'],
- 'project_name': vim_info['tenant']}
+ 'url': vim_info['url']}
servers_op = OperateLimits.OperateLimits()
try:
server_limits = servers_op.get_limits(data, tenantid)
except Exception as e:
- return Response(data={'error': str(e)},
- status=status.HTTP_500_INTERNAL_SERVER_ERROR)
+ if hasattr(e, "http_status"):
+ return Response(data={'error': str(e)}, status=e.http_status)
+ else:
+ return Response(data={'error': str(e)},
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR)
rsp = {'vimId': vim_info['vimId'],
'vimName': vim_info['name'],
diff --git a/vio/vio/swagger/views/network/views.py b/vio/vio/swagger/views/network/views.py
index 47a72b3..773f200 100644
--- a/vio/vio/swagger/views/network/views.py
+++ b/vio/vio/swagger/views/network/views.py
@@ -40,13 +40,17 @@ class CreateNetworkView(APIView):
resp = net.list_network(vimid, tenantid, target)
if resp:
resp['returnCode'] = 0
+ return Response(data=resp, status=status.HTTP_200_OK)
else:
resp = net.create_network(vimid, tenantid, body)
resp['returnCode'] = 1
- return Response(data=resp, status=status.HTTP_202_ACCEPTED)
+ return Response(data=resp, status=status.HTTP_202_ACCEPTED)
except Exception as e:
- return Response(data={'error': str(e)},
- status=status.HTTP_500_INTERNAL_SERVER_ERROR)
+ if hasattr(e, "http_status"):
+ return Response(data={'error': str(e)}, status=e.http_status)
+ else:
+ return Response(data={'error': str(e)},
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR)
def get(self, request, vimid, tenantid):
logger.info("Enter %s, method is %s, vim_id is %s",
@@ -55,10 +59,13 @@ class CreateNetworkView(APIView):
net = OperateNetwork.OperateNetwork()
try:
resp = net.list_networks(vimid, tenantid, **query)
- return Response(data=resp, status=status.HTTP_202_ACCEPTED)
+ return Response(data=resp, status=status.HTTP_200_OK)
except Exception as e:
- return Response(data={'error': str(e)},
- status=status.HTTP_500_INTERNAL_SERVER_ERROR)
+ if hasattr(e, "http_status"):
+ return Response(data={'error': str(e)}, status=e.http_status)
+ else:
+ return Response(data={'error': str(e)},
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR)
class DeleteNetworkView(APIView):
@@ -69,10 +76,13 @@ class DeleteNetworkView(APIView):
net = OperateNetwork.OperateNetwork()
try:
resp = net.list_network(vimid, tenantid, networkid)
- return Response(data=resp, status=status.HTTP_202_ACCEPTED)
+ return Response(data=resp, status=status.HTTP_200_OK)
except Exception as e:
- return Response(data={'error': str(e)},
- status=status.HTTP_500_INTERNAL_SERVER_ERROR)
+ if hasattr(e, "http_status"):
+ return Response(data={'error': str(e)}, status=e.http_status)
+ else:
+ return Response(data={'error': str(e)},
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR)
def delete(self, request, vimid, tenantid, networkid):
logger.info("Enter %s, method is %s, vim_id is %s",
@@ -80,10 +90,13 @@ class DeleteNetworkView(APIView):
net = OperateNetwork.OperateNetwork()
try:
resp = net.delete_network(vimid, tenantid, networkid)
- return Response(data=resp, status=status.HTTP_202_ACCEPTED)
+ return Response(data=resp, status=status.HTTP_204_NO_CONTENT)
except Exception as e:
- return Response(data={'error': str(e)},
- status=status.HTTP_500_INTERNAL_SERVER_ERROR)
+ if hasattr(e, "http_status"):
+ return Response(data={'error': str(e)}, status=e.http_status)
+ else:
+ return Response(data={'error': str(e)},
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR)
diff --git a/vio/vio/swagger/views/port/views.py b/vio/vio/swagger/views/port/views.py
index 907378c..8952f2b 100644
--- a/vio/vio/swagger/views/port/views.py
+++ b/vio/vio/swagger/views/port/views.py
@@ -40,13 +40,17 @@ class CreatePortView(APIView):
resp = port.list_port(vimid, tenantid, target, ignore_missing=True)
if resp:
resp['returnCode'] = 0
+ return Response(data=resp, status=status.HTTP_200_OK)
else:
resp = port.create_port(vimid, tenantid, body)
resp['returnCode'] = 1
- return Response(data=resp, status=status.HTTP_202_ACCEPTED)
+ return Response(data=resp, status=status.HTTP_202_ACCEPTED)
except Exception as e:
- return Response(data={'error': str(e)},
- status=status.HTTP_500_INTERNAL_SERVER_ERROR)
+ if hasattr(e, "http_status"):
+ return Response(data={'error': str(e)}, status=e.http_status)
+ else:
+ return Response(data={'error': str(e)},
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR)
def get(self, request, vimid, tenantid):
logger.info("Enter %s, method is %s, vim_id is %s",
@@ -55,10 +59,13 @@ class CreatePortView(APIView):
port = OperatePort.OperatePort()
try:
resp = port.list_ports(vimid, tenantid, **query)
- return Response(data=resp, status=status.HTTP_202_ACCEPTED)
+ return Response(data=resp, status=status.HTTP_200_OK)
except Exception as e:
- return Response(data={'error': str(e)},
- status=status.HTTP_500_INTERNAL_SERVER_ERROR)
+ if hasattr(e, "http_status"):
+ return Response(data={'error': str(e)}, status=e.http_status)
+ else:
+ return Response(data={'error': str(e)},
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR)
class DeletePortView(APIView):
@@ -69,10 +76,13 @@ class DeletePortView(APIView):
port = OperatePort.OperatePort()
try:
resp = port.list_port(vimid, tenantid, portid)
- return Response(data=resp, status=status.HTTP_202_ACCEPTED)
+ return Response(data=resp, status=status.HTTP_200_OK)
except Exception as e:
- return Response(data={'error': str(e)},
- status=status.HTTP_500_INTERNAL_SERVER_ERROR)
+ if hasattr(e, "http_status"):
+ return Response(data={'error': str(e)}, status=e.http_status)
+ else:
+ return Response(data={'error': str(e)},
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR)
def delete(self, request, vimid, tenantid, portid):
logger.info("Enter %s, method is %s, vim_id is %s",
@@ -80,10 +90,13 @@ class DeletePortView(APIView):
port = OperatePort.OperatePort()
try:
resp = port.delete_port(vimid, tenantid, portid)
- return Response(data=resp, status=status.HTTP_202_ACCEPTED)
+ return Response(data=resp, status=status.HTTP_204_NO_CONTENT)
except Exception as e:
- return Response(data={'error': str(e)},
- status=status.HTTP_500_INTERNAL_SERVER_ERROR)
+ if hasattr(e, "http_status"):
+ return Response(data={'error': str(e)}, status=e.http_status)
+ else:
+ return Response(data={'error': str(e)},
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR)
diff --git a/vio/vio/swagger/views/server/views.py b/vio/vio/swagger/views/server/views.py
index d6345f8..966d5aa 100644
--- a/vio/vio/swagger/views/server/views.py
+++ b/vio/vio/swagger/views/server/views.py
@@ -42,14 +42,14 @@ class ListServersView(APIView):
'vimName': vim_info['name'],
'username': vim_info['userName'],
'password': vim_info['password'],
- 'url': vim_info['url'],
- 'project_name': vim_info['tenant']}
+ 'url': vim_info['url']}
rsp = {'vimId': vim_info['vimId'],
'vimName': vim_info['name'],
'tenantId': tenantid}
servers_op = OperateServers.OperateServers()
server_name = create_req.get('name', None)
server_id = create_req.get('id', None)
+ exist = False
try:
target = server_id or server_name
server = servers_op.find_server(data, tenantid, target)
@@ -57,15 +57,22 @@ class ListServersView(APIView):
if server:
server = servers_op.get_server(data, tenantid, server.id)
rsp['returnCode'] = 0
+ exist = True
else:
rsp['returnCode'] = 1
server = servers_op.create_server(data, tenantid, create_req)
- except Exception as ex:
- return Response(data=str(ex),
- status=status.HTTP_500_INTERNAL_SERVER_ERROR)
+ except Exception as e:
+ if hasattr(e, "http_status"):
+ return Response(data={'error': str(e)}, status=e.http_status)
+ else:
+ return Response(data={'error': str(e)},
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR)
server_dict = nova_utils.server_formatter(server)
rsp.update(server_dict)
- return Response(data=rsp, status=status.HTTP_200_OK)
+ if exist:
+ return Response(data=rsp, status=status.HTTP_200_OK)
+ else:
+ return Response(data=rsp, status=status.HTTP_202_ACCEPTED)
def get(self, request, vimid, tenantid):
try:
@@ -77,15 +84,17 @@ class ListServersView(APIView):
'vimName': vim_info['name'],
'username': vim_info['userName'],
'password': vim_info['password'],
- 'url': vim_info['url'],
- 'project_name': vim_info['tenant']}
+ 'url': vim_info['url']}
query = dict(request.query_params)
servers_op = OperateServers.OperateServers()
try:
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)
+ if hasattr(e, "http_status"):
+ return Response(data={'error': str(e)}, status=e.http_status)
+ else:
+ return Response(data={'error': str(e)},
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR)
servers_resp = []
for server in servers:
@@ -112,8 +121,7 @@ class GetServerView(APIView):
'vimName': vim_info['name'],
'username': vim_info['userName'],
'password': vim_info['password'],
- 'url': vim_info['url'],
- 'project_name': vim_info['tenant']}
+ 'url': vim_info['url']}
servers_op = OperateServers.OperateServers()
try:
@@ -121,8 +129,11 @@ class GetServerView(APIView):
intfs = servers_op.list_server_interfaces(data, tenantid, server)
server_dict = nova_utils.server_formatter(server, interfaces=intfs)
except Exception as e:
- return Response(data={'error': str(e)},
- status=status.HTTP_500_INTERNAL_SERVER_ERROR)
+ if hasattr(e, "http_status"):
+ return Response(data={'error': str(e)}, status=e.http_status)
+ else:
+ return Response(data={'error': str(e)},
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR)
rsp = {'vimId': vim_info['vimId'],
'vimName': vim_info['name'],
@@ -142,11 +153,13 @@ class GetServerView(APIView):
'vimName': vim_info['name'],
'username': vim_info['userName'],
'password': vim_info['password'],
- 'url': vim_info['url'],
- 'project_name': vim_info['tenant']}
+ 'url': vim_info['url']}
try:
servers_op.delete_server(data, tenantid, serverid)
except Exception as e:
- return Response(data={'error': str(e)},
- status=status.HTTP_500_INTERNAL_SERVER_ERROR)
+ if hasattr(e, "http_status"):
+ return Response(data={'error': str(e)}, status=e.http_status)
+ else:
+ return Response(data={'error': str(e)},
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR)
return Response(status=status.HTTP_204_NO_CONTENT)
diff --git a/vio/vio/swagger/views/service/views.py b/vio/vio/swagger/views/service/views.py
index cca1456..bc17d31 100644
--- a/vio/vio/swagger/views/service/views.py
+++ b/vio/vio/swagger/views/service/views.py
@@ -34,16 +34,18 @@ class HostsView(APIView):
'vimName': vim_info['name'],
'username': vim_info['userName'],
'password': vim_info['password'],
- 'url': vim_info['url'],
- 'project_name': vim_info['tenant']}
+ 'url': vim_info['url']}
services_op = OperateService.OperateService()
try:
hosts = [nova_utils.service_formatter(svc)
for svc in services_op.list_services(data, tenantid)]
except Exception as e:
- return Response(data={'error': str(e)},
- status=status.HTTP_500_INTERNAL_SERVER_ERROR)
+ if hasattr(e, "http_status"):
+ return Response(data={'error': str(e)}, status=e.http_status)
+ else:
+ return Response(data={'error': str(e)},
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR)
rsp = {'vimid': vim_info['vimId'],
'vimName': vim_info['name'],
diff --git a/vio/vio/swagger/views/subnet/views.py b/vio/vio/swagger/views/subnet/views.py
index f6d109a..b782b50 100644
--- a/vio/vio/swagger/views/subnet/views.py
+++ b/vio/vio/swagger/views/subnet/views.py
@@ -40,13 +40,17 @@ class CreateSubnetView(APIView):
resp = subnet.list_subnet(vimid, tenantid, target, ignore_missing=True)
if resp:
resp['returnCode'] = 0
+ return Response(data=resp, status=status.HTTP_200_OK)
else:
resp = subnet.create_subnet(vimid, tenantid, body)
resp['returnCode'] = 1
- return Response(data=resp, status=status.HTTP_202_ACCEPTED)
+ return Response(data=resp, status=status.HTTP_202_ACCEPTED)
except Exception as e:
- return Response(data={'error': str(e)},
- status=status.HTTP_500_INTERNAL_SERVER_ERROR)
+ if hasattr(e, "http_status"):
+ return Response(data={'error': str(e)}, status=e.http_status)
+ else:
+ return Response(data={'error': str(e)},
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR)
def get(self, request, vimid, tenantid):
logger.info("Enter %s, method is %s, vim_id is %s",
@@ -55,10 +59,13 @@ class CreateSubnetView(APIView):
subnet = OperateSubnet.OperateSubnet()
try:
resp = subnet.list_subnets(vimid, tenantid, **query)
- return Response(data=resp, status=status.HTTP_202_ACCEPTED)
+ return Response(data=resp, status=status.HTTP_200_OK)
except Exception as e:
- return Response(data={'error': str(e)},
- status=status.HTTP_500_INTERNAL_SERVER_ERROR)
+ if hasattr(e, "http_status"):
+ return Response(data={'error': str(e)}, status=e.http_status)
+ else:
+ return Response(data={'error': str(e)},
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR)
class DeleteSubnetView(APIView):
@@ -69,10 +76,13 @@ class DeleteSubnetView(APIView):
subnet = OperateSubnet.OperateSubnet()
try:
resp = subnet.list_subnet(vimid, tenantid, subnetid)
- return Response(data=resp, status=status.HTTP_202_ACCEPTED)
+ return Response(data=resp, status=status.HTTP_200_OK)
except Exception as e:
- return Response(data={'error': str(e)},
- status=status.HTTP_500_INTERNAL_SERVER_ERROR)
+ if hasattr(e, "http_status"):
+ return Response(data={'error': str(e)}, status=e.http_status)
+ else:
+ return Response(data={'error': str(e)},
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR)
def delete(self, request, vimid, tenantid, subnetid):
logger.info("Enter %s, method is %s, vim_id is %s",
@@ -80,10 +90,13 @@ class DeleteSubnetView(APIView):
subnet = OperateSubnet.OperateSubnet()
try:
resp = subnet.delete_subnet(vimid, tenantid, subnetid)
- return Response(data=resp, status=status.HTTP_202_ACCEPTED)
+ return Response(data=resp, status=status.HTTP_204_NO_CONTENT)
except Exception as e:
- return Response(data={'error': str(e)},
- status=status.HTTP_500_INTERNAL_SERVER_ERROR)
+ if hasattr(e, "http_status"):
+ return Response(data={'error': str(e)}, status=e.http_status)
+ else:
+ return Response(data={'error': str(e)},
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR)
diff --git a/vio/vio/swagger/views/tenant/views.py b/vio/vio/swagger/views/tenant/views.py
index 3eff77f..ce50cf6 100644
--- a/vio/vio/swagger/views/tenant/views.py
+++ b/vio/vio/swagger/views/tenant/views.py
@@ -43,8 +43,11 @@ class ListTenantsView(APIView):
try:
projects = tenant_instance.get_projects(data, **query)
except Exception as e:
- return Response(data={'error': str(e)},
- status=status.HTTP_500_INTERNAL_SERVER_ERROR)
+ if hasattr(e, "http_status"):
+ return Response(data={'error': str(e)}, status=e.http_status)
+ else:
+ return Response(data={'error': str(e)},
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR)
rsp = {}
rsp['vimId'] = vim_info['vimId']
diff --git a/vio/vio/swagger/views/volume/views.py b/vio/vio/swagger/views/volume/views.py
index 73a20e6..d80d6ac 100644
--- a/vio/vio/swagger/views/volume/views.py
+++ b/vio/vio/swagger/views/volume/views.py
@@ -32,6 +32,7 @@ class GetDeleteVolumeView(APIView):
def get(self, request, vimid, tenantid, volumeid):
try:
vim_info = extsys.get_vim_by_id(vimid)
+ vim_info['tenant'] = tenantid
except VimDriverVioException as e:
return Response(data={'error': str(e)}, status=e.status_code)
@@ -44,12 +45,16 @@ class GetDeleteVolumeView(APIView):
rsp.update(vim_rsp)
return Response(data=rsp, status=status.HTTP_200_OK)
except Exception as e:
- return Response(data={'error': str(e)},
- status=status.HTTP_500_INTERNAL_SERVER_ERROR)
+ if hasattr(e, "http_status"):
+ return Response(data={'error': str(e)}, status=e.http_status)
+ else:
+ return Response(data={'error': str(e)},
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR)
def delete(self, request, vimid, tenantid, volumeid):
try:
vim_info = extsys.get_vim_by_id(vimid)
+ vim_info['tenant'] = tenantid
except VimDriverVioException as e:
return Response(data={'error': str(e)}, status=e.status_code)
@@ -59,8 +64,11 @@ class GetDeleteVolumeView(APIView):
volume_op.delete_vim_volume(volumeid)
return Response(status=status.HTTP_204_NO_CONTENT)
except Exception as e:
- return Response(data={'error': str(e)},
- status=status.HTTP_500_INTERNAL_SERVER_ERROR)
+ if hasattr(e, "http_status"):
+ return Response(data={'error': str(e)}, status=e.http_status)
+ else:
+ return Response(data={'error': str(e)},
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR)
class CreateListVolumeView(APIView):
@@ -68,6 +76,7 @@ class CreateListVolumeView(APIView):
def get(self, request, vimid, tenantid):
try:
vim_info = extsys.get_vim_by_id(vimid)
+ vim_info['tenant'] = tenantid
except VimDriverVioException as e:
return Response(data={'error': str(e)}, status=e.status_code)
@@ -87,13 +96,17 @@ class CreateListVolumeView(APIView):
rsp.update(vim_rsp)
return Response(data=rsp, status=status.HTTP_200_OK)
except Exception as e:
- return Response(data={'error': str(e)},
- status=status.HTTP_500_INTERNAL_SERVER_ERROR)
+ if hasattr(e, "http_status"):
+ return Response(data={'error': str(e)}, status=e.http_status)
+ else:
+ return Response(data={'error': str(e)},
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR)
def post(self, request, vimid, tenantid):
try:
vim_info = extsys.get_vim_by_id(vimid)
+ vim_info['tenant'] = tenantid
except VimDriverVioException as e:
return Response(data={'error': str(e)}, status=e.status_code)
@@ -128,5 +141,8 @@ class CreateListVolumeView(APIView):
rsp.update(vim_rsp)
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)
+ if hasattr(e, "http_status"):
+ return Response(data={'error': str(e)}, status=e.http_status)
+ else:
+ return Response(data={'error': str(e)},
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR)
diff --git a/vio/vio/swagger/volume_utils.py b/vio/vio/swagger/volume_utils.py
index 44fcbd7..2d20a05 100644
--- a/vio/vio/swagger/volume_utils.py
+++ b/vio/vio/swagger/volume_utils.py
@@ -51,7 +51,7 @@ def sdk_param_formatter(data):
param['username'] = data.get('userName')
param['password'] = data.get('password')
param['auth_url'] = data.get('url')
- param['project_name'] = data.get('tenant')
+ param['project_id'] = data.get('tenant')
param['user_domain_name'] = 'default'
param['project_domain_name'] = 'default'
return param