# Workload Policies

## List Policies

<mark style="color:blue;">`GET`</mark> `https://$(tvm_address):8780/v1/$(tenant_id)/workload_policy`

Requests the list of available Workload Policies

#### Path Parameters

| Name         | Type   | Description                  |
| ------------ | ------ | ---------------------------- |
| tvm\_address | string | IP or FQDN of Trilio service |
| tenant\_id   | string | ID of Tenant/Project         |

#### Headers

| Name              | Type   | Description                     |
| ----------------- | ------ | ------------------------------- |
| X-Auth-Project-Id | string | Project to authenticate against |
| X-Auth-Token      | string | Authentication token to use     |
| Accept            | string | application/json                |
| User-Agent        | string | python-workloadmgrclient        |

{% tabs %}
{% tab title="200 Response contains the list of available Workload Policies with Policy details" %}

```
HTTP/1.1 200 OK
Server: nginx/1.16.1
Date: Fri, 13 Nov 2020 13:56:08 GMT
Content-Type: application/json
Content-Length: 1399
Connection: keep-alive
X-Compute-Request-Id: req-4618161e-64e4-489a-b8fc-f3cb21d94096

{
   "policy_list":[
      {
         "id":"b79aa5f3-405b-4da4-96e2-893abf7cb5fd",
         "created_at":"2020-10-26T12:52:22.000000",
         "updated_at":"2020-10-26T12:52:22.000000",
         "status":"available",
         "name":"Gold",
         "description":"",
         "metadata":[
            
         ],
         "field_values":[
            {
               "created_at":"2020-10-26T12:52:22.000000",
               "updated_at":null,
               "deleted_at":null,
               "deleted":false,
               "version":"4.0.115",
               "id":"0201f8b4-482d-4ec1-9b92-8cf3092abcc2",
               "policy_id":"b79aa5f3-405b-4da4-96e2-893abf7cb5fd",
               "policy_field_name":"retention_policy_value",
               "value":"10"
            },
            {
               "created_at":"2020-10-26T12:52:22.000000",
               "updated_at":null,
               "deleted_at":null,
               "deleted":false,
               "version":"4.0.115",
               "id":"48cc7007-e221-44de-bd4e-6a66841bdee0",
               "policy_id":"b79aa5f3-405b-4da4-96e2-893abf7cb5fd",
               "policy_field_name":"interval",
               "value":"5"
            },
            {
               "created_at":"2020-10-26T12:52:22.000000",
               "updated_at":null,
               "deleted_at":null,
               "deleted":false,
               "version":"4.0.115",
               "id":"79070c67-9021-4220-8a79-648ffeebc144",
               "policy_id":"b79aa5f3-405b-4da4-96e2-893abf7cb5fd",
               "policy_field_name":"retention_policy_type",
               "value":"Number of Snapshots to Keep"
            },
            {
               "created_at":"2020-10-26T12:52:22.000000",
               "updated_at":null,
               "deleted_at":null,
               "deleted":false,
               "version":"4.0.115",
               "id":"9fec205a-9528-45ea-a118-ffb64d8c7d9d",
               "policy_id":"b79aa5f3-405b-4da4-96e2-893abf7cb5fd",
               "policy_field_name":"fullbackup_interval",
               "value":"-1"
            }
         ]
      }
   ]
}
```

{% endtab %}
{% endtabs %}

## Show Policy

<mark style="color:blue;">`GET`</mark> `https://$(tvm_address):8780/v1/$(tenant_id)/workload_policy/<policy_id>`

Requests the details of a given policy

#### Path Parameters

| Name         | Type   | Description                  |
| ------------ | ------ | ---------------------------- |
| tvm\_address | string | IP or FQDN of Trilio service |
| tenant\_id   | string | ID of Tenant/Project         |
| policy\_id   | string | ID of the Policy to show     |

#### Headers

