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

Cli auth.liping #640

Merged
merged 3 commits into from
Oct 24, 2016
Merged

Cli auth.liping #640

merged 3 commits into from
Oct 24, 2016

Conversation

lipingxue
Copy link
Contributor

This change includes the code change to enable AdminCLI command to support tenants.
See #620

@lipingxue
Copy link
Contributor Author

Right now, all unit tests are done manually.

  • create a tenant

[root@localhost:~] /usr/lib/vmware/vmdkops/bin/vmdkops_admin.py tenant create --name=tenant1 --vm-list photon4

 [root@localhost:~] /usr/lib/vmware/vmdkops/bin/vmdkops_admin.py tenant ls
Uuid                                  Name     Description  Default_datastore  VM_list  
------------------------------------  -------  -----------  -----------------  -------  
f140cf6e-1fea-42b0-a706-41efc52d195c  tenant1               default_ds         photon4  

 [root@localhost:~] /usr/lib/vmware/vmdkops/bin/vmdkops_admin.py tenant vm ls --name=tenant1
Uuid                                  Name     
------------------------------------  -------  
564df562-3d58-c99a-e76e-e8792b77ca2d  photon4  
  • add vm to tenant
[root@localhost:~] /usr/lib/vmware/vmdkops/bin/vmdkops_admin.py tenant vm add --name=tenant1 --vm-list photon5


[root@localhost:~] /usr/lib/vmware/vmdkops/bin/vmdkops_admin.py tenant ls 
Uuid                                  Name     Description  Default_datastore  VM_list          
------------------------------------  -------  -----------  -----------------  ---------------  
f140cf6e-1fea-42b0-a706-41efc52d195c  tenant1               default_ds         photon4,photon5  

[root@localhost:~] /usr/lib/vmware/vmdkops/bin/vmdkops_admin.py tenant vm ls --name=tenant1
Uuid                                  Name     
------------------------------------  -------  
564df562-3d58-c99a-e76e-e8792b77ca2d  photon4  
564d4728-f1c7-2029-d01e-51f5e6536cd9  photon5  
  • remove vm from tenant
[root@localhost:~] /usr/lib/vmware/vmdkops/bin/vmdkops_admin.py tenant vm rm --name=tenant1 --vm-list photon5

 [root@localhost:~] /usr/lib/vmware/vmdkops/bin/vmdkops_admin.py tenant vm ls --name=tenant1

Uuid                                  Name     
------------------------------------  -------  
564df562-3d58-c99a-e76e-e8792b77ca2d  photon4  

[root@localhost:~] /usr/lib/vmware/vmdkops/bin/vmdkops_admin.py tenant ls
Uuid                                  Name     Description  Default_datastore  VM_list  
------------------------------------  -------  -----------  -----------------  -------  
f140cf6e-1fea-42b0-a706-41efc52d195c  tenant1               default_ds         photon4  

  • Add access control for a (tenant,datastore)
[root@localhost:~] /usr/lib/vmware/vmdkops/bin/vmdkops_admin.py tenant access add --name=tenant1 --datastore=datastore1 --rights all --volume-maxsize=500MB --volume-totalsize=1GB

[root@localhost:~] /usr/lib/vmware/vmdkops/bin/vmdkops_admin.py tenant access ls --name=tenant1
Datastore   Create_volume  Delete_volume  Mount_volume  Max_volume_size  Total_size  
----------  -------------  -------------  ------------  ---------------  ----------  
datastore1  1              1              1             500.00MB         1.00GB      
  • Modify access control for a (tenant,datastore)
[root@localhost:~] /usr/lib/vmware/vmdkops/bin/vmdkops_admin.py tenant access set --name=tenant1 --datastore=datastore1 --rm-rights=mount --volume-maxsize=500MB --volume-totalsize=2GB

[root@localhost:~] /usr/lib/vmware/vmdkops/bin/vmdkops_admin.py tenant access ls --name=tenant1
Datastore   Create_volume  Delete_volume  Mount_volume  Max_volume_size  Total_size  
----------  -------------  -------------  ------------  ---------------  ----------  
datastore1  1              1              0             500.00MB         2.00GB      

[root@localhost:~] /usr/lib/vmware/vmdkops/bin/vmdkops_admin.py tenant access set --name=tenant1 --datastore=datastore1 --add-rights=mount --volume-maxsize=600MB --volume-totalsize=1GB

 [root@localhost:~] /usr/lib/vmware/vmdkops/bin/vmdkops_admin.py tenant access ls --name=tenant1
Datastore   Create_volume  Delete_volume  Mount_volume  Max_volume_size  Total_size  
----------  -------------  -------------  ------------  ---------------  ----------  
datastore1  1              1              1             600.00MB         1.00GB      
  • Remove access control for a (tenant, datastore)
[root@localhost:~] /usr/lib/vmware/vmdkops/bin/vmdkops_admin.py tenant access rm --name=tenant1 --datastore=datastore1

[root@localhost:~] /usr/lib/vmware/vmdkops/bin/vmdkops_admin.py tenant access ls --name=tenant1
Datastore  Create_volume  Delete_volume  Mount_volume  Max_volume_size  Total_size  
---------  -------------  -------------  ------------  ---------------  ----------  

