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

Commit

Permalink
In multinode mode, disallow deleting vmgroup which are not empty
Browse files Browse the repository at this point in the history
Fixes #1188
  • Loading branch information
pshahzeb committed May 3, 2017
1 parent 115bf7d commit ceafdd7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
17 changes: 12 additions & 5 deletions esx_service/utils/auth_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -559,22 +559,29 @@ def _tenant_rm(name, remove_volumes=False):
error_info = generate_error_info(ErrorCode.TENANT_NOT_EXIST, name)
return error_info

error_info, auth_mgr = get_auth_mgr_object()

if error_info:
return error_info

# check if vms that are a part of this tenant have any volumes mounted.
# If they have, can't delete the tenant.
if tenant.vms:
logging.info("_tenant_rm. VMs in tenant are %s", tenant.vms)

# in multinode mode, we cannot find VM residing on another host
# so a gracefull way to admin know about the error
if auth_mgr.mode == auth_data.DBMode.MultiNode:
error_info = generate_error_info(ErrorCode.TENANT_NOT_EMPTY, name)
logging.error(error_info.msg)
return error_info

error_info = vmdk_utils.check_volumes_mounted(tenant.vms)
if error_info:
error_info.msg = "Cannot complete vmgroup rm. " + error_info.msg
logging.error(error_info.msg)
return error_info

error_info, auth_mgr = get_auth_mgr_object()

if error_info:
return error_info

error_msg = auth_mgr.remove_tenant(tenant.id, remove_volumes)
if error_msg:
error_info = generate_error_info(ErrorCode.INTERNAL_ERROR, error_msg)
Expand Down
2 changes: 2 additions & 0 deletions esx_service/utils/error_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class ErrorCode:
TENANT_SET_ACCESS_PRIVILEGES_FAILED = 6
TENANT_GET_FAILED = 7
TENANT_NAME_INVALID = 8
TENANT_NOT_EMPTY = 9 # only used in multinode mode
# Tenant related error code end

# VM related error code start
Expand Down Expand Up @@ -87,6 +88,7 @@ class ErrorCode:
ErrorCode.TENANT_SET_ACCESS_PRIVILEGES_FAILED : "Vmgroup {0} set access privileges on datastore {1} failed with err: {2}",
ErrorCode.TENANT_GET_FAILED : "Get vmgroup {0} failed",
ErrorCode.TENANT_NAME_INVALID : "Vmgroup name {0} is invalid, only {1} is allowed",
ErrorCode.TENANT_NOT_EMPTY : "Cannot delete non empty Vmgroup {0} in Multinode mode. Remove VMs from the Vmgroup before deleting it.",

ErrorCode.VM_NOT_FOUND : "Cannot find vm {0}",
ErrorCode.REPLACE_VM_EMPTY : "Replace VM cannot be empty",
Expand Down

0 comments on commit ceafdd7

Please sign in to comment.