| Name              | Type   | Description                     |
| ----------------- | ------ | ------------------------------- |
| X-Auth-Project-Id | string | Project to authenticate against |
| X-Auth-Token      | string | Authentication token to use     |
| Accept            | string | application/json                |
| User-Agent        | string | python-workloadmgrclient        |

{% tabs %}
{% tab title="200 Returns details of the requested Workload Policy" %}

```
HTTP/1.1 200 OK
Server: nginx/1.16.1
Date: Fri, 13 Nov 2020 14:18:42 GMT
Content-Type: application/json
Content-Length: 2160
Connection: keep-alive
X-Compute-Request-Id: req-0583fc35-0f80-4746-b280-c17b32cc4b25

{
   "policy":{
      "id":"b79aa5f3-405b-4da4-96e2-893abf7cb5fd",
      "created_at":"2020-10-26T12:52:22.000000",
      "updated_at":"2020-10-26T12:52:22.000000",
      "user_id":"adfa32d7746a4341b27377d6f7c61adb",
      "project_id":"4dfe98a43bfa404785a812020066b4d6",
      "status":"available",
      "name":"Gold",
      "description":"",
      "field_values":[
         {
            "created_at":"2020-10-26T12:52:22.000000",
            "updated_at":null,
            "deleted_at":null,
            "deleted":false,
            "version":"4.0.115",
            "id":"0201f8b4-482d-4ec1-9b92-8cf3092abcc2",
            "policy_id":"b79aa5f3-405b-4da4-96e2-893abf7cb5fd",
            "policy_field_name":"retention_policy_value",
            "value":"10"
         },
         {
            "created_at":"2020-10-26T12:52:22.000000",
            "updated_at":null,
            "deleted_at":null,
            "deleted":false,
            "version":"4.0.115",
            "id":"48cc7007-e221-44de-bd4e-6a66841bdee0",
            "policy_id":"b79aa5f3-405b-4da4-96e2-893abf7cb5fd",
            "policy_field_name":"interval",
            "value":"5"
         },
         {
            "created_at":"2020-10-26T12:52:22.000000",
            "updated_at":null,
            "deleted_at":null,
            "deleted":false,
            "version":"4.0.115",
            "id":"79070c67-9021-4220-8a79-648ffeebc144",
            "policy_id":"b79aa5f3-405b-4da4-96e2-893abf7cb5fd",
            "policy_field_name":"retention_policy_type",
            "value":"Number of Snapshots to Keep"
         },
         {
            "created_at":"2020-10-26T12:52:22.000000",
            "updated_at":null,
            "deleted_at":null,
            "deleted":false,
            "version":"4.0.115",
            "id":"9fec205a-9528-45ea-a118-ffb64d8c7d9d",
            "policy_id":"b79aa5f3-405b-4da4-96e2-893abf7cb5fd",
            "policy_field_name":"fullbackup_interval",
            "value":"-1"
         }
      ],
      "metadata":[
         
      ],
      "policy_assignments":[
         {
            "created_at":"2020-10-26T12:53:01.000000",
            "updated_at":null,
            "deleted_at":null,
            "deleted":false,
            "version":"4.0.115",
            "id":"3e3f1b12-1b1f-452b-a9d2-b6e5fbf2ab18",
            "policy_id":"b79aa5f3-405b-4da4-96e2-893abf7cb5fd",
            "project_id":"4dfe98a43bfa404785a812020066b4d6",
            "policy_name":"Gold",
            "project_name":"admin"
         },
         {
            "created_at":"2020-10-29T15:39:13.000000",
            "updated_at":null,
            "deleted_at":null,
            "deleted":false,
            "version":"4.0.115",
            "id":"8b4a6236-63f1-4e2d-b8d1-23b37f4b4346",
            "policy_id":"b79aa5f3-405b-4da4-96e2-893abf7cb5fd",
            "project_id":"c76b3355a164498aa95ddbc960adc238",
            "policy_name":"Gold",
            "project_name":"robert"
         }
      ]
   }
}
```

{% endtab %}
{% endtabs %}

## list assigned Policies

