Moab Web Services > Resources > Service Templates

Service Templates

This section describes the behavior of the Service Template object in Moab Web Services. It contains the URLs, request bodies, and responses delivered to and from MWS.

Service templates are tenant objects. If you have implemented a multi-tenant environment (for more information, see About Tenants), and are logged in with an application account, you must include a proxy-user with each service call to limit the results to information that the user has permission to see. If you are logged in with an LDAP account, MWS will automatically limit the results to information that the LDAP user has permission to see. For more information, see Roles.

The Fields: Service Templates reference section contains the type and description of all fields in the ServiceTemplate object. It also contains details regarding which fields are valid during PUT and POST actions.

See Create Service from Service Template to create services from service templates.

The Service Template name has the following constraints:

Supported methods

Resource GET PUT POST DELETE
rest/service-templates Get All Service Templates -- Create Service Template --
/rest/service-templates/<id> or <name> Get Single Service Template Modify Service Template -- Cancel Service Template

This topic contains these sections:

Getting Service Templates

The HTTP GET method is used to retrieve <name> information.

Quick reference

GET http://localhost:8080/mws/rest/service-templates?api-version=3[&query={"field":"value"}&sort={"field":<1|-1>}]
GET http://localhost:8080/mws/rest/service-templates/<id>?api-version=3
GET http://localhost:8080/mws/rest/service-templates/<name>?api-version=3

Get All Service Templates

URLs and parameters

GET http://localhost:8080/mws/rest/service-templates?api-version=3[&query={"field":"value"}&sort={"field":<1|-1>}]
Parameter Required Type Valid values Description Example
query No JSON -- Query for specific results. query={"type":"vm","createdBy":"name"}
sort No JSON -- Sort the results. Use 1 for ascending and -1 for descending. sort={"name":1}

See Global URL Parameters for available URL parameters.

Sample response

JSON response
------------------------------------

