Internal functions

The following internal functions are available for you to use when creating your templates:

  • func_join
  • get_input
  • get_attribute
  • get_random_str

func_join

The func_join internal function is a string join function. A primary use of func_join is to set the names of the nodes defined in your templates.

In the example below the func_join internal function is being used to set the name of a node. The first argument to the func_join internal function is the separator character, the remaining arguments are the strings to be joined. The end result of the server name from the example above will be xxxxxxxxxx-yyyyyyyyyy-wordpress_vm-z where:

  • xxxxxxxxxx is the stack name retrieved from the user input
  • yyyyyyyyyy is the server name retrieved from the user input
  • z is a number starting with 1 generated by Dell Cloud Manager to give the server a unique name

Example

wordpress_vm:
    type: baseVM
    properties:
        name:  { func_join: ["-", [{ get_input: name }, "wordpress_vm"]]}

get_input

The get_input internal function is used to set the values of properties in your nodes to the values of inputs defined in the inputs: section of your template, some of which are entered when the user launches a blueprint.

Example

node_templates:
  test_vm:
    type: dcm.nodes.Server
    properties:
      name: "web-server"
      cloud: { get_input: [account_region_zone_selector, cloud] }              # Retrieve cloud from the AccountRegionSelector
      cloudAccountId: { get_input: [account_region_zone_selector, accountId] } # Retrieve the cloud account ID from the AccountRegionSelector
      region: { get_input: [account_region_zone_selector, region] }            # Retrieve region from the AccountRegionSelector
      zone: { get_input: [account_region_zone_selector, zone] }                # Retrieve zone from the AccountRegionSelector
      platform: { get_input: [product_selector, platform] }                    # Retrieve platform from the Product selector
      architecture: { get_input: [product_selector, architecture] }            # Retrieve architecture from the Product selector
      product: { get_input: [product_selector, product] }                      # Retrieve product from the Product selector
      image: { get_input: [product_selector, image] }                          # Retrieve machine from the Product selector
      serverProductId: { get_input: [product_selector, serverProductId] }      # Retrieve server product id from the Product selector

get_attribute

The get_attribute internal function is used to retrieve values of attributes from resources in the stack (virtual machines, firewalls and load balancers) for automation and displaying.

In the below example the get_attribute: function is is retrieving the public IP address (publicIpAddress) of a server. To get the hostname/ipaddress of a Cloud Provider load balancer the attribute is address.

Example

outputs:                                                        # Define Outputs
    application_group:                                          # Create a Group
      type: dcm.outputs.displayGroup                            # It's a displayGroup
        properties:
            displayName: "Apache Web Server Information"        # Set the display name for the group containing the outputs which appears on the Stack Overview page

    vm_ip:                                                      # Define an output
      type: string                                              # It's a string output
      description: IP of the server                             # Set the description for the string output
      value: {get_attribute: [vm, publicIpAddress]}             # Set the value to the public IP address of the server running in the stack
      properties:
        displayName: IP address                                 # Set the display name (label) for the string output
        displayGroup: application_group                         # Place this output in the displayGroup named application_group

    link:                                                       # Define another output
      type: dcm.outputs.Uri                                     # It's a URI output
      value: http://xxxxxxxxxxxxx/wp-admin                      # Set the initial value
      properties:
        host: {get_attribute: [vm, publicIpAddress]}            # Set the hostname/ipaddress portion of the URI to the public IP address of the server running in the stack
        displayName: Admin portal url                           # Set the display name (label) for the URI output
        displayGroup: application_group                         # Place this output in the displayGroup named application_group

get_random_str

The get_random_str internal function is used to generate strings with random values. By default the get_random_str function returns a string with mixed cased alpha and numeric characters. You can have the get_random_str function generate a string with special characters (e.g. ~!@#$%^&*_+,()_-=<>;,?) in addition to the mixed case alpha and numeric characters.

A good use for this function is to generate passwords. The syntax of the get_random_str function is:

get_random_str: [xx]

or

get_random_str: [xx, true]

Where xx specifies the size of the random string, and true specifies to include special characters in the generated random string.

Example

node_templates:
  docker_app:
    type: dcm.nodes.DockerApp
    properties:
      image: dell/joomla
      tag: 1.2
      runCommand: '/run.sh'
      ports: [80, 443, 3306]
      db_pass: {get_random_str: [10]}
      joomla_pass: {get_random_str: [10]}
      portBindings:
        80: [['0.0.0.0', 80]]
        443: [['0.0.0.0', 443]]
        3306: [['0.0.0.0', 3306]]
      environmentVariables:
        MYSQL_PASS: {get_property: [SELF, db_pass]}
        JOOMLA_PASS: {get_property: [SELF, joomla_pass]}
  requirements:
    - host: vm