Merge "Create message variables for exceptions"

This commit is contained in:
Jenkins 2014-08-24 20:20:08 +00:00 committed by Gerrit Code Review
commit 97d1bbdafd
3 changed files with 15 additions and 10 deletions

View File

@ -57,8 +57,9 @@ class CreateKeypair(show.ShowOne):
with open(os.path.expanduser(parsed_args.public_key)) as p: with open(os.path.expanduser(parsed_args.public_key)) as p:
public_key = p.read() public_key = p.read()
except IOError as e: except IOError as e:
raise exceptions.CommandError( msg = "Key file %s not found: %s"
"Key file %s not found: %s" % (parsed_args.public_key, e)) raise exceptions.CommandError(msg
% (parsed_args.public_key, e))
keypair = compute_client.keypairs.create( keypair = compute_client.keypairs.create(
parsed_args.name, parsed_args.name,

View File

@ -300,19 +300,22 @@ class CreateServer(show.ShowOne):
raise exceptions.CommandError("Can't open '%s': %s" % (src, e)) raise exceptions.CommandError("Can't open '%s': %s" % (src, e))
if parsed_args.min > parsed_args.max: if parsed_args.min > parsed_args.max:
raise exceptions.CommandError("min instances should be <= " msg = "min instances should be <= max instances"
"max instances") raise exceptions.CommandError(msg)
if parsed_args.min < 1: if parsed_args.min < 1:
raise exceptions.CommandError("min instances should be > 0") msg = "min instances should be > 0"
raise exceptions.CommandError(msg)
if parsed_args.max < 1: if parsed_args.max < 1:
raise exceptions.CommandError("max instances should be > 0") msg = "max instances should be > 0"
raise exceptions.CommandError(msg)
userdata = None userdata = None
if parsed_args.user_data: if parsed_args.user_data:
try: try:
userdata = open(parsed_args.user_data) userdata = open(parsed_args.user_data)
except IOError as e: except IOError as e:
raise exceptions.CommandError("Can't open '%s': %s" % msg = "Can't open '%s': %s"
raise exceptions.CommandError(msg %
(parsed_args.user_data, e)) (parsed_args.user_data, e))
block_device_mapping = dict(v.split('=', 1) block_device_mapping = dict(v.split('=', 1)
@ -1082,8 +1085,8 @@ class SetServer(command.Command):
if p1 == p2: if p1 == p2:
server.change_password(p1) server.change_password(p1)
else: else:
raise exceptions.CommandError( msg = "Passwords do not match, password unchanged"
"Passwords do not match, password unchanged") raise exceptions.CommandError(msg)
class ShowServer(show.ShowOne): class ShowServer(show.ShowOne):

View File

@ -208,7 +208,8 @@ class SetNetwork(command.Command):
if parsed_args.shared is not None: if parsed_args.shared is not None:
body['shared'] = parsed_args.shared body['shared'] = parsed_args.shared
if body == {}: if body == {}:
raise exceptions.CommandError("Nothing specified to be set") msg = "Nothing specified to be set"
raise exceptions.CommandError(msg)
update_method = getattr(client, "update_network") update_method = getattr(client, "update_network")
update_method(_id, {'network': body}) update_method(_id, {'network': body})
return return