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.teaYou 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.
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
{'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() dict_keys(['TIBCOSecurityServer', 'EMS'])
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 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.
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
- 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:
- 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.
- After unregistering the agent, the agents dictionary must be refreshed explicitly.
- Recently updated agents, solutions, products, and dictionaries must be explicitly refreshed before accessing their members, keys, items, and other details.