1414"""Port action implementations"""
1515
1616from openstackclient .common import command
17+ from openstackclient .common import exceptions
1718from openstackclient .common import parseractions
1819from openstackclient .common import utils
1920from openstackclient .identity import common as identity_common
@@ -56,8 +57,6 @@ def _get_columns(item):
5657def _get_attrs (client_manager , parsed_args ):
5758 attrs = {}
5859
59- if parsed_args .name is not None :
60- attrs ['name' ] = str (parsed_args .name )
6160 if parsed_args .fixed_ip is not None :
6261 attrs ['fixed_ips' ] = parsed_args .fixed_ip
6362 if parsed_args .device_id is not None :
@@ -75,6 +74,8 @@ def _get_attrs(client_manager, parsed_args):
7574
7675 # The remaining options do not support 'port set' command, so they require
7776 # additional check
77+ if 'name' in parsed_args and parsed_args .name is not None :
78+ attrs ['name' ] = str (parsed_args .name )
7879 if 'mac_address' in parsed_args and parsed_args .mac_address is not None :
7980 attrs ['mac_address' ] = parsed_args .mac_address
8081 if 'network' in parsed_args and parsed_args .network is not None :
@@ -145,8 +146,9 @@ def _add_updatable_args(parser):
145146 metavar = '<vnic-type>' ,
146147 choices = ['direct' , 'direct-physical' , 'macvtap' ,
147148 'normal' , 'baremetal' ],
148- help = 'VNIC type for this port (direct | direct-physical |'
149- ' macvtap | normal(default) | baremetal)' )
149+ help = "VNIC type for this port (direct | direct-physical |"
150+ " macvtap | normal | baremetal). If unspecified during"
151+ " port creation, default value will be 'normal'." )
150152 parser .add_argument (
151153 '--binding-profile' ,
152154 metavar = '<binding-profile>' ,
@@ -265,6 +267,48 @@ def take_action(self, parsed_args):
265267 ) for s in data ))
266268
267269
270+ class SetPort (command .Command ):
271+ """Set port properties"""
272+
273+ def get_parser (self , prog_name ):
274+ parser = super (SetPort , self ).get_parser (prog_name )
275+ _add_updatable_args (parser )
276+ admin_group = parser .add_mutually_exclusive_group ()
277+ admin_group .add_argument (
278+ '--enable' ,
279+ dest = 'admin_state' ,
280+ action = 'store_true' ,
281+ default = None ,
282+ help = 'Enable port' ,
283+ )
284+ admin_group .add_argument (
285+ '--disable' ,
286+ dest = 'admin_state' ,
287+ action = 'store_false' ,
288+ help = 'Disable port' ,
289+ )
290+ parser .add_argument (
291+ 'port' ,
292+ metavar = "<port>" ,
293+ help = ("Port to modify (name or ID)" )
294+ )
295+
296+ return parser
297+
298+ def take_action (self , parsed_args ):
299+ client = self .app .client_manager .network
300+
301+ _prepare_fixed_ips (self .app .client_manager , parsed_args )
302+ attrs = _get_attrs (self .app .client_manager , parsed_args )
303+
304+ if attrs == {}:
305+ msg = "Nothing specified to be set"
306+ raise exceptions .CommandError (msg )
307+
308+ obj = client .find_port (parsed_args .port , ignore_missing = False )
309+ client .update_port (obj , ** attrs )
310+
311+
268312class ShowPort (command .ShowOne ):
269313 """Display port details"""
270314
0 commit comments