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

Updated Admin CLI commands to support tenants. #620

Merged
merged 3 commits into from
Oct 21, 2016
Merged

Conversation

msterin
Copy link
Contributor

@msterin msterin commented Oct 14, 2016

Defines the syntax for the following vmdkops_admin.py commands:

tenant {create, rm , ls} - manipulates tenants
tenant vm {add, rm, ls}  - manipulates VMs for a tenant
tenant access {add, set, rm, ls} - manipulates datastore access right for a tenant

Note that the actual commands implementation is still TBD - this change only defines
new command syntax and keywords. When invoked with correct arguments, the commands simply print Not implemented.

//CC @andrewjstone @lipingxue @marksoper

Note: doc update is tracked in #622

TESTED: manually , by asking for --help. Log below

[root@localhost:~] 
[root@localhost:~] /usr/lib/vmware/vmdkops/bin/vmdkops_admin.py  status 
Version: 0.7.3eb1146-0.0.1
Status: Running
Pid: 51662
Port: 1019
LogConfigFile: /etc/vmware/vmdkops/log_config.json
LogFile: /var/log/vmware/vmdk_ops.log
LogLevel: DEBUG
[root@localhost:~] /usr/lib/vmware/vmdkops/bin/vmdkops_admin.py tenant
usage: vmdkops_admin.py tenant [-h] {access,rm,create,ls,vm} ...
vmdkops_admin.py tenant: error: too few arguments
[root@localhost:~] /usr/lib/vmware/vmdkops/bin/vmdkops_admin.py tenant create --help 
usage: vmdkops_admin.py tenant create [-h] [--vm-list vm1, vm2, ...] name

positional arguments:
  name                  The name of the tenant

optional arguments:
  -h, --help            show this help message and exit
  --vm-list vm1, vm2, ...
                        A list of VM names to place in this Tenant
[root@localhost:~] /usr/lib/vmware/vmdkops/bin/vmdkops_admin.py tenant rm --help 
usage: vmdkops_admin.py tenant rm [-h] [--remove-volumes REMOVE_VOLUMES] name

positional arguments:
  name                  The name of the tenant

optional arguments:
  -h, --help            show this help message and exit
  --remove-volumes REMOVE_VOLUMES
                        BE CAREFUL - Removes this tenant volumes when removing
                        a tenant
[root@localhost:~] /usr/lib/vmware/vmdkops/bin/vmdkops_admin.py tenant ls --help 
usage: vmdkops_admin.py tenant ls [-h]

optional arguments:
  -h, --help  show this help message and exit
[root@localhost:~] /usr/lib/vmware/vmdkops/bin/vmdkops_admin.py tenant vm --help 
usage: vmdkops_admin.py tenant vm [-h] {rm,add,ls} ...

positional arguments:
  {rm,add,ls}
    rm         Remove VM(s) from a tenant
    add        Add a VM(s) to a tenant
    ls         list VMs in a tenant

optional arguments:
  -h, --help   show this help message and exit
[root@localhost:~] /usr/lib/vmware/vmdkops/bin/vmdkops_admin.py tenant vm add --help 
usage: vmdkops_admin.py tenant vm add [-h] --name NAME --vm-list VM_LIST

optional arguments:
  -h, --help         show this help message and exit
  --name NAME        Tenant to add the VM to
  --vm-list VM_LIST  A list of VM names to add to this Tenant
[root@localhost:~] /usr/lib/vmware/vmdkops/bin/vmdkops_admin.py tenant vm rm --help 
usage: vmdkops_admin.py tenant vm rm [-h] --name NAME --vm-list VM_LIST

optional arguments:
  -h, --help         show this help message and exit
  --name NAME        Tenant to remove the VM from
  --vm-list VM_LIST  A list of VM names to rm from this Tenant
[root@localhost:~] /usr/lib/vmware/vmdkops/bin/vmdkops_admin.py tenant vm ls --help 
usage: vmdkops_admin.py tenant vm ls [-h] [--name NAME]

optional arguments:
  -h, --help   show this help message and exit
  --name NAME  Tenant to list the VMs for
[root@localhost:~] /usr/lib/vmware/vmdkops/bin/vmdkops_admin.py tenant access --help 
usage: vmdkops_admin.py tenant access [-h] {rm,add,set,ls} ...

positional arguments:
  {rm,add,set,ls}
    rm             Remove all access to a datastore for a tenant
    add            Add a datastore access for a tenant
    set            Modify datastore access for a tenant
    ls             List all access info for a tenant

optional arguments:
  -h, --help       show this help message and exit
[root@localhost:~] /usr/lib/vmware/vmdkops/bin/vmdkops_admin.py tenant access add --help 
usage: vmdkops_admin.py tenant access add [-h] --name NAME
                                          [--volume-maxsize Num{MB,GB,TB} - e.g. 2TB]
                                          --datastore DATASTORE
                                          [--rights create,delete,mount]