<mark style="color:blue;">`GET`</mark> `https://$(tvm_address):8780/v1/$(tenant_id)/workload_policy/assigned/<project_id>`

Requests the lists of Policies assigned to a Project.

#### Path Parameters

| Name         | Type   | Description                                       |
| ------------ | ------ | ------------------------------------------------- |
| tvm\_address | string | IP or FQDN of Trilio service                      |
| tenant\_id   | string | ID of Tenant/Project                              |
| project\_id  | string | ID of the Project to fetch assigned Policies from |

#### Headers

| Name              | Type   | Description                     |
| ----------------- | ------ | ------------------------------- |
| X-Auth-Project-Id | string | Project to authenticate against |
| X-Auth-Token      | string | Authentication token to use     |
| Accept            | string | application/json                |
| User-Agent        | string | python-workloadmgrclient        |

{% tabs %}
{% tab title="200 Returns list of Policies with some information assigned to the provided Project" %}

```
HTTP/1.1 200 OK
Server: nginx/1.16.1
Date: Tue, 17 Nov 2020 09:14:01 GMT
Content-Type: application/json
Content-Length: 338
Connection: keep-alive
X-Compute-Request-Id: req-57175488-d267-4dcb-90b5-f239d8b02fe2

{
   "policies":[
      {
         "created_at":"2020-10-29T15:39:13.000000",
         "updated_at":null,
         "deleted_at":null,
         "deleted":false,
         "version":"4.0.115",
         "id":"8b4a6236-63f1-4e2d-b8d1-23b37f4b4346",
         "policy_id":"b79aa5f3-405b-4da4-96e2-893abf7cb5fd",
         "project_id":"c76b3355a164498aa95ddbc960adc238",
         "policy_name":"Gold",
         "project_name":"robert"
      }
   ]
}
```

{% endtab %}
{% endtabs %}

## Create Policy

<mark style="color:green;">`POST`</mark> `https://$(tvm_address):8780/v1/$(tenant_id)/workload_policy`

Creates a Policy with the given parameters

#### Path Parameters

| Name         | Type   | Description                                   |
| ------------ | ------ | --------------------------------------------- |
| tvm\_address | string | IP or FQDN of Trilio service                  |
| tenant\_id   | string | ID of the Tenant/Project to do the restore in |

#### Headers

| Name              | Type   | Description                     |
| ----------------- | ------ | ------------------------------- |
| X-Auth-Project-Id | string | Project to authenticate against |
| X-Auth-Token      | string | Authentication token to use     |
| Content-Type      | string | application/json                |
| Accept            | string | application/json                |
| User-Agent        | string | python-workloadmgrclient        |

{% tabs %}
{% tab title="200 Policy got created successfully" %}

```
HTTP/1.1 200 OK
Server: nginx/1.16.1
Date: Tue, 17 Nov 2020 09:24:03 GMT
Content-Type: application/json
Content-Length: 1413
Connection: keep-alive
X-Compute-Request-Id: req-05e05333-b967-4d4e-9c9b-561f1a7add5a

{
   "policy":{
      "id":"23176f20-9e9d-4fc3-9d3d-f10d2b184163",
      "created_at":"2020-11-17T09:24:01.000000",
      "updated_at":"2020-11-17T09:24:01.000000",
      "status":"available",
      "name":"CLI created",
      "description":"CLI created",
      "metadata":[
         
      ],
      "field_values":[
         {
            "created_at":"2020-11-17T09:24:01.000000",
            "updated_at":null,
            "deleted_at":null,
            "deleted":false,
            "version":"4.0.115",
            "id":"767ae42d-caf0-4d36-963c-9b0e50991711",
            "policy_id":"23176f20-9e9d-4fc3-9d3d-f10d2b184163",
            "policy_field_name":"interval",
            "value":"4 hr"
         },
         {
            "created_at":"2020-11-17T09:24:01.000000",
            "updated_at":null,
            "deleted_at":null,
            "deleted":false,
            "version":"4.0.115",
            "id":"7e34ce5c-3de0-408e-8294-cc091bee281f",
            "policy_id":"23176f20-9e9d-4fc3-9d3d-f10d2b184163",
            "policy_field_name":"retention_policy_value",
            "value":"10"
         },
         {
            "created_at":"2020-11-17T09:24:01.000000",
            "updated_at":null,
            "deleted_at":null,
            "deleted":false,
            "version":"4.0.115",
            "id":"95537f7c-e59a-4365-b1e9-7fa2ed49c677",
            "policy_id":"23176f20-9e9d-4fc3-9d3d-f10d2b184163",
            "policy_field_name":"retention_policy_type",
            "value":"Number of Snapshots to Keep"
         },
         {
            "created_at":"2020-11-17T09:24:01.000000",
            "updated_at":null,
            "deleted_at":null,
            "deleted":false,
            "version":"4.0.115",
            "id":"f635bece-be61-4e72-bce4-bc72a6f549e3",
            "policy_id":"23176f20-9e9d-4fc3-9d3d-f10d2b184163",
            "policy_field_name":"fullbackup_interval",
            "value":"-1"
         }
      ]
   }
}
```

