The interpreter reads in the template, and makes itself available as engine() with the scope of the template. All resource operations are proxied through this object.
# File lib/harp-runtime/interpreter.rb, line 47 def initialize @created = [] @destroyed = [] @updated = [] end
Accept the resources from a template and add to the dictionary of resources available to the template.
# File lib/harp-runtime/interpreter.rb, line 55 def consume(template) # TODO: handle URL @@logger.info "Consume template: #{template.length.to_s}" return self end
Create a resource and wait for the resource to become available.
# File lib/harp-runtime/interpreter.rb, line 62 def create(resource) @@logger.debug "Launching resource: #{resource}." @created.push(resource) return self end
Create a set of resources; all resources must will be complete before processing continues.
# File lib/harp-runtime/interpreter.rb, line 70 def createParallel(*resources) @@logger.debug "Launching resource(s) in parallel #{resources.join(',')}." @created += resources return self end
Destroy a named resource.
# File lib/harp-runtime/interpreter.rb, line 98 def destroy(resource) @@logger.debug "Destroying resource: #{resource}." @destroyed.push resource return self end
Destroy a named resource.
# File lib/harp-runtime/interpreter.rb, line 105 def destroyParallel(*resources) @@logger.debug "Destroying resource(s) in parallel #{resources.join(',')}." @destroyed += resources return self end
# File lib/harp-runtime/interpreter.rb, line 111 def onFail(*fails) @@logger.debug "Handle fail action: #{fails.join(',')}" return self end
# File lib/harp-runtime/interpreter.rb, line 116 def play(harp_file, lifecycle) file = File.open(harp_file, "rb") harp_contents = file.read s = Sandbox.new priv = Privileges.new priv.allow_method :print priv.allow_method :puts priv.allow_method :engine priv.allow_method :die priv.instances_of(HarpInterpreter).allow_all #SandboxModule.interpreter = self SandboxModule.set_engine(self) s.run(priv, harp_contents, :base_namespace => SandboxModule) # Call create/delete etc., as defined in harp file if SandboxModule.method_defined? lifecycle @@logger.debug "Invoking lifecycle: #{lifecycle.inspect}." @@logger.debug "Invoking: #{SandboxModule.method(lifecycle)}." SandboxModule.method(lifecycle).call() else raise "No lifecycle method #{lifecycle.inspect} defined in harp." end respond end
# File lib/harp-runtime/interpreter.rb, line 147 def respond done = [] @created.each do |createe| done.push "created #{createe}" end @updated.each do |updatee| done.push "updated #{updatee}" end @destroyed.each do |destroyee| done.push "destroyed #{destroyee}" end done end
Update a resource to a new resource definition.
# File lib/harp-runtime/interpreter.rb, line 77 def update(resource) @@logger.debug "Updating resource: #{resource}." @updated.push(resource) return self end
Update a set of resources in parallel to new resource definitions.
# File lib/harp-runtime/interpreter.rb, line 84 def updateParallel(*resources) @@logger.debug "Updating resource(s) in parallel #{resources.join(',')}." @updated += resources return self end
Update a resource to an alternate definition.
# File lib/harp-runtime/interpreter.rb, line 91 def updateTo(resource_start, resource_finish) @@logger.debug "Updating resource: #{resource_start} to #{resource_finish}." @updated.push(resource_finish) return self end