Class: Shards::Workflow::DeleteByTerminal

Inherits:
Base
  • Object
show all
Defined in:
lib/shards/workflow/delete_by_terminal.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#answer, #blank_db, #client, #config, #current_loop, #domain, #flow, #location, #params, #pointer, #pointer_history, #site, #stage, #step, #success, #wf

Instance Method Summary collapse

Methods inherited from Base

#add_ask_blank_db_step, #application_reload_shards_task, #ask_blank_db, #ask_for_exit, #ask_for_exit_and_restart, #ask_for_repeat, #ask_question, #check_database_presence_in_server, #check_domain_dns_presence, #check_domain_presence_in_sites, #check_fingerprints, #check_fingerprints2, #check_shard_presence_in_shards, #choose_one, #clean_repo_and_exit, #create_database, #decamelize, #default_path, #dns_upsert, #file, #finish_successfully, #format_options, #get_file, #host, #initialize, #loop_step, #output_message, #path, #previous_pointer, #puppet_agent_update, #raise_wrong_text, #run_step, #shared_file, #shared_steps, #start, #start_at, #validate_blank_db_shard, #validate_client, #validate_domain, #validate_in_index, #validate_location, #validate_min_size, #validate_regex, #validate_stage, #validation, #yaml

Constructor Details

This class inherits a constructor from Shards::Workflow::Base

Instance Attribute Details

#database_to_dropObject

Returns the value of attribute database_to_drop.



8
9
10
# File 'lib/shards/workflow/delete_by_terminal.rb', line 8

def database_to_drop
  @database_to_drop
end

#dbObject

Returns the value of attribute db.



8
9
10
# File 'lib/shards/workflow/delete_by_terminal.rb', line 8

def db
  @db
end

#dnsObject

Returns the value of attribute dns.



8
9
10
# File 'lib/shards/workflow/delete_by_terminal.rb', line 8

def dns
  @dns
end

Instance Method Details

#ask_to_continueObject



21
22
23
24
# File 'lib/shards/workflow/delete_by_terminal.rb', line 21

def ask_to_continue
  ask_question
  raise step['wrong_message'] if answer.strip.downcase!='y'
end

#commit_changesObject



59
60
61
62
63
64
# File 'lib/shards/workflow/delete_by_terminal.rb', line 59

def commit_changes
  config.repo.message = "Deleted site: #{params[:subdomain]} and shard: #{@shard_name} in #{location.name}"
  config.repo.autocommit
  puts step['message']
  puts config.repo.message
end

#delete_databaseObject



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/shards/workflow/delete_by_terminal.rb', line 66

def delete_database

  if database_to_drop

    @db=Shards::Db.new stage: stage

    db.database_to_drop=database_to_drop

    raise "Database %s does is not in present db servers" % database_to_drop  unless db.exist?(database_to_drop)

    db.servers_to_drop.each do |host|

      puts
      puts "Database:\t #{database_to_drop}"
      puts "Host:    \t #{host}"
      puts
      puts "Do you want to delete the above database? (y) to confirm, another string to not."

      answer=$stdin.gets

      puts

      if answer.chomp.downcase=='y'
        puts "DELETING database #{database_to_drop} in #{host}"
        db.server=host
        db.drop
      else
        puts "KEEP database #{database_to_drop} in #{host}"
      end
      puts
      puts "-" * 50
      puts
    end

    raise_wrong_text database_to_drop if db.exist? database_to_drop
    puts step['message'] % database_to_drop

  else
    puts "The shard is used in other site will not be deleted"
  end
end

#delete_recordObject



26
27
28
29
30
31
32
33
# File 'lib/shards/workflow/delete_by_terminal.rb', line 26

def delete_record
  if dns.exist?
    dns.delete
    message_params= [dns.host_param, dns.resource_records.to_s]
    raise_wrong_text message_params if dns.exist?
    puts step['message'] % message_params
  end
end

#delete_site_and_shardObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/shards/workflow/delete_by_terminal.rb', line 35

def delete_site_and_shard
  site=Shards::Site.new stage
  site.subdomain_param=params[:subdomain]
  site.delete

  if site.select_by_shard.count<1

    shard=Shards::Shard.new stage
    @shard_name= site.shard
    shard.name_param = @shard_name
    shard.delete

    @database_to_drop=shard.database['database']

  end

end

#validate_subdomainObject



10
11
12
13
14
15
16
17
18
19
# File 'lib/shards/workflow/delete_by_terminal.rb', line 10

def validate_subdomain
  @dns=Shards::Dns.new stage: stage
  dns.subdomain_param=params[:subdomain]

  raise_wrong_text [dns.host_param, " doesn't exist"] unless dns.exist?

  unless dns.include_target?
    raise_wrong_text [dns.host_param, target_message_error ]
  end
end

#write_yaml_filesObject



53
54
55
56
57
# File 'lib/shards/workflow/delete_by_terminal.rb', line 53

def write_yaml_files
  puts config.repo.diff
  ask_question
  raise step['wrong_message'] if answer.strip.downcase!='y'
end