API Guide

"-------------------------------------------------------------------------------------------
---------\n"
doc.xpath('//ManagedDevice').sort_by{|d| d.at_xpath('deviceType').content}.each do |device|
svc_tag = device.at_xpath('serviceTag').content
state = device.at_xpath('state').content
ip_addr = device.at_xpath('ipAddress').content
model = device.at_xpath('model').content
dev_type = device.at_xpath('deviceType').content
print "%30s%15s%20s%20s%15s\n" % [svc_tag,state,ip_addr,model,dev_type]
end
ServiceTemplate
A ServiceTemplate is a reusable structure that denes the network topology and components of a future service deployment. A
trivial example template could be a single server component setup to run Linux. Deploying this template would result in a single
server being chosen from the available discovered resources and installing Linux on it.
Get all ServiceTemplates
Here we retrieve all ServiceTemplates and output the names of those not in draft mode ( published ). The draft property determines
if a template is in the published state. Only published templates can be deployed.
require 'ASMConfig'
url = ASM::API::URI('/ServiceTemplate')
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 'lter' query parameter. See the detail
for ServiceTemplate in Appendix B for the full list of names that can be sorted and ltered 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
19