libraries/resource_provider.rb
def create_or_update(method_1 = :create, method_2 = :update)
      ret_val = false
      desired_state = Marshal.load(Marshal.dump(@item.data))
      if @item.exists?
        @item.retrieve!
        if @item.like? desired_state
          Chef::Log.info("#{@resource_name} '#{@name}' is up to date")
        else
          diff = get_diff(@item, desired_state)
          Chef::Log.info "#{method_2.to_s.capitalize} #{@resource_name} '#{@name}'#{diff}"
          Chef::Log.debug "#{@resource_name} '#{@name}' Chef resource differs from OneView resource."
          Chef::Log.debug "Current state: #{JSON.pretty_generate(@item.data)}"
          Chef::Log.debug "Desired state: #{JSON.pretty_generate(desired_state)}"
          @context.converge_by "#{method_2.to_s.capitalize} #{@resource_name} '#{@name}'" do
            @item.update(desired_state)
          end
        end
      else
        create(method_1)
        ret_val = true
      end
      save_res_info
      ret_val
    end
# Creates the OneView resource or updates it if exists
# @param [Symbol] method_1 Method used to create/add
# @param [Symbol] method_2 Method used to update/edit
# @return [TrueClass, FalseClass] Returns true if the resource was created, false if updated or unchanged
Creates the OneView resource or updates it if exists
Creates the OneView resource or updates it if exists
def create_or_update(method_1 = :create, method_2 = :update)
      ret_val = false
      desired_state = Marshal.load(Marshal.dump(@item.data))
      if @item.exists?
        @item.retrieve!
        if @item.like? desired_state
          Chef::Log.info("#{@resource_name} '#{@name}' is up to date")
        else
          diff = get_diff(@item, desired_state)
          Chef::Log.info "#{method_2.to_s.capitalize} #{@resource_name} '#{@name}'#{diff}"
          Chef::Log.debug "#{@resource_name} '#{@name}' Chef resource differs from OneView resource."
          Chef::Log.debug "Current state: #{JSON.pretty_generate(@item.data)}"
          Chef::Log.debug "Desired state: #{JSON.pretty_generate(desired_state)}"
          @context.converge_by "#{method_2.to_s.capitalize} #{@resource_name} '#{@name}'" do
            @item.update(desired_state)
          end
        end
      else
        create(method_1)
        ret_val = true
      end
      save_res_info
      ret_val
    end
def create_or_update ( method_1 = :create , method_2 = :update ) ret_val = false desired_state = Marshal . load ( Marshal . dump ( @item . data ) ) if @item . exists? @item . retrieve! if @item . like? desired_state Chef :: Log . info ( "#{@resource_name} '#{@name}' is up to date" ) else diff = get_diff ( @item , desired_state ) Chef :: Log . info "#{method_2.to_s.capitalize} #{@resource_name} '#{@name}'#{diff}" Chef :: Log . debug "#{@resource_name} '#{@name}' Chef resource differs from OneView resource." Chef :: Log . debug "Current state: #{JSON.pretty_generate(@item.data)}" Chef :: Log . debug "Desired state: #{JSON.pretty_generate(desired_state)}" @context . converge_by "#{method_2.to_s.capitalize} #{@resource_name} '#{@name}'" do @item . update ( desired_state ) end end else create ( method_1 ) ret_val = true end save_res_info ret_val end
Creates the OneView resource or updates it if exists
Creates the OneView resource or updates it if exists
Returns true if the resource was created, false if updated or unchanged
Returns true if the resource was created false if updated or unchanged
TrueClass, FalseClass
method_1
method_2
method_2 Method used to update/edit
method_2 Method used to update / edit