Package: dfs-sdk
Datera Python SDKIntroductionThis is Python SDK version v1.2 for theDateraFabric Services API.
Download and use of this package implicitly accepts the terms in COPYINGUsers of this package are assumed to have familiarity with theDateraAPI.
Details around the API itself are not necessarily covered through this SDK.FeaturesAutomatic session management and loginAutomatic and configuable request retriesObject to REST request translationStandard Logging Format (compatible with Datera SREQ log parsing)Endpoint validation (toggleable)Dot-notation access to response attributesUDCcomplianceInstallationFrom Sourceapt-getinstallpython-virtualenv(oryuminstallpython-virtualenvforCentOS)virtualenvsdksourcesdk/bin/activategitclonehttps://github.com/Datera/python-sdk.gitcdpython-sdkpipinstall-rrequirements.txtpythonsetup.pyinstallFrom PYPIpipinstall-Udfs_sdkUniversal Datera ConfigThe Universal Datera Config (UDC) is a config that can be specified in a
number of ways:JSON file with any of the following names:.datera-configdatera-config.datera-config.jsondatera-config.jsonThe JSON file has the following configuration:{"mgmt_ip":"1.1.1.1","username":"admin","password":"password","tenant":"/root","api_version":"2.3","ldap":""}The file can be in any of the following places.  This is also the lookup
order for config files:current directoryhome directoryhome/config directory/etc/dateraIf no datera config file is found and a cinder.conf file is present, the
config parser will try and pull connection credentials from the
cinder.confTenant and API version and LDAP are always optional, but it's generally
suggested to include them in your UDC file for easy reference.Instead of a JSON file, environment variables can be used.DAT_MGMTDAT_USERDAT_PASSDAT_TENANTDAT_APIDAT_LDAPMost tools built to use the Universal Datera Config will also allow
for providing/overriding any of the config values via command line flags.--hostname--username--password--tenant--api-version--ldapDeveloping with Universal Datera ConfigTo use UDC in a new python tool is very simple just add the following to
your python script:fromdfs_sdkimportscaffoldparser=scaffold.get_argparser()parser.add_argument('my-new-arg')args=parser.parse_args()If you want to use subparsers, or customize the help outptu of your parser
then use the followingimportargparsefromdfs_sdkimportscaffoldtop_parser=scaffold.get_argparser(add_help=False)new_parser=argparse.ArgumentParser(parents=[top_parser])new_parser.add_argument('my-new-arg')args=new_parser.parse_args()Inside a script the config can be recieved by callingfromdfs_sdkimportscaffoldscaffold.get_argparser()config=scaffold.get_config()NOTE: It is no longer required to callscaffold.get_argparser()before
callingscaffold.get_config().  This is only necessary if building
a CLI tool that needs the cli parser.LoggingTo set custom logging.json fileexportDSDK_LOG_CFG=your/log/location.jsonOr the value can be set to a debug, info or errorexportDSDK_LOG_CFG=infoTo set logging to stdout.  The value can be any logging level supported by
the python logging module (eg: debug, info, etc)exportDSDK_LOG_STDOUT=debugThe debug logs generated by the python-sdk are quite large, and are on a
rotating file handler (provided that a custom logging.json file is not provided)Managed ObjectsDatera provides an application-driven storage management model, whose goal is to closely align storage
with a corresponding application's requirements.The main storage objects are defined and differentiated as follows:Application Instance (AppInstance)-    Corresponds to an application, service, etc.
-    Contains Zero or more Storage InstancesStorage Instance-    Corresponds to one set of storage requirements for a given AppInstance
-    ACL Policies, including IQN Initiators
-    Target IQN
-    Contains Zero or more VolumesVolumes-    Corresponds to a single allocated storage object
-    Size (default unit is GB)
-    Replication Factor
-    Performance Policies (QoS for Bandwidth and IOPS)
-    Protection Policies (Snapshot scheduling)Another way of viewing the managed object hierarchy is as follows:app_instances:
    - storage_instances:                 (1 or more per app_instance)
        + acl_policy                     (1 or more host initiators )
        + iqn                            (target IQN)
        + ips                            (target IPs)
        + volumes:                       (1 or more per storage_instance)
            * name
            * size
            * replication
            * performance_policy         (i.e. QoS)
            * protection_policy          (i.e. Snapshot schedules)EndpointsHTTP operations on URL endpoints is the only way to interact with the set of managed objects.
URL's have the format:http://192.168.42.13:7717/v2.3/<object_class>/[<instance>]/...where7717is the port used to access the API, and "v2.3" corresponds to an API version control.Briefly, the REST API supports 4 operations/methodscreate (POST), modify (PUT), list (GET), delete (DELETE).
Any input payload is in JSON format;  any return payload is in JSON format.
Login session keys are required within the "header" of any HTTP request.
Sessions keys have a 15 minute lifetime.For a full reference documentation of the REST API, please review the Datera REST API Guide.This Python SDK serves as a wrapper around the raw HTTP layer.Using this SDKThe Datera module is nameddfs_sdk, and the main entry point is calledDateraApi.
Obtaining an object handle can be done as follows:fromdfs_sdkimportget_api[...]api=get_api(mgmt_ip,username,password,"v2.3"**kwargs)You can also initialize the SDK using a Datera UDC file.  The following will read any valid
UDC file on the system or from the current environment variables.fromdfs_sdk.scaffoldimportget_api[...]api=get_api()Configurable OptionsThese options can be set on instantiation via theget_apiconstructorOptionDefaultDescriptiontenant'/root'Datera account tenant/subtenanttimeout300 (s)Timeout for HTTP requestssecureTrueWhether to use HTTPS (False sets HTTP)strictFalseWhether to check if an endpoint is valid before sending requestcertNoneHTTPS verification certificatecert_keyNoneHTTPS verification certificate keythread_local{}Used for passing values down to the connection layer, usually for loggingCommon Objects, Examples and  Use CasesPlease see theutilsdirectory for programming examples that cover the following:Common methods for all objects includecreate(), set(), delete(), list()To create an app_instance with nameFOO:ai=api.app_instances.create(name="FOO")Looping through objects can be done vialist():foraiinapi.app_instances.list():print"AppInstance: ",aiTo set a givenapp_instanceinto anofflinestate:ai.set(admin_state="offline")To delete a given app_instance:ai.delete()Building the PyPI packageRun the following to build the packages (if uploading, ensure the version
is incremented in constants.py)pythonsetup.pysdistbdist_wheelThen to upload the package to PyPI (this step requires valid PyPI credentials)twineuploaddist/*You can perform a test upload by running.  This requires credentials on the
test PyPI servertwineupload--repository-urlhttps://test.pypi.org/legacy/dist/*Reporting ProblemsFor problems and feedback, please open an github issue. This project is community supported.