Guest User

Untitled

a guest
Jul 16th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. hostclass :externalresources do
  2. scope_h = scope.to_hash.reject { |k,v| !( k.is_a?(String) && v.is_a?(String) ) }
  3. scope_h.keys.each do |var|
  4.  
  5. if scope_h[var][0].chr == '{'
  6. begin
  7. #Convert the variable from a string to a hash
  8. var_h = eval scope_h[var]
  9. rescue => e
  10. notice "Couldn't convert variable #{var} to hash: #{e}"
  11. end
  12.  
  13. if var_h.has_key? :type
  14. type = var_h[:type]
  15. virtual = var_h.has_key? :virtual and var_h[:virtual] == 'true'
  16.  
  17. #Split out our :type parameter
  18. var_h.reject! { |k,v| k == :type or k == :virtual }
  19.  
  20. #Create the virtual resource by sending it the type defined
  21. begin
  22. unless virtual
  23. #Make our resource
  24. send type.to_sym, var, var_h
  25. else
  26. #Call our resource function and pass it to virtual
  27. virtual send type.to_sym, var, var_h
  28. end
  29. rescue => e
  30. fail "Couldn't create resource #{var}: #{e}"
  31. end
  32. end
  33. end
  34. end
  35. end
Add Comment
Please, Sign In to add comment