The API class is the main entry point into the BlueCat API. Most use cases involve instantiating an API instance, connecting to BAM, and going from there.
An example is as follows:
#!/usr/bin/python from bluecat import api, api_exception try: # Create a connection - the URL is the same one as used for raw BAM REST API connections. conn = API('http://192.168.56.191/Services/REST/application.wadl') # Log in using an API user configured via the BAM UI. conn.login('admin', 'admin') c = conn.get_configuration('Configuration Name') for s in c.get_servers(): # Print the server name and any service IP4 addresses it has. print s.name(), s.get_service_ip4_addresses() except APIException as e: # Something went wrong. print e.get_message() some code
This is the main entry point for the API. The most common usage pattern is to create a connection via instantiation, login with the login method, then retrieve a configuration object via get_configuration or get_configurations.
classapi.API(url, sslverify=False, ca_file=None, ca_path=None, logger=None)
Bases: object
Create a connection to the BAM API.
Parameter | Description |
---|---|
url | URL of the BAM API (can be http or https). |
sslverify | Whether or not to verify the certificate installed on the BAM. Will generally be false for self signed certificates. |
ca_file | Name of the file listing CA’s for use in verification. |
ca_path | CA path used for verification. |
add_default_access_right(recipient_id, value, overrides='', properties='')
Parameter | Description |
---|---|
recipient_id | The object ID of the user or user group the access right is applied to |
value | The value of the access right being added. |
overrides | A list of type-specific overrides. |
properties |
A string including the following options:
|
Returns: Object ID of a created Access Right.
add_group(name, properties='')
Add a user group.
Parameter | Description |
---|---|
name | The name of the user group. |
properties | Adds object properties, including user-defined fields. |
Returns: The object ID of a created access right.
add_user(username, password, email='e@e', user_access_type='API', properties='')
Add a user to BAM; available options are listed in the options variable.
Parameter | Description |
---|---|
username | The name of the user. |
password | The BAM password for the user (must be set even if the authenticator property option is defined). |
The email address for the user. | |
user_access_type | API, GUI, or GUI and API (required). |
properties | String containing UDFs and options listed in the options variable. Multiple values can be separated by a | (pipe) character. You must add a | (pipe) character at the end in the properties string. |
Returns: The object ID for the new Address Manager user.
create_configuration(name)
Creates a configuration in BAM with the given name.
custom_search(filters, entity_type)
Search for an array of entities by specifying object properties. Supported for BAM version 8.1.1 or greater.
Parameter | Description |
---|---|
filters | The list of properties on which the search will be based. List and String formats are supported. |
entity_type | The object type that you want to search. |
delete_configuration(name='', entity_id=0)
Delete a configuration using name or id. Does not need both.
Parameter | Description |
---|---|
name | The name of the BAM configuration. |
entity_id | The object ID of the configuration in the BAM database. |
delete_group(name='', entity_id=0)
Delete a group, accepts either the group’s name or id.
Parameter | Description |
---|---|
name | The name of the BAM user group. |
entity_id | The object ID of the configuration in the BAM database. |
delete_user(name='', entity_id=0)
Delete a user, can use either username or id to specify which user to delete.
Parameter | Description |
---|---|
name | The name of the BAM user. |
entity_id | The object ID of the configuration in the BAM database. |
Returns: None, if successful. Raises PortalException on error.
get_aliases_by_hint(hint, retrieve_fields=True)
Get a list of alias records that matches hint.
Parameter | Description |
---|---|
hint | The following wildcards are supported in the hint option:
|
retrieve fields | Boolean input. Will not include UDFs in results if False. |
Returns: A List of alias_records.
get_all_used_locations()
Returns an array of all used locations found in BAM (not per configuration).
Returns: Returns an array of all used locations; returns an empty list if no results are found.
classmethodget_api_client(url, use_rest, **kwargs)
Generate an API Client based on the communication method set for the Gateway.
Parameter | Description |
---|---|
url | URL to the WADL or WSDL file. |
use_rest | Whether to use REST or SOAP. |
kwargs | Any keyword arguments for either client. |
get_by_object_types(pattern, types)
Gets objects based on a search pattern and a list of object types.
Parameter | Description |
---|---|
pattern | Search pattern string (will match any of the various properties of a BAM entity). |
types | List of BAM entity types (For example, [entity.View, entity.Configuration]). |
Returns: An iterator for objects found that match the pattern and types. Only the consistency of the first 1000 results can be guaranteed.
get_configuration(name)
Get a named configuration.
Parameter | Description |
---|---|
name | Name of the BAM configuration. |
Returns: configuration object of the named configuration.
get_configurations(name)
Get all configurations.
Returns: Iterator of configuration objects. Only the consistency of the first 1000 results are guaranteed.
get_country_locations()
Returns an iterator for all parent locations (countries) found in BAM (not per configuration).
Returns: An iterator for all country locations. Only the consistency of the first 1000 results are guaranteed.
get_default_access_right(recipient_id)
Parameter | Description |
---|---|
recepient_id | The object ID of the user or user group the access right is applied to. |
Returns: Access Right object.
get_deployment_task_status(deployment_token)
Parameter | Description |
---|---|
deployment_token | The string token value that is returned from the selective_deploy API method. |
Returns: Returns a json with the overall deployment status and the deployment status of individual entities. The request section displays a list of the entity IDs that were defined in the creation of the deployment task using the selective_deploy API method. The status section displays the status of the deployment. The deployment status can be QUEUED, STARTED, FINISHED, or TASK_NOT_FOUND. The responses section contains specific information about the entities including the ID of the entity, the fully qualified domain name (FQDN), record type, TTL value, record data, the operation performed on the resource record, and the result of the deployment. The errors section lists out any errors encountered during the deployment. If all entities deployed successfully, the section displays an empty list. .
get_entity_by_id(entity_id)
Get an entity by its ID. The returned object is of the correct class, or if none is defined, is an entity instance.
Parameter | Description |
---|---|
entity_id | BAM entity ID (note that these are unique across all configurations). |
Returns: Returns objects from the database referenced by their database ID and with its properties fields populated.
get_group(group_name)
Get Group :param group_name: Group name :return: User Group
get_location_by_code(code)
Use this method to get the location object with the specified hierarchical location code.
Parameter | Description |
---|---|
code | The hierarchical location code, it consists of a set of 1 to 3
alpha-numeric strings separated by a space. The first two characters
indicate a country, followed by next three characters which indicate
a city in UN/LOCODE. New custom locations created under a UN/LOCODE
city are appended to the end of the hierarchy. For example, CA TOR
OF1 indicates:
Note: The code is case-sensitive. It must be all UPPER CASE
letters. The county code and child location code should be
alphanumeric strings.
|
Returns: The location entity object that corresponds to the location code.
classmethodget_portal_version(folder_path=None)
Get the version of the API DNS Integrity Gateway.
get_system_info()
Get current system information of the BAM server.
Returns: Returns BAM system information in the form of a name/value pair dictionary.
get_tag_group_by_name(name)
Get a named tag group.
Parameter | Description |
---|---|
name | Name of the tag group. |
Returns:A tag group entity object with given name.
get_tag_groups()
Returns an iterator of tag groups found in BAM (not per Configuration).
Returns: An iterator of all tag.TagGroup objects. Only the consistency of the first 1000 results are guaranteed.
get_url()
Get the URL of the application.
get_user(username)
Get a named user.
Parameter | Description |
---|---|
username | Username of the BAM user. |
Returns: user object for the username.
get_version()
Get current system version from the system information as <major version>.<minor version>.<patch>.
Returns: Version string. eg. ‘8.0.0’.
instantiate_entity(e)
Instantiate an appropriate Python class given an entity returned from a SOAP call.
Parameter | Description |
---|---|
e | SOAP entity. |
Returns: A type specific instance object of the SOAP entity or generic entity object. None if there is no type.
login(username, password)
Login to the BAM API using the supplied username and password. The user must be set up with API access via the BAM GUI. All normal permissioning applies.
Parameter | Description |
---|---|
username | BAM username. |
password | BAM password. |
logout()
Logout from the BAM API.
print_bam_soap_methods()
Print details of the various BAM SOAP API methods to stdout. Useful for debugging purposes.
selective_deploy(entities, properties='')
Creates a deployment task to deploy changes made to specific DNS entities, such as resource records, to a managed DNS/DHCP Server. You must perform a full DNS deployment before proceeding to use the selective deployment API method. You can only deploy a maximum of 100 DNS entities per selective deployment API call. You cannot deploy dynamic records and external host records. You cannot deploy resource records if they belong to multiple DNS/DHCP Servers.
This method is available only if executed against BAM v8.3.2 or later and BDDS v8.3.2 or later.
Parameter | Description |
---|---|
entities | List of entities or entity ids of the host records.. |
properties | String including the scope option as a string value. This defines
whether the deployment task includes objects that are related to the
defined DNS resource records. The scope can be one of the following
values:
|
Returns: String token to check the deployment status.
selective_deploy_synchronous(entities, properties='', timeout=12)
Executes the selective deployment but also waits until deployment has completed. The same restrictions as in selective_deploy method are applied.
Parameter | Description |
---|---|
entities | List of entities or entity ids of the host records.. |
properties | String including the scope option as a string value. This defines
whether the deployment task includes objects that are related to the
defined DNS resource records. The scope can be one of the following
values:
|
timeout | The amount of seconds to wait till the deployment is finished. The default value is 12 seconds. |
Returns: Returns a JSON with the overall deployment status after the deployment finished, and the deployment status of individual entities. The request section displays a list of the entity IDs passed. The status section displays the status of the deployment. The deployment status can be FINISHED or TASK_NOT_FOUND. The responses section contains specific information about the entities including the ID of the entity, the fully qualified domain name (FQDN), record type, TTL value, record data, the operation performed on the resource record, and the result of the deployment. The errors section lists out any errors encountered during the deployment. If all entities deployed successfully, the section displays an empty list.