# Scripting

> Configure and use the OneFuse Scripting module with the OneFuse XUI

---

Site [llms.txt](/llms.txt)

---

To learn more about this OneFuse module, refer to [Scripting](/docs/onefuse/configure/modules/scripting/).

## Prerequisites

1. Configure OneFuse [Property Set(s)](/docs/onefuse/templating/property-sets/) and OneFuse Module Policies.
1. [Install OneFuse XUI](/docs/onefuse/consume/onefuse-xui/getting-started/#install-onefuse-xui) per CloudBolt CMP.
1. Review an overview on [OneFuse Modules](/docs/onefuse/consume/onefuse-xui/modules/) with CloudBolt CMP.
1. Create a new **Blueprint** (if none exist) or determine which existing Blueprint(s) will utilize this OneFuse Module. Resource: [Blueprints](/docs/cmp/use/blueprints/).

## Configure the Blueprint

1. **Know the name of the OneFuse Connection Info** created via [OneFuse XUI initial setup](/docs/onefuse/consume/onefuse-xui/getting-started/#initial-setup).
1. **Determine _which_ OneFuse Scripting Policies to run** for this Blueprint.
1. **Determine _when_ to run each OneFuse Scripting Policy** for the deployment provisioning lifecycle with CMP's Trigger Points.
1. **Update the Blueprint** to add in necessary parameters to invoke OneFuse Scripting Policies.
1. **Deploy the Blueprint** to provision a deployment and run Provision Script(s).
1. **Destroy the Deployment** to run Deprovision Script(s), if any.

### Update the Blueprint

1. Log in to **CloudBolt CMP**.
1. If not already on the **Catalog** page, select **Catalog** from the main menu.
1. Search and find the desired CloudBolt Blueprint.
1. **Edit the Blueprint** by selecting the gear icon on the bottom-right of the Catalog Item.

#### Add in necessary parameters

The following Parameters need to exist on the Blueprint.

Learn more about [CloudBolt Parameters](/docs/cmp/configure/order-forms-and-pricing/parameters/) for: [Blueprints](/docs/cmp/use/blueprints/customize-order-form/blueprint-level-parameters/), [Environments](/docs/cmp/use/blueprints/customize-order-form/group-and-environment-parameters/), and [Groups](/docs/cmp/configure/order-forms-and-pricing/parameters/).

**Call a Scripting Policy:**

| Parameter Name Format | Parameter Value or Format |
| --- | --- |
| `OneFuse_ScriptingPolicy_`\<ExecutionString\>`_`\<CustomID\> | \<OneFuse Connection Info Name\>`:`\<Scripting Policy Name\> |

**Parameter name components:**

- Replace `<ExecutionString>` with an appropriate [Trigger Point state](/docs/onefuse/consume/onefuse-xui/modules/trigger-points/) (see table below)
- Replace `<CustomID>` with a unique, user-defined friendly label

**Example parameter:**

```yaml
OneFuse_ScriptingPolicy_HostnameOverwrite_001MyScript: 'ConnectionInfoName:ScriptingPolicyName'
OneFuse_ScriptingPolicy_PostProvision_002MyScript: 'ConnectionInfoName:ScriptingPolicyName'
```

##### Scripting Trigger Point States

**ExecutionString** refers to a specific Trigger Point for the OneFuse Module's policy to execute on.

Replace the `<ExecutionString>` variable with one of the following values in the **Trigger Point Execution String** column:

| Job / Process | Trigger Point Name | Trigger Point Execution String | Run Sequence | Plugin Action Name |
| --- | --- | --- | --- | --- |
| Provision Server | Generated Hostname Overwrite | `HostnameOverwrite` | 1005 | OneFuse - Provision Scripting |
| Provision Server | Pre-Create Resource | `PreCreateResource` | 1005 | OneFuse - Provision Scripting |
| Provision Server | Pre-Application Installation | `PreApplication` | 1005 | OneFuse - Provision Scripting |
| Provision Server | Post-Provision | `PostProvision` | 1005 | OneFuse - Provision Scripting |
| Delete Server | Post-Delete | - | 10 | OneFuse - De-Provision Scripting |

##### CustomID

**CustomID** refers to a user-specified text string to identify and can set an order of precedence for execution when calling multiple Policies for the OneFuse Module in the same Trigger Point.

Replace the `<CustomID>` variable with a unique custom identifier:

- Format is alphanumeric characters only `A-Z, a-z, 0-9`. No spaces, underscores, hyphens, nor special characters.
- Must be unique across all Trigger Point Execution Strings for the OneFuse Module on the specific resource for the Blueprint.
- Is reusable either between different VM components of the same Blueprint or between different Blueprints.

**Specify sorting with CustomID:**

When executing multiple different OneFuse Module's Policies in the same Trigger Point, prefix the `<CustomID>` with a numeric value (for example, 001, 002, etc).

The `<CustomID>` is sorted prior to executing the OneFuse module's policies.

```yaml
# Example CustomID with sorting

001Apache
002WebApp
003BackupClient
```

##### Additional helpful properties passed to OneFuse module

**Purpose: Relate OneFuse Policy executions from different OneFuse Modules together with a Tracking ID.**

| Property and Parameter | Value Format |
| --- | --- |
| `OneFuse_Tracking_Id` | A GUID (globally unique identifier) that links OneFuse Policy Executions and the resulting Managed Objects together for a given resource on a deployment. The first OneFuse Module Policy execution will **populate this Parameter** and it will be passed into other OneFuse Modules automatically. Learn more about OneFuse [Tracking ID](/docs/onefuse/concepts/tracking-id/). |

<div class="alert alert-info" role="alert">


When a Tracking ID is not provided, a Tracking ID gets generated for the Policy execution.
</div>


**Purpose: Reference a specific NIC's values to get hostname, IP Address, etc.**

| Property Format | Example |
| --- | --- |
| `OneFuse_VmNic<#>.<value>` | See examples below |

Replace `<#>` with a number from `0` to `9`, one for each NIC.

Replace `<value>` with an appropriate key: `assignment`, `dnsServers`, `dnsSuffix`, `fqdn`, `gateway`, `hostname`, `ipAddress`, `label`, `mac`, `network`, `nicLabel`, `target`

<div class="alert alert-info" role="alert">


For most use cases, NIC 0 is the primary network interface and the target hostname is a Fully Qualified Domain Name (FQDN).
</div>


Examples:

- `OneFuse_VmNic0.dnsSuffix`
- `OneFuse_VmNic0.fqdn`
- `OneFuse_VmNic0.hostname`
- `OneFuse_VmNic0.ipAddress`
- `OneFuse_VmNic0.target`: when DNS Suffix is provided, will be the FQDN; otherwise, will be the hostname (without domain).

**Purpose: Reference VM hardware information: cpu, memory, etc.**

| Property Format | Example |
| --- | --- |
| `OneFuse_VmHardware.<value>` | See examples below |

Replace `<value>` with an appropriate key: `cpuCount`, `memoryGB`, `memoryMB`, `platformUuid`, `powerState`, `totalStorageGB`

Examples:

- `OneFuse_VmHardware.cpuCount`
- `OneFuse_VmHardware.memoryGB`
- `OneFuse_VmHardware.platformUuid`
- `OneFuse_VmHardware.powerState`
- `OneFuse_VmHardware.totalStorageGB`

### Provision

Deploy a Blueprint with the OneFuse Scripting module configured. Provisioning Script(s) will run on the resource(s).

#### Outputs

The following parameter will have the generated OneFuse Script Managed Object as a JSON string on the resource.

| Parameter Name | Parameter Value Format |
| --- | --- |
| `OneFuse_Scripting_`\<CustomID\> | _JSON string of OneFuse Script Managed Object_ |

### Deprovision

Destroy an existing resource with the OneFuse Scripting Module configured. Deprovisioning Script(s) will run on the resource(s) prior to deprovisioning.

## Trigger Points

| Job / Process | Trigger Point Name | Trigger Point Execution String | Run Sequence | Plugin Action Name |
| --- | --- | --- | --- | --- |
| Provision Server | Generated Hostname Overwrite | `HostnameOverwrite` | 1005 | OneFuse - Provision Scripting |
| Provision Server | Pre-Create Resource | `PreCreateResource` | 1005 | OneFuse - Provision Scripting |
| Provision Server | Pre-Application Installation | `PreApplication` | 1005 | OneFuse - Provision Scripting |
| Provision Server | Post-Provision | `PostProvision` | 1005 | OneFuse - Provision Scripting |
| Delete Server | Post-Delete | - | 10 | OneFuse - De-Provision Scripting |
