Script Management API

/api/space/script-management/scripts

The following operations are supported on this resource:

GET /api/space/script-management/scripts (v2)


This API locates and returns a list of available scripts in the Junos Space database and supports the paging, filtering, and sorting of data.

Filtering and sorting is supported on the key and scriptName columns.

.

Access Control

The following capabilities are required to access this API:
"ViewScriptsCap"


Example Usage

GET /api/space/script-management/scripts

Content Types

  • Produces content types:
    application/vnd.net.juniper.space.script-management.scripts+xml;version=2;q=.02
    application/vnd.net.juniper.space.script-management.scripts+json;version=2;q=.02


  • Sample Output XML:

      <scripts uri="/api/space/script-management/scripts" size="1">
        <script key="524288"
          href="/api/space/script-management/scripts/524288"
           uri="/api/space/script-management/scripts/524288">
          <scriptName>slax-event1.slax</scriptName>
        </script>
        <method href="/api/space/script-management/scripts/exec-deploy" rel="deploy-scripts"/>
        <method href="/api/space/script-management/scripts/exec-scripts" rel="execute-scripts"/>
        <method href="/api/space/script-management/scripts/exec-disable" rel="disable-scripts"/>
        <method href="/api/space/script-management/scripts/exec-enable" rel="enable-scripts"/>
        <method href="/api/space/script-management/scripts/exec-remove" rel="remove-scripts"/>
        <method href="/api/space/script-management/scripts/exec-verify" rel="verify-scripts"/>
      </scripts>


  • Sample Output JSON:

    {"scripts":
      {"@uri":"/api/space/script-management/scripts",
      "@size":"1",
      "script":
        {"@key":"524288",
        "@href":"/api/space/script-management/scripts/524288",
        "@uri":"/api/space/script-management/scripts/524288",
        "scriptName":"slax-event1.slax"},
      "method":
        [{"@href":"/api/space/script-management/scripts/exec-deploy",
        "@rel":"deploy-scripts"},
        {"@href":"/api/space/script-management/scripts/exec-scripts",
        "@rel":"execute-scripts"},
        {"@href":"/api/space/script-management/scripts/exec-disable",
        "@rel":"disable-scripts"},
        {"@href":"/api/space/script-management/scripts/exec-enable",
        "@rel":"enable-scripts"},
        {"@href":"/api/space/script-management/scripts/exec-remove",
        "@rel":"remove-scripts"},
        {"@href":"/api/space/script-management/scripts/exec-verify",
        "@rel":"verify-scripts"
      }]
    }}



    For the deprecated versions of this API, refer to :
  • version 1

POST /api/space/script-management/scripts (v1)


This API is used to add or import script contents to the platform. The script type is always determined from the contents of the script and the field script type is never evaluated (even if there is a value present in the input).

Access Control

The following capabilities are required to access this API:
"ImportScriptsCap"


Example Usage

POST /api/space/script-management/scripts

Data Notification

This API supports data notification.

See the following links for information about enabling data notifications changes to be received for this service:

  • Data Notification Usage.


Content Types

  • Consumes content types:
    application/vnd.net.juniper.space.script-management.script+xml;version=1;charset=UTF-8
    application/vnd.net.juniper.space.script-management.script+json;version=1;charset=UTF-8


  • Produces content types:
    application/vnd.net.juniper.space.script-management.script+xml;version=1
    application/vnd.net.juniper.space.script-management.script+json;version=1


  • Sample Input XML:
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <script>
          <scriptName>cpu-usage-60.slax</scriptName>
          <scriptContents><![CDATA[

    Version 1.0;
    ns junos = "http://xml.juniper.net/junos/*\/junos";
    ns xnm = "http://xml.juniper.net/xnm/1.1/xnm";
    ns jcs = "http://xml.juniper.net/junos/commit-scripts/1.0";
    ns ext = "http://xmlsoft.org/XSLT/namespace";

    import "../import/junos.xsl";

    \/*
    * This commit script checks that any interfaces with "CORE" or "core"
    * in the description is configured with an MTU of 4484.
    * The search criteria and MTU should be changed to fit the environment
    * and requirements.
    *\/


    match configuration { for-each (interfaces/interface) { var $int = name; var $unit = unit/name; var $desc = unit/description; var $mtu = mtu; if (contains($desc, "CORE") || contains($desc, "core")) { if (not ($mtu == 4484)) { <xnm:warning> { <message> { expr "MTU on backbone interface"; expr $int; expr "."; expr $unit; expr " is not set to 4484"; expr " ("; expr $mtu; expr ")"; } } } } }
    }

          ]]></scriptContents>
    </script>


    Note : The actual script provided is inside a CDATA tag.



  • Sample Output XML:
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <script>
          <id>1114117</id>
          <scriptName>slax-event1.slax</scriptName>
          <type>TYPE_EVENT</type>
          <lastestRevision>1.1</lastestRevision>
          <scriptSize>7520</scriptSize>
          <completionStatus>IMPORT_SUCCESS</completionStatus>
    </script>


  • Sample Input JSON:


    {"script":
    {"scriptName":"slax-event1.slax","scriptContents":"Version 1.0;
    ns junos = \"http:\/\/xml.juniper.net\/junos\/*\/junos\";
    ns xnm = \"http:\/\/xml.juniper.net\/xnm\/1.1\/xnm\";
    ns jcs = \"http:\/\/xml.juniper.net\/junos\/commit-scripts\/1.0\";
    ns ext = \"http:\/\/xmlsoft.org\/XSLT\/namespace\";import \"..\/import\/junos.xsl\";

    /** This commit script checks that any interfaces with \"CORE\" or \"core\"
    * in the description is configured with an MTU of 4484.
    * The search criteria and MTU should be changed to fit the environment
    * and requirements.
    *\/
    match configuration { for-each (interfaces\/interface) { var $int = name; var $unit = unit\/name; var $desc = unit\/description; var $mtu = mtu; if (contains($desc, \"CORE\") || contains($desc, \"core\")) { if (not ($mtu == 4484)) { <xnm:warning> { <message> { expr \"MTU on backbone interface\"; expr $int; expr \".\"; expr $unit; expr \" is not set to 4484\"; expr \" (\"; expr $mtu;expr \")\"; } } } } } } "} }


    Note : The actual script provided starts from
    "Version 1.0;ns junos = ........... expr $mtu; expr \")\"; } } } } }}"

    Note that all special characters, new lines, tabs, and so on must be
    escaped in the contents of the script. This change is needed to correctly
    unmarshal script content by the JAX-B unmarshaler.


  • Sample Output JSON:
    script:
    {
          id: 1114117
          scriptName: slax-event1.slax
          type: TYPE_EVENT
          lastestRevision: 1.1
          scriptSize: 7520
          completionStatus: IMPORT_SUCCESS
    }