Skip to content

Instantly share code, notes, and snippets.

@alfredcai
Last active April 3, 2018 22:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alfredcai/712f711147dbe75a854a5d989544d613 to your computer and use it in GitHub Desktop.
Save alfredcai/712f711147dbe75a854a5d989544d613 to your computer and use it in GitHub Desktop.
set dataset quota by FreeNas API
class DatasetResource(DojoResource):
# ...other functions
def obj_create(self, bundle, **kwargs):
bundle = self.full_hydrate(bundle)
props = None
dataset_quota = bundle.data.get('quota')
if dataset_quota:
props = {
'casesensitivity':'sensitive',
'compression':'inherit',
'atime':'inherit',
'quota':dataset_quota.__str__()
}
err, msg = notifier().create_zfs_dataset(
path='%s/%s' % (kwargs.get('parent').vol_name, bundle.data.get('name')),
props=props)
if err != 0:
bundle.errors['__all__'] = msg
raise ImmediateHttpResponse(
response=self.error_response(bundle.request, bundle.errors)
)
else:
notifier().dataset_init_unix('%s/%s' % (kwargs.get('parent').vol_name,bundle.data.get('name')))
# FIXME: authorization
bundle.obj = self.obj_get(bundle, pk=bundle.data.get('name'), **kwargs)
return bundle
@slntopp
Copy link

slntopp commented Nov 8, 2017

F*ng awesome, you best!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment