summaryrefslogtreecommitdiffstats
path: root/kilo
diff options
context:
space:
mode:
Diffstat (limited to 'kilo')
-rw-r--r--kilo/kilo/requests/views/flavor.py5
-rw-r--r--kilo/kilo/requests/views/hosts.py2
-rw-r--r--kilo/kilo/requests/views/image.py5
-rw-r--r--kilo/kilo/requests/views/limits.py2
-rw-r--r--kilo/kilo/requests/views/network.py4
-rw-r--r--kilo/kilo/requests/views/server.py4
-rw-r--r--kilo/kilo/requests/views/subnet.py4
-rw-r--r--kilo/kilo/requests/views/tenants.py2
-rw-r--r--kilo/kilo/requests/views/volume.py4
-rw-r--r--kilo/kilo/requests/views/vport.py45
10 files changed, 56 insertions, 21 deletions
diff --git a/kilo/kilo/requests/views/flavor.py b/kilo/kilo/requests/views/flavor.py
index 2e2194bd..fb8fb697 100644
--- a/kilo/kilo/requests/views/flavor.py
+++ b/kilo/kilo/requests/views/flavor.py
@@ -13,6 +13,7 @@
# limitations under the License.
import logging
import json
+import traceback
from rest_framework import status
from rest_framework.response import Response
@@ -118,6 +119,7 @@ class Flavors(APIView):
except VimDriverKiloException as e:
return Response(data={'error': e.content}, status=e.status_code)
except Exception as e:
+ logger.error(traceback.format_exc())
return Response(data={'error': str(e)},
status=status.HTTP_500_INTERNAL_SERVER_ERROR)
pass
@@ -240,6 +242,8 @@ class Flavors(APIView):
return Response(data={'error': e.content}, status=e.status_code)
except Exception as e:
+ logger.error(traceback.format_exc())
+
if sess and resp and resp.status_code == 200:
self.delete_flavor(sess, flavorid)
@@ -306,6 +310,7 @@ class Flavors(APIView):
except VimDriverKiloException as e:
return Response(data={'error': e.content}, status=e.status_code)
except Exception as e:
+ logger.error(traceback.format_exc())
return Response(data={'error': str(e)},
status=status.HTTP_500_INTERNAL_SERVER_ERROR)
pass
diff --git a/kilo/kilo/requests/views/hosts.py b/kilo/kilo/requests/views/hosts.py
index b9d0ed1b..dfd34513 100644
--- a/kilo/kilo/requests/views/hosts.py
+++ b/kilo/kilo/requests/views/hosts.py
@@ -13,6 +13,7 @@
# limitations under the License.
import logging
import json
+import traceback
from rest_framework import status
from rest_framework.response import Response
@@ -76,6 +77,7 @@ class Hosts(APIView):
except VimDriverKiloException as e:
return Response(data={'error': e.content}, status=e.status_code)
except Exception as e:
+ logger.error(traceback.format_exc())
return Response(data={'error': str(e)},
status=status.HTTP_500_INTERNAL_SERVER_ERROR)
diff --git a/kilo/kilo/requests/views/image.py b/kilo/kilo/requests/views/image.py
index 339c73e0..c8f66b28 100644
--- a/kilo/kilo/requests/views/image.py
+++ b/kilo/kilo/requests/views/image.py
@@ -15,6 +15,7 @@ import logging
import json
import urllib2
import threading
+import traceback
from rest_framework import status
from rest_framework.response import Response
@@ -65,6 +66,7 @@ class imageThread (threading.Thread):
logger.debug("response status code of transfer_image %s" % resp.status_code)
return None
except Exception as e:
+ logger.error(traceback.format_exc())
logger.debug("Failed to transfer_image:%s" % str(e))
return None
pass
@@ -89,6 +91,7 @@ class Images(APIView):
except VimDriverKiloException as e:
return Response(data={'error': e.content}, status=e.status_code)
except Exception as e:
+ logger.error(traceback.format_exc())
return Response(data={'error': str(e)},
status=status.HTTP_500_INTERNAL_SERVER_ERROR)
@@ -201,6 +204,7 @@ class Images(APIView):
return Response(data={'error': 'image is not accessible:%s' % str(e)},
status=status.HTTP_500_INTERNAL_SERVER_ERROR)
except Exception as e:
+ logger.error(traceback.format_exc())
return Response(data={'error': str(e)},
status=status.HTTP_500_INTERNAL_SERVER_ERROR)
pass
@@ -220,6 +224,7 @@ class Images(APIView):
except VimDriverKiloException as e:
return Response(data={'error': e.content}, status=e.status_code)
except Exception as e:
+ logger.error(traceback.format_exc())
return Response(data={'error': str(e)},
status=status.HTTP_500_INTERNAL_SERVER_ERROR)
pass
diff --git a/kilo/kilo/requests/views/limits.py b/kilo/kilo/requests/views/limits.py
index fce584f3..ee44124b 100644
--- a/kilo/kilo/requests/views/limits.py
+++ b/kilo/kilo/requests/views/limits.py
@@ -13,6 +13,7 @@
# limitations under the License.
import logging
import json
+import traceback
from rest_framework import status
from rest_framework.response import Response
@@ -75,6 +76,7 @@ class Limits(APIView):
except VimDriverKiloException as e:
return Response(data={'error': e.content}, status=e.status_code)
except Exception as e:
+ logger.error(traceback.format_exc())
return Response(data={'error': str(e)},
status=status.HTTP_500_INTERNAL_SERVER_ERROR)
diff --git a/kilo/kilo/requests/views/network.py b/kilo/kilo/requests/views/network.py
index c0133481..eb45189b 100644
--- a/kilo/kilo/requests/views/network.py
+++ b/kilo/kilo/requests/views/network.py
@@ -13,6 +13,7 @@
# limitations under the License.
import logging
import json
+import traceback
from rest_framework import status
from rest_framework.response import Response
@@ -48,6 +49,7 @@ class Networks(APIView):
except VimDriverKiloException as e:
return Response(data={'error': e.content}, status=e.status_code)
except Exception as e:
+ logger.error(traceback.format_exc())
return Response(data={'error': str(e)},
status=status.HTTP_500_INTERNAL_SERVER_ERROR)
@@ -131,6 +133,7 @@ class Networks(APIView):
except VimDriverKiloException as e:
return Response(data={'error': e.content}, status=e.status_code)
except Exception as e:
+ logger.error(traceback.format_exc())
return Response(data={'error': str(e)},
status=status.HTTP_500_INTERNAL_SERVER_ERROR)
pass
@@ -153,6 +156,7 @@ class Networks(APIView):
except VimDriverKiloException as e:
return Response(data={'error': e.content}, status=e.status_code)
except Exception as e:
+ logger.error(traceback.format_exc())
return Response(data={'error': str(e)},
status=status.HTTP_500_INTERNAL_SERVER_ERROR)
pass
diff --git a/kilo/kilo/requests/views/server.py b/kilo/kilo/requests/views/server.py
index 69216bf3..75b0a87c 100644
--- a/kilo/kilo/requests/views/server.py
+++ b/kilo/kilo/requests/views/server.py
@@ -13,6 +13,7 @@
# limitations under the License.
import logging
import json
+import traceback
from rest_framework import status
from rest_framework.response import Response
@@ -79,6 +80,7 @@ class Servers(APIView):
except VimDriverKiloException as e:
return Response(data={'error': e.content}, status=e.status_code)
except Exception as e:
+ logger.error(traceback.format_exc())
return Response(data={'error': str(e)},
status=status.HTTP_500_INTERNAL_SERVER_ERROR)
@@ -237,6 +239,7 @@ class Servers(APIView):
except VimDriverKiloException as e:
return Response(data={'error': e.content}, status=e.status_code)
except Exception as e:
+ logger.error(traceback.format_exc())
return Response(data={'error': str(e)},
status=status.HTTP_500_INTERNAL_SERVER_ERROR)
pass
@@ -256,6 +259,7 @@ class Servers(APIView):
except VimDriverKiloException as e:
return Response(data={'error': e.content}, status=e.status_code)
except Exception as e:
+ logger.error(traceback.format_exc())
return Response(data={'error': str(e)},
status=status.HTTP_500_INTERNAL_SERVER_ERROR)
pass
diff --git a/kilo/kilo/requests/views/subnet.py b/kilo/kilo/requests/views/subnet.py
index ef90c53c..3512a2f0 100644
--- a/kilo/kilo/requests/views/subnet.py
+++ b/kilo/kilo/requests/views/subnet.py
@@ -13,6 +13,7 @@
# limitations under the License.
import logging
import json
+import traceback
from rest_framework import status
from rest_framework.response import Response
@@ -50,6 +51,7 @@ class Subnets(APIView):
except VimDriverKiloException as e:
return Response(data={'error': e.content}, status=e.status_code)
except Exception as e:
+ logger.error(traceback.format_exc())
return Response(data={'error': str(e)},
status=status.HTTP_500_INTERNAL_SERVER_ERROR)
@@ -133,6 +135,7 @@ class Subnets(APIView):
except VimDriverKiloException as e:
return Response(data={'error': e.content}, status=e.status_code)
except Exception as e:
+ logger.error(traceback.format_exc())
return Response(data={'error': str(e)},
status=status.HTTP_500_INTERNAL_SERVER_ERROR)
pass
@@ -155,6 +158,7 @@ class Subnets(APIView):
except VimDriverKiloException as e:
return Response(data={'error': e.content}, status=e.status_code)
except Exception as e:
+ logger.error(traceback.format_exc())
return Response(data={'error': str(e)},
status=status.HTTP_500_INTERNAL_SERVER_ERROR)
pass
diff --git a/kilo/kilo/requests/views/tenants.py b/kilo/kilo/requests/views/tenants.py
index cefbc8a2..c8a7fff2 100644
--- a/kilo/kilo/requests/views/tenants.py
+++ b/kilo/kilo/requests/views/tenants.py
@@ -13,6 +13,7 @@
# limitations under the License.
import logging
import json
+import traceback
from rest_framework import status
from rest_framework.response import Response
@@ -70,6 +71,7 @@ class Tenants(APIView):
except VimDriverKiloException as e:
return Response(data={'error': e.content}, status=e.status_code)
except Exception as e:
+ logger.error(traceback.format_exc())
return Response(data={'error': str(e)},
status=status.HTTP_500_INTERNAL_SERVER_ERROR)
diff --git a/kilo/kilo/requests/views/volume.py b/kilo/kilo/requests/views/volume.py
index eea3537e..6682a4c4 100644
--- a/kilo/kilo/requests/views/volume.py
+++ b/kilo/kilo/requests/views/volume.py
@@ -13,6 +13,7 @@
# limitations under the License.
import logging
import json
+import traceback
from rest_framework import status
from rest_framework.response import Response
@@ -50,6 +51,7 @@ class Volumes(APIView):
except VimDriverKiloException as e:
return Response(data={'error': e.content}, status=e.status_code)
except Exception as e:
+ logger.error(traceback.format_exc())
return Response(data={'error': str(e)},
status=status.HTTP_500_INTERNAL_SERVER_ERROR)
@@ -135,6 +137,7 @@ class Volumes(APIView):
except VimDriverKiloException as e:
return Response(data={'error': e.content}, status=e.status_code)
except Exception as e:
+ logger.error(traceback.format_exc())
return Response(data={'error': str(e)},
status=status.HTTP_500_INTERNAL_SERVER_ERROR)
pass
@@ -154,6 +157,7 @@ class Volumes(APIView):
except VimDriverKiloException as e:
return Response(data={'error': e.content}, status=e.status_code)
except Exception as e:
+ logger.error(traceback.format_exc())
return Response(data={'error': str(e)},
status=status.HTTP_500_INTERNAL_SERVER_ERROR)
pass
diff --git a/kilo/kilo/requests/views/vport.py b/kilo/kilo/requests/views/vport.py
index 6738cab2..987524dd 100644
--- a/kilo/kilo/requests/views/vport.py
+++ b/kilo/kilo/requests/views/vport.py
@@ -13,6 +13,7 @@
# limitations under the License.
import logging
import json
+import traceback
from rest_framework import status
from rest_framework.response import Response
@@ -43,30 +44,33 @@ class Vports(APIView):
logger.debug("Ports--get::> %s" % request.data)
try:
# prepare request resource to vim instance
- vim = VimDriverUtils.get_vim_info(vimid)
- sess = VimDriverUtils.get_session(vim, tenantid)
-
- content, status_code = self.get_ports(sess, request, vim, tenantid, portid)
+ query = VimDriverUtils.get_query_part(request)
+ content, status_code = self.get_ports(query, vimid, tenantid, portid)
return Response(data=content, status=status_code)
except VimDriverKiloException as e:
return Response(data={'error': e.content}, status=e.status_code)
except Exception as e:
+ logger.error(traceback.format_exc())
return Response(data={'error': str(e)},
status=status.HTTP_500_INTERNAL_SERVER_ERROR)
-
- def get_ports(self, sess, request, vim, tenantid, portid=""):
+ def get_ports(self, query="", vimid="", tenantid="", portid=""):
logger.debug("Ports--get_ports::> %s" % portid)
+ vim = VimDriverUtils.get_vim_info(vimid)
+ sess = VimDriverUtils.get_session(vim, tenantid)
+
if sess:
# prepare request resource to vim instance
req_resouce = "v2.0/ports"
if portid:
req_resouce += "/%s" % portid
- query = VimDriverUtils.get_query_part(request)
if query:
req_resouce += "?%s" % query
+
+ vim = VimDriverUtils.get_vim_info(vimid)
+ sess = VimDriverUtils.get_session(vim, tenantid)
resp = sess.get(req_resouce, endpoint_filter=self.service)
content = resp.json()
vim_dict = {
@@ -80,18 +84,16 @@ class Vports(APIView):
# convert the key naming in ports
for port in content["ports"]:
# use only 1st entry of fixed_ips
- if port:
- tmpips = port.pop("fixed_ips", None)
- port.update(tmpips[0])
+ tmpips = port.pop("fixed_ips", None) if port else None
+ port.update(tmpips[0]) if tmpips and len(tmpips) > 0 else None
VimDriverUtils.replace_key_by_mapping(port,
self.keys_mapping)
else:
# convert the key naming in the port specified by id
port = content.pop("port", None)
#use only 1st entry of fixed_ips
- if port:
- tmpips = port.pop("fixed_ips", None)
- port.update(tmpips[0])
+ tmpips = port.pop("fixed_ips", None) if port else None
+ port.update(tmpips[0]) if tmpips and len(tmpips) > 0 else None
VimDriverUtils.replace_key_by_mapping(port,
self.keys_mapping)
@@ -102,12 +104,9 @@ class Vports(APIView):
def post(self, request, vimid="", tenantid="", portid=""):
logger.debug("Ports--post::> %s" % request.data)
try:
- # prepare request resource to vim instance
- vim = VimDriverUtils.get_vim_info(vimid)
- sess = VimDriverUtils.get_session(vim, tenantid)
-
#check if already created: name
- content, status_code = self.get_ports(sess, request, vim, tenantid)
+ query = "name=%s" % request.data["name"]
+ content, status_code = self.get_ports(query, vimid, tenantid, portid)
existed = False
if status_code == 200:
for port in content["ports"]:
@@ -123,15 +122,18 @@ class Vports(APIView):
return Response(data=port, status=status_code)
#otherwise create a new one
- return self.create_port(sess, request, vim, tenantid)
+ return self.create_port(request, vimid, tenantid)
except VimDriverKiloException as e:
return Response(data={'error': e.content}, status=e.status_code)
except Exception as e:
+ logger.error(traceback.format_exc())
return Response(data={'error': str(e)},
status=status.HTTP_500_INTERNAL_SERVER_ERROR)
- def create_port(self, sess, request, vim, tenantid):
+ def create_port(self, request, vimid, tenantid):
logger.debug("Ports--create::> %s" % request.data)
+ vim = VimDriverUtils.get_vim_info(vimid)
+ sess = VimDriverUtils.get_session(vim, tenantid)
if sess:
# prepare request resource to vim instance
req_resouce = "v2.0/ports"
@@ -156,7 +158,7 @@ class Vports(APIView):
resp_body = resp.json()["port"]
#use only 1 fixed_ip
tmpips = resp_body.pop("fixed_ips", None)
- if tmpips:
+ if tmpips and len(tmpips) > 0:
resp_body.update(tmpips[0])
VimDriverUtils.replace_key_by_mapping(resp_body, self.keys_mapping)
@@ -188,6 +190,7 @@ class Vports(APIView):
except VimDriverKiloException as e:
return Response(data={'error': e.content}, status=e.status_code)
except Exception as e:
+ logger.error(traceback.format_exc())
return Response(data={'error': str(e)},
status=status.HTTP_500_INTERNAL_SERVER_ERROR)
pass