{% endtab %}
{% endtabs %}

### Body Format

```
{
   "workload_policy":{
      "field_values":{
         "fullbackup_interval":"<-1 for never / 0 for always / Integer>",
         "retention_policy_type":"<Number of Snapshots to Keep/Number of days to retain Snapshots>",
         "interval":"<Integer hr>",
         "retention_policy_value":"<Integer>"
      },
      "display_name":"<String>",
      "display_description":"<String>",
      "metadata":{
         <key>:<value>
      }
   }
}
```

## Update Policy

<mark style="color:orange;">`PUT`</mark> `https://$(tvm_address):8780/v1/$(tenant_id)/workload_policy/<policy-id>`

Updates a Policy with the given information

#### Path Parameters

| Name         | Type   | Description                                   |
| ------------ | ------ | --------------------------------------------- |
| tvm\_address | string | IP or FQDN of Trilio service                  |
| tenant\_id   | string | ID of the Tenant/Project to do the restore in |
| policy\_id   | string | ID of the Policy to update                    |

#### Headers

| Name              | Type   | Description                     |
| ----------------- | ------ | ------------------------------- |
| X-Auth-Project-Id | string | Project to authenticate against |
| X-Auth-Token      | string | Authentication token to use     |
| Content-Type      | string | application/json                |
| Accept            | string | application/json                |
| User-Agent        | string | python-workloadmgrclient        |

{% tabs %}
{% tab title="200 Policy has been updated successfully" %}

```
HTTP/1.1 200 OK
Server: nginx/1.16.1
Date: Tue, 17 Nov 2020 09:32:13 GMT
Content-Type: application/json
Content-Length: 1515
Connection: keep-alive
X-Compute-Request-Id: req-9104cf1c-4025-48f5-be92-1a6b7117bf95

{
   "policy":{
      "id":"23176f20-9e9d-4fc3-9d3d-f10d2b184163",
      "created_at":"2020-11-17T09:24:01.000000",
      "updated_at":"2020-11-17T09:24:01.000000",
      "status":"available",
      "name":"API created",
      "description":"API created",
      "metadata":[
         
      ],
      "field_values":[
         {
            "created_at":"2020-11-17T09:24:01.000000",
            "updated_at":"2020-11-17T09:31:45.000000",
            "deleted_at":null,
            "deleted":false,
            "version":"4.0.115",
            "id":"767ae42d-caf0-4d36-963c-9b0e50991711",
            "policy_id":"23176f20-9e9d-4fc3-9d3d-f10d2b184163",
            "policy_field_name":"interval",
            "value":"8 hr"
         },
         {
            "created_at":"2020-11-17T09:24:01.000000",
            "updated_at":"2020-11-17T09:31:45.000000",
            "deleted_at":null,
            "deleted":false,
            "version":"4.0.115",
            "id":"7e34ce5c-3de0-408e-8294-cc091bee281f",
            "policy_id":"23176f20-9e9d-4fc3-9d3d-f10d2b184163",
            "policy_field_name":"retention_policy_value",
            "value":"20"
         },
         {
            "created_at":"2020-11-17T09:24:01.000000",
            "updated_at":"2020-11-17T09:31:45.000000",
            "deleted_at":null,
            "deleted":false,
            "version":"4.0.115",
            "id":"95537f7c-e59a-4365-b1e9-7fa2ed49c677",
            "policy_id":"23176f20-9e9d-4fc3-9d3d-f10d2b184163",
            "policy_field_name":"retention_policy_type",
            "value":"Number of days to retain Snapshots"
         },
         {
            "created_at":"2020-11-17T09:24:01.000000",
            "updated_at":"2020-11-17T09:31:45.000000",
            "deleted_at":null,
            "deleted":false,
            "version":"4.0.115",
            "id":"f635bece-be61-4e72-bce4-bc72a6f549e3",
            "policy_id":"23176f20-9e9d-4fc3-9d3d-f10d2b184163",
            "policy_field_name":"fullbackup_interval",
            "value":"7"
         }
      ]
   }
}
```

