<commit_before># OpenNebula Puppet provider for onedatastore
#
# License: APLv2
#
# Authors:
# Based upon initial work from <NAME>
# Modified by <NAME>
# Modified by <NAME> <<EMAIL>>
# Modified by <NAME>
# Modified by <NAME>
#
# Copyright
# initial provider had no copyright
# Deutsche Post E-POST Development GmbH - 2014, 2015
#

require 'rubygems'
require 'nokogiri'

Puppet::Type.type(:onedatastore).provide(:cli) do
  desc 'onedatastore provider'

  has_command(:onedatastore, 'onedatastore') do
    environment :HOME => '/root', :ONE_AUTH => '/var/lib/one/.one/one_auth'
  end

  mk_resource_methods

  def self.get_attributes
    get_checked_attributes + [:safe_dirs, :driver, :bridge_list,
     :ceph_host, :ceph_user, :ceph_secret, :pool_name, :staging_dir, :base_path,
     :ensure, :cluster, :cluster_id]
  end

  def self.get_checked_attributes
    [:name, :ds_mad, :tm_mad, :disk_type, :type]
  end  

  def create
    file = Tempfile.new("onedatastore-#{resource[:name]}")
    builder = Nokogiri::XML::Builder.new do |xml|
      xml.DATASTORE do
        self.class.get_attributes.each do |node|
          xml.send node.to_s.upcase, resource[node] unless resource[node].nil?

          if node.to_s == "cluster_id" and not resource[node].nil?
            self.debug "Warning: #{node} specified but datastore will not be added to the cluster; the only change is that the parameter is added to the onedatastore template; call `onecluster adddatastore` to add the datastore to the cluster"
          end
        end
      end
    end
    tempfile = builder.to_xml
    file.write(tempfile)
    file.close
    self.debug "Adding new datastore using: #{tempfile}"
    onedatastore('create', file.path)
    post_validate_change
    file.delete
    
    @property_hash[:ensure] = :present
  end

  def post_validate_change<commit_msg>Changed debug message to warning<commit_after># OpenNebula Puppet provider for onedatastore
#
# License: APLv2
#
# Authors:
# Based upon initial work from <NAME>
# Modified by <NAME>
# Modified by <NAME> <<EMAIL>>
# Modified by <NAME>
# Modified by <NAME>
#
# Copyright
# initial provider had no copyright
# Deutsche Post E-POST Development GmbH - 2014, 2015
#

require 'rubygems'
require 'nokogiri'

Puppet::Type.type(:onedatastore).provide(:cli) do
  desc 'onedatastore provider'

  has_command(:onedatastore, 'onedatastore') do
    environment :HOME => '/root', :ONE_AUTH => '/var/lib/one/.one/one_auth'
  end

  mk_resource_methods

  def self.get_attributes
    get_checked_attributes + [:safe_dirs, :driver, :bridge_list,
     :ceph_host, :ceph_user, :ceph_secret, :pool_name, :staging_dir, :base_path,
     :ensure, :cluster, :cluster_id]
  end

  def self.get_checked_attributes
    [:name, :ds_mad, :tm_mad, :disk_type, :type]
  end  

  def create
    file = Tempfile.new("onedatastore-#{resource[:name]}")
    builder = Nokogiri::XML::Builder.new do |xml|
      xml.DATASTORE do
        self.class.get_attributes.each do |node|
          xml.send node.to_s.upcase, resource[node] unless resource[node].nil?

          if node.to_s == "cluster_id" and not resource[node].nil?
            self.warning "#{node} specified but datastore will not be added to the cluster; the only change is that the parameter is added to the onedatastore template; call `onecluster adddatastore` to add the datastore to the cluster"
          end
        end
      end
    end
    tempfile = builder.to_xml
    file.write(tempfile)
    file.close
    self.debug "Adding new datastore using: #{tempfile}"
    onedatastore('create', file.path)
    post_validate_change
    file.delete
    
    @property_hash[:ensure] = :present
  end

  def post_validate_change
{'fraction_non_alphanumeric': 0.10764642082429501, 'fraction_numerical': 0.004880694143167028, 'mean_word_length': 3.6344221105527637, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 8}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3385550', 'n_tokens_mistral': 1265, 'n_tokens_neox': 1214, 'n_words': 336}