summaryrefslogtreecommitdiffstats
path: root/lib/puppet/provider/network_device.rb
blob: 58865fddccab87cf68218c97bbdf525e6c7419ac (plain)
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

# This is the base class of all prefetched network device provider
class Puppet::Provider::NetworkDevice < Puppet::Provider

  def self.lookup(url, name)
    raise "This provider doesn't implement the necessary lookup method"
  end

  def self.prefetch(resources)
    resources.each do |name, resource|
      if result = lookup(resource[:device_url], name)
        result[:ensure] = :present
        resource.provider = new(result)
      else
        resource.provider = new(:ensure => :absent)
      end
    end
  end

  def exists?
    @property_hash[:ensure] != :absent
  end

  def initialize(*args)
    super

    # Make a duplicate, so that we have a copy for comparison
    # at the end.
    @properties = @property_hash.dup
  end

  def create
    @property_hash[:ensure] = :present
    self.class.resource_type.validproperties.each do |property|
      if val = resource.should(property)
        @property_hash[property] = val
      end
    end
  end

  def destroy
    @property_hash[:ensure] = :absent
  end

  def flush
    @property_hash.clear
  end

  def self.instances
  end

  def former_properties
    @properties.dup
  end

  def properties
    @property_hash.dup
  end
end