Python Plug-in

Ops Center Automator Service Builder User Guide

Version
11.0.x
Audience
anonymous
Part Number
MK-99AUT002-20

The Python plug-in is a component that runs Python scripts on the Ops Center Automator host. The Python interpreter must be installed on the Ops Center Automator host before it can be used, because the Python interpreter is not installed by Ops Center Automator. To use this plug-in in a cluster environment, the Python interpreter must be installed on both the active and standby systems. The Python plug-in does not support a virtual Python environment.

Supported versions of Python

Version 3.x series

Return codes

The Python Plug-in generates the following return codes:

Return Code Description
0 Ended normally.
1 Python interpreter failed.
2 Python script failed.
3 Python script timed out.
80 Task has stopped.
127 Another error has occurred.

Property list

The following properties are available for the Python Plug-in:

Property key Property name Description Default value I/O type Required
pythonInterpreterPath Python interpreter path Specifies the path to the Python interpreter that executes the script python Input true
scriptBody Script body Specifies the Python code strings. -- Input true
importedScript Imported script

Specifies methods and constants (code string of Python) to be used in common with other Python Plug-ins placed on the same service template.

The following items can be used in the script of importedScript:

  • Functions: log() function. Same as the log() function available at scriptBody.

  • Environment variables: Same as the environment variables available at scriptBody.

-- Input false
webServiceConnectionCategory Web Service Connection Category Specify the Web Service Connection category. -- Input false
webServiceConnectionName Web Service Connection Name Specify the Web Service Connection name. -- Input false
timeout Timeout Specifies the timeout time (in seconds) for the specified script. 300 Input false
inN Input(N) Specifies an argument to be passed to the script. -- Input false
standardOutput Standard output Outputs the standard output of the specified script as a character string -- Output false
standardErrorOutput Standard error output Outputs the standard error output of the specified script as a character string -- Output false
outN Output(N) Outputs the value specified for the argument of the "outN" function in the specified script -- Output false
N: An integer in the range from 0 to 9

You specify the plug-in input/output properties in the property list. Combinations of service property values, reserved property values, and literal characters can be used for the input properties.

Variables and functions that can be used in the script

The following variables and functions can be used in the script.

Category Name Description
Variable inN The value specified for the input property (inN) is set. The value is interpreted as a character string even if the value is specified as an array or in JSON format.
Function outN (String Value) The value passed as the argument of the function is output to the component output property (outN).
Function log (String Value) You can output any strings to the tasklog. In this case, choose a log level by adding a specific prefix to the beginning of the string.
Prefix [Severe] Outputs as log level 0
[Information] Outputs as log level 10
[Fine] Outputs as log level 20
[Finer] Outputs as log level 30
[Debug] Outputs as log level 40
(No prefix) Same as the prefix [Information]
N: An integer in the range from 0 to 9

Note that if the following import lines defined by default are deleted from the script, the variables and functions mentioned previously cannot be used.

from dnaplugin import in0, in1, in2, in3, in4, in5, in6, in7, in8, in9
from dnaplugin import out0, out1, out2, out3, out4, out5, out6, out7, out8, out9
from dnaplugin import log

Environment variables that can be referenced from the script

Specify a value for the environment variables when executing the script. You can get the values for the following environment variables in the os.environ.get(key-name) or os.environ[key-name] format.

Environment variable Description Format
PLUGIN_PROPERTIES Property for the Python plug-in JSON format

{property-name:value, ...}

SERVICE_TEMPLATE_ID ID of the service template to which the Python plug-in belongs Numerical value
SERVICE_ID ID of the service running the Python plug-in Numerical value
SERVICE_TEMPLATE Information about the service template to which the Python plug-in belongs JSON format

{service-template-attribute:value, ...}

SERVICE Information about the service running the Python Plug-in JSON format

{service-attribute:value, ...}

STORAGE_PROFILES Information about the Storage Profile JSON format

[{ StorageProfile-attribute:value, ... }, ...]

WEB_SERVICE_CONNECTIONS Settings information for the Web Service Connection. This corresponds to the specified input properties ("Web Service Connection Category" and "Web Service Connection Name") seen in the following table. JSON format

[{ WebServiceConnection-attribute:value, ... }, ...]

Input properties Reference information
Web Service Connection Category Web Service Connection Name
Value is specified. (Y) Value is specified. (Y) Web Service Connection information that coincides with the specified Category and Name
Value is specified. (Y) Value is not specified. (N) Web Service Connection information that coincides with the specified Category
Value is not specified. (N) Value is specified. (Y) None
Value is not specified. (N) Value is not specified. (N) None

Sample code (scriptBody/importedScript)

The following examples show the sample code of the Python Plug-in that can be specified in the plug-in property scriptBody/importedScript:

-------------------------------------------
(scriptBody)
-------------------------------------------
# -*- coding: utf-8 -*-
import os
from dnaplugin import in0, in1, in2, in3, in4, in5, in6, in7, in8, in9
from dnaplugin import out0, out1, out2, out3, out4, out5, out6, out7, out8, out9
from dnaplugin import log
from dnaplugin_imported_script import *

hoge(CNST)
-------------------------------------------
(importedScript)
-------------------------------------------
from dnaplugin import log

def hoge(a):
  log(a + ' from common py!')

CNST = 'hoge'
-------------------------------------------