lib/percheron/unit.rb in percheron-0.7.16 vs lib/percheron/unit.rb in percheron-0.8.0
- old
+ new
@@ -1,33 +1,35 @@
+require 'percheron/unit/image_helper'
+
module Percheron
class Unit
extend Forwardable
extend ConfigDelegator
+ include Unit::ImageHelper
def_delegators :unit_config, :name, :pseudo_name, :docker_image
- def_config_item_with_default :unit_config, [], :env, :ports, :volumes,
- :dependant_unit_names, :pre_build_scripts,
- :post_start_scripts, :start_args, :dns
+ def_config_item_with_default :unit_config, [], :env, :ports, :volumes, :needed_unit_names,
+ :pre_build_scripts, :post_start_scripts, :start_args, :dns
def_config_item_with_default :unit_config, true, :startable
def initialize(config, stack, unit_name)
@config = config
@stack = stack
@unit_name = unit_name
@unit_config = stack.unit_configs[unit_name] || Hashie::Mash.new({}) # FIXME
self
end
- def dependant_units
- dependant_unit_names.each_with_object({}) do |unit_name, all|
+ def needed_units
+ needed_unit_names.each_with_object({}) do |unit_name, all|
all[unit_name] = stack.units[unit_name]
end
end
- def startable_dependant_units
- dependant_units.select { |_, unit| unit.startable? }
+ def startable_needed_units
+ needed_units.select { |_, unit| unit.startable? }
end
def metastore_key
@metastore_key ||= '%s.units.%s' % [ stack.metastore_key, name ]
end
@@ -35,35 +37,23 @@
def id
exists? ? info.id[0...12] : nil
end
def hostname
- unit_config.fetch('hostname', name)
+ unit_config.fetch('hostname', full_name)
end
- def image_name
- '%s:%s' % [ image_repo, image_version.to_s ] if image_repo && image_version
- end
-
- def image_repo
- if !buildable?
- unit_config.docker_image.split(':')[0]
- elsif pseudo?
- pseudo_full_name
- else
- full_name
+ def restart_policy
+ @restart_policy ||= begin
+ name = unit_config.fetch('restart_policy', 'always')
+ max_retry_count = unit_config.fetch('restart_policy_retry_count', 0)
+ { 'Name' => name, 'MaximumRetryCount' => max_retry_count }
end
end
- def image_version
- if buildable?
- unit_config.version
- elsif !unit_config.docker_image.nil?
- unit_config.docker_image.split(':')[1] || 'latest'
- else
- fail Errors::UnitInvalid, 'Cannot determine image version'
- end
+ def privileged
+ unit_config.fetch('privileged', false)
end
def full_name
'%s_%s' % [ stack.name, name ]
end
@@ -93,13 +83,11 @@
def exposed_ports
ports.each_with_object({}) { |p, all| all[p.split(':')[1]] = {} }
end
def links
- startable_dependant_units.map do |_, unit|
- '%s:%s' % [ unit.full_name, unit.full_name ]
- end
+ startable_needed_units.map { |_, unit| '%s:%s' % [ unit.full_name, unit.full_name ] }
end
def container
Connection.perform(Docker::Container, :get, full_name)
rescue Docker::Error::NotFoundError, Excon::Errors::SocketError
@@ -139,14 +127,10 @@
def exists?
!info.empty?
end
- def image_exists?
- image.nil? ? false : true
- end
-
def buildable?
!dockerfile.nil? && unit_config.docker_image.nil?
end
def valid?
@@ -176,8 +160,7 @@
end
def info
Hashie::Mash.new(container.info)
end
-
end
end