Hello world TOSCA template

Let's build our first template describing a compute node. We will use the indigo custom type tosca.nodes.indigo.Compute reported below. Look at the full definition here.

Before reading the example tab, try to write down the node template respecting the node type definition. Then compare it with the example.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
  tosca.nodes.indigo.Compute:
    derived_from: tosca.nodes.indigo.MonitoredCompute
    attributes:
      private_address:
        type: list
        entry_schema:
          type: string
      public_address:
        type: list
        entry_schema:
          type: string
      ctxt_log:
        type: string
    capabilities:
      scalable:
        type: tosca.capabilities.indigo.Scalable
      os:
         type: tosca.capabilities.indigo.OperatingSystem
      endpoint:
        type: tosca.capabilities.indigo.Endpoint
      host:
        type: tosca.capabilities.indigo.Container
        valid_source_types: [tosca.nodes.SoftwareComponent]"
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
    server_node:
      type: tosca.nodes.indigo.Compute
      capabilities:
        scalable:
          properties:
            count: 1
        endpoint:
          properties:
            network_name: PUBLIC
            ports:
              http:
                protocol: tcp
                source: 80
        host:
          properties:
            num_cpus: 1
            mem_size: 2
        os:
          properties:
            distribution: ubuntu
            type: linux
            version: 16.04

Info

Pay attention at the endpoint capability that specifies the network configuration and the exposed ports.

Now let try to add the inputs section in order to allow the customization of the deployment. For example, we could provide input values for the node resources (cpu, ram).

Attention

Don't forget:

  • the tag tosca_definitions_version: tosca_simple_yaml_1_0 that must appear at the beginning of the template

  • the imports tag:

    1
    2
    imports:
      - indigo_custom_types: https://raw.githubusercontent.com/indigo-dc/tosca-types/k8s/custom_types.yaml
    

1
Click on the "TOSCA template" tab to see a possible solution.
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
tosca_definitions_version: tosca_simple_yaml_1_0

imports:
  - indigo_custom_types: https://raw.githubusercontent.com/indigo-dc/tosca-types/k8s/custom_types.yaml

description: >
  Launch a compute node getting the IP and SSH credentials to access via ssh

topology_template:

  inputs:        
    num_cpus:
      type: integer
      description: Number of virtual cpus for the VM
      default: 1
      constraints:
      - valid_values: [ 1, 2, 4 ]
    mem_size:
      type: scalar-unit.size
      description: Amount of memory for the VM
      default: 2 GB
      constraints:
      - valid_values: [ 2 GB, 4 GB ]  

    num_instances:
      type: integer
      description: Number of VMs to be spawned
      default: 1      

    os_distribution: 
      type: string
      default: ubuntu


  node_templates:

    simple_node:
      type: tosca.nodes.indigo.Compute
      capabilities:
        endpoint:
          properties:
            network_name: PUBLIC
        scalable:
          properties:
            count: { get_input: num_instances }
        host:
          properties:
            num_cpus: { get_input: num_cpus }
            mem_size: { get_input: mem_size }
        os:
          properties:
            distribution: { get_input: os_distribution }
            type: linux

  outputs:
    node_ip:
      value: { get_attribute: [ simple_node, public_address, 0 ] }
    node_creds:
      value: { get_attribute: [ simple_node, endpoint, credential, 0 ] }