@lipingxue
Copy link
Contributor Author

create two tenants, make sure each tenant can only see volumes belong to that tenant

step 1: create another tenant(tenant2), add vm and access control to this tenant

[root@localhost:~] /usr/lib/vmware/vmdkops/bin/vmdkops_admin.py tenant create --name=tenant2 --vm-list=photon5

 [root@localhost:~] /usr/lib/vmware/vmdkops/bin/vmdkops_admin.py tenant ls
Uuid                                  Name     Description  Default_datastore  VM_list  
------------------------------------  -------  -----------  -----------------  -------  
f140cf6e-1fea-42b0-a706-41efc52d195c  tenant1               default_ds         photon4  
98958c5c-ae85-4a59-8e86-6845b107158c  tenant2               default_ds         photon5  

[root@localhost:~] /usr/lib/vmware/vmdkops/bin/vmdkops_admin.py tenant access add --name=tenant2 --datastore=datastore1 --rights all --volume-maxsize=1GB --volume-totalsize=2TB

[root@localhost:~] /usr/lib/vmware/vmdkops/bin/vmdkops_admin.py tenant ls
Uuid                                  Name     Description  Default_datastore  VM_list  
------------------------------------  -------  -----------  -----------------  -------  
f140cf6e-1fea-42b0-a706-41efc52d195c  tenant1               default_ds         photon4  
98958c5c-ae85-4a59-8e86-6845b107158c  tenant2               default_ds         photon5  

[root@localhost:~] /usr/lib/vmware/vmdkops/bin/vmdkops_admin.py tenant access ls --name=tenant1
Datastore   Create_volume  Delete_volume  Mount_volume  Max_volume_size  Total_size  
----------  -------------  -------------  ------------  ---------------  ----------  
datastore1  1              1              1             600.00MB         1.00GB      

[root@localhost:~] /usr/lib/vmware/vmdkops/bin/vmdkops_admin.py tenant access ls --name=tenant2
Datastore   Create_volume  Delete_volume  Mount_volume  Max_volume_size  Total_size  
----------  -------------  -------------  ------------  ---------------  ----------  
datastore1  1              1              1             1.00GB           2.00TB      

step 2: create two volumes on photon4 (VM which is associated to tenant1)

 root@photon-JQQBWNwG6 [ ~ ]# docker volume ls
DRIVER              VOLUME NAME
root@photon-JQQBWNwG6 [ ~ ]# docker volume create --driver=vmdk --name=tenant1-vol1 -o size=100MB
tenant1-vol1
root@photon-JQQBWNwG6 [ ~ ]# docker volume create --driver=vmdk --name=tenant1-vol2 -o size=100MB
tenant1-vol2

step 3: create two volumes on photon 5 (VM which is associated to tenant2)

root@photon-eZ5ILvREQ [ ~ ]# docker volume ls
DRIVER              VOLUME NAME

root@photon-eZ5ILvREQ [ ~ ]# docker volume create --driver=vmdk --name=tenant2-vol1 -o size=200MB
tenant2-vol1
root@photon-eZ5ILvREQ [ ~ ]# docker volume create --driver=vmdk --name=tenant2-vol2 -o size=200MB
tenant2-vol2

step4: run “docker volume ls” on both VMs, only volumes created by that tenant are listed
On photon4 (tenant1)

root@photon-JQQBWNwG6 [ ~ ]# docker volume ls
DRIVER              VOLUME NAME
vmdk                tenant1-vol1
vmdk                tenant1-vol2

On photon 5(tenant2)

root@photon-eZ5ILvREQ [ ~ ]# docker volume ls
DRIVER              VOLUME NAME
vmdk                tenant2-vol1
vmdk                tenant2-vol2

@lipingxue
Copy link
Contributor Author

unit test for tenant rm command

step 1: remove tenant2

[root@localhost:~] /usr/lib/vmware/vmdkops/bin/vmdkops_admin.py tenant rm --name=tenant2 --remove-volumes=True
 [root@localhost:~] 

[root@localhost:~] /usr/lib/vmware/vmdkops/bin/vmdkops_admin.py tenant ls
Uuid                                  Name     Description  Default_datastore  VM_list  
------------------------------------  -------  -----------  -----------------  -------  
f140cf6e-1fea-42b0-a706-41efc52d195c  tenant1               default_ds         photon4 

step 2: run "docker volume ls" on photon5 (which used to belong to tenant2, but now not belong to any tenant), it will only show volumes which not associated with any tenant

root@photon-eZ5ILvREQ [ ~ ]# docker volume ls
DRIVER              VOLUME NAME
vmdk                non-tenant-vol1
vmdk                non-tenant-vol2
vmdk                non-tenant-vol3

step 3: check the "/vmfs/volumes/datastore1/dockervols/", all volumes under "tenant2" are removed and directory "tenant2" is removed

@lipingxue
Copy link
Contributor Author

unit test for ls command with --tenant option



