1 # Load the Glance provider library to help
2 require File.join(File.dirname(__FILE__), '..','..','..', 'puppet/provider/glance')
4 Puppet::Type.type(:glance_image).provide(
6 :parent => Puppet::Provider::Glance
9 Glance provider to manage glance_image type.
11 Assumes that the glance-api service is on the same host and is working.
14 commands :glance => 'glance'
19 list_glance_images.collect do |image|
20 attrs = get_glance_image_attrs(image)
23 :name => attrs['name'],
24 :is_public => attrs['is_public'],
25 :container_format => attrs['container_format'],
27 :disk_format => attrs['disk_format']
32 def self.prefetch(resources)
34 resources.keys.each do |name|
35 if provider = images.find{ |pkg| pkg.name == name }
36 resources[name].provider = provider
42 @property_hash[:ensure] == :present
47 # copy_from cannot handle file://
48 if resource[:source] =~ /^\// # local file
49 location = "--file=#{resource[:source]}"
51 location = "--copy-from=#{resource[:source]}"
53 # location cannot handle file://
54 # location does not import, so no sense in doing anything more than this
55 elsif resource[:location]
56 location = "--location=#{resource[:location]}"
58 raise(Puppet::Error, "Must specify either source or location")
60 results = auth_glance('image-create', "--name=#{resource[:name]}", "--is-public=#{resource[:is_public]}", "--container-format=#{resource[:container_format]}", "--disk-format=#{resource[:disk_format]}", location)
64 # Check the old behavior of the python-glanceclient
65 if results =~ /Added new image with ID: (\S+)/
67 else # the new behavior doesn't print the status, so parse the table
68 results_array = parse_table(results)
69 results_array.each do |result|
70 if result["Property"] == "id"
79 :name => resource[:name],
80 :is_public => resource[:is_public],
81 :container_format => resource[:container_format],
82 :disk_format => resource[:disk_format],
86 fail("did not get expected message from image creation, got #{results}")
91 auth_glance('image-delete', id)
92 @property_hash[:ensure] = :absent
96 auth_glance('image-update', id, "--location=#{value}")
100 auth_glance('image-update', id, "--is-public=#{value}")
103 def disk_format=(value)
104 auth_glance('image-update', id, "--disk-format=#{value}")
107 def container_format=(value)
108 auth_glance('image-update', id, "--container-format=#{value}")
112 fail('id is read only')