22import logging
33from flask import Flask , render_template , request , jsonify
44
5+ import os
6+
57app = Flask (__name__ )
68
9+ _IS_DOCKER = True is os .getenv ('IS_DOCKER' , 'false' ).lower () == 'true'
10+
711# Configure logging
812logging .basicConfig (level = logging .INFO , format = "%(asctime)s - %(name)s - %(levelname)s - %(message)s" )
913logger = logging .getLogger (__name__ )
@@ -43,7 +47,8 @@ def compute_networks_insert(project_name: str):
4347 operation_id = '1000000000001'
4448 operation_name = 'operation-100000000001-10000000001-10000001-10000001'
4549 network_name = body ['name' ]
46- target_link = f'https://localhost:1080/compute/v1/projects/{ project_name } /global/networks/{ network_name } '
50+ host_name = 'host.docker.internal' if _IS_DOCKER else 'localhost'
51+ target_link = f'https://{ host_name } :1080/compute/v1/projects/{ project_name } /global/networks/{ network_name } '
4752 if not body or 'name' not in body :
4853 return '{"msg": "Invalid request body"}' , 400 , {'Content-Type' : 'application/json' }
4954 if not project_name :
@@ -55,6 +60,7 @@ def compute_networks_insert(project_name: str):
5560 operation_id = operation_id ,
5661 operation_name = operation_name ,
5762 project_name = project_name ,
63+ host_name = host_name ,
5864 kind = 'compute#operation' ,
5965 operation_type = 'insert' ,
6066 progress = 0 ,
@@ -66,13 +72,15 @@ def projects_testing_project_global_operation_detail(project_name: str, operatio
6672 if project_name == 'mutable-project' and 'operation-100000000001-10000000001-10000001-10000001' :
6773 operation_id = '1000000000001'
6874 network_name = 'auto-test-01'
69- target_link = f'https://localhost:1080/compute/v1/projects/{ project_name } /global/networks/{ network_name } '
75+ host_name = 'host.docker.internal' if _IS_DOCKER else 'localhost'
76+ target_link = f'https://{ host_name } :1080/compute/v1/projects/{ project_name } /global/networks/{ network_name } '
7077 return render_template (
7178 'global-operation.jinja.json' ,
7279 target_link = target_link ,
7380 operation_id = operation_id ,
7481 operation_name = operation_name ,
7582 project_name = project_name ,
83+ host_name = host_name ,
7684 kind = 'compute#operation' ,
7785 operation_type = 'insert' ,
7886 progress = 100 ,
0 commit comments