Skip to content

Client

ucmdb_rest.client.UCMDBServer(user, password, server, port=8443, protocol='https', ssl_validation=False, client_context=1, classic=True)

The primary interface for interacting with the UCMDB REST API.

This class manages the lifecycle of a UCMDB session, including authentication, token refreshment, and provides access to specialized sub-modules for topology, discovery, and policies.

Parameters:

Name Type Description Default
server str

The hostname or IP address of the UCMDB server.

required
user str

The username for authentication.

required
password str

The password for authentication.

required
port int

The REST API port (default is 8443).

8443
protocol str

The connection protocol, 'http' or 'https' (default is 'https').

'https'
ssl_validation bool

Whether to verify the server's SSL certificate (default is False).

False
client_context int

The UCMDB client context ID (default is 1).

1
classic bool

Whether UCMDB is installed in classic or containerized. Classic is a standalone installation on Windows or Linux where containerized is installed in a Linux Kubernetes or other Kubernetes cluster. If installing in an AWS EC2 instance (for example) it would be 'classic'. If installing in Google's GKE, it would be 'containerized'. True = classic, False = containerized. (default is True).

True

Attributes:

Name Type Description
session Session

The underlying HTTP session used for all requests.

data_flow DataFlowManagement

Access to probe management, ranges, and credentials.

data_model DataModel

Access to the UCMDB class model and attributes.

topology Topology

Access to CI and Relationship querying and creation.

discovery Discovery

Access to discovery jobs and inventory tools.

mgmt_zones ManagementZones

Access to management zone configurations.

policies Policies

Access to policy and compliance features.

integrations Integrations

Access to integration points and data push/pull jobs.

reports Reports

Access to UCMDB reports and query results.

system System

Access to server status, licensing, and general settings.

settings Settings

Access to infrastructure settings.

packages Packages

Access to Content Pack management.

expose ExposeCI

Access to CI export/expose features.

ldap RetrieveLDAP

Access to LDAP configuration.

Source code in ucmdb_rest\client.py
def __init__(
    self,
    user,
    password,
    server,
    port=8443,
    protocol="https",
    ssl_validation=False,
    client_context=1,
    classic=True,
):
    if classic:
        self.base_url = f"{protocol}://{server}:{port}/rest-api"
    else:
        self.base_url = f"{protocol}://{server}:{port}/ucmdb-server/rest-api"
    self.root_url = f"{protocol}://{server}:{port}"

    # Initialize Session
    self.session = requests.Session()
    self.session.verify = ssl_validation
    self.session.headers.update(
        {"Content-Type": "application/json", "Accept": "application/json"}
    )
    self.client_context = client_context
    logger.info(f'Initializing UCMDB Server connection to {server}')

    self.__user = user
    self.__password = password
    self.server = server

    # Authenticate immediately
    self.token = self._authenticate(user, password)

    # Register Service Modules (Standardized naming)
    self.data_flow = DataFlowManagement(self)
    self.data_model = DataModel(self)
    self.policies = Policies(self)
    self.topology = Topology(self)
    self.discovery = Discovery(self)
    self.expose = ExposeCI(self)
    self.integrations = Integrations(self)
    self.ldap = RetrieveLDAP(self)
    self.mgmt_zones = ManagementZones(self)
    self.reports = Reports(self)
    self.settings = Settings(self)
    self.packages = Packages(self)
    self.system = System(self)
    self.server_version = (0,0,0)
    self._initialize_server_version()

from_json(config_path) classmethod

Initialize a UCMDBServer instance from a configuration file.

Parameters:

Name Type Description Default
config_path str

The path to the JSON file containing credentials and server details.

required

Returns:

Type Description
UCMDBServer

An authenticated instance of the UCMDBServer client.

Source code in ucmdb_rest\client.py
@classmethod
def from_json(cls, config_path):
    """
    Initialize a UCMDBServer instance from a configuration file.

    Parameters
    ----------
    config_path : str
        The path to the JSON file containing credentials and server details.

    Returns
    -------
    UCMDBServer
        An authenticated instance of the UCMDBServer client.
    """
    with open(config_path,'r') as f:
        creds = json.load(f)
    return cls(user = creds['user'],
               password=creds['password'],
               server=creds['server'],
               port=creds.get('port', 8443),
               ssl_validation=creds.get('ssl_validation', False)
            )