Class: Rudy::Machine
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#==, #initialize, #refresh, #save, #to_query, #to_select, #valid?
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 Attribute Details
#instance ⇒ Object
Returns the value of attribute instance.
24
25
26
|
# File 'lib/rudy/machines.rb', line 24
def instance
@instance
end
|
Class Method Details
.generate_machine_data ⇒ Object
151
152
153
154
155
156
157
158
159
160
161
162
163
|
# File 'lib/rudy/machines.rb', line 151
def Machine.generate_machine_data
data = { :region => @@global.region.to_s,
:zone => @@global.zone.to_s,
:environment => @@global.environment.to_s,
:role => @@global.role.to_s,
:position => @@global.position.to_s,
:hosts => { :dbmaster => "127.0.0.1",
}
}
data
end
|
.generate_name(zon, env, rol, pos) ⇒ Object
76
77
78
79
|
# File 'lib/rudy/machines.rb', line 76
def Machine.generate_name(zon, env, rol, pos)
pos = pos.to_s.rjust 2, '0'
["m", zon, env, rol, pos].join(Rudy::DELIM)
end
|
Instance Method Details
#destroy ⇒ Object
142
143
144
145
|
# File 'lib/rudy/machines.rb', line 142
def destroy
@ec2inst.destroy(@awsid) if running?
super
end
|
#dns_private? ⇒ Boolean
103
104
105
|
# File 'lib/rudy/machines.rb', line 103
def dns_private?
!@dns_private.nil? && !@dns_private.empty?
end
|
#dns_public? ⇒ Boolean
100
101
102
|
# File 'lib/rudy/machines.rb', line 100
def dns_public?
!@dns_public.nil? && !@dns_public.empty?
end
|
#find_next_position ⇒ Object
66
67
68
69
70
|
# File 'lib/rudy/machines.rb', line 66
def find_next_position
list = @sdb.select(self.to_select(nil, [:position])) || []
pos = list.size + 1
pos.to_s.rjust(2, '0')
end
|
#get_instance ⇒ Object
81
82
83
|
# File 'lib/rudy/machines.rb', line 81
def get_instance
@ec2inst.get(@awsid)
end
|
#init ⇒ Object
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/rudy/machines.rb', line 26
def init
@rtype = 'm'
@region = @@global.region
@zone = @@global.zone
@environment = @@global.environment
@role = @@global.role
@position = find_next_position || '01'
@state = 'no-instance'
end
|
#inspect ⇒ Object
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/rudy/machines.rb', line 54
def inspect
update lines = []
lines << liner_note
field_names.each do |key|
next unless self.respond_to?(key)
val = self.send(key)
lines << sprintf(" %22s: %s", key, (val.is_a?(Array) ? val.join(', ') : val))
end
lines.join($/)
end
|
#liner_note ⇒ Object
37
38
39
40
41
|
# File 'lib/rudy/machines.rb', line 37
def liner_note
update info = !@dns_public.nil? && !@dns_public.empty? ? @dns_public : "#{@awsid}:#{@state}"
"%s %s" % [self.name.bright, info]
end
|
#name ⇒ Object
72
73
74
|
# File 'lib/rudy/machines.rb', line 72
def name
Machine.generate_name(@zone, @environment, @role, @position)
end
|
#restart ⇒ Object
147
148
149
|
# File 'lib/rudy/machines.rb', line 147
def restart
@ec2inst.restart(@awsid) if running?
end
|
#running? ⇒ Boolean
165
166
167
168
|
# File 'lib/rudy/machines.rb', line 165
def running?
return false if @awsid.nil? || @awsid.empty?
@ec2inst.running?(@awsid)
end
|
#start(opts = {}) ⇒ Object
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
# File 'lib/rudy/machines.rb', line 107
def start(opts={})
raise "#{name} is already running" if running?
opts = {
:min => 1,
:size => current_machine_size,
:ami => current_machine_image,
:group => current_group_name,
:keypair => root_keypairname,
:zone => @@global.zone.to_s,
:machine_data => Machine.generate_machine_data.to_yaml
}.merge(opts)
@ec2inst.create(opts) do |inst|
@awsid = inst.awsid
@created = @starts = Time.now
@state = inst.state
if current_machine_address(@position)
address = current_machine_address(@position)
puts "Associating #{address} to #{inst.awsid}"
begin
@radd.associate(address, inst.awsid)
rescue => ex
STDERR.puts "Error while associating address (#{ex.class.to_s})"
Rudy::Utils.bug()
end
end
end
self.save
self
end
|
#to_s(with_title = false) ⇒ Object
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/rudy/machines.rb', line 43
def to_s(with_title=false)
lines = []
lines << liner_note
lines.join($/)
end
|
#update ⇒ Object
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
# File 'lib/rudy/machines.rb', line 85
def update
return false unless @awsid
@instance = get_instance
if @instance.is_a?(Rudy::AWS::EC2::Instance)
@dns_public = @instance.dns_public
@dns_private = @instance.dns_private
@state = @instance.state
save
elsif @instance.nil?
@awsid = @dns_public = @dns_private = nil
@state = 'rogue'
end
end
|