diff options
author | Bin Yang <bin.yang@windriver.com> | 2019-05-28 05:32:54 +0000 |
---|---|---|
committer | Bin Yang <bin.yang@windriver.com> | 2019-05-28 05:32:54 +0000 |
commit | 9154720606df1bb43e501a63cd23beca77a409eb (patch) | |
tree | 8c90d5891f45c28a408bc52100ff78c696186380 /share/newton_base | |
parent | eb1e6c75c236bd88a3c371befebcb56fa4f9f090 (diff) |
Fix issue of v1/.../tenants API
Fix all openoapi v1 which use logger
Change-Id: Iaf82c1ca17959725531f6b340e3e770844dd222c
Issue-ID: MULTICLOUD-657
Signed-off-by: Bin Yang <bin.yang@windriver.com>
Diffstat (limited to 'share/newton_base')
-rwxr-xr-x | share/newton_base/openoapi/alarm.py | 4 | ||||
-rw-r--r-- | share/newton_base/openoapi/flavor.py | 17 | ||||
-rw-r--r-- | share/newton_base/openoapi/hosts.py | 10 | ||||
-rwxr-xr-x | share/newton_base/openoapi/hypervisor.py | 9 | ||||
-rw-r--r-- | share/newton_base/openoapi/image.py | 34 | ||||
-rw-r--r-- | share/newton_base/openoapi/limits.py | 14 | ||||
-rw-r--r-- | share/newton_base/openoapi/network.py | 9 | ||||
-rw-r--r-- | share/newton_base/openoapi/server.py | 118 | ||||
-rw-r--r-- | share/newton_base/openoapi/subnet.py | 8 | ||||
-rw-r--r-- | share/newton_base/openoapi/tenants.py | 27 | ||||
-rwxr-xr-x | share/newton_base/openoapi/vmlist.py | 16 | ||||
-rw-r--r-- | share/newton_base/openoapi/volume.py | 8 | ||||
-rw-r--r-- | share/newton_base/openoapi/vport.py | 8 |
13 files changed, 213 insertions, 69 deletions
diff --git a/share/newton_base/openoapi/alarm.py b/share/newton_base/openoapi/alarm.py index 3cbcf9ad..8538a191 100755 --- a/share/newton_base/openoapi/alarm.py +++ b/share/newton_base/openoapi/alarm.py @@ -37,6 +37,10 @@ class Alarms(APIView): ("container_format", "containerFormat")
]
+ def __init__(self):
+ super(Alarms, self).__init__()
+ self._logger = logger
+
def get(self, request, vimid="", tenantid="", alarmid=""):
logger.debug("alarms--get::> %s" % request.data)
try:
diff --git a/share/newton_base/openoapi/flavor.py b/share/newton_base/openoapi/flavor.py index 8dcd10f6..8809e83b 100644 --- a/share/newton_base/openoapi/flavor.py +++ b/share/newton_base/openoapi/flavor.py @@ -39,9 +39,13 @@ class Flavors(APIView): ("extra_specs", "extraSpecs"), ] + def __init__(self): + super(Flavors, self).__init__() + self._logger = logger + def _convert_extra_specs(self, extra_specs_vfc, extra_specs_openstack, reverse=False): if reverse == False: - #from extraSpecs to extra_specs + # from extraSpecs to extra_specs for spec in extra_specs_vfc: extra_specs_openstack[spec['keyName']] = spec['value'] else: @@ -86,7 +90,7 @@ class Flavors(APIView): else: wanted = None - #check if query contains name="flavorname" + # check if query contains name="flavorname" if query: for queryone in query.split('&'): k,v = queryone.split('=') @@ -101,7 +105,7 @@ class Flavors(APIView): if wanted == flavor["name"]: content["flavors"].append(flavor) - #iterate each flavor to get extra_specs + # iterate each flavor to get extra_specs for flavor in content["flavors"]: extraResp = self._get_flavor_extra_specs(sess, flavor["id"]) extraContent = extraResp.json() @@ -112,7 +116,7 @@ class Flavors(APIView): VimDriverUtils.replace_key_by_mapping(flavor, self.keys_mapping) - #add extra keys + # add extra keys vim_dict = { "vimName": vim["name"], "vimId": vim["vimId"], @@ -418,9 +422,12 @@ class Flavors(APIView): return resp - class APIv1Flavors(Flavors): + def __init__(self): + super(APIv1Flavors, self).__init__() + self._logger = logger + def get(self, request, cloud_owner="", cloud_region_id="", tenantid="", flavorid=""): self._logger.info("%s, %s" % (cloud_owner, cloud_region_id)) diff --git a/share/newton_base/openoapi/hosts.py b/share/newton_base/openoapi/hosts.py index e136c400..9abe63ae 100644 --- a/share/newton_base/openoapi/hosts.py +++ b/share/newton_base/openoapi/hosts.py @@ -38,6 +38,10 @@ class Hosts(APIView): ("host", "name"), ] + def __init__(self): + super(Hosts, self).__init__() + self._logger = logger + def get(self, request, vimid="", tenantid="", hostname=""): logger.info("vimid, tenantid, hostname = %s,%s,%s" % (vimid, tenantid, hostname)) if request.data: @@ -78,7 +82,7 @@ class Hosts(APIView): VimDriverUtils.replace_key_by_mapping(host, self.hosts_keys_mapping) else: - #restructure host data model + # restructure host data model old_host = content["host"] content["host"] = [] # convert the key naming in resources @@ -105,6 +109,10 @@ class Hosts(APIView): class APIv1Hosts(Hosts): + def __init__(self): + super(APIv1Hosts, self).__init__() + self._logger = logger + def get(self, request, cloud_owner="", cloud_region_id="", tenantid="", hostname=""): self._logger.info("%s, %s" % (cloud_owner, cloud_region_id)) diff --git a/share/newton_base/openoapi/hypervisor.py b/share/newton_base/openoapi/hypervisor.py index 455bad68..bc7d577f 100755 --- a/share/newton_base/openoapi/hypervisor.py +++ b/share/newton_base/openoapi/hypervisor.py @@ -29,6 +29,7 @@ logger = logging.getLogger(__name__) running_threads = {}
running_thread_lock = threading.Lock()
+
class Hypervisors(APIView):
service = {'service_type': 'compute',
'interface': 'public'}
@@ -38,6 +39,9 @@ class Hypervisors(APIView): ("container_format", "containerFormat")
]
+ def __init__(self):
+ super(Hypervisors, self).__init__()
+ self._logger = logger
def get(self, request, vimid="", tenantid="", hypervisorid=""):
logger.info("vimid, tenantid, hypervisorid = %s,%s,%s" % (vimid, tenantid, hypervisorid))
@@ -63,7 +67,6 @@ class Hypervisors(APIView): return Response(data={'error': str(e)},
status=status.HTTP_500_INTERNAL_SERVER_ERROR)
-
def get_hypervisors(self, query="", vimid="", tenantid="", hypervisorid=""):
req_resource = "/os-hypervisors"
@@ -92,6 +95,10 @@ class Hypervisors(APIView): class APIv1Hypervisors(Hypervisors):
+ def __init__(self):
+ super(APIv1Hypervisors, self).__init__()
+ self._logger = logger
+
def get(self, request, cloud_owner="", cloud_region_id="", tenantid="", hypervisorid=""):
self._logger.info("%s, %s" % (cloud_owner, cloud_region_id))
diff --git a/share/newton_base/openoapi/image.py b/share/newton_base/openoapi/image.py index e40980d6..40b4b399 100644 --- a/share/newton_base/openoapi/image.py +++ b/share/newton_base/openoapi/image.py @@ -31,9 +31,11 @@ logger = logging.getLogger(__name__) running_threads = {} running_thread_lock = threading.Lock() -class imageThread (threading.Thread): + +class ImageThread (threading.Thread): service = {'service_type': 'image', 'interface': 'public'} + def __init__(self, vimid, tenantid, imageid, imagefd): threading.Thread.__init__(self) self.vimid = vimid @@ -42,9 +44,9 @@ class imageThread (threading.Thread): self.imagefd = imagefd def run(self): - logger.debug("start imagethread %s, %s, %s" % (self.vimid, self.tenantid, self.imageid)) + logger.debug("start ImageThread %s, %s, %s" % (self.vimid, self.tenantid, self.imageid)) self.transfer_image(self.vimid, self.tenantid, self.imageid, self.imagefd) - logger.debug("stop imagethread %s, %s, %s" % (self.vimid, self.tenantid, self.imageid)) + logger.debug("stop ImageThread %s, %s, %s" % (self.vimid, self.tenantid, self.imageid)) running_thread_lock.acquire() running_threads.pop(self.imageid) running_thread_lock.release() @@ -62,7 +64,7 @@ class imageThread (threading.Thread): if vim.get('openstack_region_id')\ else vim['cloud_region_id'] - #open imageurl + # open imageurl logger.info("making image put request with URI:%s" % req_resouce) resp = sess.put(req_resouce, endpoint_filter=self.service, data=imagefd.read(), headers={"Content-Type": "application/octet-stream", @@ -87,6 +89,10 @@ class Images(APIView): ("container_format", "containerFormat") ] + def __init__(self): + super(Images, self).__init__() + self._logger = logger + def get(self, request, vimid="", tenantid="", imageid=""): logger.info("vimid, tenantid, imageid = %s,%s,%s" % (vimid, tenantid, imageid)) try: @@ -143,10 +149,10 @@ class Images(APIView): self.keys_mapping) else: # convert the key naming in the image specified by id - #image = content.pop("image", None) + # image = content.pop("image", None) VimDriverUtils.replace_key_by_mapping(content, self.keys_mapping) - #content.update(image) + # content.update(image) return content, resp.status_code @@ -156,7 +162,7 @@ class Images(APIView): logger.debug("With data = %s" % request.data) pass try: - #check if created already: check name + # check if created already: check name query = "name=%s" % request.data["name"] content, status_code = self._get_images(query, vimid, tenantid) existed = False @@ -177,7 +183,7 @@ class Images(APIView): if not imageurl: return Response(data={'error': 'imagePath is not specified'}, status=500) - #valid image url + # valid image url imagefd = urllib.request.urlopen(imageurl) if not imagefd: logger.debug("image is not available at %s" % imageurl) @@ -191,7 +197,7 @@ class Images(APIView): image = request.data VimDriverUtils.replace_key_by_mapping(image, self.keys_mapping, True) - #req_body = json.JSONEncoder().encode({"image": image}) + # req_body = json.JSONEncoder().encode({"image": image}) req_body = json.JSONEncoder().encode(image) self.service['region_name'] = vim['openstack_region_id'] \ @@ -202,7 +208,7 @@ class Images(APIView): logger.debug("with data:%s" % req_body) resp = sess.post(req_resouce, data=req_body, endpoint_filter=self.service) - #resp_body = resp.json()["image"] + # resp_body = resp.json()["image"] resp_body = resp.json() VimDriverUtils.replace_key_by_mapping(resp_body, self.keys_mapping) vim_dict = { @@ -213,11 +219,11 @@ class Images(APIView): } resp_body.update(vim_dict) - #launch a thread to download image and upload to VIM + # launch a thread to download image and upload to VIM if resp.status_code == 201: imageid = resp_body["id"] logger.debug("launch thread to upload image: %s" % imageid) - tmp_thread = imageThread(vimid, tenantid,imageid,imagefd) + tmp_thread = ImageThread(vimid, tenantid,imageid,imagefd) running_thread_lock.acquire() running_threads[imageid] = tmp_thread running_thread_lock.release() @@ -273,6 +279,10 @@ class Images(APIView): class APIv1Images(Images): + def __init__(self): + super(APIv1Images, self).__init__() + self._logger = logger + def get(self, request, cloud_owner="", cloud_region_id="", tenantid="", imageid=""): self._logger.info("%s, %s" % (cloud_owner, cloud_region_id)) diff --git a/share/newton_base/openoapi/limits.py b/share/newton_base/openoapi/limits.py index 4404972e..ee5f01c3 100644 --- a/share/newton_base/openoapi/limits.py +++ b/share/newton_base/openoapi/limits.py @@ -37,13 +37,17 @@ class Limits(APIView): service_volume = {'service_type': 'volumev2', 'interface': 'public'} + def __init__(self): + super(Limits, self).__init__() + self._logger = logger + def get(self, request, vimid="", tenantid=""): logger.info("vimid, tenantid = %s,%s" % (vimid, tenantid)) if request.data: logger.debug("With data = %s" % request.data) pass try: - #get limits first + # get limits first # prepare request resource to vim instance req_resouce = "/limits" vim = VimDriverUtils.get_vim_info(vimid) @@ -68,7 +72,7 @@ class Limits(APIView): } content_all.update(vim_dict) - #now get quota + # now get quota # prepare request resource to vim instance req_resouce = "/v2.0/quotas/%s" % tenantid @@ -82,7 +86,7 @@ class Limits(APIView): content = resp.json() content_all.update(content['quota']) - #now get volume limits + # now get volume limits # prepare request resource to vim instance req_resouce = "/limits" @@ -112,6 +116,10 @@ class Limits(APIView): class APIv1Limits(Limits): + def __init__(self): + super(APIv1Limits, self).__init__() + self._logger = logger + def get(self, request, cloud_owner="", cloud_region_id="", tenantid=""): self._logger.info("%s, %s" % (cloud_owner, cloud_region_id)) diff --git a/share/newton_base/openoapi/network.py b/share/newton_base/openoapi/network.py index 0f4a2df1..9e7f0d94 100644 --- a/share/newton_base/openoapi/network.py +++ b/share/newton_base/openoapi/network.py @@ -39,6 +39,10 @@ class Networks(APIView): ("project_id", "tenantId"), ] + def __init__(self): + super(Networks, self).__init__() + self._logger = logger + def get(self, request, vimid="", tenantid="", networkid=""): logger.info("vimid, tenantid, networkid = %s,%s,%s" % (vimid, tenantid, networkid)) if request.data: @@ -212,9 +216,12 @@ class Networks(APIView): status=status.HTTP_500_INTERNAL_SERVER_ERROR) - class APIv1Networks(Networks): + def __init__(self): + super(APIv1Networks, self).__init__() + self._logger = logger + def get(self, request, cloud_owner="", cloud_region_id="", tenantid="", networkid=""): self._logger.info("%s, %s" % (cloud_owner, cloud_region_id)) diff --git a/share/newton_base/openoapi/server.py b/share/newton_base/openoapi/server.py index 7dc229f0..ad0d7a44 100644 --- a/share/newton_base/openoapi/server.py +++ b/share/newton_base/openoapi/server.py @@ -28,15 +28,15 @@ from common.msapi import extsys logger = logging.getLogger(__name__) - running_threads = {} running_thread_lock = threading.Lock() -#assume volume is attached on server creation +# assume volume is attached on server creation class ServerVolumeAttachThread (threading.Thread): service = {'service_type': 'compute', 'interface': 'public'} + def __init__(self, vimid, tenantid, serverid, is_attach, *volumeids): threading.Thread.__init__(self) self.vimid = vimid @@ -47,7 +47,7 @@ class ServerVolumeAttachThread (threading.Thread): def run(self): logger.debug("start server thread %s, %s, %s" % (self.vimid, self.tenantid, self.serverid)) - if (self.is_attach): + if self.is_attach: self.attach_volume(self.vimid, self.tenantid, self.serverid, *self.volumeids) else: self.detach_volume(self.vimid, self.tenantid, self.serverid, *self.volumeids) @@ -67,7 +67,7 @@ class ServerVolumeAttachThread (threading.Thread): if vim.get('openstack_region_id') \ else vim['cloud_region_id'] - #check if server is ready to attach + # check if server is ready to attach logger.debug("Servers--attach_volume, wait for server to be ACTIVE::>%s" % serverid) req_resouce = "servers/%s" % serverid while True: @@ -79,7 +79,7 @@ class ServerVolumeAttachThread (threading.Thread): content = resp.json() if content and content["server"] and content["server"]["status"] == "ACTIVE": - break; + break for volumeid in volumeids: req_resouce = "servers/%s/os-volume_attachments" % serverid @@ -117,7 +117,7 @@ class ServerVolumeAttachThread (threading.Thread): if vim.get('openstack_region_id') \ else vim['cloud_region_id'] - #wait server to be ready to detach volume + # wait server to be ready to detach volume # assume attachment id is the same as volume id for volumeid in volumeids: @@ -153,8 +153,12 @@ class Servers(APIView): ("os-extended-volumes:volumes_attached", "volumeArray"), ] - def _attachVolume(self, vimid, tenantid, serverId, *volumeIds): - #has to be async mode to wait server is ready to attach volume + def __init__(self): + super(Servers, self).__init__() + self._logger = logger + + def _attach_volume(self, vimid, tenantid, serverId, *volumeIds): + # has to be async mode to wait server is ready to attach volume logger.debug("launch thread to attach volume: %s" % serverId) tmp_thread = ServerVolumeAttachThread(vimid, tenantid, serverId, True, *volumeIds) running_thread_lock.acquire() @@ -173,7 +177,7 @@ class Servers(APIView): for volumeid in volumeIds: req_resouce = "servers/%s/os-volume_attachments/%s" % (serverId, volumeid) - logger.debug("Servers--dettachVolume::>%s" % (req_resouce)) + logger.debug("Servers--dettachVolume::>%s" % req_resouce) logger.info("making request with URI:%s" % req_resouce) resp = sess.delete(req_resouce, endpoint_filter=self.service, @@ -182,7 +186,7 @@ class Servers(APIView): logger.info("request returns with status %s" % resp.status_code) logger.debug("Servers--dettachVolume resp status::>%s" % resp.status_code) - #def _convert_metadata(self, metadata_vfc, metadata_openstack, reverse=True): + # def _convert_metadata(self, metadata_vfc, metadata_openstack, reverse=True): # if not reverse: # # from vfc format to openstack format # for spec in metadata_vfc: @@ -195,7 +199,7 @@ class Servers(APIView): # metadata_vfc.append(spec) def _convert_resp(self, server): - #convert volumeArray + # convert volumeArray volumeArray = server.pop("volumeArray", None) tmpVolumeArray = [] if volumeArray and len(volumeArray) > 0: @@ -203,21 +207,25 @@ class Servers(APIView): tmpVolumeArray.append({"volumeId": vol["id"]}) server["volumeArray"] = tmpVolumeArray if len(tmpVolumeArray) > 0 else None - #convert flavor + # convert flavor flavor = server.pop("flavor", None) server["flavorId"] = flavor["id"] if flavor else None - #convert nicArray + # convert nicArray - #convert boot + # convert boot imageObj = server.pop("image", None) imageId = imageObj.pop("id", None) if imageObj else None if imageId: server["boot"] = {"type":2, "imageId": imageId} else: - server["boot"] = {"type":1, "volumeId":tmpVolumeArray.pop(0)["volumeId"] if len(tmpVolumeArray) > 0 else None} + server["boot"] = { + "type": 1, + "volumeId": tmpVolumeArray.pop(0)["volumeId"] + if len(tmpVolumeArray) > 0 else None + } - #convert OS-EXT-AZ:availability_zone + # convert OS-EXT-AZ:availability_zone server["availabilityZone"] = server.pop("OS-EXT-AZ:availability_zone", None) def get(self, request, vimid="", tenantid="", serverid=""): @@ -234,7 +242,8 @@ class Servers(APIView): logger.error("response with status = %s" % e.status_code) return Response(data={'error': e.content}, status=e.status_code) except HttpError as e: - logger.error("HttpError: status:%s, response:%s" % (e.http_status, e.response.json())) + logger.error("HttpError: status:%s, response:%s" + % (e.http_status, e.response.json())) return Response(data=e.response.json(), status=e.http_status) except Exception as e: logger.error(traceback.format_exc()) @@ -258,12 +267,13 @@ class Servers(APIView): logger.debug("with content:%s" % resp.json()) pass ports = resp.json() - if ports and ports["interfaceAttachments"] and len(ports["interfaceAttachments"]) > 0: - return [{"portId":port["port_id"]} for port in ports["interfaceAttachments"]] + if ports and ports["interfaceAttachments"] \ + and len(ports["interfaceAttachments"]) > 0: + return [{"portId":port["port_id"]} + for port in ports["interfaceAttachments"]] return None def _get_servers(self, query="", vimid="", tenantid="", serverid=None): - # prepare request resource to vim instance req_resouce = "servers" if serverid: @@ -299,8 +309,8 @@ class Servers(APIView): if not serverid: # convert the key naming in servers for server in content["servers"]: - #metadata_openstack = server.pop("metadata", None) - #if metadata_openstack: + # metadata_openstack = server.pop("metadata", None) + # if metadata_openstack: # metadata_vfc = [] # self._convert_metadata(metadata_vfc, metadata_openstack, True) # server["metadata"] = metadata_vfc @@ -312,8 +322,8 @@ class Servers(APIView): else: # convert the key naming in the server specified by id server = content.pop("server", None) - #metadata_openstack = server.pop("metadata", None) - #if metadata_openstack: + # metadata_openstack = server.pop("metadata", None) + # if metadata_openstack: # metadata_vfc = [] # self._convert_metadata(metadata_vfc, metadata_openstack, True) # server["metadata"] = metadata_vfc @@ -379,8 +389,8 @@ class Servers(APIView): if len(networks) > 0: server["networks"] = networks - #metadata_vfc = server.pop("metadata", None) - #if metadata_vfc: + # metadata_vfc = server.pop("metadata", None) + # if metadata_vfc: # metadata_openstack = {} # self._convert_metadata(metadata_vfc, metadata_openstack, True) # server["metadata"] = metadata_openstack @@ -414,8 +424,9 @@ class Servers(APIView): server["personality"] = personalities logger.info("Personalities %s" % personalities) else: - logger.error("contextarray %s format is not right.", contextarray) - return Response(data={'error': str(e)}, + errmsg = "contextarray %s format is not right." % contextarray + logger.error(errmsg) + return Response(data={'error': errmsg}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) VimDriverUtils.replace_key_by_mapping(server, @@ -441,10 +452,10 @@ class Servers(APIView): if volumearray and len(volumearray) > 0: # server is created, now attach volumes volumeIds = [extraVolume["volumeId"] for extraVolume in volumearray] - self._attachVolume(vimid, tenantid, resp_body["id"], *volumeIds) + self._attach_volume(vimid, tenantid, resp_body["id"], *volumeIds) - #metadata_openstack = resp_body.pop("metadata", None) - #if metadata_openstack: + # metadata_openstack = resp_body.pop("metadata", None) + # if metadata_openstack: # metadata_vfc = [] # self._convert_metadata(metadata_vfc, metadata_openstack, True) # resp_body["metadata"] = metadata_vfc @@ -490,14 +501,14 @@ class Servers(APIView): if vim.get('openstack_region_id') \ else vim['cloud_region_id'] - #check and dettach them if volumes attached to server + # check and dettach them if volumes attached to server server, status_code = self._get_servers("", vimid, tenantid, serverid) volumearray = server.pop("volumeArray", None) if volumearray and len(volumearray) > 0: volumeIds = [extraVolume["volumeId"] for extraVolume in volumearray] self._dettach_volume(vimid, tenantid, serverid, *volumeIds) - #delete server now + # delete server now req_resouce = "servers" if serverid: req_resouce += "/%s" % serverid @@ -518,6 +529,10 @@ class Servers(APIView): class APIv1Servers(Servers): + def __init__(self): + super(APIv1Servers, self).__init__() + self._logger = logger + def get(self, request, cloud_owner="", cloud_region_id="", tenantid="", serverid=""): self._logger.info("%s, %s" % (cloud_owner, cloud_region_id)) @@ -540,6 +555,11 @@ class APIv1Servers(Servers): class ServerAction(APIView): service = {'service_type': 'compute', 'interface': 'public'} + + def __init__(self): + super(ServerAction, self).__init__() + self._logger = logger + def post(self, request, vimid="", tenantid="", serverid=""): logger.debug("ServerAction--post::> %s" % request.data) logger.debug("vimid=%s, tenantid=%s, serverid=%s", vimid, tenantid, serverid) @@ -558,7 +578,7 @@ class ServerAction(APIView): resp_body = resp.json() return Response(data=resp_body, status=resp.status_code) - except VimDriverKiloException as e: + except VimDriverNewtonException as e: return Response(data={'error': e.content}, status=e.status_code) except HttpError as e: logger.error("HttpError: status:%s, response:%s" % (e.http_status, e.response.json())) @@ -570,6 +590,11 @@ class ServerAction(APIView): class APIv1ServerAction(ServerAction): + + def __init__(self): + super(APIv1ServerAction, self).__init__() + self._logger = logger + def post(self, request, cloud_owner="", cloud_region_id="", tenantid="", serverid=""): self._logger.info("%s, %s" % (cloud_owner, cloud_region_id)) @@ -580,6 +605,12 @@ class APIv1ServerAction(ServerAction): class ServerOsInterface(APIView): service = {'service_type': 'compute', 'interface': 'public'} + + + def __init__(self): + super(ServerOsInterface, self).__init__() + self._logger = logger + def post(self, request, vimid="", tenantid="", serverid=""): logger.debug("ServerOsInterface--post::> %s" % request.data) logger.debug("vimid=%s, tenantid=%s, serverid=%s", vimid, tenantid, serverid) @@ -598,7 +629,7 @@ class ServerOsInterface(APIView): resp_body = resp.json() return Response(data=resp_body, status=resp.status_code) - except VimDriverKiloException as e: + except VimDriverNewtonException as e: return Response(data={'error': e.content}, status=e.status_code) except HttpError as e: logger.error("HttpError: status:%s, response:%s" % (e.http_status, e.response.json())) @@ -610,6 +641,11 @@ class ServerOsInterface(APIView): class APIv1ServerOsInterface(ServerOsInterface): + + def __init__(self): + super(APIv1ServerOsInterface, self).__init__() + self._logger = logger + def post(self, request, cloud_owner="", cloud_region_id="", tenantid="", serverid=""): self._logger.info("%s, %s" % (cloud_owner, cloud_region_id)) @@ -620,6 +656,11 @@ class APIv1ServerOsInterface(ServerOsInterface): class ServerOsInterfacePort(APIView): service = {'service_type': 'compute', 'interface': 'public'} + + def __init__(self): + super(ServerOsInterfacePort, self).__init__() + self._logger = logger + def delete(self, request, vimid="", tenantid="", serverid="", portid=""): logger.debug("ServerOsInterfacePort--delete::portid=%s", portid) logger.debug("vimid=%s, tenantid=%s, serverid=%s", vimid, tenantid, serverid) @@ -638,7 +679,7 @@ class ServerOsInterfacePort(APIView): resp_body = {} return Response(data=resp_body, status=resp.status_code) - except VimDriverKiloException as e: + except VimDriverNewtonException as e: return Response(data={'error': e.content}, status=e.status_code) except HttpError as e: logger.error("HttpError: status:%s, response:%s" % (e.http_status, e.response.json())) @@ -650,6 +691,11 @@ class ServerOsInterfacePort(APIView): class APIv1ServerOsInterfacePort(ServerOsInterfacePort): + + def __init__(self): + super(APIv1ServerOsInterfacePort, self).__init__() + self._logger = logger + def delete(self, request, cloud_owner="", cloud_region_id="", tenantid="", serverid="", portid=""): self._logger.info("%s, %s" % (cloud_owner, cloud_region_id)) diff --git a/share/newton_base/openoapi/subnet.py b/share/newton_base/openoapi/subnet.py index 06e029a8..25b94aa9 100644 --- a/share/newton_base/openoapi/subnet.py +++ b/share/newton_base/openoapi/subnet.py @@ -41,6 +41,10 @@ class Subnets(APIView): ("allocation_pools", "allocationPools"), ] + def __init__(self): + super(Subnets, self).__init__() + self._logger = logger + def get(self, request, vimid="", tenantid="", subnetid=""): logger.info("vimid, tenantid, subnetid = %s,%s,%s" % (vimid, tenantid, subnetid)) if request.data: @@ -221,6 +225,10 @@ class Subnets(APIView): class APIv1Subnets(Subnets): + def __init__(self): + super(APIv1Subnets, self).__init__() + self._logger = logger + def get(self, request, cloud_owner="", cloud_region_id="", tenantid="", subnetid=""): self._logger.info("%s, %s" % (cloud_owner, cloud_region_id)) diff --git a/share/newton_base/openoapi/tenants.py b/share/newton_base/openoapi/tenants.py index a048a36e..9e41d8dc 100644 --- a/share/newton_base/openoapi/tenants.py +++ b/share/newton_base/openoapi/tenants.py @@ -37,10 +37,14 @@ class Tenants(APIView): ("projects", "tenants"), ] + def __init__(self): + super(Tenants, self).__init__() + self._logger = logger + def get(self, request, vimid=""): - logger.info("vimid = %s" % vimid) + self._logger.info("vimid = %s" % vimid) if request.data: - logger.debug("With data = %s" % request.data) + self._logger.debug("With data = %s" % request.data) pass try: #prepare request resource to vim instance @@ -57,11 +61,11 @@ class Tenants(APIView): if vim.get('openstack_region_id') \ else vim['cloud_region_id'] - logger.info("making request with URI:%s" % req_resouce) + self._logger.info("making request with URI:%s" % req_resouce) resp = sess.get(req_resouce, endpoint_filter=self.service) - logger.info("request returns with status %s" % resp.status_code) + self._logger.info("request returns with status %s" % resp.status_code) if resp.status_code == status.HTTP_200_OK: - logger.debug("with content:%s" % resp.json()) + self._logger.debug("with content:%s" % resp.json()) pass content = resp.json() @@ -85,27 +89,30 @@ class Tenants(APIView): for tenant in tmp: if tenantname == tenant['name']: content["tenants"].append(tenant) - logger.info("response with status = %s" % resp.status_code) + self._logger.info("response with status = %s" % resp.status_code) return Response(data=content, status=resp.status_code) except VimDriverNewtonException as e: - logger.error("response with status = %s" % e.status_code) + self._logger.error("response with status = %s" % e.status_code) return Response( data={'error': e.content}, status=e.status_code) except HttpError as e: - logger.error("HttpError: status:%s, response:%s" % ( + self._logger.error("HttpError: status:%s, response:%s" % ( e.http_status, e.response.json())) return Response(data=e.response.json(), status=e.http_status) except Exception as e: - logger.error(traceback.format_exc()) + self._logger.error(traceback.format_exc()) return Response( data={'error': str(e)}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) - class APIv1Tenants(Tenants): + def __init__(self): + super(APIv1Tenants, self).__init__() + self._logger = logger + def get(self, request, cloud_owner="", cloud_region_id=""): self._logger.info("registration with : %s, %s" % (cloud_owner, cloud_region_id)) diff --git a/share/newton_base/openoapi/vmlist.py b/share/newton_base/openoapi/vmlist.py index 6150b862..cd0eb6a4 100755 --- a/share/newton_base/openoapi/vmlist.py +++ b/share/newton_base/openoapi/vmlist.py @@ -21,6 +21,7 @@ from rest_framework.views import APIView from common.exceptions import VimDriverNewtonException
from newton_base.util import VimDriverUtils
+from common.msapi import extsys
logger = logging.getLogger(__name__)
@@ -37,6 +38,10 @@ class VMlist(APIView): ("container_format", "containerFormat")
]
+ def __init__(self):
+ super(VMlist, self).__init__()
+ self._logger = logger
+
def get(self, request, vimid="", tenantid="", serverid=""):
logger.info("vimid, tenantid, flavorid = %s,%s,%s" % (vimid, tenantid, flavorid))
if request.data:
@@ -82,3 +87,14 @@ class VMlist(APIView): return content, resp.status_code
+class APIv1VMlist(VMlist):
+
+ def __init__(self):
+ super(APIv1VMlist, self).__init__()
+ self._logger = logger
+
+ def get(self, request, cloud_owner="", cloud_region_id="", tenantid="", serverid=""):
+ self._logger.info("%s, %s" % (cloud_owner, cloud_region_id))
+
+ vimid = extsys.encode_vim_id(cloud_owner, cloud_region_id)
+ return super(APIv1VMlist, self).get(request, vimid, tenantid, serverid)
diff --git a/share/newton_base/openoapi/volume.py b/share/newton_base/openoapi/volume.py index 70b786b1..84ad7420 100644 --- a/share/newton_base/openoapi/volume.py +++ b/share/newton_base/openoapi/volume.py @@ -41,6 +41,10 @@ class Volumes(APIView): ("attachment_id", "attachmentId"), ] + def __init__(self): + super(Volumes, self).__init__() + self._logger = logger + def get(self, request, vimid="", tenantid="", volumeid=""): logger.info("vimid, tenantid, volumeid = %s,%s,%s" % (vimid, tenantid, volumeid)) if request.data: @@ -211,6 +215,10 @@ class Volumes(APIView): class APIv1Volumes(Volumes): + def __init__(self): + super(APIv1Volumes, self).__init__() + self._logger = logger + def get(self, request, cloud_owner="", cloud_region_id="", tenantid="", volumeid=""): self._logger.info("%s, %s" % (cloud_owner, cloud_region_id)) diff --git a/share/newton_base/openoapi/vport.py b/share/newton_base/openoapi/vport.py index ca6297dc..a98b807b 100644 --- a/share/newton_base/openoapi/vport.py +++ b/share/newton_base/openoapi/vport.py @@ -40,6 +40,10 @@ class Vports(APIView): ("ip_address", "ip"), ] + def __init__(self): + super(Vports, self).__init__() + self._logger = logger + def get(self, request, vimid="", tenantid="", portid=""): logger.info("vimid, tenantid, portid = %s,%s,%s" % (vimid, tenantid, portid)) if request.data: @@ -248,6 +252,10 @@ class Vports(APIView): class APIv1Vports(Vports): + def __init__(self): + super(APIv1Vports, self).__init__() + self._logger = logger + def get(self, request, cloud_owner="", cloud_region_id="", tenantid="", portid=""): self._logger.info("%s, %s" % (cloud_owner, cloud_region_id)) |