{
   "totalCount":4,
   "resultCount":4,
   "results":[
      {
         "attributes":{
            "moab":{
               "job":{
                  "resources":{
                     "OS":100
                  },
                  "template":"OSStorage",
                  "variables":{
                     "var1":"variable to be attached to tracking job"
                  },
                  "rules":{
                     "MOAB_DATACENTER":[
                        {
                           "value":"datacenter2",
                           "restriction":"must",
                           "comparator":"%=",
                           "displayValue":null
                        }
                     ]
                  },
                  "nodeSet": {
                    "selection": "FIRSTOF",
                    "type": "VARATTR",
                    "name": "MOAB_DATACENTER",
                    "values": ["vcenter-datacenter-416"]
                  }
               }
            },
            "sharedData":{
               "custom1":"Custom data to be attached to service",
               "custom2":"More custom data to be attached to service"
            }
         },
         "createdBy":"bob",
         "includedServices":[
         ],
         "hookDefinitions": [],
         "label":"Operating System Storage",
         "modified":null,
         "name":"OpSysStorage",
         "tags":[
            "tag1",
            "tag2",
            "tag3"
         ],
         "type":"storage",
         "version":0,
         "id":"50d4da1ac4aaceecaf386452"
      },
      {
         "attributes":{
            "moab":{
               "job":{
                  "resources":{
                     "gold":100
                  },
                  "template":"extraStorage",
                  "variables":{
                     "var1":"variable to be attached to tracking job"
                  },
                  "rules":{
                     "MOAB_DATACENTER":[
                        {
                           "value":"datacenter2",
                           "restriction":"must",
                           "comparator":"%=",
                           "displayValue":null
                        }
                     ]
                  },
                  "nodeSet": {
                    "selection": "FIRSTOF",
                    "type": "VARATTR",
                    "name": "MOAB_DATACENTER",
                    "values": ["vcenter-datacenter-416"]
                  }
               }
            },
            "sharedData":{
               "custom1":"Custom data to be attached to service",
               "custom2":"More custom data to be attached to service"
            }
         },
         "createdBy":"bob",
         "includedServices":[

         ],
         "hookDefinitions": [],
         "label":"Network Storage",
         "modified":null,
         "name":"NetworkStorage",
         "tags":[
            "tag1",
            "tag2",
            "tag3"
         ],
         "type":"storage",
         "version":0,
         "id":"50d4da1ac4aaceecaf386453"
      },
      {
         "attributes":{
            "moab":{
               "job":{
                  "image":"centos5.5-stateless",
                  "resources":{
                     "procs":1,
                     "mem":1024,
                     "disk":20480
                  },
                  "template":"genericVM",
                  "variables":{
                     "var1":"variable to be attached to tracking job"
                  },
                  "rules":{
                     "MOAB_DATACENTER":[
                        {
                           "value":"datacenter2",
                           "restriction":"must",
                           "comparator":"%=",
                           "displayValue":null
                        }
                     ]
                  },
                  "nodeSet": {
                    "selection": "FIRSTOF",
                    "type": "VARATTR",
                    "name": "MOAB_DATACENTER",
                    "values": ["vcenter-datacenter-416"]
                  }
               }
            },
            "sharedData":{
               "custom1":"Custom data to be attached to service",
               "custom2":"More custom data to be attached to service"
            }
         },
         "createdBy":"bob",
         "includedServices":[

         ],
         "hookDefinitions": [],
         "label":"Centos 5.5 VM",
         "modified":null,
         "name":"Centos55Vm",
         "tags":[
            "tag1",
            "tag2",
            "tag3"
         ],
         "type":"vm",
         "version":0,
         "id":"50d4da1ac4aaceecaf386454"
      },
      {
         "attributes":{
            "moab":{
               "dependencies":[
                  {
                     "dependency":[
                        "oss",
                        "ns"
                     ],
                     "localName":"cvm"
                  }
               ],
               "job":{
                  "rules":{
                     "MOAB_DATACENTER":[
                        {
                           "value":"datacenter2",
                           "restriction":"must",
                           "comparator":"%=",
                           "displayValue":null
                        }
                     ]
                  },
                  "nodeSet": {
                    "selection": "FIRSTOF",
                    "type": "VARATTR",
                    "name": "MOAB_DATACENTER",
                    "values": ["vcenter-datacenter-416"]
                  }
               }
            },
            "sharedData":{
               "custom1":"Custom data to be attached to service",
               "custom2":"More custom data to be attached to service"
            }
         },
         "createdBy":"bob",
         "includedServices":[
            {
               "localName":"cvm",
               "serviceTemplate":"Centos55Vm"
            },
            {
               "localName":"oss",
               "serviceTemplate":"OpSysStorage"
            },
            {
               "localName":"ns",
               "serviceTemplate":"NetworkStorage"
            }
         ],
         "hookDefinitions": [],
         "label":"Centos 5.5 VM Plus OS and Network Storage",
         "modified":null,
         "name":"Centos55VmPlusStorage",
         "tags":[
            "tag1",
            "tag2",
            "tag3"
         ],
         "type":"container",
         "version":0,
         "id":"50d4da1ac4aaceecaf386455"
      }
   ]
}

Querying service templates

It is possible to query service templates by one or more fields based on the MongoDB query syntax.

For example queries, see Querying services. In the query URL, be sure to replace "services" with "service-templates."

Sorting

See the sorting section of Global URL Parameters.

Limiting the number of results

For examples of limiting the number of results, see Limiting the number of results. In the URL, be sure to replace "services" with "service-templates."

Retrieving a subset of fields

For examples of retrieving a subset of fields, see Retrieving a subset of fields. In the URL, be sure to replace "services" with "service-templates."

Get Single Service Template

URLs and parameters

GET http://localhost:8080/mws/rest/service-templates/<id>?api-version=3[&recursive=true]
GET http://localhost:8080/mws/rest/service-templates/<name>?api-version=3[&recursive=true]
Parameter Required Type Valid values Description Example
id Yes String -- The unique identifier of the service template. Must contain exactly 24 alphanumeric characters. --
name Yes String -- The name of the service template. --
recursive No Boolean true or false true shows details about all included templates, including nested templates. Default is false . recursive=true

Only one of id or name is required.

See Global URL Parameters for available URL parameters.

Response

GET http://localhost:8080/mws/rest/service-templates/Centos55Vm?api-version=3
------------------------------------

