Remove in-place try/except blocks from shell commands
Currently we have try/except blocks for each shell command which may cause an exception, and often we unaware of all possible exceptions. Therefore our in-place messages may not correspond to real server exceptions. This patch removes in-place handlers so shell will rely on single try/except based in /ironicclient/shell.py: main, which simply prints server's exception message. Change-Id: I65dc71c6fb15483fb88ef4c6a423147fe0bb54cb Closes-Bug: #1251712
This commit is contained in:
parent
8c394d441b
commit
b55b848f14
ironicclient/v1
@ -17,7 +17,6 @@
|
||||
# under the License.
|
||||
|
||||
from ironicclient.common import utils
|
||||
from ironicclient import exc
|
||||
|
||||
|
||||
def _print_chassis_show(chassis):
|
||||
@ -29,12 +28,8 @@ def _print_chassis_show(chassis):
|
||||
@utils.arg('chassis', metavar='<chassis id>', help="UUID of chassis")
|
||||
def do_chassis_show(cc, args):
|
||||
"""Show a chassis."""
|
||||
try:
|
||||
chassis = cc.chassis.get(args.chassis)
|
||||
except exc.HTTPNotFound:
|
||||
raise exc.CommandError('Chassis not found: %s' % args.chassis)
|
||||
else:
|
||||
_print_chassis_show(chassis)
|
||||
chassis = cc.chassis.get(args.chassis)
|
||||
_print_chassis_show(chassis)
|
||||
|
||||
|
||||
def do_chassis_list(cc, args):
|
||||
@ -73,10 +68,7 @@ def do_chassis_create(cc, args):
|
||||
def do_chassis_delete(cc, args):
|
||||
"""Delete a chassis."""
|
||||
for c in args.chassis:
|
||||
try:
|
||||
cc.chassis.delete(c)
|
||||
except exc.HTTPNotFound:
|
||||
raise exc.CommandError('Chassis not found: %s' % c)
|
||||
cc.chassis.delete(c)
|
||||
print('Deleted chassis %s' % c)
|
||||
|
||||
|
||||
@ -97,20 +89,14 @@ def do_chassis_delete(cc, args):
|
||||
def do_chassis_update(cc, args):
|
||||
"""Update a chassis."""
|
||||
patch = utils.args_array_to_patch(args.op, args.attributes[0])
|
||||
try:
|
||||
chassis = cc.chassis.update(args.chassis, patch)
|
||||
except exc.HTTPNotFound:
|
||||
raise exc.CommandError('Chassis not found: %s' % args.chassis)
|
||||
chassis = cc.chassis.update(args.chassis, patch)
|
||||
_print_chassis_show(chassis)
|
||||
|
||||
|
||||
@utils.arg('chassis', metavar='<chassis id>', help="UUID of chassis")
|
||||
def do_chassis_node_list(cc, args):
|
||||
"""List the nodes contained in the chassis."""
|
||||
try:
|
||||
nodes = cc.chassis.list_nodes(args.chassis)
|
||||
except exc.HTTPNotFound:
|
||||
raise exc.CommandError(_('Chassis not found: %s') % args.chassis)
|
||||
nodes = cc.chassis.list_nodes(args.chassis)
|
||||
field_labels = ['UUID', 'Instance UUID',
|
||||
'Power State', 'Provisioning State']
|
||||
fields = ['uuid', 'instance_uuid', 'power_state', 'provision_state']
|
||||
|
@ -17,7 +17,6 @@
|
||||
# under the License.
|
||||
|
||||
from ironicclient.common import utils
|
||||
from ironicclient import exc
|
||||
|
||||
|
||||
def _print_node_show(node):
|
||||
@ -38,19 +37,11 @@ def _print_node_show(node):
|
||||
help='The id is an instance UUID')
|
||||
def do_node_show(cc, args):
|
||||
"""Show a node."""
|
||||
try:
|
||||
if args.instance_uuid:
|
||||
node = cc.node.get_by_instance_uuid(args.node)
|
||||
else:
|
||||
node = cc.node.get(args.node)
|
||||
except exc.HTTPNotFound:
|
||||
if args.instance_uuid:
|
||||
error_tmpl = _('Node not found with instance UUID: %s')
|
||||
else:
|
||||
error_tmpl = _('Node not found: %s')
|
||||
raise exc.CommandError(error_tmpl % args.node)
|
||||
if args.instance_uuid:
|
||||
node = cc.node.get_by_instance_uuid(args.node)
|
||||
else:
|
||||
_print_node_show(node)
|
||||
node = cc.node.get(args.node)
|
||||
_print_node_show(node)
|
||||
|
||||
|
||||
@utils.arg('--associated',
|
||||
@ -115,10 +106,7 @@ def do_node_create(cc, args):
|
||||
def do_node_delete(cc, args):
|
||||
"""Delete a node."""
|
||||
for n in args.node:
|
||||
try:
|
||||
cc.node.delete(n)
|
||||
except exc.HTTPNotFound:
|
||||
raise exc.CommandError(_('Node not found: %s') % n)
|
||||
cc.node.delete(n)
|
||||
print(_('Deleted node %s') % n)
|
||||
|
||||
|
||||
@ -139,20 +127,14 @@ def do_node_delete(cc, args):
|
||||
def do_node_update(cc, args):
|
||||
"""Update a node."""
|
||||
patch = utils.args_array_to_patch(args.op, args.attributes[0])
|
||||
try:
|
||||
node = cc.node.update(args.node, patch)
|
||||
except exc.HTTPNotFound:
|
||||
raise exc.CommandError(_('Node not found: %s') % args.node)
|
||||
node = cc.node.update(args.node, patch)
|
||||
_print_node_show(node)
|
||||
|
||||
|
||||
@utils.arg('node', metavar='<node id>', help="UUID of node")
|
||||
def do_node_port_list(cc, args):
|
||||
"""List the ports contained in the node."""
|
||||
try:
|
||||
ports = cc.node.list_ports(args.node)
|
||||
except exc.HTTPNotFound:
|
||||
raise exc.CommandError(_('Node not found: %s') % args.node)
|
||||
ports = cc.node.list_ports(args.node)
|
||||
field_labels = ['UUID', 'Address']
|
||||
fields = ['uuid', 'address']
|
||||
utils.print_list(ports, fields, field_labels, sortby=1)
|
||||
@ -167,11 +149,7 @@ def do_node_port_list(cc, args):
|
||||
help="Supported states: 'on' or 'off'")
|
||||
def do_node_set_power_state(cc, args):
|
||||
"""Power the node on or off."""
|
||||
try:
|
||||
state = cc.node.set_power_state(args.node, args.power_state)
|
||||
except exc.HTTPNotFound:
|
||||
raise exc.CommandError(_('Node not found: %s') % args.node)
|
||||
|
||||
state = cc.node.set_power_state(args.node, args.power_state)
|
||||
field_list = ['current', 'target']
|
||||
data = dict([(f, getattr(state, f, '')) for f in field_list])
|
||||
utils.print_dict(data, wrap=72)
|
||||
|
@ -17,7 +17,6 @@
|
||||
# under the License.
|
||||
|
||||
from ironicclient.common import utils
|
||||
from ironicclient import exc
|
||||
|
||||
|
||||
def _print_port_show(port):
|
||||
@ -29,12 +28,8 @@ def _print_port_show(port):
|
||||
@utils.arg('port', metavar='<port id>', help="UUID of port")
|
||||
def do_port_show(cc, args):
|
||||
"""Show a port."""
|
||||
try:
|
||||
port = cc.port.get(args.port)
|
||||
except exc.HTTPNotFound:
|
||||
raise exc.CommandError('Port not found: %s' % args.port)
|
||||
else:
|
||||
_print_port_show(port)
|
||||
port = cc.port.get(args.port)
|
||||
_print_port_show(port)
|
||||
|
||||
|
||||
def do_port_list(cc, args):
|
||||
@ -78,10 +73,7 @@ def do_port_create(cc, args):
|
||||
def do_port_delete(cc, args):
|
||||
"""Delete a port."""
|
||||
for p in args.port:
|
||||
try:
|
||||
cc.port.delete(p)
|
||||
except exc.HTTPNotFound:
|
||||
raise exc.CommandError('Port not found: %s' % p)
|
||||
cc.port.delete(p)
|
||||
print ('Deleted port %s' % p)
|
||||
|
||||
|
||||
@ -102,8 +94,5 @@ def do_port_delete(cc, args):
|
||||
def do_port_update(cc, args):
|
||||
"""Update a port."""
|
||||
patch = utils.args_array_to_patch(args.op, args.attributes[0])
|
||||
try:
|
||||
port = cc.port.update(args.port, patch)
|
||||
except exc.HTTPNotFound:
|
||||
raise exc.CommandError('Port not found: %s' % args.port)
|
||||
port = cc.port.update(args.port, patch)
|
||||
_print_port_show(port)
|
||||
|
Loading…
x
Reference in New Issue
Block a user