File: openstack.rb

package info (click to toggle)
puppet-module-mistral 25.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,004 kB
  • sloc: ruby: 2,093; python: 38; makefile: 11; sh: 10
file content (90 lines) | stat: -rw-r--r-- 2,347 bytes parent folder | download | duplicates (2)
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
require File.join(File.dirname(__FILE__), '..','..','..', 'puppet/provider/mistral')

Puppet::Type.type(:mistral_workflow).provide(
  :openstack,
  :parent => Puppet::Provider::Mistral
) do
  desc <<-EOT
    Mistral provider to manage workflow type
  EOT

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

  mk_resource_methods

  def create
    properties = []
    properties << (@resource[:is_public] == :true ? '--public' : '--private')
    properties << @resource[:definition_file]

    self.class.request('workflow', 'create', properties)
    @property_hash[:ensure] = :present
    @property_hash[:definition_file] = resource[:definition_file]
    @property_hash[:is_public] = resource[:is_public]
    @property_hash[:name] = name
  end

  def exists?
    @property_hash[:ensure] == :present
  end

  def destroy
    self.class.request('workflow', 'delete', @resource[:name])
    @property_hash.clear
  end

  def update
    # Update the workflow if it exists, otherwise create it
    if exists?
      properties = []
      if @resource[:is_public] == :true
        properties << '--public'
      end
      properties << @resource[:definition_file]

      self.class.request('workflow', 'update', properties)
      @property_hash[:ensure] = :present
      @property_hash[:definition_file] = resource[:definition_file]
      @property_hash[:is_public] = resource[:is_public]
      @property_hash[:name] = name
    else
      create
    end
  end

  def self.instances
    list = request('workflow', 'list')
    list.collect do |wf|
      attrs = request('workflow', 'show', wf[:id])
      new({
        :ensure => :present,
        :id     => wf[:id],
        :name   => wf[:name],
        :is_public => (attrs[:scope] == "public")
      })
    end
  end

  def self.prefetch(resources)
    workflows = instances
    resources.keys.each do |name|
      if provider = workflows.find{ |wf| wf.name == name }
        resources[name].provider = provider
      end
    end
  end

  def flush
    if @property_flush
      opts = [@resource[:name]]

      (opts << '--public') if @property_flush[:is_public] == :true
      (opts << '--private') if @property_flush[:is_public] == :false
      opts << @property_flush[:definition_file]

      self.class.request('workflow', 'update', opts)
      @property_flush.clear
    end
  end

end