[root@localhost:~] /usr/lib/vmware/vmdkops/bin/vmdkops_admin.py ls 
Volume           Datastore   Created By VM  Created                   Attached To VM  Policy  Capacity  Used     Filesystem Type  Access      Attach As               
---------------  ----------  -------------  ------------------------  --------------  ------  --------  -------  ---------------  ----------  ----------------------  
non-tenant-vol1  datastore1  photon4        Sun Aug 14 09:36:45 2016  detached        N/A     100.00MB  0B       ext4             read-write  independent_persistent  
non-tenant-vol2  datastore1  photon4        Sun Aug 14 09:40:53 2016  detached        N/A     100.00MB  0B       ext4             read-write  independent_persistent  
non-tenant-vol3  datastore1  photon4        Thu Aug 18 07:22:24 2016  detached        N/A     100.00MB  13.00MB  ext4             read-write  independent_persistent  
tenant1-vol1     datastore1  photon4        Fri Aug 19 16:13:03 2016  detached        N/A     100.00MB  13.00MB  ext4             read-write  independent_persistent  
tenant1-vol2     datastore1  photon4        Fri Aug 19 16:13:11 2016  detached        N/A     100.00MB  13.00MB  ext4             read-write  independent_persistent  

 [root@localhost:~] /usr/lib/vmware/vmdkops/bin/vmdkops_admin.py ls -c=volume,datastore,access
Volume           Datastore   Access      
---------------  ----------  ----------  
non-tenant-vol1  datastore1  read-write  
non-tenant-vol2  datastore1  read-write  
non-tenant-vol3  datastore1  read-write  
tenant1-vol1     datastore1  read-write  
tenant1-vol2     datastore1  read-write  

[root@localhost:~] /usr/lib/vmware/vmdkops/bin/vmdkops_admin.py ls --tenant=tenant1
Volume        Datastore   Created By VM  Created                   Attached To VM  Policy  Capacity  Used     Filesystem Type  Access      Attach As               
------------  ----------  -------------  ------------------------  --------------  ------  --------  -------  ---------------  ----------  ----------------------  
tenant1-vol1  datastore1  photon4        Fri Aug 19 16:13:03 2016  detached        N/A     100.00MB  13.00MB  ext4             read-write  independent_persistent  
tenant1-vol2  datastore1  photon4        Fri Aug 19 16:13:11 2016  detached        N/A     100.00MB  13.00MB  ext4             read-write  independent_persistent  

[root@localhost:~] /usr/lib/vmware/vmdkops/bin/vmdkops_admin.py ls --tenant=tenant1 -c=volume,datastore,access
Volume        Datastore   Access      
------------  ----------  ----------  
tenant1-vol1  datastore1  read-write  
tenant1-vol2  datastore1  read-write  

@lipingxue
Copy link
Contributor Author

lipingxue commented Oct 21, 2016

Please start first round review.
In the meantime, I plan to

  • to do more testings, especially more negative testings to shake out more bugs.
  • add automated testing for those new commands

@msterin
Copy link
Contributor

msterin commented Oct 21, 2016

@lipingxue - please rebase on master (which now has the CLI syntax merged) and re-push , this way we can review the delta only. Thanks

@lipingxue
Copy link
Contributor Author

lipingxue commented Oct 21, 2016

@msterin I have rebased with master and repush the change.
Most of the code related to admin CLI is in vmdkops_admin.py.
Since my previous change at auth.liping branch has not been merged to master yet (still need your final review), the diff in this change will show some changes that I made in auth.liping, which has already been reviewed by Andy and you.

@msterin
Copy link
Contributor

msterin commented Oct 22, 2016

Overall good draft and the logic is sound. Copy-n-paste should be eliminated and some consistency in messages (with the rest of the code) is needed. Also it still has a bunch of files from prior PRs, there is no need to do it - please only push the new code in this PR (you can always branch from the prior PR , this way only delta will show up on the review)

@lipingxue lipingxue merged commit 396dec8 into master Oct 24, 2016
@lipingxue
Copy link
Contributor Author

I incorrectly merged commit(SHA 396dec8) into master branch. This merge has been revert from master by Ritesh.

brunotm added a commit to brunotm/docker-volume-vsphere that referenced this pull request Oct 26, 2016
* master: (25 commits)
  Update new ESX IP
  added forgotten .so file
  Install sqlite3 py libs on ESX and load for Python2
  Added py code and binaries for sqlite3 python libs
  Update drone security
  Removed accidental .pyc files
  Handle byte to string conversions for status command.
  Auth configuration and operation admission check (Auth.liping) (vmware-archive#603)
  Revert "Cli auth.liping"
  Cli auth.liping (vmware-archive#640)
  Handle missing or invalid fs type on mount. (vmware-archive#639)
  Updated Admin CLI commands to support tenants. (vmware-archive#620)
  Workaround older versions of e2fsprogs (vmware-archive#631)
  Add auth proposal
  Made handing of missing metafile less harsh. (vmware-archive#627)
  Fixed ACLs in payload bin dir (vmware-archive#624)
  Fixed error handling for set command. (vmware-archive#610)
  Use new error variables when rolling back volume creation to avoid nil reassignment. (vmware-archive#617)
  Change wording
  Fix broken link
  ...
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants