Skip to content

SMC scripts syntax

Yann Hervé edited this page Nov 23, 2018 · 3 revisions

script syntax

The syntax of the script is made to translate exactly to an XML format, while providing a very readable syntax, which means that once you're familiar with the syntax, you can refer to the 'smc api' for a description of the resources parameters.

In practice, you often even don't need to do so: the easiest way to write script is to use the smc GUI, then to perform a query and use the retrieved object as a starting point.

elements and attributes

So, like in xml, the language is composed of elements that have attributes:

Example

The 'network' element below has 3 attributes 'name' and 'ipv4_network' and 'broadcast'

<network name="intnw3" broadcast="false" ipv4_network="192.168.3.0/24" />

The equivalent in the scripting language is:

network {
    name="intnw3"
    ipv4_network="192.168.3.0/24"
    broadcast="false"
}

The quotes surrounding the attributes values can be omitted most of the time (eg to represent simple names, number, ip addresses, constants...)

For more readability, the 'name' attribute can be placed just after the element, so our example becomes

network intnw3 {
    ipv4_network=192.168.3.0/24
    broadcast=false
}

Note that you can write several attributes on the same line, the same way you would do in xml (space-separated). To increase readability, you can separate the attributes with a ';'

network intnw3 {
    ipv4_network=192.168.3.0/24; broadcast=false
}

sub-elements

in xml, elements can contain sub-elements.

for example a single firewall has many physical interfaces (long list of attributes omitted here)

<single_fw name="myfw1" ...>
    <physical_interface name="Interface 0" ...>
    </physical_interface>

    <physical_interface name="Interface 1" ...>
    </physical_interface>
</single_fw>

The sub-elements would be expressed like this:

single_fw myfw1 {
    physical_interface "Interface 0" {
        ...
    }
    physical_interface "Interface 1" {
        ...
    }
}

Note that the quotes are mandatory here because of the 'space' character.

text section

in xml, elements can have a text, this is sometimes preferred to attributes because attributes can hold only one value.

Example:

<proxy_usage>tls_inspection</proxy_usage>

Would be written

proxy_usage {"tls_inspection"}

But it is so common to use elements and text to represent a name/value that a more compact equivalent syntax exist:

proxy_usage "tls_inspection";

In this case, the ';' is mandatory

comments

There are 3 ways to write comments:

  • shell style

      # this is a comment
    
  • c++ style

      // this is a comment
    
  • c style (multiline)

      /*
       * this is a comment
       */
    

nested form

When elements are nested and containing elements are unique, it is possible to use a more compact syntax using '.' , so:

Example:

    fw_ipv4_access_rule "myrule" {
        destinations {
            any = true
        }
        sources {
            any = true
        }
    }

Can be written:

    fw_ipv4_access_rule "myrule" {
        destinations.any = true
        sources.any = true
    }

hierarchical names

Hierarchical names are the equivalent of url 'href' in the smc-api. They represent either system elements or user-defined element

  • a hname begins with a '#'

  • a hname is composed of parts separated by a '/'

  • the first part corresponds to the element type (eg single_fw)

  • the second part corresponds to the element name (eg myfw1)

  • the rest corresponds to 'links' or 'results'

  • hnames can be discovered using the 'smc-script list' command.

  • hnames can be converted to url using the 'smc-script hname' command.

hname parts using indexes

Sometimes, it is more convenient to use an index to reference an element

For example, the default log server name contains its ip address, which requires change if you deploy the script on another smc.

Instead you can simply say, I want to use the first log server (at index 0)

"#log_server/[0]"

Example of hnames

system element representing http service

"#tcp_service/HTTP"

user-defined element representing a network

"#network/network12"

hnames are also used to represent an action on an element:

Examples

generate self-signed certificate on 'mycert2'

"#tls_signing_certificate_authority/mycert2/generate_self_signed_cert"

perform an initial contact to firewall myfw1

"#single_fw/myfw1/firewall_node/myfw1node/initial_contact"

add a rule before an existing rule in a policy

"#fw_policy/mypolicy/fw_ipv6_access_rules/myrule1/add_before"

Clone this wiki locally