Skip to content
This repository was archived by the owner on Sep 22, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changes/96.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add usage_mode and permission option in creating vfolder
23 changes: 18 additions & 5 deletions src/ai/backend/client/cli/vfolder.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ def list(list_all):
('ID', 'id'),
('Owner', 'is_owner'),
('Permission', 'permission'),
('Type', 'type'),
('Owership Type', 'ownership_type'),
('Usage Mode', 'usage_mode'),
('User', 'user'),
('Group', 'group'),
]
Expand Down Expand Up @@ -77,7 +78,15 @@ def list_allowed_types():
@click.option('--unmanaged', 'host_path', type=bool, is_flag=True,
help='Treats HOST as a mount point of unmanaged virtual folder. '
'This option can only be used by Admin or Superadmin.')
def create(name, host, group, host_path):
@click.option('-m', '--usage-mode', metavar='USAGE_MODE', type=str, default='general',
help='Purpose of the folder. Normal folders are usually set to "general". '
'Available options: "general", "data" (provides data to users), '
'and "model" (provides pre-trained models).')
@click.option('-p', '--permission', metavar='PERMISSION', type=str, default='rw',
help='Folder\'s innate permission. '
'Group folders can be shared as read-only by setting this option to "ro".'
'Invited folders override this setting by its own invitation permission.')
def create(name, host, group, host_path, usage_mode, permission):
'''Create a new virtual folder.

\b
Expand All @@ -87,9 +96,11 @@ def create(name, host, group, host_path):
with Session() as session:
try:
if host_path:
result = session.VFolder.create(name=name, unmanaged_path=host, group=group)
result = session.VFolder.create(name=name, unmanaged_path=host, group=group,
usage_mode=usage_mode, permission=permission)
else:
result = session.VFolder.create(name=name, host=host, group=group)
result = session.VFolder.create(name=name, host=host, group=group,
usage_mode=usage_mode, permission=permission)
print('Virtual folder "{0}" is created.'.format(result['name']))
except Exception as e:
print_error(e)
Expand Down Expand Up @@ -148,7 +159,9 @@ def info(name):
print('- Owner:', result['is_owner'])
print('- Permission:', result['permission'])
print('- Number of files: {0}'.format(result['numFiles']))
print('- Type: {0}'.format(result['type']))
print('- Ownership Type: {0}'.format(result['ownership_type']))
print('- Permission:', result['permission'])
print('- Usage Mode: {0}'.format(result['usage_mode']))
print('- Group ID: {0}'.format(result['group']))
print('- User ID: {0}'.format(result['user']))
except Exception as e:
Expand Down
4 changes: 4 additions & 0 deletions src/ai/backend/client/func/vfolder.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,17 @@ async def create(
host: str = None,
unmanaged_path: str = None,
group: str = None,
usage_mode: str = 'general',
permission: str = 'rw',
):
rqst = Request(api_session.get(), 'POST', '/folders')
rqst.set_json({
'name': name,
'host': host,
'unmanaged_path': unmanaged_path,
'group': group,
'usage_mode': usage_mode,
'permission': permission,
})
async with rqst.fetch() as resp:
return await resp.json()
Expand Down