Module: CloudstackClient::Template

Defined in:
lib/cloudstack_client/commands/template.rb

Instance Method Summary collapse

Instance Method Details

#get_template(name) ⇒ Object

Finds the template with the specified name.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/cloudstack_client/commands/template.rb', line 8

def get_template(name)

  # TODO: use name parameter
  # listTemplates in CloudStack 2.2 doesn't seem to work
  # when the name parameter is specified. When this is fixed,
  # the name parameter should be added to the request.
  params = {
      'command' => 'listTemplates',
      'templateFilter' => 'executable'
  }
  json = send_request(params)

  templates = json['template']
  if !templates then
    return nil
  end

  templates.each { |t|
    if t['name'] == name then
      return t
    end
  }

  nil
end

#list_templates(args = {}) ⇒ Object

Lists all templates that match the specified filter.

Allowable filter values are:

  • featured - templates that are featured and are public

  • self - templates that have been registered/created by the owner

  • self-executable - templates that have been registered/created by the owner that can be used to deploy a new VM

  • executable - all templates that can be used to deploy a new VM

  • community - templates that are public



45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/cloudstack_client/commands/template.rb', line 45

def list_templates(args = {})
  filter = args[:filter] || 'featured'
  params = {
      'command' => 'listTemplates',
      'templateFilter' => filter
  }
  params['projectid'] = args[:project_id] if args[:project_id]
  params['zoneid'] = args[:zone_id] if args[:zone_id]
  
  json = send_request(params)
  json['template'] || []
end