optional arguments:
  -h, --help            show this help message and exit
  --name NAME           The name of the tenant
  --volume-maxsize Num{MB,GB,TB} - e.g. 2TB
                        Maximum size of the volume that can be created
  --datastore DATASTORE
                        Datastore which access is controlled
  --rights create,delete,mount
                        Datastore access Permissions granted: Choices =
                        ['create', 'delete', 'mount', 'all']
[root@localhost:~] /usr/lib/vmware/vmdkops/bin/vmdkops_admin.py tenant access rm  --help 
usage: vmdkops_admin.py tenant access rm [-h] --name NAME --datastore
                                         DATASTORE

optional arguments:
  -h, --help            show this help message and exit
  --name NAME           The name of the tenant
  --datastore DATASTORE
                        Datstore which access is controlled
[root@localhost:~] /usr/lib/vmware/vmdkops/bin/vmdkops_admin.py tenant access set --help 
usage: vmdkops_admin.py tenant access set [-h]
                                          [--rm-rights create,delete,mount]
                                          --name NAME
                                          [--volume-maxsize Num{MB,GB,TB} - e.g. 2TB]
                                          [--add-rights create,delete,mount]
                                          --datastore DATASTORE

optional arguments:
  -h, --help            show this help message and exit
  --rm-rights create,delete,mount
                        Datastore access Permissions granted: Choices =
                        ['create', 'delete', 'mount', 'all']
  --name NAME           Tenant name
  --volume-maxsize Num{MB,GB,TB} - e.g. 2TB
                        Maximum size of the volume that can be created
  --add-rights create,delete,mount
                        Datastore access Permissions granted: Choices =
                        ['create', 'delete', 'mount', 'all']
  --datastore DATASTORE
                        Datastore name
[root@localhost:~] /usr/lib/vmware/vmdkops/bin/vmdkops_admin.py tenant access ls --help 
usage: vmdkops_admin.py tenant access ls [-h] --name NAME

optional arguments:
  -h, --help   show this help message and exit
  --name NAME  The name of the tenant

@pdhamdhere
Copy link
Contributor

@msterin I think you need to fix tests to remove "role" subcommand. For DS access, I only see maxVolSize. Does underlying API support maxNumVols or quota-Per-Datastore?

@msterin
Copy link
Contributor Author

msterin commented Oct 14, 2016

@pdhamdhere - yes, that's what happens in a rush :-). Thanks for the review, I will fix tests/ add numvol/quota and refresh the PR

@msterin msterin force-pushed the cli-auth.msterin branch 2 times, most recently from be031a4 to 94106c3 Compare October 14, 2016 20:05
@@ -11,7 +11,9 @@ All output from the admin cli defaults to human readable formats. It will be mad
The majority of testing will be automated. We can ensure that parsing calls the right callbacks with
the right information by generating representative input and mocking the callbacks to assert that
the right information is parsed and delivered correctly. Additionally, and specifically for testing
roles, we can create roles and then test that they act as expected by calling `role get`. Unit
access control, we can create access controk definition (tenants and privileges)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit - "control"

@@ -11,7 +11,9 @@ All output from the admin cli defaults to human readable formats. It will be mad
The majority of testing will be automated. We can ensure that parsing calls the right callbacks with
the right information by generating representative input and mocking the callbacks to assert that
the right information is parsed and delivered correctly. Additionally, and specifically for testing
roles, we can create roles and then test that they act as expected by calling `role get`. Unit
access control, we can create access controk definition (tenants and privileges)
and then test that they act as expected by invoking vmdk_ops commmands on behalf of a fake VM.
Copy link
Contributor

Choose a reason for hiding this comment

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

Can suggest using the dummy VM created with vim-cmd and say how that can be created.

