Skip to content

Commit

Permalink
Merge pull request #7 from cbrainerd/feat_pypi_doc_rebased
Browse files Browse the repository at this point in the history
Updates to prepare for PyPI releases.
  • Loading branch information
dmoxon authored Jul 6, 2016
2 parents fb00783 + 5d5d122 commit 6614bd0
Show file tree
Hide file tree
Showing 6 changed files with 147 additions and 45 deletions.
58 changes: 19 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
[![Build Status](https://travis-ci.org/Isilon/isilon_sdk.svg?branch=master)](https://travis-ci.org/Isilon/isilon_sdk)
[![](http://issuestats.com/github/isilon/isilon_sdk/badge/pr?style=flat-square)](http://issuestats.com/github/isilon/isilon_sdk)
[![Average time to resolve an issue](http://isitmaintained.com/badge/resolution/isilon/isilon_sdk.svg)](http://isitmaintained.com/project/isilon/isilon_sdk "Average time to resolve an issue")
[![Percentage of issues still open](http://isitmaintained.com/badge/open/isilon/isilon_sdk.svg)](http://isitmaintained.com/project/isilon/isilon_sdk "Percentage of issues still open")


# Isilon Software Development Kit (isi-sdk)
Language bindings for the OneFS API and tools for building them

Expand All @@ -9,54 +15,28 @@ This repository also includes tools to build PAPI bindings yourself for a large

### Installing the pre-built Python PAPI bindings

1. Download the latest package from the "releases" page of this repo.

2. Install via [Setuptools](http://pypi.python.org/pypi/setuptools). For example, unzip the package archive to a directory and from there run:
#### Prerequisites

```sh
python setup.py install --user
```
* [Python](https://www.python.org/downloads/) 2.7 or later
* [pip](https://pip.pypa.io/en/stable/installing/)

You may need to install the Python [Setuptools](http://pypi.python.org/pypi/setuptools) on your system, if they are not already installed. For instructions, see http://pypi.python.org/pypi/setuptools.
#### Installing the package

Then at a Python prompt or in your Python programs, import the package:
```python
import isi_sdk_8_0 # or isi_sdk_7_2, depending on the release you downloaded
```
If you will only connect to OneFS 8.0 and later clusters:

## Example program
`pip install isi_sdk_8_0`

Here's an example of using the Python PAPI bindings to retrieve a list of NFS exports from your cluster:
If connecting to OneFS 7.2 and later clusters:

```python
import isi_sdk_8_0 # or isi_sdk_7_2, depending on the release you downloaded
from isi_sdk_8_0.rest import ApiException
from pprint import pprint
import urllib3
urllib3.disable_warnings()
`pip install isi_sdk_7_2`

# configure username and password
isi_sdk_8_0.configuration.username = "YOUR_USERNAME"
isi_sdk_8_0.configuration.password = "YOUR_PASSWORD"
isi_sdk_8_0.configuration.verify_ssl = False
### Basic Usage

# configure host
host = "https://YOUR_CLUSTER_HOSTNAME_OR_NODE_IP_ADDRESS:8080"
api_client = isi_sdk_8_0.ApiClient(host)
protocols_api = isi_sdk_8_0.ProtocolsApi(api_client)
See the generated packages on PyPI for example code:

# get all exports
sort = "description"
limit = 50
dir = "ASC"
try:
api_response = protocols_api.list_nfs_exports(sort=sort, limit=limit, dir=dir)
pprint(api_response)
except ApiException as e:
print "Exception when calling ProtocolsApi->list_nfs_exports: %s\n" % e
```
[isi\_sdk\_8\_0](https://pypi.python.org/pypi/isi-sdk-8-0)

There are more examples of coding to the Python PAPI bindings in the `tests/` subdirectory of this repo. The tests currently run against a generic isi_sdk import which is how the bindings library is named by default if you build your own bindings. If you want to run the tests against one of the libraries you've downloaded from the prebuilt releases page, you should change the `import isi_sdk` lines to `import isi_sdk_7_2` or `import isi_sdk_8_0` depending on which one you downloaded.
[isi\_sdk\_7\_2](https://pypi.python.org/pypi/isi-sdk-7-2)

### Bindings Documentation

Expand All @@ -71,6 +51,6 @@ We intend to also publish online docs as part of the build process for this repo
### Other Isilon SDK and API links:

* For OneFS API reference documents, discussions, and blog posts, refer to the [Isilon SDK Info Hub](https://community.emc.com/docs/DOC-48273).
* To browse the Isilon InsiqhtIQ statistics API, refer to the [Stat Key Browser](https://github.com/isilon/isilon_stat_browser.git) Github repository.
* To browse the Isilon InsightIQ statistics API, refer to the [Stat Key Browser](https://github.com/isilon/isilon_stat_browser.git) Github repository.


22 changes: 17 additions & 5 deletions components/create_swagger_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,17 @@
"description", "required", "type", "default", "maximum", "minimum", "enum",
"items"]

g_operations = {} # tracks swagger ops generated from URLs to ensure uniqueness
g_operations = {} # tracks swagger ops generated from URLs to ensure uniquenes


def OneFsShortVers(host, port, auth):
"""Query a cluster and return the 2 major version digits"""
url = "https://{0}:{1}/platform/1/cluster/config".format(host, port)
config = requests.get(url, auth=auth, verify=False).json()
release = config["onefs_version"]["release"].strip("v")
short_vers = ".".join(release.split(".")[:2])
return short_vers


def IsiPropsToSwaggerParams(isiProps, paramType):
if len(isiProps) == 0:
Expand Down Expand Up @@ -954,16 +964,16 @@ def main():
"info": {
"version": "1.0.0",
"title": "Isilon SDK",
"description": "Isilon SDK - Swagger Open API Specification for OneFS API",
"termsOfService": "http://www.emc.com",
"description": "Isilon SDK - Language bindings for the OneFS API",
"termsOfService": "https://github.com/emccode/emccode.github.io/wiki/EMC-CODE-Governance,-Contributing,-and-Code-of-Conduct",
"contact": {
"name": "Isilon SDK Team",
"email": "sdk@isilon.com",
"url": "http://www.emc.com"
"url": "https://github.com/Isilon/isilon_sdk"
},
"license": {
"name": "MIT",
"url": "http://github.com/gruntjs/grunt/blob/master/LICENSE-MIT"
"url": "https://github.com/Isilon/isilon_sdk/blob/master/LICENSE"
}
},
"schemes": [
Expand Down Expand Up @@ -1158,6 +1168,8 @@ def main():
traceback.print_exc(file=sys.stderr)
failCount += 1

swaggerJson["info"]["version"] = OneFsShortVers(args.host, papi_port, auth)

print >> sys.stderr, "End points successfully processed: " + str(successCount) \
+ ", failed to process: " + str(failCount) \
+ ", excluded: " + str(len(excludeEndPoints)) + "."
Expand Down
2 changes: 1 addition & 1 deletion readme.dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ If you have a patch for the config generator scripts that improves the generated

### Custom swagger-codegen templates

In some cases the standard swagger-codegen templates may not be suitable with the OneFS API, necessitating the use of [custom templates](https://github.com/swagger-api/swagger-codegen/wiki/Building-your-own-Templates). The [Python template](./swagger_templates/python) for example, has been customized for generation of the Isilon SDK. Customized templates are located in `/swagger_templates/<language>`. This naming convention allows the automated build process to locate and use the appropriate custom templates. If no custom template exists for a language, the default template will be used automatically.
In some cases the standard swagger-codegen templates may not be suitable with the OneFS API, necessitating the use of [custom templates](https://github.com/swagger-api/swagger-codegen/wiki/Building-your-own-Templates). Some [Python templates](./swagger_templates/python) for example, have been customized for generation of the Isilon SDK. Customized templates are located in `/swagger_templates/<language>`. This naming convention allows the automated build process to locate and use the appropriate custom templates. If no custom template exists for a language, the default template will be used automatically.
45 changes: 45 additions & 0 deletions readme.pypi.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
## About
This package is part of the Isilon SDK. It includes language bindings for easier programmatic access to the OneFS API for cluster configuration (on your cluster this is the REST API made up of all the URIs underneath https://[cluster]:8080/platform/*, also called the "Platform API" or PAPI").

## Installation

`pip install PKG_NAME`


## Example program

Here's an example of using the Python PAPI bindings to retrieve a list of NFS exports from your cluster:

```python
import PKG_NAME
from PKG_NAME.rest import ApiException
from pprint import pprint
import urllib3
urllib3.disable_warnings()

# configure username and password
PKG_NAME.configuration.username = "YOUR_USERNAME"
PKG_NAME.configuration.password = "YOUR_PASSWORD"
PKG_NAME.configuration.verify_ssl = False

# configure host
host = "https://YOUR_CLUSTER_HOSTNAME_OR_NODE_IP_ADDRESS:8080"
api_client = PKG_NAME.ApiClient(host)
protocols_api = PKG_NAME.ProtocolsApi(api_client)

# get all exports
sort = "description"
limit = 50
dir = "ASC"
try:
api_response = protocols_api.list_nfs_exports(sort=sort, limit=limit, dir=dir)
pprint(api_response)
except ApiException as e:
print "Exception when calling ProtocolsApi->list_nfs_exports: %s" % e
```

There are more examples of coding to the Python PAPI bindings in the [`tests/`](https://github.com/Isilon/isilon_sdk/tree/master/tests) subdirectory of the repo. The tests currently run against a generic isi_sdk import which is how the bindings library is named by default if you build your own bindings. If you want to run the tests against one of the libraries you've downloaded from the prebuilt releases page, you should change the `import isi_sdk` lines to `import isi_sdk_7_2` or `import isi_sdk_8_0` depending on which one you downloaded.

## More info
See the Github repo for more information:
[https://github.com/isilon/isilon_sdk](https://github.com/isilon/isilon_sdk)
27 changes: 27 additions & 0 deletions swagger_templates/python/partial_header.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"""
{{#appName}}
{{{appName}}}
{{/appName}}

{{#appDescription}}
{{{appDescription}}}
{{/appDescription}}

{{#version}}OpenAPI spec version: {{{version}}}{{/version}}
{{#infoEmail}}Contact: {{{infoEmail}}}{{/infoEmail}}
Generated by: https://github.com/swagger-api/swagger-codegen.git

Custom setup.py for isilon_sdk packages.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
38 changes: 38 additions & 0 deletions swagger_templates/python/setup.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# coding: utf-8

{{>partial_header}}

import sys
from setuptools import setup, find_packages

NAME = "{{packageName}}"
VERSION = "{{packageVersion}}"
LONG_DESCRIPTION = """\
{{appDescription}}
"""

{{#apiInfo}}{{#apis}}{{^hasMore}}

# To install the library, run the following
#
# python setup.py install
#
# prerequisite: setuptools
# http://pypi.python.org/pypi/setuptools

REQUIRES = ["urllib3 >= 1.15", "six >= 1.10", "certifi", "python-dateutil"]

setup(
name=NAME,
version=VERSION,
description="{{appName}}",
author_email="{{infoEmail}}",
url="{{infoUrl}}",
keywords=["Swagger", "{{appName}}"],
install_requires=REQUIRES,
packages=find_packages(),
include_package_data=True,
long_description=LONG_DESCRIPTION.replace('PKG_NAME', NAME)
)

{{/hasMore}}{{/apis}}{{/apiInfo}}

0 comments on commit 6614bd0

Please sign in to comment.