Class: Pod
Instance Method Summary
collapse
#attach_network, #create_instance, #create_network, #create_volume, #delete_volume, #dettach_network, #execute_local, #inspect_instance, #inspect_volume, #logs, #network_exists?, #remove_instance, #remove_network, #start_instance, #stop_instance
#parse_model, #parse_template, #read_template
Instance Method Details
#clean_up ⇒ Object
90
91
92
93
|
# File 'lib/mkit/app/model/pod.rb', line 90
def clean_up
remove_instance(self.name) unless self.pod_id.nil?
MkitJob.publish(topic: :pod_destroyed, service_id: self.service.id, data: {pod_id: self.id})
end
|
#parse ⇒ Object
63
64
65
|
# File 'lib/mkit/app/model/pod.rb', line 63
def parse
parse_model(MKIt::Templates::DOCKER_RUN).result(binding)
end
|
#pre_check ⇒ Object
85
86
87
88
|
# File 'lib/mkit/app/model/pod.rb', line 85
def pre_check
raise MKIt::PodNotFoundException.new('no pod_name found') if self.name.nil?
raise MKIt::PodNotFoundException.new("no properties found for #{self.name}") if self.properties.nil?
end
|
#properties ⇒ Object
43
44
45
|
# File 'lib/mkit/app/model/pod.rb', line 43
def properties
inspect_instance(self.name)
end
|
#set_status_from_docker ⇒ Object
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/mkit/app/model/pod.rb', line 47
def set_status_from_docker
instance = self.properties
if self.properties
instance = instance.to_o
if instance.State.Running
self.status = MKIt::Status::RUNNING
else
self.status = MKIt::Status::STOPPED
end
else
self.status = MKIt::Status::PENDING
end
self.save
self.status
end
|
#start ⇒ Object
67
68
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/mkit/app/model/pod.rb', line 67
def start
if self.pod_id.nil?
docker_run = parse
MKItLogger.info("deploying docker pod, cmd [#{docker_run}]")
create_instance(docker_run)
else
pre_check
instance = self.properties.to_o
start_instance(self.name) unless instance.State.Running
end
end
|
#stop ⇒ Object
80
81
82
83
|
# File 'lib/mkit/app/model/pod.rb', line 80
def stop
pre_check
stop_instance(self.name)
end
|
#update_dns ⇒ Object
33
34
35
36
37
38
39
40
41
|
# File 'lib/mkit/app/model/pod.rb', line 33
def update_dns
self.dns_host ||= DnsHost.new(
service: self.service,
name: "#{name}.#{self.service.name}",
ip: self.ip
)
self.dns_host.ip = self.ip
self.dns_host.save
end
|
#update_ip ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/mkit/app/model/pod.rb', line 15
def update_ip
new_ip = nil
tries = 5
while (new_ip.nil? && tries > 0) do
instance = self.properties.to_o
new_ip = instance.NetworkSettings.Networks[self.service.pods_network].IPAddress
sleep(1) if new_ip.nil?
tries = tries - 1
end
if self.ip != new_ip
self.ip = new_ip
self.update_dns
MkitJob.publish(topic: :pod_ip_updated, service_id: self.service.id, pod_id: self.id)
end
MKItLogger.info("docker ip updated [#{self.ip}]")
self.ip
end
|