<commit_before># 
# Cookbook Name:: lb_stingray
# Provider:: default
#
# Copyright Riverbed, Inc. All rights reserved.
#

include RightScale::LB::Helper

action :install do

    #log "Installing Stingray Traffic Manager..."

    # Read in pretty version of the version number (include "." so as not to confuse people!)
    full_version = node[:lb_stingray][:software_version]


    # Check to ensure we've received a valid version number and bail out if not.
    if not full_version =~ /^[0-9]{1,2}\.[0-9](r[1-9]){0,1}$/
        #log "An invalid Stingray version number was detected."
        action :nothing
    else
        #log "Version #{full_version} selected."
    end 

    # Convert to the version number we actually use
    version = full_version.gsub(".", "")

    # Read in the MD5 hash (binary_hash attribute) of the software binary.  This is used in the 
    #   S3 path and to validate the download.
    binary_hash = node[:lb_stingray][:binary_hash]

    # Hard-code architecture
    arch = "x86_64"

    # Read rightlink tag in order to find out whether we need to install a gold version.
    if node[:lb_stingray][:generic_binary] == "false" then
        packagename = "ZeusTM_#{version}_Linux-#{arch}-Gold"
    else
        packagename = "ZeusTM_#{version}_Linux-#{arch}"
    end

    # Set the URL of the installation file location in S3
    s3bucket = "http://s3.amazonaws.com/stingray-rightscale-#{version}-#{binary_hash}/"
    #log "Binary download path set to #{s3bucket}"

    # The temporary directory that the binary package will be extracted to.
    directory "/tmp/#{packagename}" do
       recursive true
       action :nothing
    end

    file "/tmp/#{packagename}.tgz" do
      #log "Existing installation package found"
      action :nothing
    end

    # Fetch the binary package from the s3 bucket.
    execute "Download Stingray Binaries" do
       creates "/tmp/#{packagename}.tgz"
       cwd "/tmp"
       # Resume partial transfers, print no console output.
       #log "Downloading binary..."
       command "wget --continue --quiet #{s3bucket}#{packagename}.tgz"
       #log "Download complete!"
       # TODO: check the MD5 hash of the downloaded file against the expected value and EXPLODE if necessary
    end

    # Replay file for non-interactive installation of Stingray.
    template "/tmp/install_replay" do
        not_if { ::File.exists?("/opt/riverbed/zxtm") }
        #log "Existing configuration found."
        cookbook "lb_stingray"
        mode "0644"
        source "install.erb"
        variables( :accept_license => "accept", :path => "/opt/riverbed" )
    end

    # Unpack tarball and install software package
    execute "deploy_binaries" do
        creates "/opt/riverbed"
        cwd "/tmp"
        #log "Performing initial configuration..."
        command "\
        tar xzvf #{packagename}.tgz && ZeusTM_#{version}_Linux-#{arch}/zinstall --replay-from=/tmp/install_replay"
        notifies :delete, resources(
            :file => "/tmp/#{packagename}.tgz",
            :directory => "/tmp/#{packagename}",
            :template => "/tmp/install_replay"
        ), :delayed
        #log "Initial configuration completed!"
    end

    # Add RS-specific tunings.
    # FIXME: Do something about this - use zcli?
    template "/opt/riverbed/zxtm/conf/settings.cfg" do
        not_if { ::File.exists?("/opt/riverbed/rc.d/S20zxtm") }<commit_msg>Tidy up the provider a bit<commit_after># 
# Cookbook Name:: lb_stingray
# Provider:: default
#
# Copyright Riverbed, Inc. All rights reserved.
#

include RightScale::LB::Helper

action :install do

    # Read in pretty version of the version number (include "." so as not to confuse people!)
    full_version = node[:lb_stingray][:software_version]


    # Check to ensure we've received a valid version number and bail out if not.
    if not full_version =~ /^[0-9]{1,2}\.[0-9](r[1-9]){0,1}$/
        raise "An invalid version number was provided. Installation aborted."
    end 

    # Convert to the version number we actually use
    version = full_version.gsub(".", "")

    # Read in the MD5 hash (binary_hash attribute) of the software binary.  This is used in the 
    #   S3 path and to validate the download.
    binary_hash = node[:lb_stingray][:binary_hash]

    # Hard-code architecture
    arch = "x86_64"

    # Read rightlink tag in order to find out whether we need to install a gold version.
    if node[:lb_stingray][:generic_binary] == "false" then
        packagename = "ZeusTM_#{version}_Linux-#{arch}-Gold"
    else
        packagename = "ZeusTM_#{version}_Linux-#{arch}"
    end

    # Set the URL of the installation file location in S3
    s3bucket = "http://s3.amazonaws.com/stingray-rightscale-#{version}-#{binary_hash}/"

    # The temporary directory that the binary package will be extracted to.
    directory "/tmp/ZeusTM_#{version}_Linux-#{arch}" do
       recursive true
       action :nothing
    end

    file "/tmp/#{packagename}.tgz" do
      action :nothing
    end

    # Fetch the binary package from the s3 bucket.
    execute "Download Stingray Binaries" do
       creates "/tmp/#{packagename}.tgz"
       cwd "/tmp"
       # Resume partial transfers, print no console output.
       command "wget --continue --quiet #{s3bucket}#{packagename}.tgz"
       # TODO: check the MD5 hash of the downloaded file against the expected value and EXPLODE if necessary
    end

    # Replay file for non-interactive installation of Stingray.
    template "/tmp/install_replay" do
        not_if { ::File.exists?("/opt/riverbed/zxtm") }
        cookbook "lb_stingray"
        mode "0644"
        source "install.erb"
        variables( :accept_license => "accept", :path => "/opt/riverbed" )
    end

    # Unpack tarball and install software package
    execute "deploy_binaries" do
        creates "/opt/riverbed"
        cwd "/tmp"
        command "\
        tar xzvf #{packagename}.tgz && ZeusTM_#{version}_Linux-#{arch}/zinstall --replay-from=/tmp/install_replay"
        notifies :delete, resources(
            :file => "/tmp/#{packagename}.tgz",
            :directory => "/tmp/#{packagename}",
            :template => "/tmp/install_replay"
        ), :delayed
    end

    # Add RS-specific tunings.
    # FIXME: Do something about this - use zcli?
    template "/opt/riverbed/zxtm/conf/settings.cfg" do
        not_if { ::File.exists?("/opt/riverbed/rc.d/S20zxtm") }
{'fraction_non_alphanumeric': 0.11452165783733251, 'fraction_numerical': 0.008881271424119663, 'mean_word_length': 2.747227086981903, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 9, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2223085', 'n_tokens_mistral': 1996, 'n_tokens_neox': 1926, 'n_words': 606}