Class: Puppet::Provider::BambooEnsurableProvider

Inherits:
Puppet::Provider
  • Object
show all
Defined in:
lib/puppet/provider/bamboo_ensurable_provider.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value = {}) ⇒ BambooEnsurableProvider

Returns a new instance of BambooEnsurableProvider.



27
28
29
30
# File 'lib/puppet/provider/bamboo_ensurable_provider.rb', line 27

def initialize(value={})
  super(value)
  @dirty_flag = false
end

Class Method Details

.bamboo_resourceObject



8
9
10
11
# File 'lib/puppet/provider/bamboo_ensurable_provider.rb', line 8

def self.bamboo_resource
  notice 'should be implemented by child'
  '/rest/admin/latest/idonotexist/'
end

.instancesObject

retrieve all bamboo resources via rest endpoint



13
14
15
16
# File 'lib/puppet/provider/bamboo_ensurable_provider.rb', line 13

def self.instances
  existing_res = Bamboo::Rest.get_bamboo_settings(self.bamboo_resource)
  self.map_config_to_resource_hash(existing_res)
end

.map_config_to_resource_hash(bamboo_settings) ⇒ Object

map REST response to resource hash



33
34
35
# File 'lib/puppet/provider/bamboo_ensurable_provider.rb', line 33

def self.map_config_to_resource_hash(bamboo_settings)
  notice('Need to be implemented')
end

.prefetch(resources) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/puppet/provider/bamboo_ensurable_provider.rb', line 18

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

Instance Method Details

#createObject



51
52
53
54
# File 'lib/puppet/provider/bamboo_ensurable_provider.rb', line 51

def create
  config = map_resource_hash_to_config
  Bamboo::Rest.create_bamboo_resource(self.class.bamboo_resource, config)
end

#destroyObject



56
57
58
# File 'lib/puppet/provider/bamboo_ensurable_provider.rb', line 56

def destroy
  Bamboo::Rest.delete_bamboo_resource(self.class.bamboo_resource + @property_hash[:id].to_s)
end

#dirty_flag=(value) ⇒ Object

add this method to make test easy



47
48
49
# File 'lib/puppet/provider/bamboo_ensurable_provider.rb', line 47

def dirty_flag=(value)
  @dirty_flag = value
end

#exists?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/puppet/provider/bamboo_ensurable_provider.rb', line 42

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

#flushObject



60
61
62
63
64
65
66
# File 'lib/puppet/provider/bamboo_ensurable_provider.rb', line 60

def flush
  # need the dirty flag, otherwise flush will be invoked after create
  if @dirty_flag
    config = map_resource_hash_to_config
    Bamboo::Rest.update_bamboo_settings(self.class.bamboo_resource + @property_hash[:id].to_s, config)
  end
end

#map_resource_hash_to_configObject

map resource hash to format accepted by REST resource



38
39
40
# File 'lib/puppet/provider/bamboo_ensurable_provider.rb', line 38

def map_resource_hash_to_config
  notice('Need to be implemented')
end