Open topic with navigation

TIBCO® Enterprise Administrator 2.4.2

# tibco.tea Module

The tibco.tea module gives you access to the members and functions that can be used to access the TIBCO Enterprise Administrator server, and all products that have agents registered with the server. With the help of this module, you can perform just about any activity that can be performed using the Shell commands or the Web UI.

## The tibco.tea Module

The tibco.tea module is available as a built-in module. Before using this module, perform the steps specified in the Setting up Python Scripting section. To access the classes and members offered by tibco.tea, from the Python command line, run the following:

    import tibco.tea

You can now create an instance of the Enterprise Administrator by using the following statement:

    tea=tibco.tea.EnterpriseAdministrator()

The EnterpriseAdministrator() constructor can also take the following parameters:

- url: The default URL is http://localhost:8777.
- user: The default user is `admin`.
- pwd: The default password is `admin`.

The object, `tea`, in this example refers to an instance of EnterpriseAdministrator. You can use any name for the object, but this example uses `tea`. This is the root object of the entire object hierarchy. You need this object to perform any activity on TIBCO Enterprise Administrator. After creating this object, you can use this to register agents, create users, view machines, and so on.

Note: After connecting to the TIBCO Enterprise Administrator server for the first time using `tibco.tea.EnterpriseAdministrator()`, if the session expires, the `EnterpriseAdministrator.login()` method can be called to login again with the previously used credentials.

The session expires if the user script execution stays idle for a period longer than the value specified in`for tea.http.session.timeout` in`tea.conf`. Same is the case while debugging using interactive python shell.

## Number of Retry Attempts

You can modify tibco.tea.EnterpriseAdministrator() to support retry and wait options. Python binding attempts to connect to the server URL till the retry attempts exhaust. It waits for the specified interval (in seconds) between each retry. For example, the following code snippet tries to connect to the server 6 times, waiting 5 seconds between each retry. If the connection is successful, the attempt to retry stops.

    import tibco.tea
    tibco.tea.EnterpriseAdministrator(retry=6, wait=5)

## The Object Hierarchy

Using the `tea` object, created earlier in the example, you can get more information on the object hierarchy. Any reference to the `tea` object is a dictionary, such as tea.products, tea.agents and so on. Standard functions such as keys(), items(), and values() are available on all reference dictionaries. The standard help() function can be applied to any expression resolving to a TIBCO Enterprise Administrator object, to discover the functions available on that class of object.