the subcommand. Subcommands can have further subcommands, but currently there is only
one level of subcommands in this specification. Each subcommand can contain the same
attributes as top level commands: (func, help, args, cmds). These attributes have
identical usage to the top-level keys, except they only apply when the subcommand is
part of the command. For example the `--matches-vm` argument only applies to `role
create` or `role set` commands. It will be invalid in any other context.
part of the command. For example the `--matches-vm` argument only applies to `tenant
Copy link
Contributor

Choose a reason for hiding this comment

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

The --matches-vm option seems to be removed. Remove it from here as well.

@@ -121,6 +121,9 @@ def commands():
'attached-to', 'policy', 'capacity', 'used',
'fstype', 'access', 'attach-as'],
'metavar': 'Col1,Col2,...'
},
'--tenant' : {
'help': 'Displays only VMs for a given tenant'
Copy link
Contributor

Choose a reason for hiding this comment

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

Are there any entities to display besides VMs, if not then can reword as "Displays VMs for a given tenant".

@@ -121,6 +121,9 @@ def commands():
'attached-to', 'policy', 'capacity', 'used',
'fstype', 'access', 'attach-as'],
'metavar': 'Col1,Col2,...'
},
'--tenant' : {
'help': 'Displays only VMs for a given tenant'
Copy link
Contributor

@govint govint Oct 16, 2016

Choose a reason for hiding this comment

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

Should --tenant be a part of the ls command? It seems to be listing volumes by default.

Instead we could have like:

vmdkops_admin with commands like
a. volume - ls, create, rm, set
b. tenant - ls, create, rm, set
c.

Which is how most of the admin cli commands are laid out?
which matches with esxcli type command options where we have broad categories within which the same CRUD options are available (list, create, delete, ....)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this command is supposed to do LS on volumes , filtered by a tenant.

},
'--remove-volumes': {
'help': 'BE CAREFUL - Removes this tenant volumes when removing a tenant'
}
Copy link
Contributor

@govint govint Oct 16, 2016

Choose a reason for hiding this comment

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

Or something like "WARNING: - Removes the named tenant's volumes from all datastores the tenant has access to.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think it's much better

'func': role_rm,
'help': 'Delete a role',
'func': tenant_rm,
'help': 'Delete a tenant',
Copy link
Contributor

Choose a reason for hiding this comment

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

"Remove a tenant" as its tenant_rm vs. tenant_delete?

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, all commands are "rm"

'metavar': 'create,delete,mount'
},
'--rm-rights': {
'help': 'Datastore access Permissions granted',
Copy link
Contributor

Choose a reason for hiding this comment

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

"Datastore access permissions removed"

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, rm-rights must allow a way to specify a list of datastores or "all" datastores in one go.

'required': True
},
'--datastore': {
'help': "Datastore name",
Copy link
Contributor

Choose a reason for hiding this comment

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

This should really be a list, else users need to run the command for each and every datastore which is an effort.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree but I am not sure how to configure it. @andrewjstone - any hints here ?

Copy link
Contributor

Choose a reason for hiding this comment

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

I like the concept of accepting datastore list. However, that can be separate PR/improvement.

'args': {
'--name': {
'help': 'The name of the tenant',
'required': True
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be a list, a use case would be user wants to retire a datastore. User should be able to get all tenants to stop using the datastore.

'args': {
'--name': {
'help': 'The name of the tenant',
'required': True
Copy link
Contributor

Choose a reason for hiding this comment

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

Again, list for named tenants or make required as "False" and when not provided list access for all tenants.

@@ -324,7 +430,7 @@ def make_list_of_values(allowed):
Take a list of allowed values for an option and return a function that can be
used to typecheck a string of given values and ensure they match the allowed
values. This is required to support options that take comma seperated lists
such as --rights in 'role set --rights=create,delete,mount'
such as --rights in 'tenant set --rights=create,delete,mount'
Copy link
Contributor

Choose a reason for hiding this comment

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

Reword this to mention --add-rights or --rm-rights for tenent access set command.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that is just an example in comments, it does not need to enumerate all usages

@@ -352,6 +458,8 @@ def ls(args):
else:
header = all_ls_headers()
rows = generate_ls_rows()
if args.tenant:
print("TBD: print only VMS for the tenant ", args.tenant) # TODO
Copy link
Contributor

Choose a reason for hiding this comment

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

"Print VMs included for the tenant."

Copy link
Contributor

@govint govint left a comment

Choose a reason for hiding this comment

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

Comments on changes to options and command descriptions.

Mark Sterin added 2 commits October 16, 2016 15:34
Note that the actual commands implementation is still TBD - this change only defines
new command syntax and keywords
@msterin
Copy link
Contributor Author

msterin commented Oct 16, 2016

@govint - thanks for the review ! I replied to some of the comments and fixed the rest. Everything not replied to is fixed.

Copy link
Contributor

@pdhamdhere pdhamdhere left a comment

Choose a reason for hiding this comment

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

LGTM.

'required': True
},
'--datastore': {
'help': "Datastore name",
Copy link
Contributor

Choose a reason for hiding this comment

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

I like the concept of accepting datastore list. However, that can be separate PR/improvement.

'func': role_rm,
'help': 'Delete a role',
'func': tenant_rm,
'help': 'Delete a tenant',
Copy link
Contributor

Choose a reason for hiding this comment

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

Delete an "empty"? tenant?

@pdhamdhere
Copy link
Contributor

CC/ @lipingxue Can you please review?

@lipingxue lipingxue mentioned this pull request Oct 21, 2016
@msterin msterin merged commit 153cf67 into master Oct 21, 2016
@msterin msterin deleted the cli-auth.msterin branch October 22, 2016 00:42
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? #.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants