Class: Rudy::Backups

Inherits:
Object
  • Object
show all
Includes:
MetaData
Defined in:
lib/rudy/metadata/backups.rb

Instance Method Summary collapse

Methods included from MetaData

#format_timestamp, #initialize

Methods included from Huxtable

change_environment, change_position, change_region, change_role, change_zone, #check_keys, #config_dirname, create_domain, #current_group_name, #current_machine_address, #current_machine_count, #current_machine_group, #current_machine_hostname, #current_machine_image, #current_machine_name, #current_machine_size, #current_user, #current_user_keypairpath, debug?, #debug?, domain, domain_exists?, #group_metadata, #has_keypair?, #has_keys?, #has_pem_keys?, #has_root_keypair?, keypair_path_to_name, #known_machine_group?, #root_keypairname, #root_keypairpath, #switch_user, update_config, update_global, update_logger, #user_keypairname, #user_keypairpath

Instance Method Details

#destroy(&each_mach) ⇒ Object



19
20
21
22
23
24
# File 'lib/rudy/metadata/backups.rb', line 19

def destroy(&each_mach)
  list do |backup|
    puts "Destroying #{backup.name}"
    backup.destroy
  end
end

#get(rname = nil) ⇒ Object



44
45
46
47
48
49
50
# File 'lib/rudy/metadata/backups.rb', line 44

def get(rname=nil)
  dhash = @sdb.get(Rudy::DOMAIN, rname)
  return nil if dhash.nil? || dhash.empty?
  d = Rudy::MetaData::Backup.from_hash(dhash)
  d.update if d
  d
end

#initObject



7
8
9
10
11
12
# File 'lib/rudy/metadata/backups.rb', line 7

def init
  now = Time.now.utc
  datetime = Rudy::MetaData::Backup.format_timestamp(now).split(Rudy::DELIM)
  @created = now.to_i
  @date, @time, @second = datetime
end

#list(more = [], less = [], local = {}, &each_backup) ⇒ Object



26
27
28
29
30
# File 'lib/rudy/metadata/backups.rb', line 26

def list(more=[], less=[], local={}, &each_backup)
  backups = list_as_hash(more, less, local, &each_backup)
  backups &&= backups.values
  backups
end

#list_as_hash(more = [], less = [], local = {}, &each_backup) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/rudy/metadata/backups.rb', line 32

def list_as_hash(more=[], less=[], local={}, &each_backup)
  query = to_select([:rtype, 'back'], less, local)
  list = @sdb.select(query) || {}
  backups = {}
  list.each_pair do |n,d|
    backups[n] = Rudy::MetaData::Backup.from_hash(d)
  end
  backups.each_pair { |n,backup| each_backup.call(backup) } if each_backup
  backups = nil if backups.empty?
  backups
end

#running?Boolean

Returns:

  • (Boolean)


53
54
55
56
# File 'lib/rudy/metadata/backups.rb', line 53

def running?
  !list.nil?
  # TODO: add logic that checks whether the instances are running.
end

#to_select(*args) ⇒ Object



58
59
60
61
# File 'lib/rudy/metadata/backups.rb', line 58

def to_select(*args)
  query = super(*args)
  query << " and created != '0' order by created desc"
end