tea.products
tea.products is a dictionary with a collection of (name,value) pairs. The tea.products command is used to list the products registered with the server that support Python binding. The following is an example of the product list generated by the command:

    >>> tea.products
    {'TIBCOSecurityServer': <'TIBCOSecurityServer','
    :TIBCOSecurityServerAgent:1.0:TIBCOSecurityServer:
    TIBCOSecurityServer'>, 'EMS
    ': <'EMS',':EMSAgent:1.0:EMS:EMS'>}
    >>>

The output shows EMS as the product registered. The command help(tea.products['EMS']) lists the functions supported by the Tomcat product.

    >>> help(tea.products['EMS'])
    Help on EMSAgent_1_0_EMS in module builtins object:

    EMS = class EMSAgent_1_0_EMS(tibco.tea.TeaObject)
     |  Agent to manage EMS Servers
     |
     |  Method resolution order:
     |      EMSAgent_1_0_EMS
     |      tibco.tea.TeaObject
     |      object
     |
     |  Methods defined here:
     |
     |  registerEmsServer(self, serverName='MyEMSServer', URL='tcp://localhost:7222',
     |  userName='admin', password='', agentId=None)
     |
     |      Register an EMS Server
     |
     |      Parameters:
     |          serverName -- EMS server name (type str) (default MyEMSServer)
     |          URL -- URL (type str) (default tcp://localhost:7222)
     |          userName -- UserName (type str) (default admin)
     |          password -- Password (type str) (default )
     |          agentId -- Identifier for the agent (type agentId) (default None)
     |
     |      Result Type: reference
     |
     |  ----------------------------------------------------------------------
     |  Data and other attributes defined here:
     |
     |  module_ = None
     |
     |  omitted_operations = []
     |
     |  type_descr = {'agentTypeId': 'EMSAgent:1.0', 'concept': 'TOP_LEVEL', '...
     |
     |  ----------------------------------------------------------------------
     |  Methods inherited from tibco.tea.TeaObject:
     |
     |  __init__(self, tea, obj_descr)
     |
     |  __repr__(self)
     |
     |  __str__(self)
     |
     |  refresh_(self)
     |
     |  ----------------------------------------------------------------------
     |  Data descriptors inherited from tibco.tea.TeaObject:
     |
     |  __dict__
     |      dictionary for instance variables (if defined)
     |
     |  __weakref__
     |      list of weak references to the object (if defined)

    >>>

tea.products.keys()
You can use tea.products.keys() to get a list of names of the products registered with the server.

    >>> tea.products.keys()
    dict_keys(['TIBCOSecurityServer', 'EMS'])

tea._products_with_provisional_apis
tea._products_with_provisional_apis is used to list the products registered with the server that have provisional apis. By default, the APIs exposed by the TIBCO Enterprise Administrator server do not support Python binding.
tea. product_with_provisional_api(name)
You can check whether or not a product has provisional apis by using the function, tea.product_with_provisional_api(name). Pass the product name as the parameter to the function. On finding the product in the tea._products_with_provisional_apis dictionary, the function returns the object of the product type along with a message that the Python API for the product is provisional. It is not supported but that is likely to change in future. If the product name is found in tea.products dictionary, the function returns `None` along with a message indicating that it is available in tea.products dictionary. If not, it prints the warning message that the product with the specified name does not exist.

To support multiple retry attempts, this method also takes `retry` and `wait` as parameters as shown in the following code snippet:

    tea. product_with_provisional_api(name, retry, wait) where,
    name: is the name of the product you are looking for
    retry: is the number of retry attempts
    wait: is the interval to wait between two retry attempts.

if retry > 1, the system searches for the product in `provisional products` dictionary till the number of retry attempts exhaust. If it finds the product, it returns the product and stops further retry attempts. If the product is not found after the specified retry attempts, an exception with a message is raised.
tea. products_with_provisional_apis()
tea. products_with_provisional_apis() returns a list of names of the products having provisional API, along with a warning message that the Python API for these products are provisional. They are not supported and are likely to change in future.
tea.product()
The tea.product() method is invoked on the EnterpriseAdministrator object, which is `tea` in this example. The method returns the supported products from the Python dictionary. Takes the three parameters as shown in the code snippet:

    tea.product(name, retry, wait) where,
    name: is the name of the product you are looking for
    retry: is the number of retry attempts
    wait: is the interval to wait between two retry attempts.

if retry > 1, the system searches for the product in `products` dictionary till the number of retry attempts exhaust. If it finds the product, it returns the product and stops further retry attempts. If the product is not found after the specified retry attempts, an exception with a message is raised.

if the retry parameter is not specified, the product() method returns the specified product from the `products` dictionary if it is available in it. If it is not available in the `products` dictionary, but it is available in the `provisional products dict`, `None` is returned with a proper `WARNING` message. If it is not available in any dictionary, it returns `None` and prints a `WARNING` message.

<Product>.module_ or <Member>.module_
You can use `module_` on a product or a member to get the modules of Plain Old Java Object (POJO) objects available on the product or member.`module_` is attached to each top level or member object. For example, the following is an example of using `module_` on a member:

    tea._products_with_provisional_apis['Tomcat'].
    members['Server 1'].module_

For products, we can use `tea._products_with_provisional_apis['Tomcat'].module_` to retrieve the modules of POJOs on Tomcat. After obtaining the modules of POJO, you can pass a POJO as a parameter to a function in a Python script. For example:

    # get an instance of the product as follows -
    >>>prod = tea._products_with_provisional_apis['Tomcat']

    # Module of POJOs is available on that product or member
     in variable "module_"
    >>> mod = prod.module_

    # Instantiate the POJO class in python as follows
    >>> person = mod.Person("John Doe", 1)

    # Invoke the TeaOperation with the python object in the earlier line
     as TeaParam and consume the POJO response as a Python Object
    >>> response = prod.hw(person)

When you get an POJO as a return type, you can use the POJO like a regular Python object.

    # Use the response as you use the regular python object
    >>> response.name
    'John Doe'
    >>> response.i
    1

tea.agents
You can use tea.agents to access the agents registered with the server. For example, tea.agents.agents.registerAgent(name,url,description) helps you register an agent with the server.
tea.users
You can use tea.users to create users, assign roles, groups to users. For example, you can create users using the tea.users.createUser(self, name, password, groups, roles) command.
tea.machines
You can use tea.machines to get more information about the machines on which the agents are running.
Caution: Different versions of Python handle i18n characters, such as Chinese and Japanese differently. Python 3 supports i18n characters, so the operations and parameters are visible in Python. If you are using Python 2, the following scenarios take effect:

- If the operation name contains i18n characters, the name is considered invalid. The operation is not visible in Python.
- If the parameter name contains i18n characters, but the operation name is valid, the operation is disabled. An exception occurs when you try to access such an operation.

## The refresh_() Function

The refresh_() function is available to an instance of EnterpriseAdministrator() that helps get the latest state of the object from the remote server and agent. In this example, tea.refresh_() gets the latest state of the object. The following scenarios call for an explicit refresh:

1. After registering the first agent, the products list gets refreshed automatically, but after registering the second agent, the products list does not refresh. Remember to explicitly refresh the products list of the second agent.
2. After unregistering the agent, the agents dictionary must be refreshed explicitly.
3. Recently updated agents, solutions, products, and dictionaries must be explicitly refreshed before accessing their members, keys, items, and other details.

Did you find this helpful?

Yes No
Great!
Thanks for taking the time to give us some feedback.
Sorry about that

Why wasn't this helpful? (check all that apply)

Could not find what I was looking for
Instructions confusing or unclear
Instructions did not work

Want to tell us more?

Please select at least one option or provide details about the issue!!

Error occurred while submitting feedback.

Error2 occurred while submitting feedback.

TIBCO® Enterprise Administrator

Copyright © 1996-2025. Cloud Software Group, Inc. All Rights Reserved.