Module: Sfp::Resource

Included in:
Module::Shell
Defined in:
lib/sfpagent/module.rb

Overview

Module Sfp::Resource must be included by every module. It provides standard methods which are used by Runtime engine in mapping between SFP object and schema implementation.

accessible attributes

  • parent : holds instance of parent’s object

  • synchronized : an list of SFP procedures that must be executed in

    serial
    
  • path : an absolute path of this instance

read-only attributes

  • state : holds the current state of this module instance

  • model : holds the model of desired state of this module

    instance
    

methods:

  • init : invoked by Runtime engine after instantiating this

    module instance for initialization
    
  • update_state : invoked by Runtime engine to request this module

    instance to update the current state which should
    be kept in attribute @state
    
  • to_model : can be invoked by this module instance to set the

    current state equals the desired state (model), or
    in short: @state == @model
    
  • resolve_state : can be invoked by this module to resolve given

    reference of current state either local or other
    module instances
    
  • resolve : an alias to method resolve_state

  • resolve_model : can be invoked by this module to resolve given

    reference of desired state (model) either local or
    other module instances
    
  • log : return logger object

  • copy : copy a file, whose path is the first parameter, to

    a destination path given in the second parameter
    
  • render : render given template file, whose path is the first

    parameter, and the template's variable is a merged
    between a Hash in the second parameter with model;
    the result is returned as a string
    
  • render_file : render given template file, whose path is the first

    parameter, and the template's variable is a merged
    between a Hash on the second parameter with model;
    the result is written back to the file
    

Constant Summary collapse

@@resource =
Object.new.extend(Sfp::Resource)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#modelObject (readonly)

Returns the value of attribute model.



69
70
71
# File 'lib/sfpagent/module.rb', line 69

def model
  @model
end

#parentObject

Returns the value of attribute parent.



68
69
70
# File 'lib/sfpagent/module.rb', line 68

def parent
  @parent
end

#pathObject

Returns the value of attribute path.



68
69
70
# File 'lib/sfpagent/module.rb', line 68

def path
  @path
end

#stateObject (readonly)

Returns the value of attribute state.



69
70
71
# File 'lib/sfpagent/module.rb', line 69

def state
  @state
end

#synchronizedObject

Returns the value of attribute synchronized.



68
69
70
# File 'lib/sfpagent/module.rb', line 68

def synchronized
  @synchronized
end

Class Method Details

.resolve(path) ⇒ Object

Helper methods for resource module



87
88
89
# File 'lib/sfpagent/module.rb', line 87

def self.resolve(path)
	@@resource.resolve(path)
end

Instance Method Details

#init(model = {}) ⇒ Object



71
72
73
74
75
# File 'lib/sfpagent/module.rb', line 71

def init(model={})
	@state = {}
	@model = (model.length <= 0 ? {} : Sfp.to_ruby(model))
	@synchronized = []
end

#update_stateObject



77
78
79
# File 'lib/sfpagent/module.rb', line 77

def update_state
	@state = {}
end

#use_http_proxy?(uri) ⇒ Boolean

Returns:

  • (Boolean)


132
133
134
135
136
137
138
# File 'lib/sfpagent/module.rb', line 132

def use_http_proxy?(uri)
	ENV['no_proxy'].to_s.split(',').each { |pattern|
		pattern.chop! if pattern[-1] == '*'
		return false if uri.host[0, pattern.length] == pattern
	}
	true
end