11from faasmtools .compile_util import wasm_cmake
22from faasmtools .env import WASM_DIR
33from faasmtools .build import FAASM_LOCAL_DIR
4+ from faasmtools .endpoints import (
5+ get_faasm_invoke_host_port ,
6+ get_faasm_upload_host_port ,
7+ get_knative_headers ,
8+ )
49
510import requests
611from os .path import join
@@ -38,10 +43,11 @@ def compile(ctx, clean=False, debug=False):
3843
3944
4045@task
41- def upload (ctx , host = "upload" , port = 8002 ):
46+ def upload (ctx ):
4247 """
4348 Upload the CPython function
4449 """
50+ host , port = get_faasm_upload_host_port ()
4551 url = "http://{}:{}/f/{}/{}" .format (host , port , USER , FUNC )
4652 print ("Uploading {}/{} to {}" .format (USER , FUNC , url ))
4753 response = requests .put (url , data = open (WASM_FILE , "rb" ))
@@ -50,7 +56,11 @@ def upload(ctx, host="upload", port=8002):
5056
5157
5258@task
53- def uploadpy (ctx , func , local = False , host = "upload" , port = 8002 ):
59+ def uploadpy (ctx , func , local = False ):
60+ """
61+ Upload the given Python function
62+ """
63+ host , port = get_faasm_upload_host_port ()
5464 src_file = join (PY_FUNC_DIR , "{}.py" .format (func ))
5565
5666 if local :
@@ -69,7 +79,7 @@ def uploadpy(ctx, func, local=False, host="upload", port=8002):
6979
7080
7181@task
72- def upload_all (ctx , local = False , host = "upload" , port = 8002 ):
82+ def upload_all (ctx , local = False ):
7383 """
7484 Upload all Python functions
7585 """
@@ -78,15 +88,15 @@ def upload_all(ctx, local=False, host="upload", port=8002):
7888 funcs = [f .replace (".py" , "" ) for f in funcs ]
7989
8090 for func in funcs :
81- uploadpy (ctx , func , local = local , host = host , port = port )
91+ uploadpy (ctx , func , local = local )
8292
8393
8494@task
85- def invoke (ctx , user , func , input_data = None , host = "worker" , port = 8080 ):
95+ def invoke (ctx , user , func , input_data = None ):
8696 """
8797 Invoke a function
8898 """
89-
99+ host , port = get_faasm_invoke_host_port ()
90100 url = "http://{}:{}" .format (host , port )
91101 data = {
92102 "user" : USER ,
@@ -99,7 +109,9 @@ def invoke(ctx, user, func, input_data=None, host="worker", port=8080):
99109 if input_data :
100110 data ["input_data" ] = input_data
101111
102- response = requests .post (url , json = data )
112+ headers = get_knative_headers ()
113+ response = requests .post (url , json = data , headers = headers )
114+
103115 if response .status_code != 200 :
104116 print ("Error ({}):\n {}" .format (response .status_code , response .text ))
105117 exit (1 )
0 commit comments