Project

General

Profile

Revision 3bc253a2

Added by David Davis over 8 years ago

Refs #7642 - Create docker image and tag models

View differences:

app/models/container.rb
1 1
class Container < ActiveRecord::Base
2 2
  belongs_to :compute_resource
3
  belongs_to :docker_image
4
  belongs_to :docker_tag
3 5

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

  
8 10
  def parametrize
9
    { :name => name, :cmd => [command], :image => image, :tty => tty,
11
    { :name => name, :cmd => [command], :image => docker_image.image_id, :tty => tty,
10 12
      :attach_stdout => attach_stdout, :attach_stdout => attach_stdout,
11 13
      :attach_stderr => attach_stderr, :cpushares => cpu_shares, :cpuset => cpu_set,
12 14
      :memory => memory }
13 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
14 34
end

Also available in: Unified diff