Class: Shards::Stage
- Inherits:
-
Base
- Object
- Base
- Shards::Stage
show all
- Defined in:
- lib/shards/stage.rb
Instance Attribute Summary collapse
Attributes inherited from Base
#subdomain_param
Attributes included from Meta
#config
Instance Method Summary
collapse
Methods inherited from Base
#default_region, method_list, #set_config
Methods included from Meta
#add, #custom_yaml, #default_yaml, #get_config, #method_list, #output, #print_output, #proxy, #proxy_user, #reset_output, #run, #ssh_conn, #test_env?, #write_extra_config_dirs, #yaml_file
Constructor Details
#initialize(name, data, location_name) ⇒ Stage
Returns a new instance of Stage.
18
19
20
21
22
23
24
25
26
|
# File 'lib/shards/stage.rb', line 18
def initialize name, data, location_name
set_config
@name=name.downcase
@location_name=location_name.downcase
@variables = data
@output=[]
end
|
Instance Attribute Details
#chosen_blank_db ⇒ Object
Returns the value of attribute chosen_blank_db.
16
17
18
|
# File 'lib/shards/stage.rb', line 16
def chosen_blank_db
@chosen_blank_db
end
|
#location_name ⇒ Object
Returns the value of attribute location_name.
16
17
18
|
# File 'lib/shards/stage.rb', line 16
def location_name
@location_name
end
|
#name ⇒ Object
Returns the value of attribute name.
16
17
18
|
# File 'lib/shards/stage.rb', line 16
def name
@name
end
|
#shard ⇒ Object
Returns the value of attribute shard.
16
17
18
|
# File 'lib/shards/stage.rb', line 16
def shard
@shard
end
|
Instance Method Details
#add_domain(domain, dryrun: false) ⇒ Object
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/shards/stage.rb', line 32
def add_domain domain, dryrun: false
shard.add_domain domain
if dryrun
add_domain_message
else
shard.write_domain
end
end
|
#blank_db_shard_exist? ⇒ Boolean
120
121
122
|
# File 'lib/shards/stage.rb', line 120
def blank_db_shard_exist?
shard.list.keys.include? blank_db_shard_key
end
|
#blank_db_shard_key ⇒ Object
116
117
118
|
# File 'lib/shards/stage.rb', line 116
def blank_db_shard_key
chosen_blank_db || get('blank_db')
end
|
#check_remote_process(remote_check: :internal_host) ⇒ Object
109
110
111
112
113
114
|
# File 'lib/shards/stage.rb', line 109
def check_remote_process remote_check: :internal_host
hosts_to_check.map do |h|
@internal_host=h
[ h , send(remote_check) ]
end.to_h
end
|
#command_to_remote(cmd) ⇒ Object
74
75
76
77
78
|
# File 'lib/shards/stage.rb', line 74
def command_to_remote cmd
resp=shard.ssh! shard.command_to_remote( internal_host, cmd)
message=resp.exitstatus==0 ? 'successfully' : resp.to_s
{ status: resp.exitstatus, message: message }
end
|
#config_name ⇒ Object
48
49
50
|
# File 'lib/shards/stage.rb', line 48
def config_name
config_replace[name] || name
end
|
#config_replace ⇒ Object
52
53
54
|
# File 'lib/shards/stage.rb', line 52
def config_replace
ENV['CONFIG_REPLACE'] ? eval(ENV['CONFIG_REPLACE']) : {}
end
|
#engineering_dirname ⇒ Object
124
125
126
|
# File 'lib/shards/stage.rb', line 124
def engineering_dirname
shard.dir.split('/').first
end
|
88
89
90
|
# File 'lib/shards/stage.rb', line 88
def
[]
end
|
92
93
94
|
# File 'lib/shards/stage.rb', line 92
def
[]
end
|
#fingerprints ⇒ Object
60
61
62
63
|
# File 'lib/shards/stage.rb', line 60
def fingerprints
site = Shards::Site.new self
{ shards: shard.fingerprints, sites: site.fingerprints }
end
|
#get(var_name) ⇒ Object
44
45
46
|
# File 'lib/shards/stage.rb', line 44
def get var_name
@variables.has_key?(var_name) ? (@variables[var_name] || '') : send(var_name)
end
|
#get_production_ips ⇒ Object
96
97
98
99
|
# File 'lib/shards/stage.rb', line 96
def get_production_ips
ip_search=Shards::IpSearch.new self
@ips||=ip_search.ips
end
|
#hosts_to_check ⇒ Object
84
85
86
|
# File 'lib/shards/stage.rb', line 84
def hosts_to_check
web_server_hosts + get('extra_boxes_to_reload')
end
|
#internal_host ⇒ Object
101
102
103
|
# File 'lib/shards/stage.rb', line 101
def internal_host
@internal_host || route53_name
end
|
#puppet_agent! ⇒ Object
65
66
67
|
# File 'lib/shards/stage.rb', line 65
def puppet_agent!
command_to_remote 'sudo puppet agent -t'
end
|
#reload_shards! ⇒ Object
69
70
71
72
|
# File 'lib/shards/stage.rb', line 69
def reload_shards!
cmd="cd #{ENV['REMOTE_SERVER_CURRENT_PATH']} && RAILS_ENV=production bundle exec rake reload_shards"
command_to_remote cmd
end
|
#route53_name ⇒ Object
105
106
107
|
# File 'lib/shards/stage.rb', line 105
def route53_name
get('route53').split('.').first
end
|
#vars ⇒ Object
56
57
58
|
# File 'lib/shards/stage.rb', line 56
def vars
@variables.keys
end
|
#web_server_hosts ⇒ Object
80
81
82
|
# File 'lib/shards/stage.rb', line 80
def web_server_hosts
name=='prod' ? get_production_ips : [ internal_host ]
end
|