Created
April 11, 2016 21:04
-
-
Save MichaelSEA/056481b9fdc3e31cb57ee9e08f88f4cd to your computer and use it in GitHub Desktop.
Qumulo Read and Write Files using Qumulo REST API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import tempfile | |
import time | |
import qumulo.lib.auth | |
import qumulo.lib.request | |
import qumulo.rest.fs as fs | |
host = 'yourhostname' | |
port = 8000 | |
user = 'youracct' | |
passwd = 'yourpasswd' | |
filepath = '/users/mmurray/ftt/cheri_bee_story.jpg' | |
def login(host, user, passwd, port): | |
'''Obtain credentials from the REST server''' | |
connection = None | |
credentials = None | |
try: | |
# Create a connection to the REST server | |
connection = qumulo.lib.request.Connection(host, int(port)) | |
# Provide username and password to retreive authentication tokens | |
# used by the credentials object | |
login_results, _ = qumulo.rest.auth.login( | |
connection, None, user, passwd) | |
# Create the credentials object which will be used for | |
# authenticating rest calls | |
credentials = qumulo.lib.auth.Credentials.from_login_response(login_results) | |
except Exception, excpt: | |
print "Error connecting to the REST server: %s" % excpt | |
print __doc__ | |
sys.exit(1) | |
return connection, credentials | |
connection = None | |
credentials = None | |
while (True): | |
try: | |
# write out a file using REST API then read it back to a different file | |
# get file contents for a well-known file | |
# file = tempfile.TemporaryFile() | |
file = open('./test.jpg', 'r+') | |
fs.write_file(connection, credentials, file, "/users/mmurray/test/") | |
file2 = open('./test2.jpg','w+') | |
fs.read_file(connection, credentials, file2, "/users/mmurray/test/test.jpg") | |
print "been there, read that..." | |
file.close() | |
time.sleep(60) | |
except (qumulo.lib.request.RequestError, AttributeError): | |
# auth failures usually return a RequestError with Error 401 I think... try logging in again | |
connection, credentials = login(host, user, passwd, port) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment