Giter Site home page Giter Site logo

tusharlimbhore / sdk Goto Github PK

View Code? Open in Web Editor NEW

This project forked from vmware/alb-sdk

0.0 1.0 0.0 88.3 MB

Avi SDK and Utilities

License: Apache License 2.0

Python 45.34% Shell 0.14% Makefile 0.01% CSS 0.34% HTML 4.42% JavaScript 0.10% Go 48.80% Java 0.85%

sdk's Introduction

Avi SDK and Utilities

Build Status

This repository includes API documentation, SDK and sample source to integrate into the Avi Solution. Below is brief description of the contents.

  • doc: Avi API documentation includes documentation for the load balancer objects, Analytics Metrics, and Log Analytics APIs.
  • python: Source for the Python SDK. The pip package can be downloaded from Releases. Here are list of important SDK directories:
    • samples: Python samples are in the python/avi/sdk/samples directory.
      • autoscale: Gives ControlScript examples for server autoscaling.
      • heat: Provides a heat example for pool servers that can be used with the server autoscale feature and ControlScripts.
      • virtualservice_examples_api: Provides examples of programmatically creating most common virtual services, such as basic VS, SSL VS, analytics APIs, tenant-based APIs, etc.
    • utils: Useful utilities for devops automation.
      • f5_converter: Is a utility for converting an F5 configuration into an Avi Vantage configuration.
      • httppolicyset_templates: Provides easy-to-use templates for creating HTTP request and redirect policies for most common use cases.
      • Mesos: Provides CRUD APIs to create a Marathon app with Avi labels.

Installation

Pip packages are hosted on GitHub. They can be installed simply as:

Avi SDK Install

$ pip install avisdk

Avi Migration Tools Install - installs F5-to-Avi and NetScaler-to-Avi conversion tools

$ pip install avimigrationtools

Python Virtual-Environment-based Installation

It is recommended to use a virtual-environment-based installation if you are just experimenting with the SDK or F5 converter.

$ apt-get install python-dev python-pip python-virtualenv python-cffi libssl-dev libffi-dev
$ virtualenv avi
$ cd avi
$ source bin/activate
$ pip install avimigrationtools avisdk
$ f5_converter.py -h
$ netscaler_converter.py -h
$ deactivate

Usage

ApiSession Usage

from avi.sdk.avi_api import ApiSession
# create Avi API Session
api = ApiSession.get_session("10.10.10.42", "admin", "something", tenant="admin")

# create virtualservice using pool sample_pool
pool_obj = api.get_object_by_name('pool', 'sample_pool')
pool_ref = api.get_obj_ref(pool_obj)
services_obj = [{'port': 80, 'enable_ssl': False}]
vs_obj = {'name': 'sample_vs', 'ip_address': {'addr': '11.11.11.42', 'type': 'V4'},
         'services': services_obj, 'pool_ref': pool_ref}
resp = api.post('virtualservice', data=vs_obj)

# print list of all virtualservices
resp = api.get('virtualservice')
for vs in resp.json()['results']:
    print vs['name']

# delete virtualservice
resp = api.delete_by_name('virtualservice', 'sample_vs')

If ApiSession is invoked in the context of a control script, then token can be used for authentication. Along with that, information regarding username and tenant information can also be retrieved as follows:

token=os.environ.get('API_TOKEN')
user=os.environ.get('USER')
tenant=os.environ.get('TENANT')
api = ApiSession.get_session("localhost", user, token=token, tenant=tenant)

SAML Authentication Usage

prerequisite:

  1. SAML configured/enabled Controller.

To set up SAML SSO controller, please refer the below link. (https://avinetworks.com/docs/17.2/single-sign-on-with-saml/)

Currently, the SDK supports two IDPs for SAML-based authentication:

  1. Okta
  2. Onelogin

SAML-based Session Usage for the Okta IDP

from avi.sdk.saml_avi_api import OktaSAMLApiSession
# create Avi API Session
api = OktaSAMLApiSession("10.10.10.42", "okta_username", "okta_password")

# create virtualservice using pool sample_pool
pool_obj = api.get_object_by_name('pool', 'sample_pool')
pool_ref = api.get_obj_ref(pool_obj)
services_obj = [{'port': 80, 'enable_ssl': False}]
vs_obj = {'name': 'sample_vs', 'ip_address': {'addr': '11.11.11.42', 'type': 'V4'},
         'services': services_obj, 'pool_ref': pool_ref}
resp = api.post('virtualservice', data=vs_obj)

# print list of all virtualservices
resp = api.get('virtualservice')
for vs in resp.json()['results']:
    print vs['name']

# delete virtualservice
resp = api.delete_by_name('virtualservice', 'sample_vs')

SAML-based Session Usage for the OneLogin IDP

from avi.sdk.saml_avi_api import OneloginSAMLApiSession
# create Avi API Session
api = OneloginSAMLApiSession("10.10.10.42", "onelogin_username", "onelogin_password")

# create virtualservice using pool sample_pool
pool_obj = api.get_object_by_name('pool', 'sample_pool')
pool_ref = api.get_obj_ref(pool_obj)
services_obj = [{'port': 80, 'enable_ssl': False}]
vs_obj = {'name': 'sample_vs', 'ip_address': {'addr': '11.11.11.42', 'type': 'V4'},
         'services': services_obj, 'pool_ref': pool_ref}
resp = api.post('virtualservice', data=vs_obj)

# print list of all virtualservices
resp = api.get('virtualservice')
for vs in resp.json()['results']:
    print vs['name']

# delete virtualservice
resp = api.delete_by_name('virtualservice', 'sample_vs')

SAML session can also be invoked by following:

api = ApiSession.get_session("10.10.10.42", "onelogin_username", "onelogin_password", idp_class=OneloginSAMLApiSession)
api = ApiSession.get_session("10.10.10.42", "onelogin_username", "onelogin_password", idp_class=OktaSAMLApiSession)

F5 Converter Usage

See all the F5 converter options

f5_converter.py -h

Convert bigip.conf into Avi configuration. Output is in output directory

f5_converter.py -f bigip.conf
ls output

Netscaler Converter Usage

See all the Netscaler converter options

netscaler_converter.py -h

Convert ns.conf into Avi configuration. Output is in output directory

netscaler_converter.py -f ns.conf
ls output

virtualservice_examples_api Usage

Create a basic virtualservice named basic-vs

virtualservice_examples_api.py -h
virtualservice_examples_api.py -c 10.10.25.42 -i 10.90.64.141 -o create-basic-vs -s 10.90.64.12

sdk's People

Contributors

chaitanyadeshpande avatar rishabh-baranwal avatar khaltore avatar chaitanyaavi avatar ypraveen avatar gitshrikant avatar karthikvas avatar patilshrikant786 avatar jeyanthinath avatar rohan-sss1 avatar patilshrikant486 avatar nmandeyam avatar jacekkrzeminski avatar ericsysmin avatar squirrelala avatar thebertster avatar rangar avatar skdas avatar adityats avatar yograjshisode avatar chauhanshubham avatar rameshtathe avatar mbarooah avatar cjawale avatar rahulmitra avatar chugh007 avatar chandrak6464 avatar christiantreutler-avi avatar gcox1 avatar jaysidhdumbali avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.