@@ -828,6 +828,18 @@ def get_parser(self, prog_name):
828828 action = 'store_true' ,
829829 help = _ ('Wait for build to complete' ),
830830 )
831+ parser .add_argument (
832+ '--tag' ,
833+ metavar = '<tag>' ,
834+ action = 'append' ,
835+ default = [],
836+ dest = 'tags' ,
837+ help = _ (
838+ 'Tags for the server. '
839+ 'Specify multiple times to add multiple tags. '
840+ '(supported by --os-compute-api-version 2.52 or above)'
841+ ),
842+ )
831843 return parser
832844
833845 def take_action (self , parsed_args ):
@@ -1141,6 +1153,16 @@ def _match_image(image_api, wanted_properties):
11411153 if parsed_args .description :
11421154 boot_kwargs ['description' ] = parsed_args .description
11431155
1156+ if parsed_args .tags :
1157+ if compute_client .api_version < api_versions .APIVersion ('2.52' ):
1158+ msg = _ (
1159+ '--os-compute-api-version 2.52 or greater is required to '
1160+ 'support the --tag option'
1161+ )
1162+ raise exceptions .CommandError (msg )
1163+
1164+ boot_kwargs ['tags' ] = parsed_args .tags
1165+
11441166 if parsed_args .host :
11451167 if compute_client .api_version < api_versions .APIVersion ("2.74" ):
11461168 msg = _ ("Specifying --host is not supported for "
@@ -1408,6 +1430,30 @@ def get_parser(self, prog_name):
14081430 help = _ ('Only display unlocked servers. '
14091431 'Requires ``--os-compute-api-version`` 2.73 or greater.' ),
14101432 )
1433+ parser .add_argument (
1434+ '--tags' ,
1435+ metavar = '<tag>' ,
1436+ action = 'append' ,
1437+ default = [],
1438+ dest = 'tags' ,
1439+ help = _ (
1440+ 'Only list servers with the specified tag. '
1441+ 'Specify multiple times to filter on multiple tags. '
1442+ '(supported by --os-compute-api-version 2.26 or above)'
1443+ ),
1444+ )
1445+ parser .add_argument (
1446+ '--not-tags' ,
1447+ metavar = '<tag>' ,
1448+ action = 'append' ,
1449+ default = [],
1450+ dest = 'not_tags' ,
1451+ help = _ (
1452+ 'Only list servers without the specified tag. '
1453+ 'Specify multiple times to filter on multiple tags. '
1454+ '(supported by --os-compute-api-version 2.26 or above)'
1455+ ),
1456+ )
14111457 return parser
14121458
14131459 def take_action (self , parsed_args ):
@@ -1463,6 +1509,27 @@ def take_action(self, parsed_args):
14631509 'changes-before' : parsed_args .changes_before ,
14641510 'changes-since' : parsed_args .changes_since ,
14651511 }
1512+
1513+ if parsed_args .tags :
1514+ if compute_client .api_version < api_versions .APIVersion ('2.26' ):
1515+ msg = _ (
1516+ '--os-compute-api-version 2.26 or greater is required to '
1517+ 'support the --tag option'
1518+ )
1519+ raise exceptions .CommandError (msg )
1520+
1521+ search_opts ['tags' ] = parsed_args .tags
1522+
1523+ if parsed_args .not_tags :
1524+ if compute_client .api_version < api_versions .APIVersion ('2.26' ):
1525+ msg = _ (
1526+ '--os-compute-api-version 2.26 or greater is required to '
1527+ 'support the --not-tag option'
1528+ )
1529+ raise exceptions .CommandError (msg )
1530+
1531+ search_opts ['not-tags' ] = parsed_args .not_tags
1532+
14661533 support_locked = (compute_client .api_version >=
14671534 api_versions .APIVersion ('2.73' ))
14681535 if not support_locked and (parsed_args .locked or parsed_args .unlocked ):
@@ -2795,6 +2862,18 @@ def get_parser(self, prog_name):
27952862 help = _ ('New server description (supported by '
27962863 '--os-compute-api-version 2.19 or above)' ),
27972864 )
2865+ parser .add_argument (
2866+ '--tag' ,
2867+ metavar = '<tag>' ,
2868+ action = 'append' ,
2869+ default = [],
2870+ dest = 'tags' ,
2871+ help = _ (
2872+ 'Tag for the server. '
2873+ 'Specify multiple times to add multiple tags. '
2874+ '(supported by --os-compute-api-version 2.26 or above)'
2875+ ),
2876+ )
27982877 return parser
27992878
28002879 def take_action (self , parsed_args ):
@@ -2833,6 +2912,17 @@ def take_action(self, parsed_args):
28332912 raise exceptions .CommandError (msg )
28342913 server .update (description = parsed_args .description )
28352914
2915+ if parsed_args .tags :
2916+ if server .api_version < api_versions .APIVersion ('2.26' ):
2917+ msg = _ (
2918+ '--os-compute-api-version 2.26 or greater is required to '
2919+ 'support the --tag option'
2920+ )
2921+ raise exceptions .CommandError (msg )
2922+
2923+ for tag in parsed_args .tags :
2924+ server .add_tag (tag = tag )
2925+
28362926
28372927class ShelveServer (command .Command ):
28382928 _description = _ ("Shelve server(s)" )
@@ -3174,7 +3264,7 @@ def take_action(self, parsed_args):
31743264
31753265
31763266class UnsetServer (command .Command ):
3177- _description = _ ("Unset server properties" )
3267+ _description = _ ("Unset server properties and tags " )
31783268
31793269 def get_parser (self , prog_name ):
31803270 parser = super (UnsetServer , self ).get_parser (prog_name )
@@ -3198,6 +3288,18 @@ def get_parser(self, prog_name):
31983288 help = _ ('Unset server description (supported by '
31993289 '--os-compute-api-version 2.19 or above)' ),
32003290 )
3291+ parser .add_argument (
3292+ '--tag' ,
3293+ metavar = '<tag>' ,
3294+ action = 'append' ,
3295+ default = [],
3296+ dest = 'tags' ,
3297+ help = _ (
3298+ 'Tag to remove from the server. '
3299+ 'Specify multiple times to remove multiple tags. '
3300+ '(supported by --os-compute-api-version 2.26 or later'
3301+ ),
3302+ )
32013303 return parser
32023304
32033305 def take_action (self , parsed_args ):
@@ -3223,6 +3325,17 @@ def take_action(self, parsed_args):
32233325 description = "" ,
32243326 )
32253327
3328+ if parsed_args .tags :
3329+ if compute_client .api_version < api_versions .APIVersion ('2.26' ):
3330+ msg = _ (
3331+ '--os-compute-api-version 2.26 or greater is required to '
3332+ 'support the --tag option'
3333+ )
3334+ raise exceptions .CommandError (msg )
3335+
3336+ for tag in parsed_args .tags :
3337+ compute_client .servers .delete_tag (server , tag = tag )
3338+
32263339
32273340class UnshelveServer (command .Command ):
32283341 _description = _ ("Unshelve server(s)" )
0 commit comments