API Guide

Table Of Contents
result = ASM::API::sign {
RestClient.get url
}
# Do some XML processing to find all published templates
doc = Nokogiri::XML(result)
templates = doc.xpath('//ServiceTemplate')
published = templates.select{|t| t.at_xpath('draft').content == 'false'}
template_names = published.collect{|t| t.at_xpath('templateName').content}
print "Published Templates:\n"
template_names.each{|name| print "%s\n" % name}
Get a ServiceTemplate by name
Here we retrieve an existing ServiceTemplate from ASM named 'TwoServers' by passing the 'filter' query
parameter. See the detail for ServiceTemplate in Appendix B for the full list of names that can be sorted
and filtered on. Note that even if the template name is unique this method will always return a container
around the result(s). For example, in the case of XML the root element is <ServiceTemplates>.
require 'ASMConfig'
url = ASM::API::URI('/ServiceTemplate')
template_name = 'TwoServers'
template_filter = "eq,name,#{template_name}"
response = ASM::API::sign {
RestClient.get url, {:params=>{:filter=>template_filter}}
}
The response object is not shown for this example because it is too verbose. However, within the
ServiceTemplate XML are parameters designated with the element <requiredAtDeploy>. If this value is
true, then this parameter will be required when this ServiceTemplate is deployed. Otherwise the
parameter is optional. For example, the server host name is required in this extracted snippet of the
ServiceTemplate. Save the result above to a file inspect the full XML for a ServiceTemplate.
<parameters>
<id>os_host_name</id>
<value/>
<type>STRING</type>
<displayName>Host Name</displayName>
<required>true</required>
<requiredAtDeployment>true</requiredAtDeployment>
<hideFromTemplate>true</hideFromTemplate>
<min>0</min>
<max>0</max>
<dependencyTarget>generate_host_name</dependencyTarget>
<dependencyValue>false</dependencyValue>
</parameters>
Publish a ServiceTemplate
In order to use a ServiceTemplate to deploy a Service, the ServiceTemplate must be first published. This is
accomplished by setting the ServiceTemplate element <draft> to false. i.e. it is no longer in the draft state.
require 'ASMConfig'
templateId = "ff8080814be03f17014bea250f100b7d"
url = ASM::API::URI("/ServiceTemplate/%s"%templateId)
22