1717 print_gateways_table ,
1818)
1919from dstack ._internal .core .errors import CLIError , ResourceNotExistsError
20+ from dstack ._internal .core .models .common import EntityReference
2021from dstack ._internal .core .models .gateways import GatewayStatus
2122from dstack ._internal .utils .json_utils import pydantic_orjson_dumps_with_indent
2223from dstack ._internal .utils .logging import get_logger
@@ -67,7 +68,7 @@ def _register(self):
6768 )
6869 delete_parser .set_defaults (subfunc = self ._delete )
6970 delete_parser .add_argument (
70- "name" , help = "The name of the gateway"
71+ "name" , type = EntityReference . parse , help = "The name of the gateway"
7172 ).completer = GatewayNameCompleter () # type: ignore[attr-defined]
7273 delete_parser .add_argument (
7374 "-y" , "--yes" , action = "store_true" , help = "Don't ask for confirmation"
@@ -78,7 +79,7 @@ def _register(self):
7879 )
7980 update_parser .set_defaults (subfunc = self ._update )
8081 update_parser .add_argument (
81- "name" , help = "The name of the gateway"
82+ "name" , type = EntityReference . parse , help = "The name of the gateway"
8283 ).completer = GatewayNameCompleter () # type: ignore[attr-defined]
8384 update_parser .add_argument (
8485 "--set-default" , action = "store_true" , help = "Set it the default gateway for the project"
@@ -89,7 +90,7 @@ def _register(self):
8990 "get" , help = "Get a gateway" , formatter_class = self ._parser .formatter_class
9091 )
9192 get_parser .add_argument (
92- "name" , metavar = "NAME" , help = "The name of the gateway"
93+ "name" , metavar = "NAME" , type = EntityReference . parse , help = "The name of the gateway"
9394 ).completer = GatewayNameCompleter () # type: ignore[attr-defined]
9495 get_parser .add_argument (
9596 "--json" ,
@@ -108,7 +109,7 @@ def _list(self, args: argparse.Namespace):
108109 if args .watch and args .format == "json" :
109110 raise CLIError ("JSON output is not supported together with --watch" )
110111
111- gateways = self .api .client .gateways .list (self .api .project )
112+ gateways = self .api .client .gateways .list (self .api .project , include_imported = True )
112113 deprecated_router_gateways = [
113114 g .name
114115 for g in gateways
@@ -127,45 +128,66 @@ def _list(self, args: argparse.Namespace):
127128 if args .format == "json" :
128129 print_gateways_json (gateways , project = self .api .project )
129130 else :
130- print_gateways_table (gateways , verbose = args .verbose )
131+ print_gateways_table (
132+ gateways , current_project = self .api .project , verbose = args .verbose
133+ )
131134 return
132135
133136 try :
134137 with Live (console = console , refresh_per_second = LIVE_TABLE_REFRESH_RATE_PER_SEC ) as live :
135138 while True :
136- live .update (get_gateways_table (gateways , verbose = args .verbose ))
139+ live .update (
140+ get_gateways_table (
141+ gateways , current_project = self .api .project , verbose = args .verbose
142+ )
143+ )
137144 time .sleep (LIVE_TABLE_PROVISION_INTERVAL_SECS )
138- gateways = self .api .client .gateways .list (self .api .project )
145+ gateways = self .api .client .gateways .list (
146+ self .api .project , include_imported = True
147+ )
139148 except KeyboardInterrupt :
140149 pass
141150
142151 def _delete (self , args : argparse .Namespace ):
143- gateway = self .api .client .gateways .get (self .api .project , args .name )
144- print_gateways_table ([gateway ])
152+ if args .name .project is not None :
153+ console .print (
154+ "The [code]<project>/<gateway>[/] format is not supported for gateway names."
155+ " Can only delete gateways owned by the current project"
156+ )
157+ exit (1 )
158+ name = args .name .name
159+ gateway = self .api .client .gateways .get (self .api .project , name )
160+ print_gateways_table ([gateway ], current_project = self .api .project )
145161 if args .yes or confirm_ask ("Do you want to delete the gateway?" ):
146162 with console .status ("Deleting gateway..." ):
147- self .api .client .gateways .delete (self .api .project , [args . name ])
163+ self .api .client .gateways .delete (self .api .project , [name ])
148164 console .print ("Gateway deleted" )
149165 else :
150166 console .print ("Exiting..." )
151167 return
152168
153169 def _update (self , args : argparse .Namespace ):
170+ if args .name .project is not None :
171+ console .print (
172+ "The [code]<project>/<gateway>[/] format is not supported for gateway names."
173+ " Can only update gateways owned by the current project"
174+ )
175+ exit (1 )
176+ name = args .name .name
154177 with console .status ("Updating gateway..." ):
155178 if args .set_default :
156- self .api .client .gateways .set_default (self .api .project , args . name )
179+ self .api .client .gateways .set_default (self .api .project , name )
157180 if args .domain :
158- self .api .client .gateways .set_wildcard_domain (
159- self .api .project , args .name , args .domain
160- )
161- gateway = self .api .client .gateways .get (self .api .project , args .name )
162- print_gateways_table ([gateway ])
181+ self .api .client .gateways .set_wildcard_domain (self .api .project , name , args .domain )
182+ gateway = self .api .client .gateways .get (self .api .project , name )
183+ print_gateways_table ([gateway ], current_project = self .api .project )
163184
164185 def _get (self , args : argparse .Namespace ):
165186 # TODO: Implement non-json output format
166187 try :
167188 gateway = self .api .client .gateways .get (
168- project_name = self .api .project , gateway_name = args .name
189+ project_name = args .name .project or self .api .project ,
190+ gateway_name = args .name .name ,
169191 )
170192 except ResourceNotExistsError :
171193 console .print ("Gateway not found" )
0 commit comments