@@ -49,6 +49,7 @@ def delete_project(ctx, id: str = None, protocol: str = None, host: str = None,
4949
5050
5151@click .option ("-n" , "--name" , required = False , default = None , help = "Name of new project." )
52+ @click .option ("-n" , "--nr-of-combiners" , required = False , default = 1 , help = "Number of combiners for the project (admin feature)." )
5253@click .option ("-p" , "--protocol" , required = False , default = STUDIO_DEFAULTS ["protocol" ], help = "Communication protocol of studio (api)" )
5354@click .option ("-H" , "--host" , required = False , default = STUDIO_DEFAULTS ["host" ], help = "Hostname of studio (api)" )
5455@click .option ("--branch" , required = False , default = None , help = "Studio branch (default main). Requires admin in Studio" )
@@ -61,6 +62,7 @@ def delete_project(ctx, id: str = None, protocol: str = None, host: str = None,
6162def create_project (
6263 ctx ,
6364 name : str = None ,
65+ nr_of_combiners : int = 1 ,
6466 protocol : str = None ,
6567 host : str = None ,
6668 no_interactive : bool = False ,
@@ -90,7 +92,11 @@ def create_project(
9092 else :
9193 # Call the authentication API
9294 try :
93- response = requests .post (url , data = {"name" : name , "studio_branch" : branch , "fedn_image" : image , "fedn_repo" : repository }, headers = headers )
95+ response = requests .post (
96+ url ,
97+ data = {"name" : name , "nr_of_combiners" : nr_of_combiners , "studio_branch" : branch , "fedn_image" : image , "fedn_repo" : repository },
98+ headers = headers ,
99+ )
94100 response_message = response .json ().get ("message" )
95101 if response .status_code == 201 :
96102 click .secho (f"Project with name '{ name } ' created." , fg = "green" )
@@ -260,3 +266,54 @@ def no_project_exists(response) -> bool:
260266 elif response_json .get ("error" ):
261267 return True
262268 return False
269+
270+
271+ @click .option ("-id" , "--id" , required = True , help = "Slug of the project to add the combiner to." )
272+ @click .option ("-nr_of_combiners" , "--nr_of_combiners" , required = True , help = "Total number of combiners to deploy." )
273+ @click .option ("--branch" , required = False , default = None , help = "Studio branch (optional)" )
274+ @click .option ("--image" , required = False , default = None , help = "FEDn image (optional)" )
275+ @click .option ("--repository" , required = False , default = None , help = "FEDn repo URL (optional)" )
276+ @click .option ("-p" , "--protocol" , required = False , default = STUDIO_DEFAULTS ["protocol" ], help = "Protocol to use for Studio API" )
277+ @click .option ("-H" , "--host" , required = False , default = STUDIO_DEFAULTS ["host" ], help = "Host to use for Studio API" )
278+ @project_cmd .command ("add-combiner" )
279+ @click .pass_context
280+ def add_combiner_to_project (
281+ ctx ,
282+ id : str ,
283+ nr_of_combiners : str ,
284+ branch : str = None ,
285+ image : str = None ,
286+ repository : str = None ,
287+ protocol : str = None ,
288+ host : str = None ,
289+ ):
290+ """Add a Combiner (and optional Server Functions) to an existing project."""
291+ studio_api = True
292+ headers = {"Content-Type" : "application/json" }
293+
294+ _token = get_token (None , True )
295+ if _token :
296+ headers ["Authorization" ] = _token
297+
298+ url = get_api_url (protocol = protocol , host = host , port = None , endpoint = "projects/add_combiner" , usr_api = studio_api )
299+
300+ payload = {
301+ "project_slug" : id ,
302+ "nr_of_combiners" : nr_of_combiners ,
303+ }
304+ if branch :
305+ payload ["studio_branch" ] = branch
306+ if image :
307+ payload ["fedn_image" ] = image
308+ if repository :
309+ payload ["fedn_repo" ] = repository
310+
311+ try :
312+ response = requests .post (url , json = payload , headers = headers )
313+ if response .status_code in [200 , 201 , 202 ]:
314+ click .secho (f"Combiner deployment initiated for project '{ id } '." , fg = "green" )
315+ else :
316+ click .secho (f"Failed to initiate combiner deployment: { response .status_code } " , fg = "red" )
317+ print_response (response , "error" , True )
318+ except requests .exceptions .RequestException as e :
319+ click .secho (f"Request failed: { e } " , fg = "red" )
0 commit comments