summaryrefslogtreecommitdiffstats
path: root/newton
diff options
context:
space:
mode:
Diffstat (limited to 'newton')
-rw-r--r--newton/newton/requests/views/flavor.py5
-rw-r--r--newton/newton/requests/views/hosts.py2
-rw-r--r--newton/newton/requests/views/image.py5
-rw-r--r--newton/newton/requests/views/limits.py2
-rw-r--r--newton/newton/requests/views/network.py4
-rw-r--r--newton/newton/requests/views/server.py4
-rw-r--r--newton/newton/requests/views/subnet.py4
-rw-r--r--newton/newton/requests/views/tenants.py2
-rw-r--r--newton/newton/requests/views/volume.py4
-rw-r--r--newton/newton/requests/views/vport.py45
10 files changed, 56 insertions, 21 deletions
diff --git a/newton/newton/requests/views/flavor.py b/newton/newton/requests/views/flavor.py
index 197ecd8b..c59c42cf 100644
--- a/newton/newton/requests/views/flavor.py
+++ b/newton/newton/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 VimDriverNewtonException 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)
@@ -303,6 +307,7 @@ class Flavors(APIView):
except VimDriverNewtonException 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/newton/newton/requests/views/hosts.py b/newton/newton/requests/views/hosts.py
index f0ea6862..7801c557 100644
--- a/newton/newton/requests/views/hosts.py
+++ b/newton/newton/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 VimDriverNewtonException 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/newton/newton/requests/views/image.py b/newton/newton/requests/views/image.py
index 24f4cb47..bf24771d 100644
--- a/newton/newton/requests/views/image.py
+++ b/newton/newton/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 VimDriverNewtonException 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 VimDriverNewtonException 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/newton/newton/requests/views/limits.py b/newton/newton/requests/views/limits.py
index 33e4af3a..83d0e505 100644
--- a/newton/newton/requests/views/limits.py
+++ b/newton/newton/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 VimDriverNewtonException 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/newton/newton/requests/views/network.py b/newton/newton/requests/views/network.py
index 0f591bee..a1b440d8 100644
--- a/newton/newton/requests/views/network.py
+++ b/newton/newton/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 VimDriverNewtonException 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 VimDriverNewtonException 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 VimDriverNewtonException 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/newton/newton/requests/views/server.py b/newton/newton/requests/views/server.py
index 26f30de1..51a0efa6 100644
--- a/newton/newton/requests/views/server.py
+++ b/newton/newton/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 VimDriverNewtonException 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)
@@ -236,6 +238,7 @@ class Servers(APIView):
except VimDriverNewtonException 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
@@ -255,6 +258,7 @@ class Servers(APIView):
except VimDriverNewtonException 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/newton/newton/requests/views/subnet.py b/newton/newton/requests/views/subnet.py
index 24304633..b37d4d33 100644
--- a/newton/newton/requests/views/subnet.py
+++ b/newton/newton/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 VimDriverNewtonException 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 VimDriverNewtonException 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 VimDriverNewtonException 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/newton/newton/requests/views/tenants.py b/newton/newton/requests/views/tenants.py
index f94140cb..7f82bb67 100644
--- a/newton/newton/requests/views/tenants.py
+++ b/newton/newton/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
@@ -75,6 +76,7 @@ class Tenants(APIView):
except VimDriverNewtonException 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/newton/newton/requests/views/volume.py b/newton/newton/requests/views/volume.py
index f9df7572..a126aadc 100644
--- a/newton/newton/requests/views/volume.py
+++ b/newton/newton/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 VimDriverNewtonException 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 VimDriverNewtonException 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 VimDriverNewtonException 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/newton/newton/requests/views/vport.py b/newton/newton/requests/views/vport.py
index 750726ea..a5b8db93 100644
--- a/newton/newton/requests/views/vport.py
+++ b/newton/newton/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 VimDriverNewtonException 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 VimDriverNewtonException 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 VimDriverNewtonException 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