Skip to main content

Infoblox client

Project description

ib-client

Pypi version Build Status Windows Build Status Coverage Status Documentation Status

The simplest infoblox client!

Why another infoblox client?

This may be the first question that come to your mind if you know that there is already a client supported by Infoblox.

The answer is genericity. I try to be the more generic as possible to support all the objects proposed by the infoblox API through the instropection of its API. If you know the wapi documentation of an object / function, you will know how to use through the client which has a simple and intuitive API.

Installation

pip install ib-client

N.B: ib-client works starting from python 3.6

Documentation

The documentation is available at https://ib-client.readthedocs.io/en/stable/.

Features

  • A client that allows you to perform all the operations available in the infoblox api.
  • A CLI that allows you to quickly perform the same operations as you will do with the client.
  • Ability to perform custom requests.
  • Ability to load .env files to configure the client or the CLI.

Usage

Client

Here is how you can instantiate the client.

from infoblox import Client

client = Client(url='https://foo.com/wapi/v2.8', user='foo', password='foo')

To create a network:

network = client.get_object('network')
network.create(network='10.1.0.0/16')

To read all networks created:

network.get()

You will have an output similar to the following:

[
    {
        "_ref": "network/ZG5zLm5ldHdvcmskMTAuMS4wLjAvMTYvMA:10.1.0.0%2F16",
        "network": "10.1.0.0/16",
        "network_view": "default"
    },
    {
        "_ref": "network/ZG5zLm5ldHdvcmskMTAuMi4wLjAvMTYvMA:10.2.0.0%2F16",
        "network": "10.2.0.0/16",
        "network_view": "default"
    }
]

To modify a network:

network.update(object_ref='network/ZG5zLm5ldHdvcmskMTAuMS4wLjAvMTYvMA:10.1.0.0/16', comment='just a comment')

If you want to search for the network modified, you can do this:

network.get(params={'comment~': 'just'}, return_fields=['network', 'networkview', 'comment'])

It is also interesting to notice in the last call how we filtered the fields to be returned. The output contains the network modified previously.

[
    {
        "_ref": "network/ZG5zLm5ldHdvcmskMTAuMS4wLjAvMTYvMA:10.1.0.0%2F16",
        "comment": "just a comment",
        "network": "10.1.0.0/16",
        "network_view": "default"
    }
]

N.B: the reference is always returned, so this is why we don't need to mention it in the return_fields parameter.

Finally to delete a network, you can perform this call:

network.delete(object_ref='network/ZG5zLm5ldHdvcmskMTAuMS4wLjAvMTYvMA:10.1.0.0/16')

Simple enough!

CLI

Before using the CLI, you will have to set 3 environment variables, otherwise you will have an error. The 3 environment variables are:

  • IB_URL: the wapi infoblox url like https://foo/wapi/v2.8
  • IB_USER: the user to connect to
  • IB_PASSWORD: the user's password

If you don't want to repeat these actions, you can create a .env file in the directory where you want to use the CLI. You need to provide the above information in the form KEY=VALUE, one per line.

The cli has help information available to help you quickly understand how to use it

ib -h
Usage: ib [OPTIONS] COMMAND [ARGS]...

  Infoblox Command Line Interface. It allows you to interact with infoblox
  in the same way you will do with the python api client.

Options:
  --version   Show the version and exit.
  -h, --help  Show this message and exit.

Commands:
  object            Performs various object operations.
  objects           Lists the available objects supports by the infoblox...
  request           Makes a custom request using the request object of...
  schema            Shows the api schema.
  shell-completion  Installs shell completion.

Each command also has help information available through the -h option. You can activate the shell completion on bash, fish, zsh and Powershell by doing the following command:

ib shell-completion

Note: On Powershell, you may encounter an error in non administrator mode and if you are in administrator mode, and you still encounter an error like the following:

Set-ExecutionPolicy : Windows PowerShell updated your execution policy successfully, but the setting is overridden
by a policy defined at a more specific scope.  Due to the override, your shell will retain its current effective
execution policy of Bypass. Type "Get-ExecutionPolicy -List" to view your execution policy settings.
For more information please see "Get-Help Set-ExecutionPolicy".

Please refer to microsoft documentation to know how to fix the issue.

We will now perform the same operations realized in the client part.

Create a network:

ib object -n network create -a '{"network": "10.1.0.0/16"}'

Notes:

  • the -n option after object command specifies the object to work on.
  • On Powershell, you will need a different syntax to escape properly json arguments:
ib object -n network create -a "{\"network\": \"10.1.0.0/16\"}"

I know it is ugly and tricky, but we can't do differently on Windows :(

To get all created networks:

ib object -n network get

Update a network:

ib object -n network update -o network/ZG5zLm5ldHdvcmskMTAuMS4wLjAvMTYvMA:10.1.0.0%2F16 -a '{"comment":"just a comment"}'

Search for a network:

ib object -n network get -p '{"comment~":"just"}' --return-fields=network,networkview,comment

Delete a network:

ib object -n network delete -o network/ZG5zLm5ldHdvcmskMTAuMS4wLjAvMTYvMA:10.1.0.0%2F16

Warnings

  • The client was created by working on major version 2 of the infoblox API, so it is sure to work on it, will not work on a previous major version and is not sure to work on a higher major version.
  • I don't have much time to test my client on an infoblox server, so it's likely there are some bugs. Feel free to suggest pull requests. See the CONTRIBUTING.md file for more details. All contributions are welcome :)

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

ib-client-0.1.1.tar.gz (26.0 kB view details)

Uploaded Source

Built Distribution

ib_client-0.1.1-py3-none-any.whl (22.0 kB view details)

Uploaded Python 3

File details

Details for the file ib-client-0.1.1.tar.gz.

File metadata

  • Download URL: ib-client-0.1.1.tar.gz
  • Upload date:
  • Size: 26.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.0

File hashes

Hashes for ib-client-0.1.1.tar.gz
Algorithm Hash digest
SHA256 82a385e2422bf193e3ace47eb816ed54040f0bcb037a0546be820ba252785b1a
MD5 182f2b5e43f212b3449c9322f8836118
BLAKE2b-256 59577c9f33944b04f824ae5bbaa8337634999c3e5a90a6e0c382aac046bf238d

See more details on using hashes here.

File details

Details for the file ib_client-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: ib_client-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 22.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.0

File hashes

Hashes for ib_client-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6901ce4a68808afd7f479188397bea6aebec961ea71013e3ba41d1211801fcf6
MD5 d7d0d912cccc6b96c9d29e38f02d77ae
BLAKE2b-256 5fb828065636d33a8be4a00838703570d8fcf68f5f964fbc62fad8da6cc7c1be

See more details on using hashes here.

Supported by

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