class Elasticachesnapshot::ORENCLI

Public Instance Methods

create(snapshot_name= "snapshot-" + Time.now.to_i.to_s) click to toggle source
# File lib/elasticache_snapshot/elasticache_snapshot.rb, line 16
def create(snapshot_name= "snapshot-" + Time.now.to_i.to_s)
    create_snapshot("#{snapshot_name}")
end
delete(snapshot_name) click to toggle source
# File lib/elasticache_snapshot/elasticache_snapshot.rb, line 21
def delete(snapshot_name)
    delete_snapshot("#{snapshot_name}")
end
list(name=nil) click to toggle source
# File lib/elasticache_snapshot/elasticache_snapshot.rb, line 11
def list(name=nil)
  describe_snapshots
end

Private Instance Methods

create_snapshot(snapshot_name) click to toggle source
# File lib/elasticache_snapshot/elasticache_snapshot.rb, line 65
def create_snapshot(snapshot_name)
  unless elaction_snapshot_node.include?("Error")
    puts "Create #{snapshot_name} from #{elaction_snapshot_node}..."
    elc.create_snapshot({ :cache_cluster_id => elaction_snapshot_node, :snapshot_name => snapshot_name })
  else
    puts elaction_snapshot_node 
  end
end
delete_snapshot(snapshot_name) click to toggle source
# File lib/elasticache_snapshot/elasticache_snapshot.rb, line 74
def delete_snapshot(snapshot_name)
  elc.delete_snapshot({ :snapshot_name => snapshot_name })
  puts "Deleted #{snapshot_name}"
end
describe_snapshots(name=nil) click to toggle source
# File lib/elasticache_snapshot/elasticache_snapshot.rb, line 32
def describe_snapshots(name=nil)
  snapshots = []
  elc.describe_snapshots[:snapshots].each do |snapshot|
    snapshot_create_time = ""
    snapshot[:node_snapshots].each do |node_snapshot|
      snapshot_create_time = node_snapshot[:snapshot_create_time]
    end
    snapshots << [ snapshot[:snapshot_name], "#{snapshot_create_time}" ]
  end
  snapshot_table = Terminal::Table.new :headings => ['SNAPSHOT Name', 'SNAPSHOT Create time'], :rows => snapshots
  puts snapshot_table
end
elaction_snapshot_node() click to toggle source
# File lib/elasticache_snapshot/elasticache_snapshot.rb, line 45
def elaction_snapshot_node
  cluster = []
  elc.describe_cache_clusters.cache_clusters.each do |i|
    cluster << { :cluster_id => i.cache_cluster_id, :create_time => i.cache_cluster_create_time, :cache_cluster_status => i.cache_cluster_status }
  end

  sorted = cluster.sort {|x, y| y[:create_time] <=> x[:create_time]}

  unless sorted[0][:cache_cluster_status].include?("snapshotting")
    replica_node = sorted[0][:cluster_id]
    elc.describe_replication_groups.replication_groups[0].node_groups[0].node_group_members.each do |node|
      if node.current_role == "replica" and node[:cache_cluster_id] == replica_node
        return node[:cache_cluster_id]
      end
    end
  else
    return "Error, Snapshotting..."
  end
end
elc() click to toggle source
# File lib/elasticache_snapshot/elasticache_snapshot.rb, line 27
def elc
  AWS.config.credentials
  AWS::ElastiCache.new.client
end