Project

General

Profile

Revision 5397ee73

Added by David Davis over 7 years ago

Fixes #9382 - Use connection info when connecting to docker

View differences:

app/models/foreman_docker/docker.rb
8 8
      ComputeResource.model_name
9 9
    end
10 10

  
11
    def self.get_container(container)
12
      conn = container.compute_resource.docker_connection
13
      ::Docker::Container.get(container.uuid, {}, conn)
14
    end
15

  
11 16
    def capabilities
12 17
      [:image]
13 18
    end
......
29 34
    end
30 35

  
31 36
    def available_images
32
      client.images.all
37
      ::Docker::Image.all({}, docker_connection)
33 38
    end
34 39

  
35 40
    def local_images(filter = '')
36
      client # initialize Docker-Api
37
      ::Docker::Image.all('filter' => filter)
41
      ::Docker::Image.all({ 'filter' => filter }, docker_connection)
38 42
    end
39 43

  
40 44
    def tags_for_local_image(image)
......
45 49
    end
46 50

  
47 51
    def exist?(name)
48
      ::Docker::Image.exist?(name)
52
      ::Docker::Image.exist?(name, {}, docker_connection)
49 53
    end
50 54

  
51 55
    def image(id)
52
      client.image_get(id)
56
      ::Docker::Image.get(id, {}, docker_connection)
53 57
    end
54 58

  
55 59
    def tags(image_name)
......
65 69
    end
66 70

  
67 71
    def search(term = '')
68
      client.images.image_search(:term => term)
72
      ::Docker::Image.search({ :term => term }, docker_connection)
69 73
    end
70 74

  
71 75
    def provider_friendly_name
......
76 80
      options = vm_instance_defaults.merge(args)
77 81
      logger.debug("Creating container with the following options: #{options.inspect}")
78 82
      docker_command do
79
        ::Docker::Container.create(options)
83
        ::Docker::Container.create(options, docker_connection)
80 84
      end
81 85
    end
82 86

  
83 87
    def create_image(args = {})
84 88
      logger.debug("Creating docker image with the following options: #{args.inspect}")
85 89
      docker_command do
86
        ::Docker::Image.create(args)
90
        ::Docker::Image.create(args, credentials, docker_connection)
87 91
      end
88 92
    end
89 93

  
......
94 98

  
95 99
    def console(uuid)
96 100
      test_connection
97
      container = ::Docker::Container.get(uuid)
101
      container = ::Docker::Container.get(uuid, {}, docker_connection)
98 102
      {
99 103
        :name       => container.info['Name'],
100 104
        'timestamp' => Time.now.utc,
......
102 106
      }
103 107
    end
104 108

  
109
    def api_version
110
      ::Docker.version(docker_connection)
111
    end
112

  
113
    def authenticate!
114
      ::Docker.authenticate!(credentials, docker_connection)
115
    end
116

  
105 117
    def test_connection(options = {})
106 118
      super
107
      client.present?
119
      api_version
120
      credentials.empty? ? true : authenticate!
108 121
    # This should only rescue Fog::Errors, but Fog returns all kinds of errors...
109 122
    rescue => e
110 123
      errors[:base] << e.message
111 124
      false
112 125
    end
113 126

  
127
    def docker_connection
128
      @docker_connection ||= ::Docker::Connection.new(url, credentials)
129
    end
130

  
114 131
    protected
115 132

  
116 133
    def docker_command
......
141 158
      @client ||= ::Fog::Compute.new(opts)
142 159
    end
143 160

  
144
    def api_version
145
      @api_version ||= client.send(:client).api_version
161
    def credentials
162
      @credentials ||= {}.tap do |options|
163
        options[:username] = user if user.present?
164
        options[:password] = password if password.present?
165
        options[:email] = email if email.present?
166
      end
146 167
    end
147 168
  end
148 169
end

Also available in: Unified diff