Class: Ironfan::Provider::Resource

Inherits:
Builder
  • Object
show all
Defined in:
lib/ironfan/headers.rb,
lib/ironfan/provider.rb

Constant Summary collapse

@@known =
{}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Builder

ui, #ui

Instance Attribute Details

#ownerObject

Returns the value of attribute owner.



71
72
73
# File 'lib/ironfan/provider.rb', line 71

def owner
  @owner
end

#usersObject

Returns the value of attribute users.



72
73
74
# File 'lib/ironfan/provider.rb', line 72

def users
  @users
end

Class Method Details

.aggregate!(*p) ⇒ Object



107
# File 'lib/ironfan/provider.rb', line 107

def self.aggregate!(*p)           Ironfan.noop(self,__method__,*p);   end

.create!(*p) ⇒ Object

Manipulation



104
# File 'lib/ironfan/provider.rb', line 104

def self.create!(*p)              Ironfan.noop(self,__method__,*p);   end

.destroy!(*p) ⇒ Object



108
# File 'lib/ironfan/provider.rb', line 108

def self.destroy!(*p)             Ironfan.noop(self,__method__,*p);   end

.forget(id) ⇒ Object



144
145
146
# File 'lib/ironfan/provider.rb', line 144

def self.forget(id)
  self.known.delete(id)
end

.forget!Object



140
141
142
# File 'lib/ironfan/provider.rb', line 140

def self.forget!
  @@known[self.name] = { }
end

.handleObject



77
# File 'lib/ironfan/provider.rb', line 77

def self.handle ; name.to_s.gsub(/.*::/,'').to_sym ; end

.knownObject

Provide a separate namespace in @@known for each subclass



149
150
151
# File 'lib/ironfan/provider.rb', line 149

def self.known
  @@known[self.name] ||= {}
end

.load!(*p) ⇒ Object

Discovery



95
# File 'lib/ironfan/provider.rb', line 95

def self.load!(*p)                Ironfan.noop(self,__method__,*p);   end

.multiple?Boolean

Can multiple instances of this resource be associated with the computer?

Returns:

  • (Boolean)


90
# File 'lib/ironfan/provider.rb', line 90

def self.multiple?()              false;                  end

.patiently(name, error_class, options = {}) ⇒ Object



153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# File 'lib/ironfan/provider.rb', line 153

def self.patiently(name, error_class, options={})
  options[:message]    ||= 'ignoring %s'
  options[:wait_time]  ||= 1
  options[:max_tries]  ||= 10

  success = false
  tries   = 0
  until success or (tries > options[:max_tries]) do
    begin
      result = yield
      success = true # If we made it to this line, the yield didn't raise an exception
    rescue error_class => e
      tries += 1
      if options[:ignore] and options[:ignore].call(e)
        success = true
        Ironfan.substep(name, options[:message] % e.message, options[:display] ? :red : :gray)
      else
        Ironfan.substep(name, options[:message] % e.message, options[:display] ? :red : :gray)
        Ironfan.substep(name, "sleeping #{options[:sleep_time]} second(s) before trying again")
        sleep options[:wait_time]
        result = e
      end
    end
  end

  if success
    return result
  else
    ui.warn("Gave up after #{options[:max_tries]} attempts to execute #{name} code")
    raise result
  end
end

.prepare!(*p) ⇒ Object



106
# File 'lib/ironfan/provider.rb', line 106

def self.prepare!(*p)             Ironfan.noop(self,__method__,*p);   end

.recall(id = nil) ⇒ Object



135
136
137
138
# File 'lib/ironfan/provider.rb', line 135

def self.recall(id=nil)
  return self.known if id.nil?
  self.known[id]
end

.recall?(id) ⇒ Boolean

Returns:

  • (Boolean)


131
132
133
# File 'lib/ironfan/provider.rb', line 131

def self.recall?(id)
  self.known.include? id
end

.receive(obj) ⇒ Object



79
80
81
82
# File 'lib/ironfan/provider.rb', line 79

def self.receive(obj)
  obj = obj.symbolize_keys if obj.is_a?(Hash)
  super(obj)
end

.register(native) ⇒ Object

Register and return the (adapted) object with the collection



126
127
128
129
# File 'lib/ironfan/provider.rb', line 126

def self.register(native)
  result = new(:adaptee => native) or return
  remember result
end

.remember(resource, options = {}) ⇒ Object



118
119
120
121
122
123
# File 'lib/ironfan/provider.rb', line 118

def self.remember(resource,options={})
  index = options[:id] || resource.name
  index += options[:append_id] if options[:append_id]
  Chef::Log.debug("Loaded #{resource}")
  self.known[index] = resource
end

.save!(*p) ⇒ Object



105
# File 'lib/ironfan/provider.rb', line 105

def self.save!(*p)                Ironfan.noop(self,__method__,*p);   end

.shared?Boolean

Flags

Non-shared resources live and die with the computer

Returns:

  • (Boolean)


88
# File 'lib/ironfan/provider.rb', line 88

def self.shared?()                true;                   end

.validate_computer!(*p) ⇒ Object



96
# File 'lib/ironfan/provider.rb', line 96

def self.validate_computer!(*p)   Ironfan.noop(self,__method__,*p);   end

.validate_resources!(*p) ⇒ Object



97
# File 'lib/ironfan/provider.rb', line 97

def self.validate_resources!(*p)  Ironfan.noop(self,__method__,*p);   end

Instance Method Details

#bogus?Boolean

Returns:

  • (Boolean)


75
# File 'lib/ironfan/provider.rb', line 75

def bogus?()                      !bogus.empty?;          end

#on_correlate(*p) ⇒ Object



99
# File 'lib/ironfan/provider.rb', line 99

def on_correlate(*p)              Ironfan.noop(self,__method__,*p);   end