{% endtab %}
{% endtabs %}

### Body Format

```
{
   "policy":{
      "field_values":{
         "fullbackup_interval":"<-1 for never / 0 for always / Integer>",
         "retention_policy_type":"<Number of Snapshots to Keep/Number of days to retain Snapshots>",
         "interval":"<Integer hr>",
         "retention_policy_value":"<Integer>"
      },
      "display_name":"String",
      "display_description":"String",
      "metadata":{
         <key>:<value>
      }
   }
}
```

## Assign Policy

<mark style="color:green;">`POST`</mark> `https://$(tvm_address):8780/v1/$(tenant_id)/workload_policy/<policy-id>`

Updates a Policy with the given information

#### Path Parameters

| Name         | Type   | Description                                   |
| ------------ | ------ | --------------------------------------------- |
| tvm\_address | string | IP or FQDN of Trilio service                  |
| tenant\_id   | string | ID of the Tenant/Project to do the restore in |
| policy\_id   | string | ID of the Policy to assign                    |

#### Headers

| Name              | Type   | Description                     |
| ----------------- | ------ | ------------------------------- |
| X-Auth-Project-Id | string | Project to authenticate against |
| X-Auth-Token      | string | Authentication token to use     |
| Content-Type      | string | application/json                |
| Accept            | string | application/json                |
| User-Agent        | string | python-workloadmgrclient        |

{% tabs %}
{% tab title="200 Policy has been assigned successfully" %}

