File: openstack.rb

package info (click to toggle)
puppet-module-neutron 25.0.0-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,708 kB
  • sloc: ruby: 12,680; python: 38; sh: 15; makefile: 10
file content (76 lines) | stat: -rw-r--r-- 1,911 bytes parent folder | download | duplicates (4)
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
require File.join(File.dirname(__FILE__), '..','..','..',
                  'puppet/provider/neutron')

Puppet::Type.type(:neutron_security_group).provide(
  :openstack,
  :parent => Puppet::Provider::Neutron
) do
  desc <<-EOT
     Manage Neutron security group
  EOT

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

  def initialize(value={})
    super(value)
  end

  def create
    opts = [@resource[:name]]
    (opts << '--id' << @resource[:id]) if @resource[:id]
    (opts << '--description' << @resource[:description]) if @resource[:description]
    (opts << '--project' << @resource[:project]) if @resource[:project]
    (opts << '--project-domain' << @resource[:project_domain]) if @resource[:project_domain]
    @property_hash = self.class.request('security group', 'create', opts)
    @property_hash[:ensure] = :present
  end

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

  def destroy
    self.class.request('security group', 'delete', @property_hash[:id])
  end

  mk_resource_methods

  def id=(value)
    fail('id is read only')
  end

  def description=(value)
    fail('description is read only')
  end

  def project=(value)
    fail('project is read only')
  end

  def project_domain=(value)
    fail('project_domain is read only')
  end

  def self.instances
    request('security group', 'list', ['--all']).collect do |attrs|
      new(
          :ensure         => :present,
          :name           => attrs[:name],
          :id             => attrs[:id],
          :description    => attrs[:description],
          :project        => attrs[:project],
          :project_domain => attrs[:project_domain]
      )
    end
  end

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

end