Class: Chef::Provider::OneFlowTemplate
- Inherits:
-
LWRPBase
- Object
- LWRPBase
- Chef::Provider::OneFlowTemplate
- Defined in:
- lib/chef/provider/one_flow_template.rb
Overview
Implementation of Provider class.
Instance Method Summary collapse
-
#initialize(*args) ⇒ OneFlowTemplate
constructor
A new instance of OneFlowTemplate.
- #load_current_resource ⇒ Object
- #load_template_hash ⇒ Object
- #whyrun_supported? ⇒ Boolean
Constructor Details
#initialize(*args) ⇒ OneFlowTemplate
Returns a new instance of OneFlowTemplate.
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/chef/provider/one_flow_template.rb', line 34 def initialize(*args) super if !@new_resource.flow_url.nil? flow_url = @new_resource.flow_url elsif !run_context.chef_provisioning.flow_url.nil? flow_url = run_context.chef_provisioning.flow_url elsif !ENV['ONE_FLOW_URL'].nil? flow_url = ENV['ONE_FLOW_URL'] else fail 'OneFlow API URL must be specified.' end @flow_lib = Chef::Provisioning::OpenNebulaDriver::FlowLib.new(flow_url, driver.one.client.one_auth) end |
Instance Method Details
#load_current_resource ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/chef/provider/one_flow_template.rb', line 52 def load_current_resource @current_resource = Chef::Resource::OneFlowTemplate.new(@new_resource.name, run_context) template_name = @new_resource.name unless @new_resource.template.nil? tpl = load_template_hash if tpl.nil? @current_resource.exists = false return end tpl = @flow_lib.merge_template(tpl, @new_resource., true, false) template_name = tpl[:name] if tpl.key?(:name) end template_id = @flow_lib.get_unique_template_id(template_name, true) @current_resource.exists = !template_id.nil? return unless @current_resource.exists @current_resource.template(@flow_lib.get_template(template_id)) @current_resource.mode(@flow_lib.(template_id)) @current_resource.template_equal = @new_resource.template.nil? ? true : @flow_lib.hash_eq?( @current_resource.template, @flow_lib.normalize_template(@new_resource.name, driver, @flow_lib.merge_template(@current_resource.template, tpl), true) ) @current_resource.mode_equal = @current_resource.mode == @new_resource.mode @current_resource.equal = @current_resource.template_equal && @current_resource.mode_equal end |
#load_template_hash ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/chef/provider/one_flow_template.rb', line 83 def load_template_hash template = {} case @new_resource.template when Hash template = @new_resource.template when Fixnum template = @flow_lib.get_template(@new_resource.template) when String case @new_resource.template when %r{^file://(.*)$} template = JSON.parse(::File.read(Regexp.last_match[1]), :symbolize_names => true) when %r{^(?:(\w+)(?::(.*?))?@)?(https?://.*)$} response = RestClient::Request.execute( method: :get, url: Regexp.last_match[3], user: Regexp.last_match[1], password: Regexp.last_match[2] ) template = JSON.parse(response, :symbolize_names => true) else tid = @flow_lib.get_unique_template_id(@new_resource.template) template = @flow_lib.get_template(tid) end end template end |
#whyrun_supported? ⇒ Boolean
48 49 50 |
# File 'lib/chef/provider/one_flow_template.rb', line 48 def whyrun_supported? true end |