```
HTTP/1.1 200 OK
Server: nginx/1.16.1
Date: Tue, 17 Nov 2020 09:46:23 GMT
Content-Type: application/json
Content-Length: 2318
Connection: keep-alive
X-Compute-Request-Id: req-169a53e4-b1c9-4bd1-bf68-3416d177d868

{
   "policy":{
      "id":"23176f20-9e9d-4fc3-9d3d-f10d2b184163",
      "created_at":"2020-11-17T09:24:01.000000",
      "updated_at":"2020-11-17T09:24:01.000000",
      "user_id":"adfa32d7746a4341b27377d6f7c61adb",
      "project_id":"4dfe98a43bfa404785a812020066b4d6",
      "status":"available",
      "name":"API created",
      "description":"API created",
      "field_values":[
         {
            "created_at":"2020-11-17T09:24:01.000000",
            "updated_at":"2020-11-17T09:31:45.000000",
            "deleted_at":null,
            "deleted":false,
            "version":"4.0.115",
            "id":"767ae42d-caf0-4d36-963c-9b0e50991711",
            "policy_id":"23176f20-9e9d-4fc3-9d3d-f10d2b184163",
            "policy_field_name":"interval",
            "value":"8 hr"
         },
         {
            "created_at":"2020-11-17T09:24:01.000000",
            "updated_at":"2020-11-17T09:31:45.000000",
            "deleted_at":null,
            "deleted":false,
            "version":"4.0.115",
            "id":"7e34ce5c-3de0-408e-8294-cc091bee281f",
            "policy_id":"23176f20-9e9d-4fc3-9d3d-f10d2b184163",
            "policy_field_name":"retention_policy_value",
            "value":"20"
         },
         {
            "created_at":"2020-11-17T09:24:01.000000",
            "updated_at":"2020-11-17T09:31:45.000000",
            "deleted_at":null,
            "deleted":false,
            "version":"4.0.115",
            "id":"95537f7c-e59a-4365-b1e9-7fa2ed49c677",
            "policy_id":"23176f20-9e9d-4fc3-9d3d-f10d2b184163",
            "policy_field_name":"retention_policy_type",
            "value":"Number of days to retain Snapshots"
         },
         {
            "created_at":"2020-11-17T09:24:01.000000",
            "updated_at":"2020-11-17T09:31:45.000000",
            "deleted_at":null,
            "deleted":false,
            "version":"4.0.115",
            "id":"f635bece-be61-4e72-bce4-bc72a6f549e3",
            "policy_id":"23176f20-9e9d-4fc3-9d3d-f10d2b184163",
            "policy_field_name":"fullbackup_interval",
            "value":"7"
         }
      ],
      "metadata":[
         
      ],
      "policy_assignments":[
         {
            "created_at":"2020-11-17T09:46:22.000000",
            "updated_at":null,
            "deleted_at":null,
            "deleted":false,
            "version":"4.0.115",
            "id":"4794ed95-d8d1-4572-93e8-cebd6d4df48f",
            "policy_id":"23176f20-9e9d-4fc3-9d3d-f10d2b184163",
            "project_id":"cbad43105e404c86a1cd07c48a737f9c",
            "policy_name":"API created",
            "project_name":"services"
         },
         {
            "created_at":"2020-11-17T09:46:22.000000",
            "updated_at":null,
            "deleted_at":null,
            "deleted":false,
            "version":"4.0.115",
            "id":"68f187a6-3526-4a35-8b2d-cb0e9f497dd8",
            "policy_id":"23176f20-9e9d-4fc3-9d3d-f10d2b184163",
            "project_id":"c76b3355a164498aa95ddbc960adc238",
            "policy_name":"API created",
            "project_name":"robert"
         }
      ]
   },
   "failed_ids":[
      
   ]
}
```

{% endtab %}
{% endtabs %}

### Body Format

```
{
   "policy":{
      "remove_projects":[
         "<project_id>"
      ],
      "add_projects":[
         "<project_id>",
      ]
   }
}
```

## Delete Policy

<mark style="color:red;">`DELETE`</mark> `https://$(tvm_address):8780/v1/$(tenant_id)/workload_policy/<policy_id>`

Deletes a given Policy

#### Path Parameters

| Name         | Type   | Description                  |
| ------------ | ------ | ---------------------------- |
| tvm\_address | string | IP or FQDN of Trilio service |
| tenant\_id   | string | ID of Tenant/Project         |
| policy\_id   | string | ID of the Policy to delete   |

#### Headers

| Name              | Type   | Description                     |
| ----------------- | ------ | ------------------------------- |
| X-Auth-Project-Id | string | Project to authenticate against |
| X-Auth-Token      | string | Authentication token to use     |
| Accept            | string | application/json                |
| User-Agent        | string | python-workloadmgrclient        |

{% tabs %}
{% tab title="202 Deletion Request accepted" %}

```
HTTP/1.1 202 Accepted
Server: nginx/1.16.1
Date: Tue, 17 Nov 2020 09:56:03 GMT
Content-Type: text/html; charset=UTF-8
Content-Length: 0
Connection: keep-alive
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.trilio.io/openstack/tvo-4.0/api-guide/workload-policies.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
