Project

General

Profile

Download (994 Bytes) Statistics
| Branch: | Tag: | Revision:

foreman-docker / app / models / container.rb @ 3bc253a2

1
class Container < ActiveRecord::Base
2
  belongs_to :compute_resource
3
  belongs_to :docker_image
4
  belongs_to :docker_tag
5

    
6
  attr_accessible :command, :image, :name, :compute_resource_id, :entrypoint,
7
                  :cpu_set, :cpu_shares, :memory, :tty, :attach_stdin,
8
                  :attach_stdout, :attach_stderr, :tag
9

    
10
  def parametrize
11
    { :name => name, :cmd => [command], :image => docker_image.image_id, :tty => tty,
12
      :attach_stdout => attach_stdout, :attach_stdout => attach_stdout,
13
      :attach_stderr => attach_stderr, :cpushares => cpu_shares, :cpuset => cpu_set,
14
      :memory => memory }
15
  end
16

    
17
  def image
18
    docker_image.try(:image_id)
19
  end
20

    
21
  def image=(image_id)
22
    image = DockerImage.find_or_create_by_image_id!(image_id)
23
    self.docker_image_id = image.id
24
  end
25

    
26
  def tag
27
    docker_tag.try(:tag)
28
  end
29

    
30
  def tag=(tag_name)
31
    tag = DockerTag.find_or_create_by_tag_and_docker_image_id!(tag_name, docker_image_id)
32
    self.docker_tag_id = tag.id
33
  end
34
end