Skip to content

Commit c7d3f4e

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "SDK refactor: Prepare network agent commands"
2 parents d9361cb + b860ba0 commit c7d3f4e

3 files changed

Lines changed: 24 additions & 4 deletions

File tree

openstackclient/network/v2/network_agent.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from osc_lib import utils
2121

2222
from openstackclient.i18n import _
23+
from openstackclient.network import sdk_utils
2324

2425

2526
LOG = 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+
3848
class 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.
7284
class 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.
141155
class 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

openstackclient/tests/unit/network/v2/fakes.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,8 @@ def create_one_network_agent(attrs=None):
565565
agent_attrs.update(attrs)
566566
agent = fakes.FakeResource(info=copy.deepcopy(agent_attrs),
567567
loaded=True)
568+
agent.is_admin_state_up = agent_attrs['admin_state_up']
569+
agent.is_alive = agent_attrs['alive']
568570
return agent
569571

570572
@staticmethod

openstackclient/tests/unit/network/v2/test_network_agent.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,8 @@ def test_network_agents_list_host(self):
195195
self.assertEqual(self.data, list(data))
196196

197197

198+
# TODO(huanxuan): Also update by the new attribute name
199+
# "is_admin_state_up" after sdk 0.9.12
198200
class TestSetNetworkAgent(TestNetworkAgent):
199201

200202
_network_agent = (

0 commit comments

Comments
 (0)