{
   "attributes":{
      "moab":{
         "job":{
            "image":"centos5.5-stateless",
            "resources":{
               "procs":1,
               "mem":1024,
               "disk":20480
            },
            "template":"genericVM",
            "variables":{
               "var1":"variable to be attached to tracking job"
            },
            "rules":{
               "MOAB_DATACENTER":[
                  {
                     "value":"datacenter2",
                     "restriction":"must",
                     "comparator":"%=",
                     "displayValue":null
                  }
               ]
            },
            "nodeSet":"FIRSTOF:FEATURE:feature1"
         }
      },
      "sharedData":{
         "custom1":"Custom data to be attached to service",
         "custom2":"More custom data to be attached to service"
      }
   },
   "createdBy":"bob",
   "id":"50d4da1ac4aaceecaf386454",
   "includedServices":[
   ],
   "hookDefinitions": [],
   "label":"Centos 5.5 VM",
   "modified":null,
   "name":"Centos55Vm",
   "tags":[
      "tag1",
      "tag2",
      "tag3"
   ],
   "type":"vm",
   "version":0
}
GET http://localhost:8080/mws/rest/service-templates/OpSysStorage?api-version=3
------------------------------------

{
   "attributes":{
      "moab":{
         "job":{
            "resources":{
               "OS":100
            },
            "template":"OSStorage",
            "variables":{
               "var1":"variable to be attached to tracking job"
            },
            "rules":{
               "MOAB_DATACENTER":[
                  {
                     "value":"datacenter2",
                     "restriction":"must",
                     "comparator":"%=",
                     "displayValue":null
                  }
               ]
            },
            "nodeSet":"FIRSTOF:FEATURE:feature1"
         }
      },
      "sharedData":{
         "custom1":"Custom data to be attached to service",
         "custom2":"More custom data to be attached to service"
      }
   },
   "createdBy":"bob",
   "id":"50d4da1ac4aaceecaf386452",
   "includedServices":[
   ],
   "hookDefinitions": [],
   "label":"Operating System Storage",
   "modified":null,
   "name":"OpSysStorage",
   "tags":[
      "tag1",
      "tag2",
      "tag3"
   ],
   "type":"storage",
   "version":0
}
GET http://localhost:8080/mws/rest/service-templates/NetworkStorage?api-version=3
------------------------------------

{
   "attributes":{
      "moab":{
         "job":{
            "resources":{
               "gold":100
            },
            "template":"extraStorage",
            "variables":{
               "var1":"variable to be attached to tracking job"
            },
            "rules":{
               "MOAB_DATACENTER":[
                  {
                     "value":"datacenter2",
                     "restriction":"must",
                     "comparator":"%=",
                     "displayValue":null
                  }
               ]
            },
            "nodeSet":"FIRSTOF:FEATURE:feature1"
         }
      },
      "sharedData":{
         "custom1":"Custom data to be attached to service",
         "custom2":"More custom data to be attached to service"
      }
   },
   "createdBy":"bob",
   "id":"50d4da1ac4aaceecaf386453",
   "includedServices":[
   ],
   "hookDefinitions": [],
   "label":"Network Storage",
   "modified":null,
   "name":"NetworkStorage",
   "tags":[
      "tag1",
      "tag2",
      "tag3"
   ],
   "type":"storage",
   "version":0
}
GET http://localhost:8080/mws/rest/service-templates/Centos55VmPlusStorage?api-version=3
------------------------------------

{
   "attributes":{
      "moab":{
         "dependencies":[
            {
               "dependency":[
                  "oss",
                  "ns"
               ],
               "localName":"cvm"
            }
         ],
         "job":{
            "rules":{
               "MOAB_DATACENTER":[
                  {
                     "value":"datacenter2",
                     "restriction":"must",
                     "comparator":"%=",
                     "displayValue":null
                  }
               ]
            },
            "nodeSet":"FIRSTOF:FEATURE:feature1"
         }
      },
      "sharedData":{
         "custom1":"Custom data to be attached to service",
         "custom2":"More custom data to be attached to service"
      }
   },
   "createdBy":"bob",
   "id":"50d4da1ac4aaceecaf386455",
   "includedServices":[
      {
         "localName":"cvm",
         "serviceTemplate":"Centos55Vm"
      },
      {
         "localName":"oss",
         "serviceTemplate":"OpSysStorage"
      },
      {
         "localName":"ns",
         "serviceTemplate":"NetworkStorage"
      }
   ],
   "hookDefinitions": [],
   "label":"Centos 5.5 VM Plus OS and Network Storage",
   "modified":null,
   "name":"Centos55VmPlusStorage",
   "tags":[
      "tag1",
      "tag2",
      "tag3"
   ],
   "type":"container",
   "version":0
}

Creating Service Templates

The HTTP POST method is used to create Service Templates.

Quick reference

