foreman_reserve 0.1.8.2 → 0.1.8.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +1 -1
- data/app/controllers/{foreman_reserve/api/hosts_controller.rb → api/v2/reserves_controller.rb} +68 -55
- data/app/models/host/host_extensions.rb +31 -0
- data/config/routes.rb +23 -5
- data/foreman_reserve.gemspec +4 -27
- data/lib/foreman_reserve.rb +2 -1
- data/lib/foreman_reserve/engine.rb +20 -6
- metadata +5 -63
- data/Gemfile +0 -14
- data/Gemfile.lock +0 -33
- data/app/models/foreman_reserve/host_extensions.rb +0 -33
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9950443650dc6c90eb1f50231b1682743479c137
|
4
|
+
data.tar.gz: 2c86d8839a22a4b3f7044472ad145af0f4f922b1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 36e1b1b07b6849e5dc4f6c60dcff26640c8e2c3ebe9b4c38b05902c56df47c76a97269d23db5cb4ec47a7fad5b01391e402bc76a5c7152c3cd71bdd2d87005d7
|
7
|
+
data.tar.gz: d567d2c8df0418bec61a318bda98c7d79d353a01eda0b9c20d91285d2792b33b300b7193da8173aba78135e836d5b559800150f654bfe9162385bf2130ad9f22
|
data/Rakefile
CHANGED
@@ -21,7 +21,7 @@ Jeweler::Tasks.new do |gem|
|
|
21
21
|
gem.description = %Q{Plugin engine for Foreman to reserve a host}
|
22
22
|
gem.email = "dcaroest@redhat.com"
|
23
23
|
gem.authors = ["David Caro", "Joseph Mitchell Magen"]
|
24
|
-
gem.version = '0.1.8.
|
24
|
+
gem.version = '0.1.8.3'
|
25
25
|
end
|
26
26
|
#Jeweler::RubygemsDotOrgTasks.new
|
27
27
|
|
data/app/controllers/{foreman_reserve/api/hosts_controller.rb → api/v2/reserves_controller.rb}
RENAMED
@@ -1,45 +1,8 @@
|
|
1
1
|
module Api
|
2
|
-
module
|
3
|
-
class
|
2
|
+
module V2
|
3
|
+
class ReservesController < V2::BaseController
|
4
4
|
unloadable
|
5
5
|
|
6
|
-
# Get the list of reserved hosts
|
7
|
-
# @param query [String] Query to filter the hosts with
|
8
|
-
def get_reserved(query='')
|
9
|
-
hosts = User.current.admin? ? Host::Managed : Host::Managed.my_hosts
|
10
|
-
hosts = hosts.search_for(query)
|
11
|
-
hosts.find_all do |host|
|
12
|
-
params = host.info()['parameters']
|
13
|
-
params and
|
14
|
-
params.key?('RESERVED') and
|
15
|
-
params['RESERVED'] != 'false'
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
# Get the list of available hosts
|
20
|
-
# @param query [String] Query to filter the hosts with
|
21
|
-
def get_free(query='')
|
22
|
-
hosts = User.current.admin? ? Host::Managed : Host::Managed.my_hosts
|
23
|
-
hosts = hosts.search_for(query)
|
24
|
-
hosts.find_all do |host|
|
25
|
-
params = host.info()['parameters']
|
26
|
-
params and
|
27
|
-
params.key?('RESERVED') and
|
28
|
-
params['RESERVED'] == 'false'
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
# Return not found
|
33
|
-
# @param exception [String] Message to show
|
34
|
-
def not_found(exception = nil)
|
35
|
-
logger.debug "not found: #{exception}" if exception
|
36
|
-
respond_to do |format|
|
37
|
-
format.html { render "common/404", :status => 404 }
|
38
|
-
format.json { head :status => 404}
|
39
|
-
format.yaml { head :status => 404}
|
40
|
-
end
|
41
|
-
true
|
42
|
-
end
|
43
6
|
|
44
7
|
# <b>API METHOD</b>: Reserve one or more hosts, will return 404 if the
|
45
8
|
# given query gives no results and 406 (Not acceptable) if not enough free
|
@@ -74,9 +37,9 @@ module Api
|
|
74
37
|
lock.flock(File::LOCK_UN)
|
75
38
|
end
|
76
39
|
respond_to do |format|
|
77
|
-
format.json {render :json => @hosts }
|
78
|
-
format.yaml {render :text => @hosts.to_yaml}
|
79
|
-
format.html {not_found }
|
40
|
+
format.json { render :json => @hosts }
|
41
|
+
format.yaml { render :text => @hosts.to_yaml }
|
42
|
+
format.html { not_found }
|
80
43
|
end
|
81
44
|
end
|
82
45
|
|
@@ -87,7 +50,7 @@ module Api
|
|
87
50
|
#
|
88
51
|
# * <tt><b>amount</b> (Int)</tt> <i>(defaults to: <tt>1</tt>)</i> ---
|
89
52
|
# Amount of hosts to release
|
90
|
-
# * <tt><b>host_name</b> (String)</tt>
|
53
|
+
# * <tt><b>host_name</b> (String)</tt>
|
91
54
|
# <i>(defaults to: <tt>''</tt>)</i> ---
|
92
55
|
# If given, will also filter by that host name
|
93
56
|
# * <tt><b>query</b> (String)</tt> <i>(defaults to: <tt>''</tt>)</i> ---
|
@@ -108,9 +71,9 @@ module Api
|
|
108
71
|
@hosts = reserved_hosts.each { |host| host.release! }
|
109
72
|
end
|
110
73
|
respond_to do |format|
|
111
|
-
format.json {render :json => @hosts.map(&:name) }
|
112
|
-
format.yaml {render :text => @hosts.to_yaml}
|
113
|
-
format.html {
|
74
|
+
format.json { render :json => @hosts.map(&:name) }
|
75
|
+
format.yaml { render :text => @hosts.to_yaml }
|
76
|
+
format.html { render :json => hosts }
|
114
77
|
end
|
115
78
|
end
|
116
79
|
|
@@ -124,9 +87,9 @@ module Api
|
|
124
87
|
hosts = get_reserved(params[:query])
|
125
88
|
return not_found if hosts.empty?
|
126
89
|
respond_to do |format|
|
127
|
-
format.json {render :json => hosts }
|
128
|
-
format.yaml {render :text => hosts.to_yaml}
|
129
|
-
format.html {
|
90
|
+
format.json { render :json => hosts }
|
91
|
+
format.yaml { render :text => hosts.to_yaml }
|
92
|
+
format.html { render :json => hosts }
|
130
93
|
end
|
131
94
|
end
|
132
95
|
|
@@ -148,9 +111,9 @@ module Api
|
|
148
111
|
hosts = hosts[0..(amount-1)]
|
149
112
|
end
|
150
113
|
respond_to do |format|
|
151
|
-
format.json {render :json => hosts }
|
152
|
-
format.yaml {render :text => hosts.to_yaml}
|
153
|
-
format.html {
|
114
|
+
format.json { render :json => hosts }
|
115
|
+
format.yaml { render :text => hosts.to_yaml }
|
116
|
+
format.html { render :json => hosts }
|
154
117
|
end
|
155
118
|
end
|
156
119
|
|
@@ -179,10 +142,60 @@ module Api
|
|
179
142
|
end
|
180
143
|
@hosts = get_reserved(params[:query])
|
181
144
|
respond_to do |format|
|
182
|
-
format.json {render :json => @hosts }
|
183
|
-
format.yaml {render :text => @hosts.to_yaml}
|
184
|
-
format.html {
|
145
|
+
format.json { render :json => @hosts }
|
146
|
+
format.yaml { render :text => @hosts.to_yaml }
|
147
|
+
format.html { render :json => hosts }
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
private
|
152
|
+
|
153
|
+
# Get the list of reserved hosts
|
154
|
+
# @param query [String] Query to filter the hosts with
|
155
|
+
def get_reserved(query='')
|
156
|
+
hosts = User.current.admin? ? Host : my_hosts
|
157
|
+
hosts = hosts.search_for(query)
|
158
|
+
hosts.find_all do |host|
|
159
|
+
params = host.info()['parameters']
|
160
|
+
params and
|
161
|
+
params.key?('RESERVED') and
|
162
|
+
params['RESERVED'] != 'false'
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
# Get the list of available hosts
|
167
|
+
# @param query [String] Query to filter the hosts with
|
168
|
+
def get_free(query='')
|
169
|
+
hosts = User.current.admin? ? Host : my_hosts
|
170
|
+
hosts = hosts.search_for(query)
|
171
|
+
hosts.find_all do |host|
|
172
|
+
params = host.info()['parameters']
|
173
|
+
params and
|
174
|
+
params.key?('RESERVED') and
|
175
|
+
params['RESERVED'] == 'false'
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
def my_hosts
|
180
|
+
if SETTINGS[:version].to_s.to_f >= 1.5
|
181
|
+
# Foreman 1.5+
|
182
|
+
Host.authorized(:view_hosts, Host)
|
183
|
+
else
|
184
|
+
# Foreman < 1.5
|
185
|
+
Host.my_hosts
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
# Return not found
|
190
|
+
# @param exception [String] Message to show
|
191
|
+
def not_found(exception = nil)
|
192
|
+
logger.debug "not found: #{exception}" if exception
|
193
|
+
respond_to do |format|
|
194
|
+
format.html { render "common/404", :status => 404 }
|
195
|
+
format.json { head :status => 404}
|
196
|
+
format.yaml { head :status => 404}
|
185
197
|
end
|
198
|
+
true
|
186
199
|
end
|
187
200
|
|
188
201
|
# Return HTTP 406 (Not acceptable)
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Host::HostExtensions
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
module InstanceMethods
|
4
|
+
|
5
|
+
# Reserve the host
|
6
|
+
#
|
7
|
+
# @param reason [String] Reason to reserve the host under
|
8
|
+
def reserve!(reason = 'true')
|
9
|
+
param = "RESERVED"
|
10
|
+
if p=host_parameters.find_by_name(param)
|
11
|
+
p.update_attribute(:value, reason)
|
12
|
+
else
|
13
|
+
host_parameters.create!(:name => param, :value => reason)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
# Release the host
|
18
|
+
def release!
|
19
|
+
param = "RESERVED"
|
20
|
+
if p=host_parameters.find_by_name(param)
|
21
|
+
p.update_attribute(:value, "false")
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# Return a json represenatation of the host
|
26
|
+
def as_json(options={})
|
27
|
+
super(:methods => [:host_parameters])
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
data/config/routes.rb
CHANGED
@@ -1,9 +1,27 @@
|
|
1
1
|
Rails.application.routes.draw do
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
3
|
+
namespace :api, :defaults => {:format => 'json'} do
|
4
|
+
get 'hosts_reserve' => 'v2/reserves#reserve'
|
5
|
+
get 'hosts_release' => 'v2/reserves#release'
|
6
|
+
get 'show_available' => 'v2/reserves#show_available'
|
7
|
+
get 'show_reserved' => 'v2/reserves#show_reserved'
|
8
|
+
get 'update_reserved_reason' => 'v2/reserves#update_reason'
|
9
|
+
|
10
|
+
scope "(:apiv)", :module => :v2,
|
11
|
+
:defaults => {:apiv => 'v2'},
|
12
|
+
:apiv => /v1|v2/,
|
13
|
+
:constraints => ApiConstraints.new(:version => 2) do
|
14
|
+
|
15
|
+
resources :reserves, :only => [] do
|
16
|
+
collection do
|
17
|
+
get 'reserve'
|
18
|
+
get 'release'
|
19
|
+
get 'show_available'
|
20
|
+
get 'show_reserved'
|
21
|
+
get 'update_reserved_reason' => 'reserves#update_reason'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
8
26
|
|
9
27
|
end
|
data/foreman_reserve.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "foreman_reserve"
|
8
|
-
s.version = "0.1.8.
|
8
|
+
s.version = "0.1.8.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["David Caro", "Joseph Mitchell Magen"]
|
12
|
-
s.date = "2014-
|
12
|
+
s.date = "2014-03-07"
|
13
13
|
s.description = "Plugin engine for Foreman to reserve a host"
|
14
14
|
s.email = "dcaroest@redhat.com"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -18,14 +18,12 @@ Gem::Specification.new do |s|
|
|
18
18
|
]
|
19
19
|
s.files = [
|
20
20
|
".document",
|
21
|
-
"Gemfile",
|
22
|
-
"Gemfile.lock",
|
23
21
|
"LICENSE.txt",
|
24
22
|
"README.rdoc",
|
25
23
|
"Rakefile",
|
26
24
|
"VERSION",
|
27
|
-
"app/controllers/
|
28
|
-
"app/models/
|
25
|
+
"app/controllers/api/v2/reserves_controller.rb",
|
26
|
+
"app/models/host/host_extensions.rb",
|
29
27
|
"config/routes.rb",
|
30
28
|
"foreman_reserve.gemspec",
|
31
29
|
"lib/foreman_reserve.rb",
|
@@ -37,26 +35,5 @@ Gem::Specification.new do |s|
|
|
37
35
|
s.require_paths = ["lib"]
|
38
36
|
s.rubygems_version = "2.0.14"
|
39
37
|
s.summary = "Plugin engine for Foreman to reserve a host"
|
40
|
-
|
41
|
-
if s.respond_to? :specification_version then
|
42
|
-
s.specification_version = 4
|
43
|
-
|
44
|
-
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
45
|
-
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
46
|
-
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
47
|
-
s.add_development_dependency(%q<bundler>, ["~> 1.2.2"])
|
48
|
-
s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
|
49
|
-
else
|
50
|
-
s.add_dependency(%q<shoulda>, [">= 0"])
|
51
|
-
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
52
|
-
s.add_dependency(%q<bundler>, ["~> 1.2.2"])
|
53
|
-
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
54
|
-
end
|
55
|
-
else
|
56
|
-
s.add_dependency(%q<shoulda>, [">= 0"])
|
57
|
-
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
58
|
-
s.add_dependency(%q<bundler>, ["~> 1.2.2"])
|
59
|
-
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
60
|
-
end
|
61
38
|
end
|
62
39
|
|
data/lib/foreman_reserve.rb
CHANGED
@@ -1,13 +1,27 @@
|
|
1
|
-
require 'foreman_reserve'
|
2
|
-
require 'rails'
|
3
|
-
require 'action_controller'
|
4
|
-
|
5
1
|
module ForemanReserve
|
6
2
|
class Engine < ::Rails::Engine
|
7
3
|
|
8
4
|
config.to_prepare do
|
9
|
-
|
10
|
-
|
5
|
+
if SETTINGS[:version].to_s.to_f >= 1.2
|
6
|
+
# Foreman 1.2
|
7
|
+
Host::Managed.send :include, Host::HostExtensions
|
8
|
+
else
|
9
|
+
# Foreman < 1.2
|
10
|
+
Host.send :include, Host::HostExtensions
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
initializer 'foreman_reserve.register_plugin', :after=> :finisher_hook do |app|
|
15
|
+
Foreman::Plugin.register :foreman_reserve do
|
16
|
+
requires_foreman '>= 1.4'
|
17
|
+
|
18
|
+
security_block :foreman_reserve do
|
19
|
+
permission :view_reserved_hosts, { 'api/v2/reserves' => [:show_available, :show_reserved] }
|
20
|
+
permission :reserve_and_free_hosts, { 'api/v2/reserves' => [:reserve, :release, :update_reason] }
|
21
|
+
end
|
22
|
+
|
23
|
+
role "Reserve Hosts", [:view_reserved_hosts, :reserve_and_free_hosts]
|
24
|
+
end
|
11
25
|
end
|
12
26
|
|
13
27
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: foreman_reserve
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.8.
|
4
|
+
version: 0.1.8.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Caro
|
@@ -9,64 +9,8 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
13
|
-
dependencies:
|
14
|
-
- !ruby/object:Gem::Dependency
|
15
|
-
name: shoulda
|
16
|
-
requirement: !ruby/object:Gem::Requirement
|
17
|
-
requirements:
|
18
|
-
- - '>='
|
19
|
-
- !ruby/object:Gem::Version
|
20
|
-
version: '0'
|
21
|
-
type: :development
|
22
|
-
prerelease: false
|
23
|
-
version_requirements: !ruby/object:Gem::Requirement
|
24
|
-
requirements:
|
25
|
-
- - '>='
|
26
|
-
- !ruby/object:Gem::Version
|
27
|
-
version: '0'
|
28
|
-
- !ruby/object:Gem::Dependency
|
29
|
-
name: rdoc
|
30
|
-
requirement: !ruby/object:Gem::Requirement
|
31
|
-
requirements:
|
32
|
-
- - ~>
|
33
|
-
- !ruby/object:Gem::Version
|
34
|
-
version: '3.12'
|
35
|
-
type: :development
|
36
|
-
prerelease: false
|
37
|
-
version_requirements: !ruby/object:Gem::Requirement
|
38
|
-
requirements:
|
39
|
-
- - ~>
|
40
|
-
- !ruby/object:Gem::Version
|
41
|
-
version: '3.12'
|
42
|
-
- !ruby/object:Gem::Dependency
|
43
|
-
name: bundler
|
44
|
-
requirement: !ruby/object:Gem::Requirement
|
45
|
-
requirements:
|
46
|
-
- - ~>
|
47
|
-
- !ruby/object:Gem::Version
|
48
|
-
version: 1.2.2
|
49
|
-
type: :development
|
50
|
-
prerelease: false
|
51
|
-
version_requirements: !ruby/object:Gem::Requirement
|
52
|
-
requirements:
|
53
|
-
- - ~>
|
54
|
-
- !ruby/object:Gem::Version
|
55
|
-
version: 1.2.2
|
56
|
-
- !ruby/object:Gem::Dependency
|
57
|
-
name: jeweler
|
58
|
-
requirement: !ruby/object:Gem::Requirement
|
59
|
-
requirements:
|
60
|
-
- - ~>
|
61
|
-
- !ruby/object:Gem::Version
|
62
|
-
version: 1.8.4
|
63
|
-
type: :development
|
64
|
-
prerelease: false
|
65
|
-
version_requirements: !ruby/object:Gem::Requirement
|
66
|
-
requirements:
|
67
|
-
- - ~>
|
68
|
-
- !ruby/object:Gem::Version
|
69
|
-
version: 1.8.4
|
12
|
+
date: 2014-03-07 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
70
14
|
description: Plugin engine for Foreman to reserve a host
|
71
15
|
email: dcaroest@redhat.com
|
72
16
|
executables: []
|
@@ -76,14 +20,12 @@ extra_rdoc_files:
|
|
76
20
|
- README.rdoc
|
77
21
|
files:
|
78
22
|
- .document
|
79
|
-
- Gemfile
|
80
|
-
- Gemfile.lock
|
81
23
|
- LICENSE.txt
|
82
24
|
- README.rdoc
|
83
25
|
- Rakefile
|
84
26
|
- VERSION
|
85
|
-
- app/controllers/
|
86
|
-
- app/models/
|
27
|
+
- app/controllers/api/v2/reserves_controller.rb
|
28
|
+
- app/models/host/host_extensions.rb
|
87
29
|
- config/routes.rb
|
88
30
|
- foreman_reserve.gemspec
|
89
31
|
- lib/foreman_reserve.rb
|
data/Gemfile
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
source "http://rubygems.org"
|
2
|
-
# Add dependencies required to use your gem here.
|
3
|
-
# Example:
|
4
|
-
# gem "activesupport", ">= 2.3.5"
|
5
|
-
|
6
|
-
# Add dependencies to develop your gem here.
|
7
|
-
# Include everything needed to run rake, tests, features, etc.
|
8
|
-
group :development do
|
9
|
-
gem "shoulda", ">= 0"
|
10
|
-
gem "rdoc", "~> 3.12"
|
11
|
-
gem "bundler", "~> 1.2.2"
|
12
|
-
gem "jeweler", "~> 1.8.4"
|
13
|
-
# gem "rcov", ">= 0"
|
14
|
-
end
|
data/Gemfile.lock
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
GEM
|
2
|
-
remote: http://rubygems.org/
|
3
|
-
specs:
|
4
|
-
activesupport (3.2.9)
|
5
|
-
i18n (~> 0.6)
|
6
|
-
multi_json (~> 1.0)
|
7
|
-
git (1.2.5)
|
8
|
-
i18n (0.6.1)
|
9
|
-
jeweler (1.8.4)
|
10
|
-
bundler (~> 1.0)
|
11
|
-
git (>= 1.2.5)
|
12
|
-
rake
|
13
|
-
rdoc
|
14
|
-
json (1.7.5)
|
15
|
-
multi_json (1.3.7)
|
16
|
-
rake (10.0.2)
|
17
|
-
rdoc (3.12)
|
18
|
-
json (~> 1.4)
|
19
|
-
shoulda (3.3.2)
|
20
|
-
shoulda-context (~> 1.0.1)
|
21
|
-
shoulda-matchers (~> 1.4.1)
|
22
|
-
shoulda-context (1.0.1)
|
23
|
-
shoulda-matchers (1.4.1)
|
24
|
-
activesupport (>= 3.0.0)
|
25
|
-
|
26
|
-
PLATFORMS
|
27
|
-
ruby
|
28
|
-
|
29
|
-
DEPENDENCIES
|
30
|
-
bundler (~> 1.2.2)
|
31
|
-
jeweler (~> 1.8.4)
|
32
|
-
rdoc (~> 3.12)
|
33
|
-
shoulda
|
@@ -1,33 +0,0 @@
|
|
1
|
-
module ForemanReserve
|
2
|
-
module HostExtensions
|
3
|
-
extend ActiveSupport::Concern
|
4
|
-
module InstanceMethods
|
5
|
-
|
6
|
-
# Reserve the host
|
7
|
-
#
|
8
|
-
# @param reason [String] Reason to reserve the host under
|
9
|
-
def reserve!(reason = 'true')
|
10
|
-
param = "RESERVED"
|
11
|
-
if p=host_parameters.find_by_name(param)
|
12
|
-
p.update_attribute(:value, reason)
|
13
|
-
else
|
14
|
-
host_parameters.create!(:name => param, :value => reason)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
# Release the host
|
19
|
-
def release!
|
20
|
-
param = "RESERVED"
|
21
|
-
if p=host_parameters.find_by_name(param)
|
22
|
-
p.update_attribute(:value, "false")
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
# Return a json represenatation of the host
|
27
|
-
def as_json(options={})
|
28
|
-
super(:methods => [:host_parameters])
|
29
|
-
end
|
30
|
-
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|