Skip to main content

Python SX client-side library

Project description

Introduction

sxclient is a library which implements client-side methods for communicating with an SX Cluster. Using the provided objects and functions, it is possible to prepare and send a query as per the API documentation at http://docs.skylable.com/.

Internally, sxclient uses requests library (http://python-requests.org/) and currently requires Python 2.7.

Usage

In order to run an operation provided by the library, you have to perform some preparatory actions:

  • prepare a Cluster object, containing cluster location data;

  • prepare a UserData object, containing user credentials used to authorize operations;

  • prepare either a ClusterSession object or SXClient object which serves as a context for the connections with the cluster.

Afterwards, you can run a series of operations using the previously created ClusterSession object as a context.

Initializing Cluster object

The most basic way of initializing the Cluster object is to pass the cluster name:

cluster = sxclient.Cluster('my.cluster.example.com')

If the passed name is not a FQDN, you should pass an IP address too. It will be used to communicate with the cluster in place of name.

cluster = sxclient.Cluster('clustername', ip_address='127.0.0.1')

In case you don’t want the connection to be secured by SSL, set is_secure to False:

cluster = sxclient.Cluster('my.cluster.example.com', is_secure=False)

You can also pass a custom port number:

cluster = sxclient.Cluster('my.cluster.example.com', port=8000)

Initializing UserData object

There are multiple initialization methods for UserData. You can provide a path to the key file:

user_data = sxclient.UserData.from_key_path('/path/to/keyfile')

The key itself can be provided too — either encoded in base64:

user_data = sxclient.UserData.from_key('ZP1rHyR0QB6zEvCwYexGl9SF1G143C/D2hG9rEisLL2zJV3kWQvtAwAA')

or in its binary form:

user_data = sxclient.UserData('d\xfdk\x1f$t@\x1e\xb3\x12\xf0\xb0a\xecF\x97\xd4\x85\xd4mx\xdc/\xc3\xda\x11\xbd\xacH\xac,\xbd\xb3%]\xe4Y\x0b\xed\x03\x00\x00')

You can also initialize the object with username and password (and cluster UUID):

user_data = sxclient.UserData.from_userpass_pair('a_user', 'a_password', '10ca10ca-10ca-10ca-10ca-10ca10ca10ca')

Initializing SXController object

After preparing Cluster and UserData objects an SXController object can be created:

sx = sxclient.SXController(cluster, user_data)

In order to use a custom CA certificate for verification, pass a path to CA bundle in verify parameter:

sx = sxclient.SXController(cluster, user_data, verify='/path/to/ca/bundle')

You can then get all available commands from

print sx.available_operations

You can call any operation via

sx.listUsers.call(...)

The return value is a HTTP response object holding the response from SX server. If a command supports JSON format (as most of them use) you can call it directly:

sx.listUsers.json_call(...)

After you are done working with SXController gracefuly close it:

sx.close()

Running an operation

Currently the following operations are available:

createBlocks
createUser
createVolume
deleteFile
deleteVolume
flushUploadedFile
getBlocks
getClusterMetadata
getClusterStatus
getFile
getFileMeta
getNodeStatus
getVolumeACL
initializeAddChunk
initializeFile
listFileRevisions
listFiles
listNodes
listUsers
listVolumes
locateVolume
modifyUser
modifyVolume
removeUser
setClusterMetadata
setVolumeACL
updateVolumeACL
whoAmI

High level operations

Since uploading and downloading files requires some low level knowledge about underlying SX protocol we give helpers to simplify that. For a given SXController if you wish to upload file use:

import os
file_size = os.stat('myfile.txt').st_size
uploader = sxclient.SXFileUploader(sxcontroller)
with open('myfile.txt', 'r') as fo:
   uploader.upload_stream('my-volume', file_size, 'my_new_file_name.txt', fo)

and if you wish to download file use:

downloader = sxclient.SXFileDownloader(sxcontroller)
content = downloader.get_file_content('my-volume', 'my_new_file_name.txt')

For more information regarding usage of a specific objects see its docstring. For example, to see the description for listVolumes, you can use the Python built-in help function:

>>> help(sx.listVolumes)

or pydoc while in the shell:

$ pydoc sx.listVolumes

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sxclient-0.9.2.tar.gz (20.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sxclient-0.9.2-py2-none-any.whl (34.7 kB view details)

Uploaded Python 2

File details

Details for the file sxclient-0.9.2.tar.gz.

File metadata

  • Download URL: sxclient-0.9.2.tar.gz
  • Upload date:
  • Size: 20.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for sxclient-0.9.2.tar.gz
Algorithm Hash digest
SHA256 9a0abec8431c901a2338696988c5f2c95b73880d1ef13a7b4805a5deea93e00e
MD5 45e6253859734aac1a98ac08429df413
BLAKE2b-256 956e1e913335e5a7b66059ddb36b67f52f0ca6a7bcba0b659870dc076f856679

See more details on using hashes here.

File details

Details for the file sxclient-0.9.2-py2-none-any.whl.

File metadata

File hashes

Hashes for sxclient-0.9.2-py2-none-any.whl
Algorithm Hash digest
SHA256 7e6d6f5f4a23a9ce8e51afe42e00877155e6fc0300cff77936af2df6c93d9814
MD5 fd5b8244bb2c7d62bd538cd8b08288ce
BLAKE2b-256 c99bc30e36046c65c74b9071d7da51a4b90126f55737988a5d42dc725b1806bd

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page