POST http://localhost:8080/mws/rest/service-templates?api-version=3

If you are logged in as an application account or LDAP user and submit a service template without specifying the user, MWS considers the user as which you are logged in the user of the service template.

Create Service Template

URLs and parameters

POST http://localhost:8080/mws/rest/service-templates?api-version=3

See Global URL Parameters for available URL parameters.

Request body

The tenant field is required and must contain only letters, digits, periods, dashes, and underscores. For POST and PUT actions, the tenant name or ID, or both the name and ID must be specified; if both the name and ID are specified, they must both refer to the same tenant or MWS returns an error.

includedServices is a key-value pair of the internal service name and the serviceTemplate. The service name is unique for each service container.

The name field is deprecated in version 8.1.0. If it is set, it must be unique. However, if the name field is not set, a new UUID will be automatically generated for each service without a name value.

The label field is required and must not be blank. However, if the name field is already specified by the client, it will be automatically used as the label.

If neither name or label field is set during service creation, an error will occur.

For information about configuring service lifecycle phase hooks on a service template, see Creating Service Lifecycle Phase Hooks on the Services resource page.

Sample response

JSON response for successful POST
------------------------------------

{"id":"4f06111184ae2bbfa31fa4c7"}

Modifying Service Templates

The HTTP PUT method is used to modify Service Templates.

The modified field is not automatically updated. It will need to be changed by the user.

Quick reference

PUT http://localhost:8080/mws/rest/service-templates/<id>?api-version=3
PUT http://localhost:8080/mws/rest/service-templates/<name>?api-version=3

Modify Service Template

URLs and parameters

PUT http://localhost:8080/mws/rest/service-templates/<id>
PUT http://localhost:8080/mws/rest/service-templates/<name>
Parameter Required Type Valid values Description
id Yes String (24 alphanumeric characters) The unique identifier of the service template.
name Yes String -- The name of the service template.

Only one of id or name is required.

See Global URL Parameters for available URL parameters.

Request body

This is similar to create, except you change the request body to what you need modified.

The request body below shows some of the fields that are available when modifying a Service Template, along with some sample values.

PUT http://localhost:8080/mws/rest/service-templates/Centos55Vm?api-version=3
------------------------------------

{
   "label":"Centos 5.5 VM (updated)",
   "createdBy":"newUser",
   "tags":["newTag","newTag2"],
   "attributes":{
      "moab":{
         "job":{
            "image":"centos5.5-stateful",
            "resources":{
               "procs":2,
               "mem":2048,
               "disk":22480
            },
            "template":"genericVM",
            "variables":{
               "newVar":"variable to be attached to tracking job",
            }
         }
      },
      "sharedData":{
         "custom3":"Custom data to be attached to service",
         "custom4":"More custom data to be attached to service"
      }
   }
}

Sample response

JSON response for successful PUT
------------------------------------

{
   "attributes":{
      "moab":{
         "job":{
            "image":"centos5.5-stateful",
            "resources":{
               "procs":2,
               "mem":2048,
               "disk":22480
            },
            "template":"genericVM",
            "variables":{
               "newVar":"variable to be attached to tracking job"
            }
         }
      },
      "sharedData":{
         "custom3":"Custom data to be attached to service",
         "custom4":"More custom data to be attached to service"
      }
   },
   "createdBy":"newUser",
   "id":"50d4de6bc4aa6ca84bbe9be4",
   "includedServices":[
   ],
   "hookDefinitions": [],
   "label":"Centos 5.5 VM (updated)",
   "modified":"2012-12-21 15:12:01 MST",
   "name":"Centos55Vm",
   "tags":[
      "newTag",
      "newTag2"
   ],
   "type":"vm",
   "version":0
}

Deleting (Canceling) Service Templates

The HTTP DELETE method is used to delete Service Templates.

Quick reference

DELETE http://localhost:8080/mws/rest/service-templates/<id>?api-version=3
DELETE http://localhost:8080/mws/rest/service-templates/<name>?api-version=3

Cancel Service Template

URLs and parameters

DELETE http://localhost:8080/mws/rest/service-templates/<id|name>?api-version=3
Parameter Required Type Valid values Description
id Yes String (24 alphanumeric characters) The unique identifier of the service template.
name Yes String -- The name of the service template.

Only one of id or name is required.

See Global URL Parameters for available URL parameters.

Response

Related Topics 

© 2015 Adaptive Computing