Skip to content
This repository has been archived by the owner on Nov 9, 2020. It is now read-only.

Returning proper exit code in cases where vmdkops admin command fails. #1543

Merged
merged 1 commit into from
Jul 6, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 24 additions & 26 deletions esx_service/cli/vmdkops_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -776,15 +776,15 @@ def human_readable(size_in_bytes):
def policy_create(args):
output = vsan_policy.create(args.name, args.content)
if output:
print(output)
return err_out(output)
else:
print('Successfully created policy: {0}'.format(args.name))


def policy_rm(args):
output = vsan_policy.delete(args.name)
if output:
print(output)
return err_out(output)
else:
print('Successfully removed policy: {0}'.format(args.name))

Expand Down Expand Up @@ -815,7 +815,7 @@ def policy_ls(args):
def policy_update(args):
output = vsan_policy.update(args.name, args.content)
if output:
print(output)
return err_out(output)
else:
print('Successfully updated policy: {0}'.format(args.name))

Expand Down Expand Up @@ -850,9 +850,9 @@ def set_vol_opts(args):
if set_ok:
print('Successfully updated settings for : {0}'.format(args.volume))
else:
print('Failed to update {0} for {1}.'.format(args.options, args.volume))
return err_out('Failed to update {0} for {1}.'.format(args.options, args.volume))
except Exception as ex:
print('Failed to update {0} for {1} - {2}.'.format(args.options,
return err_out('Failed to update {0} for {1} - {2}.'.format(args.options,
args.volume,
str(ex)))

Expand Down Expand Up @@ -899,10 +899,6 @@ def get_version():
except:
return NOT_AVAILABLE

def operation_fail(error_info):
print(error_info)
return error_info

def tenant_ls_headers():
""" Return column names for tenant ls command """
headers = ['Uuid', 'Name', 'Description', 'Default_datastore', 'VM_list']
Expand Down Expand Up @@ -958,7 +954,7 @@ def tenant_create(args):
privileges=[])

if error_info:
return operation_fail(error_info.msg)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is operation_fail still being used? If not, we should remove it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I have removed it. See line 902

return err_out(error_info.msg)
else:
print("vmgroup '{}' is created. Do not forget to run 'vmgroup vm add' to add vm to vmgroup.".format(args.name))

Expand All @@ -970,7 +966,7 @@ def tenant_update(args):
default_datastore=args.default_datastore)

if error_info:
return operation_fail(error_info.msg)
return err_out(error_info.msg)
else:
print("vmgroup modify succeeded")

Expand All @@ -986,20 +982,20 @@ def tenant_rm(args):
error_info = auth_api._tenant_rm(args.name, remove_volumes)

if error_info:
return operation_fail(error_info.msg)
return err_out(error_info.msg)
else:
print("vmgroup rm succeeded")

def tenant_ls(args):
""" Handle tenant ls command """
error_info, tenant_list = auth_api._tenant_ls()
if error_info:
return operation_fail(error_info.msg)
return err_out(error_info.msg)

header = tenant_ls_headers()
error_info, rows = generate_tenant_ls_rows(tenant_list)
if error_info:
print(error_info.msg)
return err_out(error_info.msg)
else:
print(cli_table.create(header, rows))

Expand All @@ -1008,7 +1004,7 @@ def tenant_vm_add(args):
error_info = auth_api._tenant_vm_add(args.name, args.vm_list)

if error_info:
return operation_fail(error_info.msg)
return err_out(error_info.msg)
else:
print("vmgroup vm add succeeded")

Expand All @@ -1017,7 +1013,7 @@ def tenant_vm_rm(args):
error_info = auth_api._tenant_vm_rm(args.name, args.vm_list)

if error_info:
return operation_fail(error_info.msg)
return err_out(error_info.msg)
else:
print("vmgroup vm rm succeeded")

Expand All @@ -1026,7 +1022,7 @@ def tenant_vm_replace(args):
error_info = auth_api._tenant_vm_replace(args.name, args.vm_list)

if error_info:
return operation_fail(error_info.msg)
return err_out(error_info.msg)
else:
print("vmgroup vm replace succeeded")

Expand Down Expand Up @@ -1054,12 +1050,11 @@ def tenant_vm_ls(args):
# Handling _DEFAULT tenant case separately to print info message
# instead of printing empty list
if (args.name == auth_data_const.DEFAULT_TENANT):
print("{0} tenant contains all VMs which were not added to other tenants".format(auth_data_const.DEFAULT_TENANT))
return
return err_out("{0} tenant contains all VMs which were not added to other tenants".format(auth_data_const.DEFAULT_TENANT))

error_info, vms = auth_api._tenant_vm_ls(args.name)
if error_info:
return operation_fail(error_info.msg)
return err_out(error_info.msg)

header = tenant_vm_ls_headers()
rows = generate_tenant_vm_ls_rows(vms)
Expand All @@ -1083,7 +1078,7 @@ def tenant_access_add(args):
)

if error_info:
return operation_fail(error_info.msg)
return err_out(error_info.msg)
else:
print("vmgroup access add succeeded")

Expand All @@ -1103,15 +1098,15 @@ def tenant_access_set(args):
volume_totalsize_in_MB=volume_totalsize_in_MB)

if error_info:
return operation_fail(error_info.msg)
return err_out(error_info.msg)
else:
print("vmgroup access set succeeded")

def tenant_access_rm(args):
""" Handle tenant access rm command """
error_info = auth_api._tenant_access_rm(args.name, args.datastore)
if error_info:
return operation_fail(error_info.msg)
return err_out(error_info.msg)
else:
print("vmgroup access rm succeeded")

Expand Down Expand Up @@ -1147,12 +1142,12 @@ def tenant_access_ls(args):
name = args.name
error_info, privileges = auth_api._tenant_access_ls(name)
if error_info:
return operation_fail(error_info.msg)
return err_out(error_info.msg)

header = tenant_access_ls_headers()
error_info, rows = generate_tenant_access_ls_rows(privileges, name)
if error_info:
print(error_info.msg)
return err_out(error_info.msg)
else:
print(cli_table.create(header, rows))

Expand Down Expand Up @@ -1198,7 +1193,10 @@ def is_local_vmfs(datastore_name):


def err_out(_msg, _info=None):
"""A helper to print a message with (optional) info about DB MOde. Returns the message"""
"""
A helper to print an error message with (optional) info if the vmdkops admin command fails.
Returns the message.
"""
print(_msg)
if _info:
print("Additional information: {}".format(_info))
Expand Down