is_keepalive?

in playbooks/roles/cyclecloud_cluster/projects/openpbs/cluster-init/files/autostop.rb [22:68]


def is_keepalive?
    
    if File.exist?(KEEPALIVE_FILE) then
        mtime = File.mtime KEEPALIVE_FILE
    
        if (Time.new - mtime) > KEEPALIVE_THROTTLE then
            log "Deleting #{KEEPALIVE_FILE} because it has been more than #{KEEPALIVE_THROTTLE} seconds since it was created."
            log "Will be recreated the next iteration."
            File.delete KEEPALIVE_FILE
        end

        
        
        return true
    end
    
    log "Checking to see if this node has KeepAlive=true"
    
    username = `jetpack config cyclecloud.config.username`.strip
    password = `jetpack config cyclecloud.config.password`.strip
    web_server = `jetpack config cyclecloud.config.web_server`.strip
    cluster_name = `jetpack config cyclecloud.cluster.name`.strip
    node_name = `jetpack config cyclecloud.node.name`.strip
    
    cluster_status = JSON.parse(`curl -k -u "#{username}:#{password}" 
    
    
    
    am_i_keepalive = true
    
    cluster_status["nodes"].each do |node|
       if node["Name"] == node_name then
            am_i_keepalive = node["KeepAlive"]
       end
    end
    
    
    if am_i_keepalive then
        log "This node does have KeepAlive=true. Creating #{KEEPALIVE_FILE} and will check again in #{KEEPALIVE_THROTTLE} seconds"
        touch = File.new(KEEPALIVE_FILE, 'w')
        touch.puts "This file was created because this node was marked as KeepAlive when this file was created. Will try again in #{KEEPALIVE_THROTTLE} seconds"
        touch.close
    end
        
    return am_i_keepalive
end