BlueCat Library Address Manager REST v1 API reference - BlueCat Python Library - 24.1

BlueCat Python Library Guide

Locale
English
Product name
BlueCat Python Library
Version
24.1

The BlueCat Library API provides access to BlueCat Address Manager functionality that can be used outside of BlueCat Address Manager and BlueCat Gateway — that is, without the need for Gateway. It contains a set of wrapper classes that abstract functionality available for each resource from the Address Manager API Client.

Use the BlueCat Library APIs when building standalone automation solutions that don't need to work in BlueCat Gateway or use a Gateway UI.

Accessing the BlueCat Library API

To access the API in your scripts, import the appropriate libraries, then create an instance of the Client class of the type that you need. You can then reference API methods, functions, subclasses, and so on from that Client instance as needed.

The following Clients and Modules are available:

  • bluecat_libraries.address_manager.api: This Client class provides access to the main Address Manager REST v1 Client API. It lets you perform Address Manager and Gateway actions that don't require a UI.

  • bluecat_libraries.address_manager.api.models: The models module includes classes and methods for working with data models for BlueCat Address Manager object types.

  • bluecat_libraries.address_manager.constants: Some of the inputs and outputs from the Address Manager API use fixed values for certain fields. The constants class contains enumerated values to help work with data you send to and acquire from Address Manager.

Tip: You can trap application exceptions with bluecat_libraries.http_client.exceptions. For more details, see BlueCat Python REST v1 API exceptions.

For example, the following Python script prints the names and addresses of servers from a given BlueCat Address Manager (BAM) configuration, using the Address Manager Client class.
# Print the names and addresses of servers under a given BlueCat Address Manager (BAM) configuration.

from bluecat_libraries.address_manager.api import Client
from bluecat_libraries.address_manager.constants import ObjectType
from bluecat_libraries.http_client.exceptions import ErrorResponse

with Client(<bam_url>) as client:
    client.login(<username>, <password>)

    try:
        config = client.get_entity_by_name(0, <config_name>, ObjectType.CONFIGURATION)
        if config is None:
            print("No configuration found with the given name.")
        else:
            servers = client.get_entities(config["id"], ObjectType.SERVER)
            for server in servers:
                print(server["name"], server["properties"]["servicesIPv4Address"])
    except ErrorResponse as e:
        # `client.get_entity_by_name()` and `client.get_entities()` call BAM endpoints so either may
        # result in an error response.
        print(e.message)

    client.logout()