system.config.replace
New in 8.3.8
This function is used in Python Scripting.
Description​
Replaces an existing resource completely with a new configuration. The resource must already exist.
Client Permission Restrictions​
This scripting function has no Client Permission restrictions.
Syntax​
system.config.replace(*moduleId, typeId, [name], [collection], signature, [config], [backupConfig], [files], [description], [enabled], [attributes], [actor])
tip
An asterisk indicates that all parameters following it are expecting keywords when the function is being called in your script. This means that, when using an asterisk-marked parameter, both the parameter and argument must be specified. For example, moduleId="ignition".
Parameters​
| Type | Parameter | Description |
|---|---|---|
| String | *moduleId | The module ID portion of the resource type identifier. |
| String | *typeId | The type ID portion of the resource type identifier. |
| String | *name | The name of the resource. Required for named resources, but must be omitted for singleton resources. [Optional] |
| String | *collection | The collection containing the resource. If omitted, uses the active definition. [Optional] |
| String | *signature | The hex-encoded signature of the resource. |
| Dictionary | *config | A dictionary representing the resoure configuration, matching the resource type's JSON schema. If not provided, the files argument must be provided. [Optional] |
| Dictionary | *backupConfig | A dictionary representing the backup configuration for resources that support backup data. [Optional] |
| Dictionary | *files | A dictionary of additional files to include with the resource. Keys are filenames, values can be byte arrays, strings, lists, or dictionaries. If not provided, the config argument must be provided. [Optional] |
| String | *description | A description for the resource. [Optional] |
| Boolean | *enabled | Whether the replacement resource should be enabled. If omitted, the resource will be in the same state after its configuration is replaced. [Optional] |
| Dictionary | *attributes | A dictionary of resource attributes to set. [Optional] |
| String | *actor | A string identifying the actor performing the operation. If not specified, an identifier will be automatically generated. [Optional] |
Returns​
PyResource - The newly configured resource, as a PyResource that can also be read as plain Python properties.
Scope​
Gateway
Code Examples​
Code Snippet
# This example will replace our existing "MySQL" database connection configuration with a configuration that
# uses a different schema in the Connect URL and "Sticky" Failover Mode.
# Get the required signature using getResource()
# Declare required variables for getResource()
moduleId = "ignition"
typeId = "database-connection"
name = "MySQL"
myResource = system.config.getResource(moduleId=moduleId, typeId=typeId, name=name)
signature = myResource.signature
# Use the information we got for the replace() function
# Declare the rest of the required variables for replace()
config = {
"connectURL": "jdbc:mysql://localhost:3306/devDB",
"connectionProps": "zeroDateTimeBehavior\u003dCONVERT_TO_NULL;connectTimeout\u003d120000;socketTimeout\u003d120000;useSSL\u003dfalse;allowPublicKeyRetrieval\u003dtrue;rewriteBatchedStatements\u003dtrue;disableMariaDbDriver",
"connectionResetParams": "",
"defaultTransactionLevel": "DEFAULT",
"driver": "MySQL",
"evictionRate": -1,
"evictionTests": 3,
"evictionTime": 1800000,
"failoverMode": "STICKY",
"failoverProfile": "",
"includeSchemaInTableName": false,
"poolInitSize": 0,
"poolMaxActive": 8,
"poolMaxIdle": 8,
"poolMaxWait": 5000,
"poolMinIdle": 0,
"slowQueryLogThreshold": 60000,
"testOnBorrow": true,
"testOnReturn": false,
"testWhileIdle": false,
"translator": "MYSQL",
"username": "root",
"validationQuery": "SELECT 1",
"validationSleepTime": 10000
}
# Call the replace() function
system.config.replace(moduleId=moduleId, typeId=typeId, name=name, signature=signature, config=config)