2020from osc_lib import utils
2121
2222from openstackclient .i18n import _
23+ from openstackclient .network import sdk_utils
2324
2425
2526LOG = logging .getLogger (__name__ )
@@ -31,10 +32,19 @@ def _format_admin_state(state):
3132
3233_formatters = {
3334 'admin_state_up' : _format_admin_state ,
35+ 'is_admin_state_up' : _format_admin_state ,
3436 'configurations' : utils .format_dict ,
3537}
3638
3739
40+ def _get_network_columns (item ):
41+ column_map = {
42+ 'is_admin_state_up' : 'admin_state_up' ,
43+ 'is_alive' : 'alive' ,
44+ }
45+ return sdk_utils .get_osc_show_columns_for_sdk_resource (item , column_map )
46+
47+
3848class DeleteNetworkAgent (command .Command ):
3949 _description = _ ("Delete network agent(s)" )
4050
@@ -69,6 +79,8 @@ def take_action(self, parsed_args):
6979 raise exceptions .CommandError (msg )
7080
7181
82+ # TODO(huanxuan): Use the SDK resource mapped attribute names once the
83+ # OSC minimum requirements include SDK 1.0.
7284class ListNetworkAgent (command .Lister ):
7385 _description = _ ("List network agents" )
7486
@@ -98,8 +110,8 @@ def take_action(self, parsed_args):
98110 'agent_type' ,
99111 'host' ,
100112 'availability_zone' ,
101- 'alive ' ,
102- 'admin_state_up ' ,
113+ 'is_alive ' ,
114+ 'is_admin_state_up ' ,
103115 'binary'
104116 )
105117 column_headers = (
@@ -138,6 +150,8 @@ def take_action(self, parsed_args):
138150 ) for s in data ))
139151
140152
153+ # TODO(huanxuan): Use the SDK resource mapped attribute names once the
154+ # OSC minimum requirements include SDK 1.0.
141155class SetNetworkAgent (command .Command ):
142156 _description = _ ("Set network agent properties" )
143157
@@ -172,6 +186,8 @@ def take_action(self, parsed_args):
172186 attrs = {}
173187 if parsed_args .description is not None :
174188 attrs ['description' ] = str (parsed_args .description )
189+ # TODO(huanxuan): Also update by the new attribute name
190+ # "is_admin_state_up" after sdk 0.9.12
175191 if parsed_args .enable :
176192 attrs ['admin_state_up' ] = True
177193 if parsed_args .disable :
@@ -194,6 +210,6 @@ def get_parser(self, prog_name):
194210 def take_action (self , parsed_args ):
195211 client = self .app .client_manager .network
196212 obj = client .get_agent (parsed_args .network_agent )
197- columns = tuple ( sorted ( list ( obj . keys ())) )
213+ display_columns , columns = _get_network_columns ( obj )
198214 data = utils .get_item_properties (obj , columns , formatters = _formatters ,)
199- return columns , data
215+ return display_columns , data
0 commit comments