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

VMODL API for multi-tenancy support #754

Merged
merged 14 commits into from
Dec 12, 2016
Merged

Conversation

shaominchen
Copy link
Contributor

@shaominchen shaominchen commented Nov 19, 2016

The implementation (to integrate with auth_api) has not been implemented yet. Please review the API signatures first.

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.

Looks generally good , no comments for the the content of the model . JavaDocs should be a bit more elaborate, it's awfully short now :-).
[Sam] Agree with you. Will add more detailed JavaDocs.

More comments inline.

BTW I think we need to remove the Java file with the (obsolete) model draft
[Sam] Will do.


@JavaDocs(parent=_name, docs =
"""
Max volume size allowed on this datastore
Copy link
Contributor

Choose a reason for hiding this comment

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

need units. I suggest the attribute name to have "in_bytes" or whatever at the end. Actually, in_Mib should be fine

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 PR will include VMODL definitions only. In the next PR I will provide the implementation along with the unit tests.

Will add _in_MiB suffix.

"""
)
@Attribute(parent=_name, typ="string")
def usage_quota(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

_in_MiB ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, will add _in_MiB suffix.


@JavaDocs(parent=_name, docs =
"""
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.

what if the datastore name changes (and url stays the same) ? Should we keep url here ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch! I will use datastore URL instead. BTW, this issue already exists in the existing logic. I have filed a tracking issue: #782.


@JavaDocs(parent=_name, docs =
"""
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.

Any limitations ? Length ? Char set ? Can it be unicode ?

Copy link
Contributor Author

@shaominchen shaominchen Nov 29, 2016

Choose a reason for hiding this comment

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

Will document the length limitation for name and description.

AFAIK, VMODL string supports unicode on all different language bindings: C++, Java, Python, etc. But this is implicit and we don't usually document this in the JavaDoc.

"""
)
@Method(parent=_name, wsdlName="AddVMs")
@Param(name="vms", typ="string[]")
Copy link
Contributor

Choose a reason for hiding this comment

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

a question abut all *VMs() operations: should we use vim.VirtualMachine MoRef instead of strings here ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will use MoRef consistently for all references of VMs and Datastores.

"""
)
@Method(parent=_name, wsdlName="RemoveTenant")
@Param(name="name", typ="string")
Copy link
Contributor

Choose a reason for hiding this comment

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

vim.vcs.Tenant instead of string here ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since all Tenant related APIs use tenant name as the unique key, I think it makes sense to also use name as the key for this API. What do you think?


@JavaDocs(parent=_name, docs=
"""
Query Tenants for the given name. Return all Tenants if name is null.
Copy link
Contributor

Choose a reason for hiding this comment

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

will we support globbing (e.g. ? *) If yes needs to be documented

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've thought about this. Globbing is typically used by shells for matching file and directory names using wildcards. Even though our Tenant name does map to a directory in the backend, this implementation detail should not be exposed to customers. Regular expressions are actually more commonly used in commands / functions for pattern matching in string text. However, supporting regex seems an overkill for our current requirements.

So, for now I think we can keep it simple, i.e. not supporting globbing or regex. In the future if there are real requirements for this, we can add this feature without breaking backward compatibility.

@Param(name="new_name", typ="string", flags=F_OPTIONAL)
@Param(name="new_description", typ="string", flags=F_OPTIONAL)
@Return(typ="void")
def RemoveTenant(self, name):
Copy link
Contributor

Choose a reason for hiding this comment

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

needs to be ModifyTenant

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy-paste error. Will fix.



# _VERSION = newestVersions.Get("vim")
_VERSION = 'vim.version.version10'
Copy link
Contributor

Choose a reason for hiding this comment

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

I think common modules import and version should be imported from a single file instead of copy-pasted to each module

Copy link
Contributor Author

@shaominchen shaominchen Nov 30, 2016

Choose a reason for hiding this comment

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

Make sense, will introduce a common module for this.

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've decided to merge all classes into one single file/module as this seems more consistent with Python style. So no need to introduce a common module anymore.

@Method(parent=_name, wsdlName="RemoveVMs")
@Param(name="vms", typ="string[]")
@Return(typ='void')
def RemoveVMsFromTenant(self, vms):
Copy link
Contributor

Choose a reason for hiding this comment

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

Rename to "RemoveVMs"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will fix.

This class provides operations to manage VMs and privileges associated with a tenant.
'''

_name = "vim.vcs.TenantManager"
Copy link
Contributor

Choose a reason for hiding this comment

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

_name should not be "vim.vcs.TenantManager". This class is a "Tenant" class.

Copy link
Contributor Author

@shaominchen shaominchen Nov 30, 2016

Choose a reason for hiding this comment

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

Thanks for catching this. Will fix.

Copy link
Contributor

@lipingxue lipingxue left a comment

Choose a reason for hiding this comment

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

Overall looks good.
A general comment is we need to think about how to handle the exception in all VMODL functions? We should define some faults for "VsphereContainerService". This can be addressed in separate PR.

)
@Method(parent=_name, wsdlName="RemoveTenant")
@Param(name="name", typ="string")
@Param(name="remove_volumes", typ="boolean")
Copy link
Contributor

Choose a reason for hiding this comment

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

param "remove_volumes" is a "optional" param.

Copy link
Contributor

Choose a reason for hiding this comment

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

All functions in class "TenantManager" can also through exception. For example "CreateTenant" may through an exception when the name specified is the same as existing tenant.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will address this.


@JavaDocs(parent=_name, docs =
"""
Tenant is an abstraction of a group of VMs and the associated access
Copy link
Contributor

Choose a reason for hiding this comment

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

I think Tenant is an abstraction of "a group of VMs", but not the "associated access privileges".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will clarify a little bit.

"""
)
@Method(parent=_name, wsdlName="AddPrivilege")
@Param(name="privilege", typ="vim.vcs.storage.DatastoreAccessPrivilege")
Copy link
Contributor

Choose a reason for hiding this comment

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

As we discussed, user should be able to switch "default_datastore" when adding a new datastore access privilege. So we need a new param "switch_default_datastore" here.

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 will address this in next update.

@shaominchen
Copy link
Contributor Author

@msterin @lipingxue

I've updated the PR based on your comments. Also redesigned some APIs. Major changes since last update:

  1. Add detailed comments for all classes, methods, fields, parameters, return values and exceptions.
  2. Add exception handling for all VMODL APIs
  3. Use MoRef for all Datastore and VM references
  4. Merge all classes into one single file/module

Exception handling is a major missing part that we haven't discussed before. I plan to introduce one or more exceptions to handle all different error conditions. Maybe we should have a discussion about this after everyone is back.

@shaominchen
Copy link
Contributor Author

@lipingxue Addressed your comments.

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. One nit about the naming - please take a look

faults=["vim.fault.NotFound"])
@Param(name="datastore", typ="vim.Datastore", flags=F_OPTIONAL)
@Return(typ='vim.vcs.storage.DatastoreAccessPrivilege[]')
def GetPrivileges(self, datastore):
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: it feels strange that AddPrivilige is singular but GetPrivileges is plural. I suggest to stick with singular everywhere.

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'm actually following existing VSAN VMODL style. Basically, if the return type is an array, the name will be plural, for example: GetTenants, GetVMs, GetPrivileges. Or if the input parameter is an array, the name is also plural: AddVMs, RemoveVMs, ReplaceVMs.

Please let me know if you still have concern about this. I can change it in the next PR if needed.

@lipingxue
Copy link
Contributor

LGTM to me.

@shaominchen shaominchen changed the title VMODL API for multi-tenancy support [DRAFT] VMODL API for multi-tenancy support Dec 12, 2016
@shaominchen shaominchen merged commit 5630254 into master Dec 12, 2016
@shaominchen shaominchen deleted the vmodl_multi_tenancy.shchen branch December 12, 2016 19:11
# 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