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

Create volume on default datastore if default_ds is set for _DEFAULT tenant #1095

Merged
merged 5 commits into from
Mar 30, 2017

Conversation

lipingxue
Copy link
Contributor

@lipingxue lipingxue commented Mar 27, 2017

Fixed #1044
This PR includes the fix for:

  1. Datastore used for the first "user created" privilege will be set to "default_ds" for that tenant.
  2. When creating Docker volume with short name from a VM in __DEFAULT tenant, use "default_ds" (if set) , not the vm_datastore

@lipingxue lipingxue force-pushed the create_vol_on_default_ds.liping branch from 0c9e3ba to a65fb75 Compare March 29, 2017 17:52
@lipingxue
Copy link
Contributor Author

Per offline discussion with Mark and Sam, I reverted the change in _tenant_access_add.
User need to specify --default-datastore flag when running vm-group access add to
set the default datastore for a vm-group. After setting, user can run vm-group ls to list the vm-group and the column Default_datastore will show the default datastore of that vm-group.

@lipingxue
Copy link
Contributor Author

Run the following test manually.
Configuration: VM "photon-6" is created on "datastore1". This VM belongs _DEFAULT tenant.

step1: Add a privilege for _DEFAULT vm-group with "--default-datastore" flag specified to set the default datastore of _DEFAULT vm-group to "datastore2"

[root@localhost:~] /usr/lib/vmware/vmdkops/bin/vmdkops_admin.py vm-group ls
Uuid                                  Name      Description               Default_datastore  VM_list  
------------------------------------  --------  ------------------------  -----------------  -------  
11111111-1111-1111-1111-111111111111  _DEFAULT  This is a default tenant            

[root@localhost:~] /usr/lib/vmware/vmdkops/bin/vmdkops_admin.py vm-group access add --name=_DEFAULT --datastore=datastore2 --allow-create --default-datastore
vm-group access add succeeded
[root@localhost:~] 
[root@localhost:~] 
[root@localhost:~] /usr/lib/vmware/vmdkops/bin/vmdkops_admin.py vm-group access ls --name=_DEFAULT
Datastore   Allow_create  Max_volume_size  Total_size  
----------  ------------  ---------------  ----------  
datastore2  True          Unset            Unset       
            True          Unset            Unset       

step2: check default_datastore of vm-group _DEFAULT

[root@localhost:~] /usr/lib/vmware/vmdkops/bin/vmdkops_admin.py vm-group ls
Uuid                                  Name      Description               Default_datastore  VM_list  
------------------------------------  --------  ------------------------  -----------------  -------  
11111111-1111-1111-1111-111111111111  _DEFAULT  This is a default tenant  datastore2                  

step3: create a volume with short name, make sure this volume is created on the default datastore "datastore2" instead of vm datastore "datastore1".

root@photon-KwqUODFXp [ ~ ]# docker volume ls
DRIVER              VOLUME NAME
root@photon-KwqUODFXp [ ~ ]# 
root@photon-KwqUODFXp [ ~ ]# docker volume create --driver=vsphere --name=vol1
vol1
root@photon-KwqUODFXp [ ~ ]# 
root@photon-KwqUODFXp [ ~ ]# docker volume ls
DRIVER              VOLUME NAME
vsphere             vol1@datastore2

@lipingxue
Copy link
Contributor Author

@msterin @shaominchen I have changed this PR per yesterday's offline discussion. Please review it, thanks!

Copy link
Contributor

@shuklanirdesh82 shuklanirdesh82 left a comment

Choose a reason for hiding this comment

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

@lipingxue

Your changes looks OK to me. Can you please add some basic automated tests with your proposed code?

Thanks!

Copy link
Contributor

@shaominchen shaominchen left a comment

Choose a reason for hiding this comment

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

LGTM.

Copy link
Contributor

@msterin msterin left a comment

Choose a reason for hiding this comment

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

So this fixes the main issue - "when default_ds for named tenant is set, use it instead of VM DS", right ?

The code LGTM - please make sure CI passes before merge

"""
Check if need update default_datastore for this tenant
"""
# In _tenant_access_add, we decide to automatically set the datastore for the first user added privilege
Copy link
Contributor

Choose a reason for hiding this comment

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

Please run this comment by someone in the office - the comment looks very confusing to me but maybe I am reading it wrong

@@ -654,6 +654,35 @@ def check_privilege_parameters(privilege):

return None

def need_update_default_ds(conn, tenant_id):
"""
Check if need update default_datastore for this tenant
Copy link
Contributor

Choose a reason for hiding this comment

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

so what does it return ? Why a tuple ?

@@ -654,6 +654,35 @@ def check_privilege_parameters(privilege):

return None

def need_update_default_ds(conn, tenant_id):
Copy link
Contributor

Choose a reason for hiding this comment

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

the name is confusing. I can't suggest a better name because I don't understand what this is doing. Can you elaborate ?


# if default_datastore is not set for tenant,
# default_datastore_url will be set to None
error_info, default_datastore_url = auth_api.get_default_datastore_url(tenant_name)
Copy link
Contributor

Choose a reason for hiding this comment

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

please update the admin command line message on group creation to something like "vm-group xxx is created. Do not forget to vm-group vm add and vm-group privilege add to enable better access control"
(adjust to reflect the correct commands please)

@lipingxue
Copy link
Contributor Author

@msterin @shuklanirdesh82 I have addressed your comments. Please review it.

Copy link
Contributor

@msterin msterin left a comment

Choose a reason for hiding this comment

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

LGTM with 1 request to change the message text before merge

@@ -854,7 +854,8 @@ def tenant_create(args):
if error_info:
return operation_fail(error_info.msg)
else:
print("vm-group create succeeded")
print("vm-group create succeeded. vm-group '{}' is created. Do not forget to run "
"command 'vm-group vm add' and 'vm-group access add' to enable better access control.".format(args.name))
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggestion:
"vm-group '{}' is created. Do not forget to run 'vm-group vm add' and 'vm-group access add' commands to enable access control.".format(args.name))

@lipingxue lipingxue merged commit 67bf73c into master Mar 30, 2017
@shuklanirdesh82 shuklanirdesh82 deleted the create_vol_on_default_ds.liping branch March 31, 2017 07:58
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[DEFAULT tenant] Volume is created on the datastore where vm resides and not on specified default-datastore
5 participants