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.
19
20
21
22
23
24
25
26
27
|
# File 'lib/shards/stage.rb', line 19
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
|
#host_list ⇒ Object
122
123
124
|
# File 'lib/shards/stage.rb', line 122
def host_list
@host_list || hosts_to_check
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
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/shards/stage.rb', line 33
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
137
138
139
|
# File 'lib/shards/stage.rb', line 137
def blank_db_shard_exist?
shard.list.keys.include? blank_db_shard_key
end
|
#blank_db_shard_key ⇒ Object
133
134
135
|
# File 'lib/shards/stage.rb', line 133
def blank_db_shard_key
chosen_blank_db || get('blank_db')
end
|
#check_remote_process(remote_check: :internal_host) ⇒ Object
126
127
128
129
130
131
|
# File 'lib/shards/stage.rb', line 126
def check_remote_process remote_check: :internal_host
host_list.map do |h|
@internal_host=h
[ h , send(remote_check) ]
end.to_h
end
|
#command_to_remote(cmd) ⇒ Object
75
76
77
78
79
|
# File 'lib/shards/stage.rb', line 75
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
49
50
51
|
# File 'lib/shards/stage.rb', line 49
def config_name
config_replace[name] || name
end
|
#config_replace ⇒ Object
53
54
55
|
# File 'lib/shards/stage.rb', line 53
def config_replace
ENV['CONFIG_REPLACE'] ? eval(ENV['CONFIG_REPLACE']) : {}
end
|
#engineering_config_file ⇒ Object
101
102
103
|
# File 'lib/shards/stage.rb', line 101
def engineering_config_file
"#{engineering_dirname}_production.yml"
end
|
#engineering_dirname ⇒ Object
141
142
143
|
# File 'lib/shards/stage.rb', line 141
def engineering_dirname
shard.dir.split('/').first
end
|
89
90
91
|
# File 'lib/shards/stage.rb', line 89
def
[]
end
|
93
94
95
|
# File 'lib/shards/stage.rb', line 93
def
[]
end
|
97
98
99
|
# File 'lib/shards/stage.rb', line 97
def
[]
end
|
#fingerprints ⇒ Object
61
62
63
64
|
# File 'lib/shards/stage.rb', line 61
def fingerprints
site = Shards::Site.new self
{ shards: shard.fingerprints, sites: site.fingerprints }
end
|
#get(var_name) ⇒ Object
45
46
47
|
# File 'lib/shards/stage.rb', line 45
def get var_name
@variables.has_key?(var_name) ? (@variables[var_name] || '') : send(var_name)
end
|
#get_production_hosts ⇒ Object
105
106
107
|
# File 'lib/shards/stage.rb', line 105
def get_production_hosts
@host_list || @ips || get_production_ips
end
|
#get_production_ips ⇒ Object
109
110
111
112
|
# File 'lib/shards/stage.rb', line 109
def get_production_ips
ip_search=Shards::IpSearch.new self
@ips||=ip_search.ips
end
|
#hosts_to_check ⇒ Object
85
86
87
|
# File 'lib/shards/stage.rb', line 85
def hosts_to_check
web_server_hosts + get('extra_boxes_to_reload')
end
|
#internal_host ⇒ Object
114
115
116
|
# File 'lib/shards/stage.rb', line 114
def internal_host
@internal_host || route53_name
end
|
#puppet_agent! ⇒ Object
66
67
68
|
# File 'lib/shards/stage.rb', line 66
def puppet_agent!
command_to_remote 'sudo puppet agent -t'
end
|
#reload_shards! ⇒ Object
70
71
72
73
|
# File 'lib/shards/stage.rb', line 70
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
118
119
120
|
# File 'lib/shards/stage.rb', line 118
def route53_name
get('route53').split('.').first
end
|
#vars ⇒ Object
57
58
59
|
# File 'lib/shards/stage.rb', line 57
def vars
@variables.keys
end
|
#web_server_hosts ⇒ Object
81
82
83
|
# File 'lib/shards/stage.rb', line 81
def web_server_hosts
name=='prod' ? get_production_hosts : [ internal_host ]
end
|