Merge "SDK refactor: Prepare network agent commands"
This commit is contained in:
commit
c7d3f4eae9
@ -20,6 +20,7 @@ from osc_lib import exceptions
|
|||||||
from osc_lib import utils
|
from osc_lib import utils
|
||||||
|
|
||||||
from openstackclient.i18n import _
|
from openstackclient.i18n import _
|
||||||
|
from openstackclient.network import sdk_utils
|
||||||
|
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
@ -31,10 +32,19 @@ def _format_admin_state(state):
|
|||||||
|
|
||||||
_formatters = {
|
_formatters = {
|
||||||
'admin_state_up': _format_admin_state,
|
'admin_state_up': _format_admin_state,
|
||||||
|
'is_admin_state_up': _format_admin_state,
|
||||||
'configurations': utils.format_dict,
|
'configurations': utils.format_dict,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def _get_network_columns(item):
|
||||||
|
column_map = {
|
||||||
|
'is_admin_state_up': 'admin_state_up',
|
||||||
|
'is_alive': 'alive',
|
||||||
|
}
|
||||||
|
return sdk_utils.get_osc_show_columns_for_sdk_resource(item, column_map)
|
||||||
|
|
||||||
|
|
||||||
class DeleteNetworkAgent(command.Command):
|
class DeleteNetworkAgent(command.Command):
|
||||||
_description = _("Delete network agent(s)")
|
_description = _("Delete network agent(s)")
|
||||||
|
|
||||||
@ -69,6 +79,8 @@ class DeleteNetworkAgent(command.Command):
|
|||||||
raise exceptions.CommandError(msg)
|
raise exceptions.CommandError(msg)
|
||||||
|
|
||||||
|
|
||||||
|
# TODO(huanxuan): Use the SDK resource mapped attribute names once the
|
||||||
|
# OSC minimum requirements include SDK 1.0.
|
||||||
class ListNetworkAgent(command.Lister):
|
class ListNetworkAgent(command.Lister):
|
||||||
_description = _("List network agents")
|
_description = _("List network agents")
|
||||||
|
|
||||||
@ -98,8 +110,8 @@ class ListNetworkAgent(command.Lister):
|
|||||||
'agent_type',
|
'agent_type',
|
||||||
'host',
|
'host',
|
||||||
'availability_zone',
|
'availability_zone',
|
||||||
'alive',
|
'is_alive',
|
||||||
'admin_state_up',
|
'is_admin_state_up',
|
||||||
'binary'
|
'binary'
|
||||||
)
|
)
|
||||||
column_headers = (
|
column_headers = (
|
||||||
@ -138,6 +150,8 @@ class ListNetworkAgent(command.Lister):
|
|||||||
) for s in data))
|
) for s in data))
|
||||||
|
|
||||||
|
|
||||||
|
# TODO(huanxuan): Use the SDK resource mapped attribute names once the
|
||||||
|
# OSC minimum requirements include SDK 1.0.
|
||||||
class SetNetworkAgent(command.Command):
|
class SetNetworkAgent(command.Command):
|
||||||
_description = _("Set network agent properties")
|
_description = _("Set network agent properties")
|
||||||
|
|
||||||
@ -172,6 +186,8 @@ class SetNetworkAgent(command.Command):
|
|||||||
attrs = {}
|
attrs = {}
|
||||||
if parsed_args.description is not None:
|
if parsed_args.description is not None:
|
||||||
attrs['description'] = str(parsed_args.description)
|
attrs['description'] = str(parsed_args.description)
|
||||||
|
# TODO(huanxuan): Also update by the new attribute name
|
||||||
|
# "is_admin_state_up" after sdk 0.9.12
|
||||||
if parsed_args.enable:
|
if parsed_args.enable:
|
||||||
attrs['admin_state_up'] = True
|
attrs['admin_state_up'] = True
|
||||||
if parsed_args.disable:
|
if parsed_args.disable:
|
||||||
@ -194,6 +210,6 @@ class ShowNetworkAgent(command.ShowOne):
|
|||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
client = self.app.client_manager.network
|
client = self.app.client_manager.network
|
||||||
obj = client.get_agent(parsed_args.network_agent)
|
obj = client.get_agent(parsed_args.network_agent)
|
||||||
columns = tuple(sorted(list(obj.keys())))
|
display_columns, columns = _get_network_columns(obj)
|
||||||
data = utils.get_item_properties(obj, columns, formatters=_formatters,)
|
data = utils.get_item_properties(obj, columns, formatters=_formatters,)
|
||||||
return columns, data
|
return display_columns, data
|
||||||
|
@ -565,6 +565,8 @@ class FakeNetworkAgent(object):
|
|||||||
agent_attrs.update(attrs)
|
agent_attrs.update(attrs)
|
||||||
agent = fakes.FakeResource(info=copy.deepcopy(agent_attrs),
|
agent = fakes.FakeResource(info=copy.deepcopy(agent_attrs),
|
||||||
loaded=True)
|
loaded=True)
|
||||||
|
agent.is_admin_state_up = agent_attrs['admin_state_up']
|
||||||
|
agent.is_alive = agent_attrs['alive']
|
||||||
return agent
|
return agent
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -195,6 +195,8 @@ class TestListNetworkAgent(TestNetworkAgent):
|
|||||||
self.assertEqual(self.data, list(data))
|
self.assertEqual(self.data, list(data))
|
||||||
|
|
||||||
|
|
||||||
|
# TODO(huanxuan): Also update by the new attribute name
|
||||||
|
# "is_admin_state_up" after sdk 0.9.12
|
||||||
class TestSetNetworkAgent(TestNetworkAgent):
|
class TestSetNetworkAgent(TestNetworkAgent):
|
||||||
|
|
||||||
_network_agent = (
|
_network_agent = (
|
||||||
|
Loading…
x
Reference in New Issue
Block a user