diff options
author | Haibin Huang <haibin.huang@intel.com> | 2018-12-05 18:53:14 +0800 |
---|---|---|
committer | Haibin Huang <haibin.huang@intel.com> | 2018-12-05 18:54:35 +0800 |
commit | b6c3bf2a5478ab604d67ca4c9ba1942d2cc3e07e (patch) | |
tree | d9223f38b28d4181d944fb53f399801262c4dff5 /pike | |
parent | 0f8c7107308a0191c2c4df8a3070ed8868c64480 (diff) |
Fix pep error for pike resource
Change-Id: I778232ecbb74dc9e6a9e7a2bf4ca6a6b70f0e196
Issue-ID: MULTICLOUD-424
Signed-off-by: Haibin Huang <haibin.huang@intel.com>
Diffstat (limited to 'pike')
-rw-r--r-- | pike/pike/__init__.py | 1 | ||||
-rw-r--r-- | pike/pike/middleware.py | 3 | ||||
-rw-r--r-- | pike/pike/resource/__init__.py | 1 | ||||
-rw-r--r-- | pike/pike/resource/tests/tests_infra_workload.py | 318 | ||||
-rw-r--r-- | pike/pike/resource/views/infra_workload.py | 80 | ||||
-rw-r--r-- | pike/pike/settings.py | 4 | ||||
-rw-r--r-- | pike/pike/urls.py | 8 |
7 files changed, 210 insertions, 205 deletions
diff --git a/pike/pike/__init__.py b/pike/pike/__init__.py index afa702d3..ae1ce9db 100644 --- a/pike/pike/__init__.py +++ b/pike/pike/__init__.py @@ -11,4 +11,3 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. - diff --git a/pike/pike/middleware.py b/pike/pike/middleware.py index f2618e06..4f19da08 100644 --- a/pike/pike/middleware.py +++ b/pike/pike/middleware.py @@ -19,6 +19,7 @@ from onaplogging.mdcContext import MDC FORWARDED_FOR_FIELDS = ["HTTP_X_FORWARDED_FOR", "HTTP_X_FORWARDED_HOST", "HTTP_X_FORWARDED_SERVER"] + class LogContextMiddleware(object): # the last IP behind multiple proxies, if no exist proxies @@ -43,7 +44,6 @@ class LogContextMiddleware(object): return ip - def process_request(self, request): # fetch propageted Id from other component. if do not fetch id, # generate one. @@ -62,4 +62,3 @@ class LogContextMiddleware(object): MDC.clear() return response - diff --git a/pike/pike/resource/__init__.py b/pike/pike/resource/__init__.py index 741e0afb..5a9af6b8 100644 --- a/pike/pike/resource/__init__.py +++ b/pike/pike/resource/__init__.py @@ -11,4 +11,3 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. - diff --git a/pike/pike/resource/tests/tests_infra_workload.py b/pike/pike/resource/tests/tests_infra_workload.py index 73d4ffca..a94a53f3 100644 --- a/pike/pike/resource/tests/tests_infra_workload.py +++ b/pike/pike/resource/tests/tests_infra_workload.py @@ -15,92 +15,99 @@ import mock import unittest -import json from rest_framework import status -from common.utils import restcall from common.msapi.helper import Helper as helper from pike.resource.views.infra_workload import InfraWorkload from pike.resource.views.infra_workload import APIv1InfraWorkload -MOCK_TOKEN_RESPONSE = {"access": - {"token": - {"issued_at":"2018-05-10T16:56:56.000000Z", - "expires":"2018-05-10T17:56:56.000000Z", - "id":"4a832860dd744306b3f66452933f939e", - "tenant":{"domain":{"id":"default","name":"Default"}, - "enabled":"true","id":"0e148b76ee8c42f78d37013bf6b7b1ae", - "name":"VIM"}},"serviceCatalog":[], - "user":{"domain":{"id":"default","name":"Default"}, - "id":"ba76c94eb5e94bb7bec6980e5507aae2", - "name":"demo"}}} - -MOCK_HEAT_CREATE_BODY1 = { - "generic-vnf-id":"MOCK_GENERIF_VNF_ID1", - "vf-module-id":"MOCK_VF_MODULE_ID1", - "oof_directives":{ - "directives":[ - { - "id":"MOCK_VNFC_ID1", - "type": "vnfc", - "directives":[{ - "type":"flavor_directives", - "attributes":[ - { - "attribute_name":"flavor1", - "attribute_value":"m1.hpa.medium" - } - ] - }, - { - "type":"sriovNetNetwork_directives", - "attributes":[ - { - "attribute_name":"physnetwork_label", - "attribute_value":"physnet1" - } - ] - - } - ] - } - ] - }, - "sdnc_directives":{}, - "template_type":"HEAT", - "template_data":{ - "files":{ }, - "disable_rollback":True, - "parameters":{ - "flavor1":"m1.heat" - }, - "stack_name":"teststack", - "template":{ - "heat_template_version":"2013-05-23", - "description":"Simple template to test heat commands", - "parameters": - { - "flavor":{ - "default":"m1.tiny", - "type":"string" - } - }, - "resources":{ - "hello_world":{ - "type":"OS::Nova::Server", - "properties":{ - "key_name":"heat_key", - "flavor":{ - "get_param":"flavor" - }, - "image":"40be8d1a-3eb9-40de-8abd-43237517384f", - "user_data":"#!/bin/bash -xv\necho \"hello world\" > /root/hello-world.txt\n" - } - } - } - }, - "timeout_mins":60 - } +MOCK_TOKEN_RESPONSE = { + "access": { + "token": { + "issued_at": "2018-05-10T16:56:56.000000Z", + "expires": "2018-05-10T17:56:56.000000Z", + "id": "4a832860dd744306b3f66452933f939e", + "tenant": { + "domain": {"id": "default", "name": "Default"}, + "enabled": "true", + "id": "0e148b76ee8c42f78d37013bf6b7b1ae", + "name": "VIM" + } + }, + "serviceCatalog": [], + "user": { + "domain": {"id": "default", "name": "Default"}, + "id": "ba76c94eb5e94bb7bec6980e5507aae2", + "name": "demo" + } + } +} + +MOCK_HEAT_CREATE_BODY1 = { + "generic-vnf-id": "MOCK_GENERIF_VNF_ID1", + "vf-module-id": "MOCK_VF_MODULE_ID1", + "oof_directives": { + "directives": [ + { + "id": "MOCK_VNFC_ID1", + "type": "vnfc", + "directives": [ + { + "type": "flavor_directives", + "attributes": [ + { + "attribute_name": "flavor1", + "attribute_value": "m1.hpa.medium" + } + ] + }, + { + "type": "sriovNetNetwork_directives", + "attributes": [ + { + "attribute_name": "physnetwork_label", + "attribute_value": "physnet1" + } + ] + } + ] + } + ] + }, + "sdnc_directives": {}, + "template_type": "HEAT", + "template_data": { + "files": {}, + "disable_rollback": True, + "parameters": { + "flavor1": "m1.heat" + }, + "stack_name": "teststack", + "template": { + "heat_template_version": "2013-05-23", + "description": "Simple template to test heat commands", + "parameters": { + "flavor": { + "default": "m1.tiny", + "type": "string" + } + }, + "resources": { + "hello_world": { + "type": "OS::Nova::Server", + "properties": { + "key_name": "heat_key", + "flavor": { + "get_param": "flavor" + }, + "image": "40be8d1a-3eb9-40de-8abd-43237517384f", + "user_data": "#!/bin/bash -xv\necho \"hello world\" > /root/hello-world.txt\n" + } + } + } + }, + "timeout_mins": 60 + } } MOCK_HEAT_CREATE_RESPONSE1 = { @@ -112,51 +119,51 @@ MOCK_HEAT_CREATE_RESPONSE1 = { MOCK_HEAT_LIST_RESPONSE1 = { 'stacks': [ { - 'stack_status':"CREATE_IN_PROCESS" + 'stack_status': "CREATE_IN_PROCESS" } ] } -MOCK_HEAT_CREATE_BODY2 = { - "generic-vnf-id":"MOCK_GENERIF_VNF_ID1", - "vf-module-id":"MOCK_VF_MODULE_ID1", - "template_type":"HEAT", - "template_data":{ - "files":{ }, - "disable_rollback":True, - "parameters":{ - "flavor1":"m1.heat" - }, - "stack_name":"teststack", - "template":{ - "heat_template_version":"2013-05-23", - "description":"Simple template to test heat commands", - "parameters": - { - "flavor":{ - "default":"m1.tiny", - "type":"string" - } - }, - "resources":{ - "hello_world":{ - "type":"OS::Nova::Server", - "properties":{ - "key_name":"heat_key", - "flavor":{ - "get_param":"flavor" - }, - "image":"40be8d1a-3eb9-40de-8abd-43237517384f", - "user_data":"#!/bin/bash -xv\necho \"hello world\" > /root/hello-world.txt\n" - } - } - } - }, - "timeout_mins":60 - } +MOCK_HEAT_CREATE_BODY2 = { + "generic-vnf-id": "MOCK_GENERIF_VNF_ID1", + "vf-module-id": "MOCK_VF_MODULE_ID1", + "template_type": "HEAT", + "template_data": { + "files": {}, + "disable_rollback": True, + "parameters": { + "flavor1": "m1.heat" + }, + "stack_name": "teststack", + "template": { + "heat_template_version": "2013-05-23", + "description": "Simple template to test heat commands", + "parameters": { + "flavor": { + "default": "m1.tiny", + "type": "string" + } + }, + "resources": { + "hello_world": { + "type": "OS::Nova::Server", + "properties": { + "key_name": "heat_key", + "flavor": { + "get_param": "flavor" + }, + "image": "40be8d1a-3eb9-40de-8abd-43237517384f", + "user_data": "#!/bin/bash -xv\necho \"hello world\" > /root/hello-world.txt\n" + } + } + } + }, + "timeout_mins": 60 + } } + class InfraWorkloadTest(unittest.TestCase): def setUp(self): self._InfraWorkload = InfraWorkload() @@ -167,18 +174,18 @@ class InfraWorkloadTest(unittest.TestCase): @mock.patch.object(helper, 'MultiCloudServiceHelper') @mock.patch.object(helper, 'MultiCloudIdentityHelper') - def test_post(self, mock_MultiCloudIdentityHelper, mock_MultiCloudServiceHelper): + def test_post(self, mock_MultiCloudIdentityHelper, mock_MultiCloudServiceHelper): mock_request = mock.Mock() mock_request.META = {"testkey": "testvalue"} mock_request.data = MOCK_HEAT_CREATE_BODY1 - mock_MultiCloudIdentityHelper.side_effect= [ + mock_MultiCloudIdentityHelper.side_effect = [ (0, MOCK_TOKEN_RESPONSE, status.HTTP_201_CREATED) - ] + ] - mock_MultiCloudServiceHelper.side_effect= [ + mock_MultiCloudServiceHelper.side_effect = [ (0, MOCK_HEAT_CREATE_RESPONSE1, status.HTTP_201_CREATED) - ] + ] vimid = "CloudOwner_Region1" @@ -186,21 +193,20 @@ class InfraWorkloadTest(unittest.TestCase): self.assertEqual(response.status_code, status.HTTP_201_CREATED) pass - @mock.patch.object(helper, 'MultiCloudServiceHelper') @mock.patch.object(helper, 'MultiCloudIdentityHelper') - def test_post_wo_oof_directive(self, mock_MultiCloudIdentityHelper, mock_MultiCloudServiceHelper): + def test_post_wo_oof_directive(self, mock_MultiCloudIdentityHelper, mock_MultiCloudServiceHelper): mock_request = mock.Mock() mock_request.META = {"testkey": "testvalue"} mock_request.data = MOCK_HEAT_CREATE_BODY2 - mock_MultiCloudIdentityHelper.side_effect= [ + mock_MultiCloudIdentityHelper.side_effect = [ (0, MOCK_TOKEN_RESPONSE, status.HTTP_201_CREATED) - ] + ] - mock_MultiCloudServiceHelper.side_effect= [ + mock_MultiCloudServiceHelper.side_effect = [ (0, MOCK_HEAT_CREATE_RESPONSE1, status.HTTP_201_CREATED) - ] + ] vimid = "CloudOwner_Region1" @@ -210,17 +216,17 @@ class InfraWorkloadTest(unittest.TestCase): @mock.patch.object(helper, 'MultiCloudServiceHelper') @mock.patch.object(helper, 'MultiCloudIdentityHelper') - def test_get(self, mock_MultiCloudIdentityHelper, mock_MultiCloudServiceHelper): + def test_get(self, mock_MultiCloudIdentityHelper, mock_MultiCloudServiceHelper): mock_request = mock.Mock() mock_request.META = {"testkey": "testvalue"} - mock_MultiCloudIdentityHelper.side_effect= [ + mock_MultiCloudIdentityHelper.side_effect = [ (0, MOCK_TOKEN_RESPONSE, status.HTTP_201_CREATED) - ] + ] - mock_MultiCloudServiceHelper.side_effect= [ + mock_MultiCloudServiceHelper.side_effect = [ (0, MOCK_HEAT_LIST_RESPONSE1, status.HTTP_200_OK) - ] + ] vimid = "CloudOwner_Region1" mock_stack_id = "MOCKED_HEAT_STACK_ID1" @@ -229,20 +235,19 @@ class InfraWorkloadTest(unittest.TestCase): self.assertEqual(response.status_code, status.HTTP_200_OK) pass - @mock.patch.object(helper, 'MultiCloudServiceHelper') @mock.patch.object(helper, 'MultiCloudIdentityHelper') - def test_delete(self, mock_MultiCloudIdentityHelper, mock_MultiCloudServiceHelper): + def test_delete(self, mock_MultiCloudIdentityHelper, mock_MultiCloudServiceHelper): mock_request = mock.Mock() mock_request.META = {"testkey": "testvalue"} - mock_MultiCloudIdentityHelper.side_effect= [ + mock_MultiCloudIdentityHelper.side_effect = [ (0, MOCK_TOKEN_RESPONSE, status.HTTP_201_CREATED) - ] + ] - mock_MultiCloudServiceHelper.side_effect= [ + mock_MultiCloudServiceHelper.side_effect = [ (0, MOCK_HEAT_LIST_RESPONSE1, status.HTTP_200_OK) - ] + ] vimid = "CloudOwner_Region1" mock_stack_id = "MOCKED_HEAT_STACK_ID1" @@ -262,18 +267,18 @@ class APIv1InfraWorkloadTest(unittest.TestCase): @mock.patch.object(helper, 'MultiCloudServiceHelper') @mock.patch.object(helper, 'MultiCloudIdentityHelper') - def test_post(self, mock_MultiCloudIdentityHelper, mock_MultiCloudServiceHelper): + def test_post(self, mock_MultiCloudIdentityHelper, mock_MultiCloudServiceHelper): mock_request = mock.Mock() mock_request.META = {"testkey": "testvalue"} mock_request.data = MOCK_HEAT_CREATE_BODY1 - mock_MultiCloudIdentityHelper.side_effect= [ + mock_MultiCloudIdentityHelper.side_effect = [ (0, MOCK_TOKEN_RESPONSE, status.HTTP_201_CREATED) - ] + ] - mock_MultiCloudServiceHelper.side_effect= [ + mock_MultiCloudServiceHelper.side_effect = [ (0, MOCK_HEAT_CREATE_RESPONSE1, status.HTTP_201_CREATED) - ] + ] cloud_owner = "CloudOwner" cloud_region_id = "Region1" @@ -282,21 +287,19 @@ class APIv1InfraWorkloadTest(unittest.TestCase): self.assertEqual(response.status_code, status.HTTP_201_CREATED) pass - @mock.patch.object(helper, 'MultiCloudServiceHelper') @mock.patch.object(helper, 'MultiCloudIdentityHelper') - def test_get(self, mock_MultiCloudIdentityHelper, mock_MultiCloudServiceHelper): + def test_get(self, mock_MultiCloudIdentityHelper, mock_MultiCloudServiceHelper): mock_request = mock.Mock() mock_request.META = {"testkey": "testvalue"} - mock_MultiCloudIdentityHelper.side_effect= [ + mock_MultiCloudIdentityHelper.side_effect = [ (0, MOCK_TOKEN_RESPONSE, status.HTTP_201_CREATED) - ] + ] - mock_MultiCloudServiceHelper.side_effect= [ + mock_MultiCloudServiceHelper.side_effect = [ (0, MOCK_HEAT_LIST_RESPONSE1, status.HTTP_200_OK) - ] - + ] cloud_owner = "CloudOwner" cloud_region_id = "Region1" @@ -306,20 +309,19 @@ class APIv1InfraWorkloadTest(unittest.TestCase): self.assertEqual(response.status_code, status.HTTP_200_OK) pass - @mock.patch.object(helper, 'MultiCloudServiceHelper') @mock.patch.object(helper, 'MultiCloudIdentityHelper') - def test_delete(self, mock_MultiCloudIdentityHelper, mock_MultiCloudServiceHelper): + def test_delete(self, mock_MultiCloudIdentityHelper, mock_MultiCloudServiceHelper): mock_request = mock.Mock() mock_request.META = {"testkey": "testvalue"} - mock_MultiCloudIdentityHelper.side_effect= [ + mock_MultiCloudIdentityHelper.side_effect = [ (0, MOCK_TOKEN_RESPONSE, status.HTTP_201_CREATED) - ] + ] - mock_MultiCloudServiceHelper.side_effect= [ + mock_MultiCloudServiceHelper.side_effect = [ (0, MOCK_HEAT_LIST_RESPONSE1, status.HTTP_200_OK) - ] + ] cloud_owner = "CloudOwner" cloud_region_id = "Region1" diff --git a/pike/pike/resource/views/infra_workload.py b/pike/pike/resource/views/infra_workload.py index 45352bde..0a3a5743 100644 --- a/pike/pike/resource/views/infra_workload.py +++ b/pike/pike/resource/views/infra_workload.py @@ -26,7 +26,6 @@ from common.msapi import extsys from common.msapi.helper import Helper as helper from common.utils import restcall from common.exceptions import VimDriverNewtonException -from newton_base.util import VimDriverUtils logger = logging.getLogger(__name__) @@ -41,7 +40,7 @@ class InfraWorkload(APIView): self._logger.info("data: %s" % request.data) self._logger.debug("META: %s" % request.META) - try : + try: data = request.data oof_directive = data.get("oof_directives", {}) template_type = data.get("template_type", None) @@ -70,12 +69,12 @@ class InfraWorkload(APIView): # reset to make sure "files" are empty template_data["file"] = {} - #authenticate + # authenticate cloud_owner, regionid = extsys.decode_vim_id(vimid) # should go via multicloud proxy so that the selflink is updated by multicloud retcode, v2_token_resp_json, os_status = helper.MultiCloudIdentityHelper( - settings.MULTICLOUD_API_V1_PREFIX, - cloud_owner, regionid, "/v2.0/tokens") + settings.MULTICLOUD_API_V1_PREFIX, + cloud_owner, regionid, "/v2.0/tokens") if retcode > 0 or not v2_token_resp_json: logger.error("authenticate fails:%s,%s, %s" % (cloud_owner, regionid, v2_token_resp_json)) @@ -85,8 +84,12 @@ class InfraWorkload(APIView): resource_uri = "/stacks" self._logger.info("retrieve stack resources, URI:%s" % resource_uri) retcode, content, os_status = helper.MultiCloudServiceHelper(cloud_owner, - regionid, v2_token_resp_json, service_type, - resource_uri, template_data, "POST") + regionid, + v2_token_resp_json, + service_type, + resource_uri, + template_data, + "POST") stack1 = content.get('stack', None) if retcode == 0 and content else None resp_template = { "template_type": template_type, @@ -100,11 +103,11 @@ class InfraWorkload(APIView): else: msg = "The template type %s is not supported" % (template_type) self._logger.warn(msg) - return Response(data={"error":msg}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) + return Response(data={"error": msg}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) except VimDriverNewtonException as e: self._logger.error("Plugin exception> status:%s,error:%s" - % (e.status_code, e.content)) + % (e.status_code, e.content)) return Response(data={'error': e.content}, status=e.status_code) except HttpError as e: self._logger.error("HttpError: status:%s, response:%s" % (e.http_status, e.response.json())) @@ -114,12 +117,11 @@ class InfraWorkload(APIView): return Response(data={'error': str(e)}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) - def get(self, request, vimid="", requri=""): self._logger.info("vimid, requri: %s, %s" % (vimid, requri)) self._logger.debug("META: %s" % request.META) - try : + try: # assume the workload_type is heat template_type = "heat" stack_id = requri @@ -128,7 +130,7 @@ class InfraWorkload(APIView): retcode, v2_token_resp_json, os_status = helper.MultiCloudIdentityHelper( settings.MULTICLOUD_API_V1_PREFIX, cloud_owner, regionid, "/v2.0/tokens") - if retcode > 0 or not v2_token_resp_json: + if retcode > 0 or not v2_token_resp_json: logger.error("authenticate fails:%s, %s, %s" % (cloud_owner, regionid, v2_token_resp_json)) return @@ -139,7 +141,7 @@ class InfraWorkload(APIView): retcode, content, os_status = helper.MultiCloudServiceHelper(cloud_owner, regionid, v2_token_resp_json, service_type, resource_uri, None, "GET") stacks = content.get('stacks', []) if retcode == 0 and content else [] - stack_status = stacks[0]["stack_status"] if len(stacks)>0 else "" + stack_status = stacks[0]["stack_status"] if len(stacks) > 0 else "" resp_template = { "template_type": template_type, @@ -157,7 +159,7 @@ class InfraWorkload(APIView): return Response(data=resp_template, status=status.HTTP_200_OK) except VimDriverNewtonException as e: self._logger.error("Plugin exception> status:%s,error:%s" - % (e.status_code, e.content)) + % (e.status_code, e.content)) return Response(data={'error': e.content}, status=e.status_code) except HttpError as e: self._logger.error("HttpError: status:%s, response:%s" % (e.http_status, e.response.json())) @@ -180,7 +182,7 @@ class InfraWorkload(APIView): cloud_owner, regionid = extsys.decode_vim_id(vimid) # should go via multicloud proxy so that the selflink is updated by multicloud retcode, v2_token_resp_json, os_status = helper.MultiCloudIdentityHelper(settings.MULTICLOUD_API_V1_PREFIX, - cloud_owner, regionid, "/v2.0/tokens") + cloud_owner, regionid, "/v2.0/tokens") if retcode > 0: logger.error("authenticate fails:%s, %s, %s" % (cloud_owner, regionid, v2_token_resp_json)) return None @@ -189,16 +191,16 @@ class InfraWorkload(APIView): # common prefix aai_cloud_region = "/cloud-infrastructure/cloud-regions/cloud-region/%s/%s/tenants/tenant/%s" \ - % (cloud_owner, regionid, tenant_id) + % (cloud_owner, regionid, tenant_id) # get stack resource service_type = "orchestration" - resource_uri = "/stacks/%s/resources"%(stack_id) + resource_uri = "/stacks/%s/resources" % (stack_id) self._logger.info("retrieve stack resources, URI:%s" % resource_uri) retcode, content, os_status = helper.MultiCloudServiceHelper(cloud_owner, regionid, v2_token_resp_json, service_type, resource_uri, None, "GET") resources = content.get('resources', []) if retcode == 0 and content else [] - #find and update resources + # find and update resources transactions = [] for resource in resources: if resource.get('resource_status', None) != "CREATED_COMPLETE": @@ -209,7 +211,7 @@ class InfraWorkload(APIView): resource_uri = "/servers/%s" % (resource['physical_resource_id']) self._logger.info("retrieve vserver detail, URI:%s" % resource_uri) retcode, content, os_status = helper.MultiCloudServiceHelper(cloud_owner, regionid, v2_token_resp_json, service_type, - resource_uri, None, "GET") + resource_uri, None, "GET") self._logger.debug(" resp data:%s" % content) vserver_detail = content.get('server', None) if retcode == 0 and content else None if vserver_detail: @@ -232,8 +234,9 @@ class InfraWorkload(APIView): "vserver-selflink": vserver_link, "prov-status": vserver_detail['status'] }, - "uri": aai_cloud_region + "/vservers/vserver/%s"\ - % ( vserver_detail['id'])} + "uri": aai_cloud_region + "/vservers/vserver/%s" + % (vserver_detail['id']) + } try: # then update the resource @@ -244,12 +247,12 @@ class InfraWorkload(APIView): content = json.JSONDecoder().decode(content) self._logger.debug("AAI update %s response: %s" % (aai_resource['uri'], content)) except Exception as e: - self._logger.error(traceback.format_exc()) + self._logger.error(traceback.format_exc(e)) pass aai_resource_transactions = {"put": [aai_resource]} transactions.append(aai_resource_transactions) - #self._logger.debug("aai_resource :%s" % aai_resource_transactions) + # self._logger.debug("aai_resource :%s" % aai_resource_transactions) pass for resource in resources: @@ -260,8 +263,13 @@ class InfraWorkload(APIView): service_type = "network" resource_uri = "/v2.0/ports/%s" % (resource['physical_resource_id']) self._logger.info("retrieve vserver detail, URI:%s" % resource_uri) - retcode, content, os_status = helper.MultiCloudServiceHelper(cloud_owner, regionid, v2_token_resp_json, service_type, - resource_uri, None, "GET") + retcode, content, os_status = helper.MultiCloudServiceHelper(cloud_owner, + regionid, + v2_token_resp_json, + service_type, + resource_uri, + None, + "GET") self._logger.debug(" resp data:%s" % content) vport_detail = content.get('port', None) if retcode == 0 and content else None @@ -275,7 +283,7 @@ class InfraWorkload(APIView): "interface-id": vport_detail['id'], "macaddr": vport_detail['mac_address'] }, - 'uri': aai_cloud_region + "/vservers/vserver/%s/l-interfaces/l-interface/%s" \ + 'uri': aai_cloud_region + "/vservers/vserver/%s/l-interfaces/l-interface/%s" % (vport_detail['device_id'], vport_detail['name']) } try: @@ -287,7 +295,7 @@ class InfraWorkload(APIView): content = json.JSONDecoder().decode(content) self._logger.debug("AAI update %s response: %s" % (aai_resource['uri'], content)) except Exception as e: - self._logger.error(traceback.format_exc()) + self._logger.error(traceback.format_exc(e)) pass aai_resource_transactions = {"put": [aai_resource]} @@ -299,7 +307,7 @@ class InfraWorkload(APIView): aai_transactions = {"transactions": transactions} self._logger.debug("aai_transactions :%s" % aai_transactions) - return aai_transactions + return aai_transactions def delete(self, request, vimid="", requri=""): self._logger.info("vimid, requri: %s, %s" % (vimid, requri)) @@ -320,7 +328,7 @@ class InfraWorkload(APIView): retcode, v2_token_resp_json, os_status = helper.MultiCloudIdentityHelper( settings.MULTICLOUD_API_V1_PREFIX, cloud_owner, regionid, "/v2.0/tokens") - if retcode > 0 or not v2_token_resp_json: + if retcode > 0 or not v2_token_resp_json: logger.error("authenticate fails:%s, %s, %s" % (cloud_owner, regionid, v2_token_resp_json)) return # tenant_id = v2_token_resp_json["access"]["token"]["tenant"]["id"] @@ -361,7 +369,7 @@ class InfraWorkload(APIView): return Response(status=os_status) except VimDriverNewtonException as e: self._logger.error("Plugin exception> status:%s,error:%s" - % (e.status_code, e.content)) + % (e.status_code, e.content)) return Response(data={'error': e.content}, status=e.status_code) except HttpError as e: self._logger.error("HttpError: status:%s, response:%s" % (e.http_status, e.response.json())) @@ -391,22 +399,22 @@ class APIv1InfraWorkload(InfraWorkload): # self._logger = logger def post(self, request, cloud_owner="", cloud_region_id="", requri=""): - #self._logger.info("cloud owner, cloud region id, data: %s,%s, %s" % (cloud_owner, cloud_region_id, request.data)) - #self._logger.debug("META: %s" % request.META) + # self._logger.info("cloud owner, cloud region id, data: %s,%s, %s" % (cloud_owner, cloud_region_id, request.data)) + # self._logger.debug("META: %s" % request.META) vimid = extsys.encode_vim_id(cloud_owner, cloud_region_id) return super(APIv1InfraWorkload, self).post(request, vimid, requri) def get(self, request, cloud_owner="", cloud_region_id="", requri=""): - #self._logger.info("cloud owner, cloud region id, data: %s,%s, %s" % (cloud_owner, cloud_region_id, request.data)) - #self._logger.debug("META: %s" % request.META) + # self._logger.info("cloud owner, cloud region id, data: %s,%s, %s" % (cloud_owner, cloud_region_id, request.data)) + # self._logger.debug("META: %s" % request.META) vimid = extsys.encode_vim_id(cloud_owner, cloud_region_id) return super(APIv1InfraWorkload, self).get(request, vimid, requri) def delete(self, request, cloud_owner="", cloud_region_id="", requri=""): - #self._logger.info("cloud owner, cloud region id, data: %s,%s, %s" % (cloud_owner, cloud_region_id, request.data)) - #self._logger.debug("META: %s" % request.META) + # self._logger.info("cloud owner, cloud region id, data: %s,%s, %s" % (cloud_owner, cloud_region_id, request.data)) + # self._logger.debug("META: %s" % request.META) vimid = extsys.encode_vim_id(cloud_owner, cloud_region_id) return super(APIv1InfraWorkload, self).delete(request, vimid, requri) diff --git a/pike/pike/settings.py b/pike/pike/settings.py index d40c9870..406a58da 100644 --- a/pike/pike/settings.py +++ b/pike/pike/settings.py @@ -93,7 +93,7 @@ CACHES = { MSB_SERVICE_ADDR = os.environ.get('MSB_ADDR', "127.0.0.1") MSB_SERVICE_PORT = os.environ.get('MSB_PORT', "80") -#[Multicloud] +# [Multicloud] MULTICLOUD_PREFIX = "http://%s:%s/api/multicloud-pike/v0" % ( MSB_SERVICE_ADDR, MSB_SERVICE_PORT) @@ -129,7 +129,7 @@ config.yamlConfig(filepath=LOGGING_FILE, watchDog=True) if 'test' in sys.argv: - #LOGGING['handlers']['pike_handler']['filename'] = 'logs/pike.log' + # LOGGING['handlers']['pike_handler']['filename'] = 'logs/pike.log' REST_FRAMEWORK = {} import platform diff --git a/pike/pike/urls.py b/pike/pike/urls.py index 8b8eb3be..f347da1a 100644 --- a/pike/pike/urls.py +++ b/pike/pike/urls.py @@ -27,9 +27,9 @@ urlpatterns = [ url(r'^api/multicloud-pike/v0/(?P<vimid>[0-9a-zA-Z_-]+)/exten', include('pike.extensions.urls')), url(r'^api/multicloud-pike/v0/(?P<vimid>[0-9a-zA-Z_-]+)/', - include('pike.proxy.urls')), + include('pike.proxy.urls')), url(r'^api/multicloud-pike/v0/(?P<vimid>[0-9a-zA-Z_-]+)/tenants$', - tenants.Tenants.as_view()), + tenants.Tenants.as_view()), url(r'^api/multicloud-pike/v0/(?P<vimid>[0-9a-zA-Z_-]+)/' '(?P<tenantid>[0-9a-zA-Z_-]{20,})/', include('pike.requests.urls')), url(r'^api/multicloud-pike/v0/(?P<vimid>[0-9a-zA-Z_-]+)/capacity_check/?$', @@ -52,11 +52,9 @@ urlpatterns = [ url(r'^api/multicloud-pike/v1/(?P<cloud_owner>[0-9a-zA-Z_-]+)/(?P<cloud_region_id>[0-9a-zA-Z_-]+)/' '(?P<tenantid>[0-9a-zA-Z_-]{20,})/', include('pike.requests.urlsV1')), url(r'^api/multicloud-pike/v1/(?P<cloud_owner>[0-9a-zA-Z_-]+)/(?P<cloud_region_id>[0-9a-zA-Z_-]+)/capacity_check/?$', - capacity.APIv1CapacityCheck.as_view()), + capacity.APIv1CapacityCheck.as_view()), url(r'^api/multicloud-pike/v1/(?P<cloud_owner>[0-9a-zA-Z_-]+)/(?P<cloud_region_id>[0-9a-zA-Z_-]+)/infra_workload/?$', infra_workload.APIv1InfraWorkload.as_view()), url(r'^api/multicloud-pike/v1/(?P<cloud_owner>[0-9a-zA-Z_-]+)/(?P<cloud_region_id>[0-9a-zA-Z_-]+)/infra_workload/(?P<requri>[0-9a-zA-Z_-]*)/?$', infra_workload.APIv1InfraWorkload.as_view()), ] - - |