Hitachi

JP1 Version 12 JP1/Automatic Operation Service Template Reference


4.2.20 Python plug-in

Function

This plug-in can execute Python scripts.

Cautionary notes

Version

01.00.01

Tag

Execute Script

Return codes

Return code

Description

0

Ended normally.

1

Python interpreter failed.

2

Python script failed.

3

Python script timed out.

80

Task execution has stopped.

127

An error other than the above occurred.

Property list

The following table describes the properties.

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

R

scriptBody

Script Body

Specifies the Python code.

--

Input

R

importedScript

Imported script

Specify the methods and constants (strings in Python code) that are shared with other Python plug-ins used in the same service template.

--

Input

O

webServiceConnectionCategory

Web Service Connection Category

Specify the Web Service Connection category.

--

Input

O

webServiceConnectionName

Web Service Connection Name

Specify the Web Service Connection name.

--

Input

O

timeout

Time Out

Specifies the timeout time (in seconds) for the specified script.

300

Input

O

inN#

Script Input (N#)

Specifies an argument to be passed to the script.

--

Input

O

standardOutput

Standard Output

Outputs the standard output of the specified script as a character string.

--

Output

O

standardErrorOutput

Standard Error Output

Outputs the standard error output of the specified script as a character string.

--

Output

O

outN#

Script Output (N#)

Outputs the value specified for the argument of the "outN#" function in the specified script.

--

Output

O

#

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 Body

The following variables and functions can be used in the Script Body.

Table 4‒14: Variables and functions that can be used in the Script Body

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)

Outputs as log level 10 (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 above 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 Body

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[key-name] or os.environ.get(key-name) format.

Table 4‒15: Environment variables that can be referenced from the Script Body

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...}

WEB_SERVICE_CONNECTIONS

Settings information for the Web Service Connection. #

JSON format

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

#

This corresponds to the specified input properties ("Web Service Connection Category" and "Web Service Connection Name") seen in the following table.

Input properties specification

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

About imported scripts

If you want to share methods and constants with other Python plug-ins used in the same service template, define the methods and constants in the importedScript property.

By mapping the importedScript property to the service input property, and then mapping the importedScript properties of other Python plug-ins to the same service input property, you can share the methods and constants defined in the imported script with the Script Body of each Python plug-in.

Sample imported script

Script Body
# -*- 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)
Imported script
from dnaplugin import log
 
def hoge(a):
    log(a + ' from common py!')
 
CNST = 'hoge'