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
|
attr_accessible :command, :repository_name, :name, :compute_resource_id, :entrypoint,
|
15
|
:cpu_set, :cpu_shares, :memory, :tty, :attach_stdin, :registry_id,
|
16
|
:attach_stdout, :attach_stderr, :tag, :uuid, :environment_variables_attributes
|
17
|
|
18
|
def repository_pull_url
|
19
|
repo = tag.blank? ? repository_name : "#{repository_name}:#{tag}"
|
20
|
repo = registry.prefixed_url(repo) if registry
|
21
|
repo
|
22
|
end
|
23
|
|
24
|
def parametrize
|
25
|
{ 'name' => name,
|
26
|
'Image' => repository_pull_url,
|
27
|
'Tty' => tty, 'Memory' => memory,
|
28
|
'Entrypoint' => entrypoint.try(:split), 'Cmd' => command.try(:split),
|
29
|
'AttachStdout' => attach_stdout, 'AttachStdin' => attach_stdin,
|
30
|
'AttachStderr' => attach_stderr, 'CpuShares' => cpu_shares,
|
31
|
'Cpuset' => cpu_set,
|
32
|
'Env' => environment_variables.map { |env| "#{env.name}=#{env.value}" } }
|
33
|
end
|
34
|
|
35
|
def in_fog
|
36
|
@fog_container ||= compute_resource.vms.get(uuid)
|
37
|
end
|
38
|
end
|