File: openstack.rb

package info (click to toggle)
puppet-module-tempest 25.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,000 kB
  • sloc: ruby: 1,268; python: 38; sh: 10; makefile: 10
file content (50 lines) | stat: -rw-r--r-- 1,521 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
require File.join(File.dirname(__FILE__), '..','..','..', 'puppet/provider/tempest')

Puppet::Type.type(:tempest_glance_id_setter).provide(
  :openstack,
  :parent => Puppet::Provider::Tempest
) do

  @credentials = Puppet::Provider::Openstack::CredentialsV3.new

  def file_path
    resource[:tempest_conf_path]
  end

  def exists?
    conf = Puppet::Type::Tempest_config
      .new(:title => resource[:name], :path => file_path)
    entry = Puppet::Type.type(:tempest_config).provider(:ini_setting).new(conf)
    entry.exists?
  end

  def create
    conf = Puppet::Type::Tempest_config
      .new(:title => resource[:name], :value => get_image_id, :path => file_path)
    entry = Puppet::Type.type(:tempest_config).provider(:ini_setting).new(conf)
    entry.create
  end

  def destroy
    conf = Puppet::Type::Tempest_config
      .new(:title => resource[:name], :path => file_path)
    entry = Puppet::Type.type(:tempest_config).provider(:ini_setting).new(conf)
    entry.destroy
  end

  def get_image_id
    if resource[:ensure] == :present or resource[:ensure].nil?
      if @image_id.nil?
        images = self.class.request('image', 'list', file_path)
        img = images.detect {|img| img[:name] == resource[:image_name]}
        if img.nil?
          raise(Puppet::Error, "Image #{resource[:image_name]} not found!")
        end
        @image_id = img[:id]
      end
    elsif resource[:ensure] != :absent
      raise(Puppet::Error, "Cannot ensure to #{resource[:ensure]}")
    end
    @image_id
  end
end