1
|
class Container < ActiveRecord::Base
|
2
|
include Authorizable
|
3
|
include Taxonomix
|
4
|
|
5
|
belongs_to :compute_resource
|
6
|
belongs_to :registry, :class_name => "DockerRegistry", :foreign_key => :registry_id
|
7
|
has_many :environment_variables, :dependent => :destroy, :foreign_key => :reference_id,
|
8
|
:inverse_of => :container,
|
9
|
:class_name => 'EnvironmentVariable',
|
10
|
:validate => false
|
11
|
accepts_nested_attributes_for :environment_variables, :allow_destroy => true
|
12
|
include ForemanDocker::ParameterValidators
|
13
|
|
14
|
has_many :exposed_ports, :dependent => :destroy, :foreign_key => :reference_id,
|
15
|
:inverse_of => :container,
|
16
|
:class_name => 'ExposedPort',
|
17
|
:validate => true
|
18
|
|
19
|
has_many :dns, :dependent => :destroy, :foreign_key => :reference_id,
|
20
|
:inverse_of => :container,
|
21
|
:class_name => 'ForemanDocker::Dns',
|
22
|
:validate => true
|
23
|
|
24
|
accepts_nested_attributes_for :exposed_ports, :allow_destroy => true
|
25
|
scoped_search :on => :name
|
26
|
|
27
|
validates :name, :uniqueness => { :scope => :compute_resource_id }
|
28
|
|
29
|
def repository_pull_url
|
30
|
repo = tag.blank? ? repository_name : "#{repository_name}:#{tag}"
|
31
|
repo = registry.prefixed_url(repo) if registry
|
32
|
repo
|
33
|
end
|
34
|
|
35
|
def parametrize
|
36
|
{ 'name' => name,
|
37
|
'Image' => repository_pull_url,
|
38
|
'Tty' => tty,
|
39
|
'Memory' => ::ForemanDocker::Utility.parse_memory(memory),
|
40
|
'Entrypoint' => entrypoint.try(:split), 'Cmd' => command.try(:split),
|
41
|
'AttachStdout' => attach_stdout, 'AttachStdin' => attach_stdin,
|
42
|
'AttachStderr' => attach_stderr, 'CpuShares' => cpu_shares,
|
43
|
'Cpuset' => cpu_set,
|
44
|
'Env' => environment_variables.map { |env| "#{env.name}=#{env.value}" },
|
45
|
'ExposedPorts' => Hash[*exposed_ports.map { |v| [v.name + "/" + v.value, {}] }.flatten],
|
46
|
'HostConfig' => {
|
47
|
'Dns' => dns.map { |env| "#{env.name}" }
|
48
|
} }
|
49
|
end
|
50
|
|
51
|
def in_fog
|
52
|
@fog_container ||= compute_resource.vms.get(uuid)
|
53
|
end
|
54
|
|
55
|
def self.humanize_class_name(_name = nil)
|
56
|
_("Docker/Container")
|
57
|
end
|
58
|
end
|