foreman_docker 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/api/v2/containers_controller.rb +170 -0
- data/app/controllers/containers_controller.rb +33 -1
- data/app/helpers/containers_helper.rb +28 -5
- data/app/models/concerns/fog_extensions/fogdocker/images.rb +14 -0
- data/app/models/docker_registry.rb +1 -0
- data/app/views/api/v2/containers/base.json.rabl +3 -0
- data/app/views/api/v2/containers/index.json.rabl +3 -0
- data/app/views/api/v2/containers/main.json.rabl +9 -0
- data/app/views/api/v2/containers/show.json.rabl +7 -0
- data/app/views/compute_resources_vms/index/_docker.html.erb +1 -1
- data/app/views/containers/_list.html.erb +2 -2
- data/app/views/containers/show.html.erb +1 -1
- data/config/routes.rb +29 -4
- data/lib/foreman_docker/engine.rb +39 -5
- data/lib/foreman_docker/version.rb +1 -1
- data/test/functionals/api/v2/containers_controller_test.rb +70 -0
- data/test/integration/container_test.rb +1 -0
- data/test/units/docker_registry_test.rb +4 -3
- metadata +83 -75
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 86749f058604f314afa36079efedb8335d2ef47e
|
4
|
+
data.tar.gz: b8ef0a060b0475b26e09b4a6cf2696d544005d80
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 448a15eb9db1bfa4ed7f18037ab4cb9ff094ba7887663016b9a960bca4403ce24e419f02440c60c8baea03a961d31b66d7c003868e0ef72dd397a5fe19628708
|
7
|
+
data.tar.gz: 2ca249ac65d7589834c7f583312b180d6689ad8b20f85811a2aecd2c99704d20f34377b29e0a97ee47988a089c2ddd414bba0378afd191e6e9797d5ce52f9460
|
@@ -0,0 +1,170 @@
|
|
1
|
+
# module ForemanDocker
|
2
|
+
module Api
|
3
|
+
module V2
|
4
|
+
class ContainersController < ::Api::V2::BaseController
|
5
|
+
before_filter :find_resource, :except => %w(index create)
|
6
|
+
|
7
|
+
resource_description do
|
8
|
+
resource_id 'containers'
|
9
|
+
api_version 'v2'
|
10
|
+
api_base_url '/api/v2'
|
11
|
+
end
|
12
|
+
|
13
|
+
api :GET, '/containers/', N_('List all containers')
|
14
|
+
api :GET, '/compute_resources/:compute_resource_id/containers/',
|
15
|
+
N_('List all containers in a compute resource')
|
16
|
+
param :compute_resource_id, :identifier
|
17
|
+
param_group :pagination, ::Api::V2::BaseController
|
18
|
+
|
19
|
+
def index
|
20
|
+
if params[:compute_resource_id].present?
|
21
|
+
@containers = Container.where(:compute_resource_id => params[:compute_resource_id])
|
22
|
+
else
|
23
|
+
@containers = Container.all
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
api :GET, '/containers/:id/', N_('Show a container')
|
28
|
+
api :GET, '/compute_resources/:compute_resource_id/containers/:id',
|
29
|
+
N_('Show container in a compute resource')
|
30
|
+
param :id, :identifier, :required => true
|
31
|
+
param :compute_resource_id, :identifier
|
32
|
+
|
33
|
+
def show
|
34
|
+
end
|
35
|
+
|
36
|
+
def_param_group :container do
|
37
|
+
param :container, Hash, :required => true, :action_aware => true do
|
38
|
+
param :name, String, :required => true
|
39
|
+
param_group :taxonomies, ::Api::V2::BaseController
|
40
|
+
param :compute_resource_id, :identifier, :required => true
|
41
|
+
param :registry_id, :identifier, :desc => N_('Registry this container will have to use
|
42
|
+
to get the image')
|
43
|
+
param :image, String, :desc => N_('Image to use to create the container.
|
44
|
+
Format should be repository:tag, e.g: centos:7')
|
45
|
+
param :tty, :bool
|
46
|
+
param :entrypoint, String
|
47
|
+
param :cmd, String
|
48
|
+
param :memory, String
|
49
|
+
param :cpu_shares, :number
|
50
|
+
param :cpu_sets, String
|
51
|
+
param :environment_variables, Hash
|
52
|
+
param :attach_stdout, :bool
|
53
|
+
param :attach_stdin, :bool
|
54
|
+
param :attach_stderr, :bool
|
55
|
+
param :katello, :bool
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
api :POST, '/containers/', N_('Create a container')
|
60
|
+
api :POST, '/compute_resources/:compute_resource_id/containers/',
|
61
|
+
N_('Create container in a compute resource')
|
62
|
+
param_group :container, :as => :create
|
63
|
+
|
64
|
+
def create
|
65
|
+
@container = Service::Containers.new.start_container!(set_wizard_state)
|
66
|
+
set_container_taxonomies
|
67
|
+
process_response @container.save
|
68
|
+
rescue ActiveModel::MassAssignmentSecurity::Error => e
|
69
|
+
render :json => { :error => _("Wrong attributes: %s") % e.message },
|
70
|
+
:status => :unprocessable_entity
|
71
|
+
end
|
72
|
+
|
73
|
+
api :DELETE, '/containers/:id/', N_('Delete a container')
|
74
|
+
api :DELETE, '/compute_resources/:compute_resource_id/containers/:id',
|
75
|
+
N_('Delete container in a compute resource')
|
76
|
+
param :id, :identifier, :required => true
|
77
|
+
param :compute_resource_id, :identifier
|
78
|
+
|
79
|
+
def destroy
|
80
|
+
process_response @container.destroy
|
81
|
+
end
|
82
|
+
|
83
|
+
api :GET, '/containers/:id/logs', N_('Show container logs')
|
84
|
+
api :GET, '/compute_resources/:compute_resource_id/containers/:id/logs',
|
85
|
+
N_('Show logs from a container in a compute resource')
|
86
|
+
param :id, :identifier, :required => true
|
87
|
+
param :compute_resource_id, :identifier
|
88
|
+
param :stdout, :bool
|
89
|
+
param :stderr, :bool
|
90
|
+
param :tail, Fixnum, N_('Number of lines to tail. Default: 100')
|
91
|
+
|
92
|
+
def logs
|
93
|
+
render :json => { :logs => Docker::Container.get(@container.uuid)
|
94
|
+
.logs(:stdout => (params[:stdout] || true),
|
95
|
+
:stderr => (params[:stderr] || false),
|
96
|
+
:tail => (params[:tail] || 100)) }
|
97
|
+
end
|
98
|
+
|
99
|
+
api :PUT, '/containers/:id/power', N_('Run power operation on a container')
|
100
|
+
api :PUT, '/compute_resources/:compute_resource_id/containers/:id/power',
|
101
|
+
N_('Run power operation on a container in a compute resource')
|
102
|
+
param :id, :identifier, :required => true
|
103
|
+
param :compute_resource_id, :identifier
|
104
|
+
param :power_action, String,
|
105
|
+
:required => true,
|
106
|
+
:desc => N_('power action, valid actions are (start), (stop), (status)')
|
107
|
+
|
108
|
+
def power
|
109
|
+
power_actions = %(start stop status)
|
110
|
+
if power_actions.include? params[:power_action]
|
111
|
+
response = if params[:power_action] == 'status'
|
112
|
+
{ :running => @container.in_fog.ready? }
|
113
|
+
else
|
114
|
+
{ :running => @container.in_fog.send(params[:power_action]) }
|
115
|
+
end
|
116
|
+
render :json => response
|
117
|
+
else
|
118
|
+
render :json =>
|
119
|
+
{ :error => _("Unknown method: available power operations are %s") %
|
120
|
+
power_actions.join(', ') }, :status => :unprocessable_entity
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
private
|
125
|
+
|
126
|
+
def set_wizard_state
|
127
|
+
wizard_properties = { :preliminary => [:compute_resource_id],
|
128
|
+
:image => [:registry_id, :repository_name, :tag, :katello],
|
129
|
+
:configuration => [:name, :command, :entrypoint, :cpu_set,
|
130
|
+
:cpu_shares, :memory],
|
131
|
+
:environment => [:tty, :attach_stdin, :attach_stdout,
|
132
|
+
:attach_stderr] }
|
133
|
+
|
134
|
+
wizard_state = DockerContainerWizardState.create
|
135
|
+
wizard_properties.each do |step, properties|
|
136
|
+
property_values = properties.each_with_object({}) do |property, values|
|
137
|
+
values[:"#{property}"] = params[:container][:"#{property}"]
|
138
|
+
end
|
139
|
+
wizard_state.send(:"create_#{step}", property_values)
|
140
|
+
end
|
141
|
+
|
142
|
+
if params[:container][:environment_variables].present?
|
143
|
+
wizard_state.environment.environment_variables =
|
144
|
+
params[:container][:environment_variables]
|
145
|
+
end
|
146
|
+
wizard_state.tap(&:save)
|
147
|
+
end
|
148
|
+
|
149
|
+
def set_container_taxonomies
|
150
|
+
Taxonomy.enabled_taxonomies.each do |taxonomy|
|
151
|
+
if params[:container][:"#{taxonomy}"].present?
|
152
|
+
@container.send(:"#{taxonomy}=", params[:container][:"#{taxonomy}"])
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
def action_permission
|
158
|
+
case params[:action]
|
159
|
+
when 'logs'
|
160
|
+
:view
|
161
|
+
when 'power'
|
162
|
+
:edit
|
163
|
+
else
|
164
|
+
super
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
170
|
+
# end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
class ContainersController < ::ApplicationController
|
2
2
|
include ForemanDocker::FindContainer
|
3
3
|
|
4
|
-
before_filter :find_container, :only => [:show, :commit]
|
4
|
+
before_filter :find_container, :only => [:show, :commit, :power]
|
5
5
|
|
6
6
|
def index
|
7
7
|
@container_resources = allowed_resources
|
@@ -48,6 +48,28 @@ class ContainersController < ::ApplicationController
|
|
48
48
|
{ :container => @container, :e => e }
|
49
49
|
end
|
50
50
|
|
51
|
+
def power
|
52
|
+
compute_resource = @container.compute_resource
|
53
|
+
@docker_container = compute_resource.find_vm_by_uuid(@container.uuid)
|
54
|
+
run_container_action(@docker_container.ready? ? :stop : :start)
|
55
|
+
end
|
56
|
+
|
57
|
+
def run_container_action(action)
|
58
|
+
if @docker_container.send(action)
|
59
|
+
@docker_container.reload
|
60
|
+
notice _("%{vm} is now %{vm_state}") %
|
61
|
+
{ :vm => @docker_container, :vm_state => @docker_container.state.capitalize }
|
62
|
+
redirect_to containers_path(:id => @container.id)
|
63
|
+
else
|
64
|
+
error _("failed to %{action} %{vm}") % { :action => _(action), :vm => @docker_container }
|
65
|
+
redirect_to :back
|
66
|
+
end
|
67
|
+
# This should only rescue Fog::Errors, but Fog returns all kinds of errors...
|
68
|
+
rescue => e
|
69
|
+
error _("Error - %{message}") % { :message => _(e.message) }
|
70
|
+
redirect_to :back
|
71
|
+
end
|
72
|
+
|
51
73
|
private
|
52
74
|
|
53
75
|
def action_permission
|
@@ -56,6 +78,16 @@ class ContainersController < ::ApplicationController
|
|
56
78
|
:view
|
57
79
|
when 'commit'
|
58
80
|
:commit
|
81
|
+
when 'power'
|
82
|
+
:power_compute_resources_vms
|
83
|
+
else
|
84
|
+
super
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def current_permission
|
89
|
+
if params[:action] == 'power'
|
90
|
+
:power_compute_resources_vms
|
59
91
|
else
|
60
92
|
super
|
61
93
|
end
|
@@ -1,8 +1,4 @@
|
|
1
1
|
module ContainersHelper
|
2
|
-
def managed_icon(container, resource)
|
3
|
-
icon_text(managed?(container, resource) ? 'check' : 'unchecked')
|
4
|
-
end
|
5
|
-
|
6
2
|
def managed?(container, resource)
|
7
3
|
uuids_in_resource(resource).include? container.identity
|
8
4
|
end
|
@@ -39,7 +35,7 @@ module ContainersHelper
|
|
39
35
|
button_group(
|
40
36
|
link_to(_('Commit'), '#commit-modal', :'data-toggle' => 'modal')
|
41
37
|
),
|
42
|
-
button_group(
|
38
|
+
button_group(container_power_action(container.in_fog)),
|
43
39
|
button_group(
|
44
40
|
display_delete_if_authorized(
|
45
41
|
hash_for_container_path(:id => container.id)
|
@@ -51,6 +47,33 @@ module ContainersHelper
|
|
51
47
|
)
|
52
48
|
end
|
53
49
|
|
50
|
+
def container_power_action(vm, authorizer = nil)
|
51
|
+
if managed?(vm, @compute_resource)
|
52
|
+
id = Container.find_by_uuid(vm.identity).id
|
53
|
+
opts = hash_for_power_container_path(:id => id)
|
54
|
+
.merge(:auth_object => @compute_resource,
|
55
|
+
:permission => 'power_compute_resources_vms',
|
56
|
+
:authorizer => authorizer)
|
57
|
+
else
|
58
|
+
opts = hash_for_power_compute_resource_vm_path(:compute_resource_id => @compute_resource,
|
59
|
+
:id => vm.identity)
|
60
|
+
.merge(:auth_object => @compute_resource, :permission => 'power_compute_resources_vms',
|
61
|
+
:authorizer => authorizer)
|
62
|
+
end
|
63
|
+
html = if vm.ready?
|
64
|
+
{ :confirm => power_on_off_message(vm), :class => "btn btn-danger" }
|
65
|
+
else
|
66
|
+
{ :class => "btn btn-info" }
|
67
|
+
end
|
68
|
+
|
69
|
+
display_link_if_authorized "Power #{action_string(vm)}", opts, html.merge(:method => :put)
|
70
|
+
end
|
71
|
+
|
72
|
+
def power_on_off_message(vm)
|
73
|
+
_("Are you sure you want to power %{act} %{vm}?") % { :act => action_string(vm).downcase.strip,
|
74
|
+
:vm => vm }
|
75
|
+
end
|
76
|
+
|
54
77
|
def auto_complete_docker_search(name, val, options = {})
|
55
78
|
addClass options, 'form-control'
|
56
79
|
text_field_tag(name, val, options)
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# Compatibility fixes - to be removed once 1.7 compatibility is no longer required
|
2
|
+
module FogExtensions
|
3
|
+
module Fogdocker
|
4
|
+
module Images
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
def image_search(query = {})
|
8
|
+
Docker::Util.parse_json(Docker.connection.get('/images/search', query)).map do |image|
|
9
|
+
downcase_hash_keys(image)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -8,6 +8,7 @@ class DockerRegistry < ActiveRecord::Base
|
|
8
8
|
|
9
9
|
validates_lengths_from_database
|
10
10
|
validates :name, :presence => true, :uniqueness => true
|
11
|
+
validates :url, :presence => true, :uniqueness => true
|
11
12
|
|
12
13
|
scoped_search :on => :name, :complete_value => true
|
13
14
|
scoped_search :on => :url
|
@@ -0,0 +1,9 @@
|
|
1
|
+
object @container
|
2
|
+
|
3
|
+
extends 'api/v2/containers/base'
|
4
|
+
|
5
|
+
attributes :command, :compute_resource_id, :compute_resource_name, :entrypoint,
|
6
|
+
:cpu_set, :cpu_shares, :memory, :tty,
|
7
|
+
:attach_stdin, :attach_stdout, :attach_stderr,
|
8
|
+
:repository_name, :tag, :registry_id, :registry_name,
|
9
|
+
:created_at, :updated_at
|
@@ -20,7 +20,7 @@
|
|
20
20
|
<td> <%= vm.attributes['status'] %> </td>
|
21
21
|
<td> <span <%= vm_power_class(vm.ready?) %>> <%= vm_state(vm) %></span> </td>
|
22
22
|
<td>
|
23
|
-
<%= action_buttons(
|
23
|
+
<%= action_buttons(container_power_action(vm),
|
24
24
|
display_delete_if_authorized(hash_for_compute_resource_vm_path(:compute_resource_id => @compute_resource, :id => vm.id))) %>
|
25
25
|
</td>
|
26
26
|
|
@@ -24,9 +24,9 @@
|
|
24
24
|
<span class="glyphicon glyphicon-time"></span> <%= container.ready? ? time_ago_in_words(container.started_at) : "N/A" %>
|
25
25
|
</td>
|
26
26
|
<td class="hidden-tablet hidden-xs text-center"><%= link_to resource, compute_resource_path(resource) %> </td>
|
27
|
-
<td class="hidden-tablet hidden-xs text-center"><%=
|
27
|
+
<td class="hidden-tablet hidden-xs text-center"><%= managed?(container, resource) ? _('Yes') : _('No') %></td>
|
28
28
|
<% @compute_resource = resource %>
|
29
|
-
<td><%= action_buttons(
|
29
|
+
<td><%= action_buttons(container_power_action(container),
|
30
30
|
display_delete_if_authorized(hash_for_container_path(:compute_resource_id => resource,
|
31
31
|
:id => container.id).
|
32
32
|
merge(:auth_object => resource, :auth_action => 'destroy',
|
@@ -47,7 +47,7 @@
|
|
47
47
|
<td><%= _('Environment Variables') %></td>
|
48
48
|
<td>
|
49
49
|
<table id="environment_variables" class="table table-bordered" style="table-layout:fixed; word-wrap: break-word">
|
50
|
-
<% @container.in_fog.attributes['config_env'].each do |environment_variable| %>
|
50
|
+
<% (@container.in_fog.attributes['config_env'] || []).each do |environment_variable| %>
|
51
51
|
<% pair = environment_variable.split("=") %>
|
52
52
|
<tr>
|
53
53
|
<td><b><%= pair.first %></b></td>
|
data/config/routes.rb
CHANGED
@@ -2,6 +2,7 @@ Rails.application.routes.draw do
|
|
2
2
|
resources :containers, :only => [:index, :new, :show, :destroy] do
|
3
3
|
member do
|
4
4
|
post :commit
|
5
|
+
put :power
|
5
6
|
end
|
6
7
|
end
|
7
8
|
|
@@ -10,10 +11,34 @@ Rails.application.routes.draw do
|
|
10
11
|
end
|
11
12
|
|
12
13
|
resources :image_search, :only => [] do
|
13
|
-
|
14
|
-
|
15
|
-
|
14
|
+
member do
|
15
|
+
get :auto_complete_repository_name
|
16
|
+
get :auto_complete_image_tag
|
17
|
+
get :search_repository
|
18
|
+
end
|
16
19
|
end
|
17
20
|
|
18
|
-
resources :registries, :
|
21
|
+
resources :registries, :except => [:show]
|
22
|
+
|
23
|
+
scope :foreman_docker, :path => '/docker' do
|
24
|
+
namespace :api, :defaults => { :format => 'json' } do
|
25
|
+
scope "(:apiv)", :module => :v2, :defaults => { :apiv => 'v2' }, :apiv => /v2/,
|
26
|
+
:constraints => ApiConstraints.new(:version => 2) do
|
27
|
+
resources :containers, :only => [:index, :create, :show, :destroy] do
|
28
|
+
member do
|
29
|
+
get :logs
|
30
|
+
put :power
|
31
|
+
end
|
32
|
+
end
|
33
|
+
resources :compute_resources, :only => [] do
|
34
|
+
resources :containers, :only => [:index, :create, :show, :destroy] do
|
35
|
+
member do
|
36
|
+
get :logs
|
37
|
+
put :power
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
19
44
|
end
|
@@ -57,11 +57,20 @@ module ForemanDocker
|
|
57
57
|
end
|
58
58
|
|
59
59
|
security_block :containers do
|
60
|
-
permission :view_containers,
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
permission :
|
60
|
+
permission :view_containers,
|
61
|
+
:containers => [:index, :show],
|
62
|
+
:'api/v2/containers' => [:index, :show, :logs]
|
63
|
+
permission :commit_containers, :containers => [:commit]
|
64
|
+
permission :create_containers,
|
65
|
+
:'containers/steps' => [:show, :update],
|
66
|
+
:containers => [:new],
|
67
|
+
:'api/v2/containers' => [:create, :power]
|
68
|
+
permission :destroy_containers,
|
69
|
+
:containers => [:destroy],
|
70
|
+
:'api/v2/containers' => [:destroy]
|
71
|
+
permission :power_compute_resources_vms,
|
72
|
+
:containers => [:power],
|
73
|
+
:'api/v2/containers' => [:create, :power]
|
65
74
|
end
|
66
75
|
|
67
76
|
security_block :registries do
|
@@ -76,6 +85,26 @@ module ForemanDocker
|
|
76
85
|
:auto_complete_image_tag,
|
77
86
|
:search_repository]
|
78
87
|
end
|
88
|
+
|
89
|
+
# apipie API documentation
|
90
|
+
# Only available in 1.8, otherwise it has to be in the initializer below
|
91
|
+
if SETTINGS[:version].to_s.include?('develop') ||
|
92
|
+
Gem::Version.new(SETTINGS[:version]) >= Gem::Version.new('1.8')
|
93
|
+
apipie_documented_controllers [
|
94
|
+
"#{ForemanDocker::Engine.root}/app/controllers/api/v2/*.rb"]
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
initializer "foreman_docker.apipie" do
|
100
|
+
# this condition is here for compatibility reason to work with Foreman 1.4.x
|
101
|
+
# Also need to handle the reverse of the 1.8 method above
|
102
|
+
unless SETTINGS[:version].to_s.include?('develop') ||
|
103
|
+
Gem::Version.new(SETTINGS[:version]) >= Gem::Version.new('1.8')
|
104
|
+
if Apipie.configuration.api_controllers_matcher.is_a?(Array)
|
105
|
+
Apipie.configuration.api_controllers_matcher <<
|
106
|
+
"#{ForemanDocker::Engine.root}/app/controllers/api/v2/*.rb"
|
107
|
+
end
|
79
108
|
end
|
80
109
|
end
|
81
110
|
|
@@ -85,13 +114,18 @@ module ForemanDocker
|
|
85
114
|
|
86
115
|
require 'fog/fogdocker/models/compute/server'
|
87
116
|
require 'fog/fogdocker/models/compute/image'
|
117
|
+
require 'fog/fogdocker/models/compute/images'
|
88
118
|
require File.expand_path('../../../app/models/concerns/fog_extensions/fogdocker/server',
|
89
119
|
__FILE__)
|
90
120
|
require File.expand_path('../../../app/models/concerns/fog_extensions/fogdocker/image',
|
91
121
|
__FILE__)
|
122
|
+
require File.expand_path('../../../app/models/concerns/fog_extensions/fogdocker/images',
|
123
|
+
__FILE__)
|
92
124
|
config.to_prepare do
|
93
125
|
Fog::Compute::Fogdocker::Server.send(:include, ::FogExtensions::Fogdocker::Server)
|
94
126
|
Fog::Compute::Fogdocker::Image.send(:include, ::FogExtensions::Fogdocker::Image)
|
127
|
+
# Compatibility fixes - to be removed once 1.7 compatibility is no longer required
|
128
|
+
Fog::Compute::Fogdocker::Images.send(:include, ::FogExtensions::Fogdocker::Images)
|
95
129
|
::Taxonomy.send(:include, ForemanDocker::TaxonomyExtensions)
|
96
130
|
end
|
97
131
|
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'test_plugin_helper'
|
2
|
+
|
3
|
+
module Api
|
4
|
+
module V2
|
5
|
+
class ContainersControllerTest < ActionController::TestCase
|
6
|
+
test 'index returns a list of all containers' do
|
7
|
+
get :index, {}, set_session_user
|
8
|
+
assert_response :success
|
9
|
+
assert_template 'index'
|
10
|
+
end
|
11
|
+
|
12
|
+
context 'container operations' do
|
13
|
+
setup do
|
14
|
+
@container = FactoryGirl.create(:container, :name => 'foo')
|
15
|
+
end
|
16
|
+
|
17
|
+
test 'logs returns latest lines of container log' do
|
18
|
+
fake_container = Struct.new(:logs)
|
19
|
+
fake_container.expects(:logs).returns('I am a log').twice
|
20
|
+
Docker::Container.expects(:get).with(@container.uuid).returns(fake_container)
|
21
|
+
get :logs, :id => @container.id
|
22
|
+
assert_response :success
|
23
|
+
assert_equal ActiveSupport::JSON.decode(response.body)['logs'], fake_container.logs
|
24
|
+
end
|
25
|
+
|
26
|
+
test 'show returns information about container' do
|
27
|
+
get :show, :id => @container.id
|
28
|
+
assert_response :success
|
29
|
+
assert_equal ActiveSupport::JSON.decode(response.body)['name'], 'foo'
|
30
|
+
end
|
31
|
+
|
32
|
+
test 'delete removes a container in foreman and in Docker host' do
|
33
|
+
delete :destroy, :id => @container.id
|
34
|
+
assert_response :success
|
35
|
+
assert_equal ActiveSupport::JSON.decode(response.body)['name'], 'foo'
|
36
|
+
end
|
37
|
+
|
38
|
+
test 'power call turns on/off container in Docker host' do
|
39
|
+
Fog.mock!
|
40
|
+
Fog::Compute::Fogdocker::Server.any_instance.expects(:start)
|
41
|
+
put :power, :id => @container.id, :power_action => 'start'
|
42
|
+
assert_response :success
|
43
|
+
end
|
44
|
+
|
45
|
+
test 'power call checks status of container in Docker host' do
|
46
|
+
Fog.mock!
|
47
|
+
Fog::Compute::Fogdocker::Server.any_instance.expects(:ready?).returns(false)
|
48
|
+
put :power, :id => @container.id, :power_action => 'status'
|
49
|
+
assert_response :success
|
50
|
+
assert_equal ActiveSupport::JSON.decode(response.body)['running'], false
|
51
|
+
end
|
52
|
+
|
53
|
+
test 'power call host' do
|
54
|
+
Fog.mock!
|
55
|
+
Fog::Compute::Fogdocker::Server.any_instance.expects(:ready?).returns(false)
|
56
|
+
put :power, :id => @container.id, :power_action => 'status'
|
57
|
+
assert_response :success
|
58
|
+
assert_equal ActiveSupport::JSON.decode(response.body)['running'], false
|
59
|
+
end
|
60
|
+
|
61
|
+
test 'creates a container with correct params' do
|
62
|
+
Service::Containers.any_instance.expects(:pull_image).returns(true)
|
63
|
+
Service::Containers.any_instance.expects(:start_container).returns(true)
|
64
|
+
post :create, :container => { :name => 'foo', :registry_id => 3, :image => 'centos:7' }
|
65
|
+
assert_response :created
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -8,6 +8,7 @@ class ContainerIntegrationTest < ActionDispatch::IntegrationTest
|
|
8
8
|
|
9
9
|
context 'available compute resource' do
|
10
10
|
test 'shows containers list if compute resource is available' do
|
11
|
+
Fog.mock!
|
11
12
|
ComputeResource.any_instance.stubs(:vms).returns([])
|
12
13
|
FactoryGirl.create(:docker_cr)
|
13
14
|
visit containers_path
|
@@ -22,8 +22,9 @@ class DockerRegistryTest < ActiveSupport::TestCase
|
|
22
22
|
assert registry.is_decryptable?(registry.password_in_db)
|
23
23
|
end
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
25
|
+
%w(name url).each do |property|
|
26
|
+
test "registries need a #{property}" do
|
27
|
+
refute FactoryGirl.build(:docker_registry, property.to_sym => '').valid?
|
28
|
+
end
|
28
29
|
end
|
29
30
|
end
|
metadata
CHANGED
@@ -1,41 +1,41 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: foreman_docker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Lobato, Amos Benari
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-02-
|
11
|
+
date: 2015-02-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: docker-api
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ~>
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '1.
|
19
|
+
version: '1.17'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ~>
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '1.
|
26
|
+
version: '1.17'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: wicked
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ~>
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '1.1'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ~>
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '1.1'
|
41
41
|
description: Provision and manage Docker containers and images from Foreman.
|
@@ -45,92 +45,99 @@ executables: []
|
|
45
45
|
extensions: []
|
46
46
|
extra_rdoc_files: []
|
47
47
|
files:
|
48
|
-
- LICENSE
|
49
|
-
- README.md
|
50
|
-
- Rakefile
|
51
|
-
- app/assets/javascripts/foreman_docker/image_step.js
|
52
|
-
- app/assets/stylesheets/foreman_docker/autocomplete.css.scss
|
53
|
-
- app/assets/stylesheets/foreman_docker/terminal.css.scss
|
54
|
-
- app/controllers/concerns/foreman_docker/find_container.rb
|
55
|
-
- app/controllers/containers/steps_controller.rb
|
56
|
-
- app/controllers/containers_controller.rb
|
57
|
-
- app/controllers/image_search_controller.rb
|
58
|
-
- app/controllers/registries_controller.rb
|
59
|
-
- app/helpers/container_steps_helper.rb
|
60
|
-
- app/helpers/containers_helper.rb
|
61
|
-
- app/models/concerns/fog_extensions/fogdocker/image.rb
|
62
|
-
- app/models/concerns/fog_extensions/fogdocker/server.rb
|
63
|
-
- app/models/concerns/foreman_docker/parameter_validators.rb
|
64
|
-
- app/models/container.rb
|
65
|
-
- app/models/docker_container_wizard_state.rb
|
66
|
-
- app/models/docker_container_wizard_states/configuration.rb
|
67
|
-
- app/models/docker_container_wizard_states/environment.rb
|
68
|
-
- app/models/docker_container_wizard_states/environment_variable.rb
|
69
|
-
- app/models/docker_container_wizard_states/image.rb
|
70
|
-
- app/models/docker_container_wizard_states/preliminary.rb
|
71
|
-
- app/models/docker_registry.rb
|
72
|
-
- app/models/environment_variable.rb
|
73
|
-
- app/models/foreman_docker/docker.rb
|
74
|
-
- app/models/foreman_docker/taxonomy_extensions.rb
|
75
|
-
- app/models/service/containers.rb
|
76
|
-
- app/models/service/registry_api.rb
|
77
|
-
- app/views/api/v1/compute_resources/docker.json
|
78
|
-
- app/views/api/v2/compute_resources/docker.json
|
79
48
|
- app/views/compute_resources/form/_docker.html.erb
|
80
49
|
- app/views/compute_resources/show/_docker.html.erb
|
81
|
-
- app/views/
|
82
|
-
- app/views/
|
83
|
-
- app/views/
|
84
|
-
- app/views/containers/
|
85
|
-
- app/views/containers/index.
|
86
|
-
- app/views/containers/show.
|
87
|
-
- app/views/
|
88
|
-
- app/views/containers/steps/_image_hub_tab.html.erb
|
89
|
-
- app/views/containers/steps/_title.html.erb
|
90
|
-
- app/views/containers/steps/configuration.html.erb
|
50
|
+
- app/views/image_search/_repository_search_results.html.erb
|
51
|
+
- app/views/api/v2/compute_resources/docker.json
|
52
|
+
- app/views/api/v2/containers/main.json.rabl
|
53
|
+
- app/views/api/v2/containers/base.json.rabl
|
54
|
+
- app/views/api/v2/containers/index.json.rabl
|
55
|
+
- app/views/api/v2/containers/show.json.rabl
|
56
|
+
- app/views/api/v1/compute_resources/docker.json
|
91
57
|
- app/views/containers/steps/environment.html.erb
|
58
|
+
- app/views/containers/steps/_title.html.erb
|
59
|
+
- app/views/containers/steps/_form_buttons.html.erb
|
92
60
|
- app/views/containers/steps/image.html.erb
|
93
61
|
- app/views/containers/steps/preliminary.html.erb
|
94
|
-
- app/views/
|
95
|
-
- app/views/
|
96
|
-
- app/views/
|
97
|
-
- app/views/
|
62
|
+
- app/views/containers/steps/_image_hub_tab.html.erb
|
63
|
+
- app/views/containers/steps/configuration.html.erb
|
64
|
+
- app/views/containers/_list.html.erb
|
65
|
+
- app/views/containers/show.html.erb
|
66
|
+
- app/views/containers/index.html.erb
|
98
67
|
- app/views/registries/edit.html.erb
|
99
|
-
- app/views/registries/index.html.erb
|
100
68
|
- app/views/registries/new.html.erb
|
69
|
+
- app/views/registries/_form.html.erb
|
70
|
+
- app/views/registries/index.html.erb
|
71
|
+
- app/views/foreman_docker/common_parameters/_environment_variable.html.erb
|
72
|
+
- app/views/images/form/_docker.html.erb
|
73
|
+
- app/views/compute_resources_vms/form/_docker.html.erb
|
74
|
+
- app/views/compute_resources_vms/index/_docker.html.erb
|
75
|
+
- app/views/compute_resources_vms/show/_docker.html.erb
|
76
|
+
- app/models/docker_registry.rb
|
77
|
+
- app/models/service/registry_api.rb
|
78
|
+
- app/models/service/containers.rb
|
79
|
+
- app/models/concerns/fog_extensions/fogdocker/image.rb
|
80
|
+
- app/models/concerns/fog_extensions/fogdocker/images.rb
|
81
|
+
- app/models/concerns/fog_extensions/fogdocker/server.rb
|
82
|
+
- app/models/concerns/foreman_docker/parameter_validators.rb
|
83
|
+
- app/models/docker_container_wizard_state.rb
|
84
|
+
- app/models/container.rb
|
85
|
+
- app/models/environment_variable.rb
|
86
|
+
- app/models/foreman_docker/taxonomy_extensions.rb
|
87
|
+
- app/models/foreman_docker/docker.rb
|
88
|
+
- app/models/docker_container_wizard_states/environment.rb
|
89
|
+
- app/models/docker_container_wizard_states/image.rb
|
90
|
+
- app/models/docker_container_wizard_states/configuration.rb
|
91
|
+
- app/models/docker_container_wizard_states/environment_variable.rb
|
92
|
+
- app/models/docker_container_wizard_states/preliminary.rb
|
93
|
+
- app/controllers/api/v2/containers_controller.rb
|
94
|
+
- app/controllers/containers/steps_controller.rb
|
95
|
+
- app/controllers/concerns/foreman_docker/find_container.rb
|
96
|
+
- app/controllers/registries_controller.rb
|
97
|
+
- app/controllers/image_search_controller.rb
|
98
|
+
- app/controllers/containers_controller.rb
|
99
|
+
- app/helpers/containers_helper.rb
|
100
|
+
- app/helpers/container_steps_helper.rb
|
101
|
+
- app/assets/javascripts/foreman_docker/image_step.js
|
102
|
+
- app/assets/stylesheets/foreman_docker/terminal.css.scss
|
103
|
+
- app/assets/stylesheets/foreman_docker/autocomplete.css.scss
|
101
104
|
- config/routes.rb
|
102
|
-
- db/migrate/
|
105
|
+
- db/migrate/20141018110810_add_uuid_to_containers.rb
|
106
|
+
- db/migrate/20141028164206_change_memory_in_container.rb
|
103
107
|
- db/migrate/20141005233312_create_containers.rb
|
108
|
+
- db/migrate/20141028164633_change_cpuset_in_container.rb
|
109
|
+
- db/migrate/20141009011026_add_attributes_to_container.rb
|
110
|
+
- db/migrate/20141222113313_create_wizard_states.rb
|
111
|
+
- db/migrate/20150129054944_add_katello_flag_to_containers.rb
|
104
112
|
- db/migrate/20141007225130_add_compute_resource_id_to_container.rb
|
105
113
|
- db/migrate/20141009001613_add_tag_to_container.rb
|
106
|
-
- db/migrate/
|
114
|
+
- db/migrate/20141120123003_add_user_credentials_to_docker_registries.rb
|
115
|
+
- db/migrate/20140930175337_add_email_to_compute_resource.rb
|
107
116
|
- db/migrate/20141010173220_create_docker_images.rb
|
108
|
-
- db/migrate/
|
117
|
+
- db/migrate/20150122011747_add_katello_flag_to_docker_wizard_image.rb
|
109
118
|
- db/migrate/20141024163003_create_docker_registries.rb
|
110
|
-
- db/migrate/20141028164206_change_memory_in_container.rb
|
111
|
-
- db/migrate/20141028164633_change_cpuset_in_container.rb
|
112
|
-
- db/migrate/20141120123003_add_user_credentials_to_docker_registries.rb
|
113
119
|
- db/migrate/20141209182008_remove_docker_tables.rb
|
114
|
-
- db/migrate/20141222113313_create_wizard_states.rb
|
115
|
-
- db/migrate/20150122011747_add_katello_flag_to_docker_wizard_image.rb
|
116
|
-
- db/migrate/20150129054944_add_katello_flag_to_containers.rb
|
117
|
-
- lib/foreman_docker.rb
|
118
|
-
- lib/foreman_docker/engine.rb
|
119
120
|
- lib/foreman_docker/tasks/test.rake
|
120
121
|
- lib/foreman_docker/version.rb
|
122
|
+
- lib/foreman_docker/engine.rb
|
123
|
+
- lib/foreman_docker.rb
|
121
124
|
- locale/Makefile
|
125
|
+
- LICENSE
|
126
|
+
- Rakefile
|
127
|
+
- README.md
|
128
|
+
- test/functionals/api/v2/containers_controller_test.rb
|
129
|
+
- test/functionals/containers_steps_controller_test.rb
|
130
|
+
- test/functionals/container_controller_test.rb
|
131
|
+
- test/factories/docker_registry.rb
|
122
132
|
- test/factories/compute_resources.rb
|
123
133
|
- test/factories/containers.rb
|
124
|
-
- test/factories/docker_registry.rb
|
125
|
-
- test/functionals/container_controller_test.rb
|
126
|
-
- test/functionals/containers_steps_controller_test.rb
|
127
|
-
- test/integration/container_steps_test.rb
|
128
|
-
- test/integration/container_test.rb
|
129
|
-
- test/test_plugin_helper.rb
|
130
134
|
- test/units/container_test.rb
|
131
|
-
- test/units/containers_service_test.rb
|
132
135
|
- test/units/docker_registry_test.rb
|
133
136
|
- test/units/registry_api_test.rb
|
137
|
+
- test/units/containers_service_test.rb
|
138
|
+
- test/test_plugin_helper.rb
|
139
|
+
- test/integration/container_steps_test.rb
|
140
|
+
- test/integration/container_test.rb
|
134
141
|
homepage: http://github.com/theforeman/foreman-docker
|
135
142
|
licenses:
|
136
143
|
- GPL-3
|
@@ -141,21 +148,22 @@ require_paths:
|
|
141
148
|
- lib
|
142
149
|
required_ruby_version: !ruby/object:Gem::Requirement
|
143
150
|
requirements:
|
144
|
-
- -
|
151
|
+
- - '>='
|
145
152
|
- !ruby/object:Gem::Version
|
146
153
|
version: '0'
|
147
154
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
148
155
|
requirements:
|
149
|
-
- -
|
156
|
+
- - '>='
|
150
157
|
- !ruby/object:Gem::Version
|
151
158
|
version: '0'
|
152
159
|
requirements: []
|
153
160
|
rubyforge_project:
|
154
|
-
rubygems_version: 2.
|
161
|
+
rubygems_version: 2.0.14
|
155
162
|
signing_key:
|
156
163
|
specification_version: 4
|
157
164
|
summary: Provision and manage Docker containers and images from Foreman
|
158
165
|
test_files:
|
166
|
+
- test/functionals/api/v2/containers_controller_test.rb
|
159
167
|
- test/functionals/containers_steps_controller_test.rb
|
160
168
|
- test/functionals/container_controller_test.rb
|
161
169
|
- test/factories/docker_registry.rb
|