In [1]:
# imports
import os
import sys
import time
import traceback
import threading

from qumulo.rest_client import RestClient

Setup credentials, create the parent directory


In [2]:
rc = RestClient("<qumulo-cluster>", 8000)
rc.login("<qumulo-user>", "<qumulo-password>")

def create_dir(rc, name, dir_path='/'):
    try:
        rc.fs.create_directory(name = name, dir_path = dir_path)
    except:
        exc_type, exc_value, exc_traceback = sys.exc_info()
        print("Exception: %s" % exc_value)

# Create base user directory, if it doesn't already exist
create_dir(rc, name='users', dir_path='/')
create_dir(rc, name='dept', dir_path='/users')


Exception: Error 409: fs_entry_exists_error: { ino=190000930 }

Create 5,000 Quotas


In [3]:
threads = []
thread_count = 20
dir_count = 5000

def create_quotas(start_dir, end_dir):
    rc = RestClient("product", 8000)
    rc.login("admin", "admin")
    for dir_num in range(start_dir, end_dir):
        dir_name = 'u-' + str(dir_num)
        try:
            dir_res = rc.fs.get_attr(path='/users/dept/' + dir_name)
        except:
            dir_res = rc.fs.create_directory(name=dir_name, dir_path='/users/dept')
        dir_id = dir_res['file_number']
        quota_res = rc.quota.create_quota(id_ = dir_id, limit_in_bytes = 1000000000)

        
for proc_num in range(0, thread_count):
    start_dir = proc_num*dir_count / thread_count
    end_dir = (proc_num+1)*dir_count / thread_count
    t = threading.Thread(target=create_quotas, args=(start_dir, end_dir))
    threads.append(t)
    t.start()

# Check aggregates to see when all directories and quotas exist
while int(rc.fs.read_dir_aggregates(path='/users/dept/')['total_directories']) < 5000:
    print(int(rc.fs.read_dir_aggregates(path='/users/dept/')['total_directories']))
    time.sleep(2.5)

print("Done!")


0
539
1140
1765
2348
2980
3614
4199
4823
Done!

Enumerate all quotas and show a specific one


In [4]:
new_q = None
for d in rc.quota.get_all_quotas_with_status():
    for q in d['quotas']:
        if q['path'] == '/users/dept/u-238/':
            print q
            new_q = q


{u'path': u'/users/dept/u-238/', u'capacity_usage': u'4096', u'limit': u'1000000000', u'id': u'3078036753'}

In [5]:
rc.quota.get_quota_with_status(new_q['id'])


Out[5]:
{u'capacity_usage': u'4096',
 u'id': u'3078036753',
 u'limit': u'1000000000',
 u'path': u'/users/dept/u-238/'}

Create and write a 1 GB file


In [6]:
new_file = rc.fs.create_file(name="1GB.txt", dir_path="/users/dept/u-238")

In [7]:
import StringIO
f = StringIO.StringIO()
f.write('0'*1000000000)
written_file = rc.fs.write_file(data_file = f, path=new_file['path'])

Can we still write to this directory?


In [8]:
new_file = rc.fs.create_file(name="just-one-more-please.txt", dir_path="/users/dept/u-238")


---------------------------------------------------------------------------
RequestError                              Traceback (most recent call last)
<ipython-input-8-fd5a009f3e49> in <module>()
----> 1 new_file = rc.fs.create_file(name="just-one-more-please.txt", dir_path="/users/dept/u-238")

/Users/tommy/python-environments/data-analysis/lib/python2.7/site-packages/qumulo/rest_client.pyc in wrapper(self, *args, **kwargs)
     95                 **kwargs)
     96         except request.RequestError as e:
---> 97             self.client.handle_request_error(e)
     98             response = request_method(
     99                 self.client.conninfo,

/Users/tommy/python-environments/data-analysis/lib/python2.7/site-packages/qumulo/rest_client.pyc in wrapper(self, *args, **kwargs)
     93                 self.client.credentials,
     94                 *args,
---> 95                 **kwargs)
     96         except request.RequestError as e:
     97             self.client.handle_request_error(e)

/Users/tommy/python-environments/data-analysis/lib/python2.7/site-packages/qumulo/rest/fs.pyc in create_file(conninfo, credentials, name, dir_path, dir_id)
    274     method = "POST"
    275     return request.rest_request(conninfo, credentials, method, unicode(uri),
--> 276         body=config)
    277 
    278 def validate_major_minor_numbers(file_type, major_minor_numbers):

/Users/tommy/python-environments/data-analysis/lib/python2.7/site-packages/qumulo/lib/request.pyc in rest_request(conninfo, credentials, method, uri, *args, **kwargs)
    503     rest = APIRequest(conninfo, credentials, method, uri, *args, **kwargs)
    504     rest.send_request()
--> 505     rest.get_response()
    506     return RestResponse(rest.response_obj, rest.response_etag)
    507 

/Users/tommy/python-environments/data-analysis/lib/python2.7/site-packages/qumulo/lib/request.pyc in get_response(self)
    463         if not self._success():
    464             raise RequestError(self._status(), self._reason(),
--> 465                 self.response_obj)
    466 
    467     def _body_text(self, encoded=True):

RequestError: Error 500: fs_no_space_error: Quota for { ino=3078036753 } over limit

Delete all quotas


In [9]:
d = rc.quota.get_all_quotas_with_status()
for q in d:
    for quota in q['quotas']:
        # but only delete them if they are in /users/dept
        if '/users/dept' in quota['path']:
            rc.quota.delete_quota(id_ = quota['id'])

Tree delete all of the user directories and check if it's gone


In [10]:
rc.fs.delete_tree(path='/users/dept/')


Out[10]:
{u'monitor_uri': u'/v1/files/3192036729/delete-tree/status'}

In [ ]:
rc.fs.read_directory(path='/users/')

In [ ]: