Resource Source

Input:

Expects the value to be provided as input to the request.

1{
2  "source-input" :
3  {
4    "description": "This is Input Resource Source Node Type",
5    "version": "1.0.0",
6    "properties": {},
7    "derived_from": "tosca.nodes.ResourceSource"
8  }
9}

Default:

Expects the value to be defaulted in the model itself.

1{
2  "source-default" :
3  {
4    "description": "This is Default Resource Source Node Type",
5    "version": "1.0.0",
6    "properties": {},
7    "derived_from": "tosca.nodes.ResourceSource"
8  }
9}

Sql:

Expects the SQL query to be modeled; that SQL query can be parameterized, and the parameters be other resources resolved through other means. If that’s the case, this data dictionary definition will have to define key-dependencies along with input-key-mapping.

CDS is currently deployed along the side of SDNC, hence the primary database connection provided by the framework is to SDNC database.

image0

 1 {
 2   "description": "This is Database Resource Source Node Type",
 3   "version": "1.0.0",
 4   "properties": {
 5     "type": {
 6       "required": true,
 7       "type": "string",
 8       "constraints": [
 9         {
10           "valid_values": [
11             "SQL"
12           ]
13         }
14       ]
15     },
16     "endpoint-selector": {
17       "required": false,
18       "type": "string"
19     },
20     "query": {
21       "required": true,
22       "type": "string"
23     },
24     "input-key-mapping": {
25       "required": false,
26       "type": "map",
27       "entry_schema": {
28         "type": "string"
29       }
30     },
31     "output-key-mapping": {
32       "required": false,
33       "type": "map",
34       "entry_schema": {
35         "type": "string"
36       }
37     },
38     "key-dependencies": {
39       "required": true,
40       "type": "list",
41       "entry_schema": {
42         "type": "string"
43       }
44     }
45   },
46   "derived_from": "tosca.nodes.ResourceSource"
47 }

Connection to a specific database can be expressed through the endpoint-selector property, which refers to a macro defining the information about the database the connect to. Understand TOSCA Macro in the context of CDS.

 1{
 2  "dsl_definitions": {
 3    "dynamic-db-source": {
 4      "type": "maria-db",
 5      "url": "jdbc:mysql://localhost:3306/sdnctl",
 6      "username": "<username>",
 7      "password": "<password>"
 8    }
 9  }
10}

Rest:

Expects the URI along with the VERB and the payload, if needed.

CDS is currently deployed along the side of SDNC, hence the default rest connection provided by the framework is to SDNC MDSAL.

image1

 1 {
 2   "description": "This is Rest Resource Source Node Type",
 3   "version": "1.0.0",
 4   "properties": {
 5     "type": {
 6       "required": false,
 7       "type": "string",
 8       "default": "JSON",
 9       "constraints": [
10         {
11           "valid_values": [
12             "JSON"
13           ]
14         }
15       ]
16     },
17     "verb": {
18       "required": false,
19       "type": "string",
20       "default": "GET",
21       "constraints": [
22         {
23           "valid_values": [
24             "GET", "POST", "DELETE", "PUT"
25           ]
26         }
27       ]
28     },
29     "payload": {
30       "required": false,
31       "type": "string",
32       "default": ""
33     },
34     "endpoint-selector": {
35       "required": false,
36       "type": "string"
37     },
38     "url-path": {
39       "required": true,
40       "type": "string"
41     },
42     "path": {
43       "required": true,
44       "type": "string"
45     },
46     "expression-type": {
47       "required": false,
48       "type": "string",
49       "default": "JSON_PATH",
50       "constraints": [
51         {
52           "valid_values": [
53             "JSON_PATH",
54             "JSON_POINTER"
55           ]
56         }
57       ]
58     },
59     "input-key-mapping": {
60       "required": false,
61       "type": "map",
62       "entry_schema": {
63         "type": "string"
64       }
65     },
66     "output-key-mapping": {
67       "required": false,
68       "type": "map",
69       "entry_schema": {
70         "type": "string"
71       }
72     },
73     "key-dependencies": {
74       "required": true,
75       "type": "list",
76       "entry_schema": {
77         "type": "string"
78       }
79     }
80   },
81   "derived_from": "tosca.nodes.ResourceSource"
82 }

Connection to a specific REST system can be expressed through the endpoint-selector property, which refers to a macro defining the information about the REST system the connect to. Understand TOSCA Macro in the context of CDS.

Few ways are available to authenticate to the REST system:
  • token-auth

  • basic-auth

  • ssl-basic-auth

token-auth:

1{
2  "dsl_definitions": {
3    "dynamic-rest-source": {
4      "type" : "token-auth",
5      "url" : "http://localhost:32778",
6      "token" : "<token>"
7    }
8  }
9}

basic-auth:

 1{
 2  "dsl_definitions": {
 3    "dynamic-rest-source": {
 4      "type" : "basic-auth",
 5      "url" : "http://localhost:32778",
 6      "username" : "<username>",
 7      "password": "<password>"
 8    }
 9  }
10}

ssl-basic-auth:

 1{
 2  "dsl_definitions": {
 3    "dynamic-rest-source": {
 4      "type" : "ssl-basic-auth",
 5      "url" : "http://localhost:32778",
 6      "keyStoreInstance": "JKS or PKCS12",
 7      "sslTrust": "trusture",
 8      "sslTrustPassword": "<password>",
 9      "sslKey": "keystore",
10      "sslKeyPassword": "<password>"
11    }
12  }
13}

Capability:

Expects a script to be provided.

image2

 1 {
 2   "description": "This is Component Resource Source Node Type",
 3   "version": "1.0.0",
 4   "properties": {
 5     "script-type": {
 6       "required": true,
 7       "type": "string",
 8       "default": "kotlin",
 9       "constraints": [
10         {
11           "valid_values": [
12             "kotlin",
13             "jython"
14           ]
15         }
16       ]
17     },
18     "script-class-reference": {
19       "description": "Capability reference name for internal and kotlin, for jython script file path",
20       "required": true,
21       "type": "string"
22     },
23     "instance-dependencies": {
24       "required": false,
25       "description": "Instance dependency Names to Inject to Kotlin / Jython Script.",
26       "type": "list",
27       "entry_schema": {
28         "type": "string"
29       }
30     },
31     "key-dependencies": {
32       "description": "Resource Resolution dependency dictionary names.",
33       "required": true,
34       "type": "list",
35       "entry_schema": {
36         "type": "string"
37       }
38     }
39   },
40   "derived_from": "tosca.nodes.ResourceSource"
41 }

Complex Type:

Value will be resolved through REST., and output will be a complex type.

Modeling reference: Modeling Concepts#rest

In this example, we’re making a POST request to an IPAM system with no payload.

Some ingredients are required to perform the query, in this case, $prefixId. Hence It is provided as an input-key-mapping and defined as a key-dependencies. Please refer to the modeling guideline for more in depth understanding.

As part of this request, the expected response will be as below.

 1 {
 2   "id": 4,
 3   "address": "192.168.10.2/32",
 4   "vrf": null,
 5   "tenant": null,
 6   "status": 1,
 7   "role": null,
 8   "interface": null,
 9   "description": "",
10   "nat_inside": null,
11   "created": "2018-08-30",
12   "last_updated": "2018-08-30T14:59:05.277820Z"
13 }

What is of interest is the address and id fields. For the process to return these two values, we need to create a custom data-type, as bellow

 1{
 2  "version": "1.0.0",
 3  "description": "This is Netbox IP Data Type",
 4  "properties": {
 5    "address": {
 6      "required": true,
 7      "type": "string"
 8    },
 9    "id": {
10      "required": true,
11      "type": "integer"
12    }
13  },
14  "derived_from": "tosca.datatypes.Root"
15}

The type of the data dictionary will be dt-netbox-ip.

To tell the resolution framework what is of interest in the response, the output-key-mapping section is used. The process will map the output-key-mapping to the defined data-type.

{
  "tags" : "oam-local-ipv4-address",
  "name" : "create_netbox_ip",
  "property" : {
    "description" : "netbox ip",
    "type" : "dt-netbox-ip"
  },
  "updated-by" : "adetalhouet",
  "sources" : {
    "config-data" : {
      "type" : "source-rest",
      "properties" : {
        "type" : "JSON",
        "verb" : "POST",
        "endpoint-selector" : "ipam-1",
        "url-path" : "/api/ipam/prefixes/$prefixId/available-ips/",
        "path" : "",
        "input-key-mapping" : {
          "prefixId" : "prefix-id"
        },
        "output-key-mapping" : {
          "address" : "address",
          "id" : "id"
        },
        "key-dependencies" : [ "prefix-id" ]
      }
    }
  }
}