Class: Shards::Workflow::DeleteByApi

Inherits:
ByApi
  • Object
show all
Defined in:
lib/shards/workflow/delete_by_api.rb

Instance Attribute Summary collapse

Attributes inherited from ByApi

#log

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 ByApi

#output_message, #write_yaml_files

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, #write_yaml_files, #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_api.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_api.rb', line 8

def db
  @db
end

#dnsObject

Returns the value of attribute dns.



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

def dns
  @dns
end

Instance Method Details

#commit_changesObject



48
49
50
51
52
53
54
# File 'lib/shards/workflow/delete_by_api.rb', line 48

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

#delete_databaseObject



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/shards/workflow/delete_by_api.rb', line 56

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|

      output_message "Database:\t #{database_to_drop}"
      output_message "Host:    \t #{host}"
      output_message "DELETING database #{database_to_drop} in #{host}"
      db.server=host
      db.drop

    end

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

  else
    output_message "The shard is in use by other site, will not be deleted"
  end
end

#delete_recordObject



21
22
23
24
25
26
27
28
# File 'lib/shards/workflow/delete_by_api.rb', line 21

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?
    output_message step['message'] % message_params
  end
end

#delete_site_and_shardObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/shards/workflow/delete_by_api.rb', line 30

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_api.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