Class: ForemanDocker::Docker
- Inherits:
-
ComputeResource
- Object
- ComputeResource
- ForemanDocker::Docker
- Defined in:
- app/models/foreman_docker/docker.rb
Class Method Summary collapse
Instance Method Summary collapse
- #api_version ⇒ Object
- #authenticate! ⇒ Object
- #available_images ⇒ Object
- #capabilities ⇒ Object
- #console(uuid) ⇒ Object
- #create_container(args = {}) ⇒ Object
- #create_image(args = {}) ⇒ Object
- #docker_connection ⇒ Object
- #exist?(name) ⇒ Boolean
- #image(id) ⇒ Object
- #local_images(filter = '') ⇒ Object
- #max_cpu_count ⇒ Object
- #max_memory ⇒ Object
- #provided_attributes ⇒ Object
- #provider_friendly_name ⇒ Object
- #search(term = '') ⇒ Object
- #supports_update? ⇒ Boolean
- #tags(image_name) ⇒ Object
- #tags_for_local_image(image, tag = nil) ⇒ Object
- #test_connection(options = {}) ⇒ Object
- #vm_instance_defaults ⇒ Object
Class Method Details
.get_container(container) ⇒ Object
12 13 14 15 |
# File 'app/models/foreman_docker/docker.rb', line 12 def self.get_container(container) conn = container.compute_resource.docker_connection ::Docker::Container.get(container.uuid, {}, conn) end |
.model_name ⇒ Object
8 9 10 |
# File 'app/models/foreman_docker/docker.rb', line 8 def self.model_name ComputeResource.model_name end |
Instance Method Details
#api_version ⇒ Object
108 109 110 |
# File 'app/models/foreman_docker/docker.rb', line 108 def api_version ::Docker.version(docker_connection) end |
#authenticate! ⇒ Object
112 113 114 |
# File 'app/models/foreman_docker/docker.rb', line 112 def authenticate! ::Docker.authenticate!(credentials, docker_connection) end |
#available_images ⇒ Object
37 38 39 |
# File 'app/models/foreman_docker/docker.rb', line 37 def available_images ::Docker::Image.all({}, docker_connection) end |
#capabilities ⇒ Object
17 18 19 |
# File 'app/models/foreman_docker/docker.rb', line 17 def capabilities [] end |
#console(uuid) ⇒ Object
98 99 100 101 102 103 104 105 106 |
# File 'app/models/foreman_docker/docker.rb', line 98 def console(uuid) test_connection container = ::Docker::Container.get(uuid, {}, docker_connection) { :name => container.info['Name'], 'timestamp' => Time.now.utc, 'output' => container.logs(:stdout => true, :tail => 100) } end |
#create_container(args = {}) ⇒ Object
78 79 80 81 82 83 84 |
# File 'app/models/foreman_docker/docker.rb', line 78 def create_container(args = {}) = vm_instance_defaults.merge(args) logger.debug("Creating container with the following options: #{.inspect}") docker_command do ::Docker::Container.create(, docker_connection) end end |
#create_image(args = {}) ⇒ Object
86 87 88 89 90 91 |
# File 'app/models/foreman_docker/docker.rb', line 86 def create_image(args = {}) logger.debug("Creating docker image with the following options: #{args.inspect}") docker_command do ::Docker::Image.create(args, credentials, docker_connection) end end |
#docker_connection ⇒ Object
126 127 128 |
# File 'app/models/foreman_docker/docker.rb', line 126 def docker_connection @docker_connection ||= ::Docker::Connection.new(url, credentials) end |
#exist?(name) ⇒ Boolean
54 55 56 |
# File 'app/models/foreman_docker/docker.rb', line 54 def exist?(name) ::Docker::Image.exist?(name, {}, docker_connection) end |
#image(id) ⇒ Object
58 59 60 |
# File 'app/models/foreman_docker/docker.rb', line 58 def image(id) ::Docker::Image.get(id, {}, docker_connection) end |
#local_images(filter = '') ⇒ Object
41 42 43 |
# File 'app/models/foreman_docker/docker.rb', line 41 def local_images(filter = '') ::Docker::Image.all({ 'filter' => filter }, docker_connection) end |
#max_cpu_count ⇒ Object
33 34 35 |
# File 'app/models/foreman_docker/docker.rb', line 33 def max_cpu_count ::Docker.info['NCPU'] || 1 end |
#max_memory ⇒ Object
29 30 31 |
# File 'app/models/foreman_docker/docker.rb', line 29 def max_memory 16 * 1024 * 1024 * 1024 end |
#provided_attributes ⇒ Object
25 26 27 |
# File 'app/models/foreman_docker/docker.rb', line 25 def provided_attributes super.merge(:mac => :mac) end |
#provider_friendly_name ⇒ Object
74 75 76 |
# File 'app/models/foreman_docker/docker.rb', line 74 def provider_friendly_name 'Docker' end |
#search(term = '') ⇒ Object
70 71 72 |
# File 'app/models/foreman_docker/docker.rb', line 70 def search(term = '') client.images.image_search(:term => term) end |
#supports_update? ⇒ Boolean
21 22 23 |
# File 'app/models/foreman_docker/docker.rb', line 21 def supports_update? false end |
#tags(image_name) ⇒ Object
62 63 64 65 66 67 68 |
# File 'app/models/foreman_docker/docker.rb', line 62 def (image_name) if exist?(image_name) (image(image_name)) else Service::RegistryApi.docker_hub.(image_name).map { |tag| tag['name'] } end end |
#tags_for_local_image(image, tag = nil) ⇒ Object
45 46 47 48 49 50 51 52 |
# File 'app/models/foreman_docker/docker.rb', line 45 def (image, tag = nil) result = image.info['RepoTags'].map do |image_tag| _, tag = image_tag.split(':') tag end result = (result, tag) if tag result end |
#test_connection(options = {}) ⇒ Object
116 117 118 119 120 121 122 123 124 |
# File 'app/models/foreman_docker/docker.rb', line 116 def test_connection( = {}) super api_version credentials.empty? ? true : authenticate! # This should only rescue Fog::Errors, but Fog returns all kinds of errors... rescue => e errors[:base] << e. false end |
#vm_instance_defaults ⇒ Object
93 94 95 96 |
# File 'app/models/foreman_docker/docker.rb', line 93 def vm_instance_defaults ActiveSupport::HashWithIndifferentAccess.new('name' => "foreman_#{Time.now.to_i}", 'Cmd' => ['/bin/bash']) end |