summaryrefslogtreecommitdiff
path: root/chef-server-api/app
diff options
context:
space:
mode:
authorThom May <thom.may@betfair.com>2010-07-05 17:23:46 +0100
committerSeth Falcon <seth@opscode.com>2010-11-01 10:44:52 -0700
commitf560b3d51dcbbab34c5aca057ac8b3dad22f4f97 (patch)
tree28b0c83bf660f90ea7a726dc367b6afe21162575 /chef-server-api/app
parent2580139b2b9372538f2e6c59e969939814ead3d5 (diff)
downloadchef-f560b3d51dcbbab34c5aca057ac8b3dad22f4f97.tar.gz
Add satisfy_all function
This function takes a cookbook and a list of version constraints and attempts to return a single cookbook that satisfies those constraints
Diffstat (limited to 'chef-server-api/app')
-rw-r--r--chef-server-api/app/controllers/nodes.rb40
1 files changed, 30 insertions, 10 deletions
diff --git a/chef-server-api/app/controllers/nodes.rb b/chef-server-api/app/controllers/nodes.rb
index f4b4abe2b1..b9317de8c1 100644
--- a/chef-server-api/app/controllers/nodes.rb
+++ b/chef-server-api/app/controllers/nodes.rb
@@ -7,9 +7,9 @@
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
-#
+#
# http://www.apache.org/licenses/LICENSE-2.0
-#
+#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -21,12 +21,12 @@ require 'chef/cookbook/metadata/version'
require 'chef' / 'node'
class Nodes < Application
-
+
provides :json
-
- before :authenticate_every
+
+ before :authenticate_every
before :admin_or_requesting_node, :only => [ :update, :destroy, :cookbooks ]
-
+
CMP = {
"<<" => lambda { |v, r| v < r },
"<=" => lambda { |v, r| v <= r },
@@ -39,7 +39,7 @@ class Nodes < Application
PATTERN = /\A\s*(#{qcmp})?\s*(#{Chef::Cookbook::Metadata::Version::PATTERN})\s*\z/
def index
- @node_list = Chef::Node.cdb_list
+ @node_list = Chef::Node.cdb_list
display(@node_list.inject({}) do |r,n|
r[n] = absolute_url(:node, n); r
end)
@@ -58,7 +58,7 @@ class Nodes < Application
def create
@node = params["inflated_object"]
begin
- Chef::Node.cdb_load(@node.name)
+ Chef::Node.cdb_load(@node.name)
raise Conflict, "Node already exists"
rescue Chef::Exceptions::CouchDBNotFound
end
@@ -83,7 +83,7 @@ class Nodes < Application
def destroy
begin
@node = Chef::Node.cdb_load(params[:id])
- rescue Chef::Exceptions::CouchDBNotFound => e
+ rescue Chef::Exceptions::CouchDBNotFound => e
raise NotFound, "Cannot load node #{params[:id]}"
end
@node.cdb_destroy
@@ -94,7 +94,7 @@ class Nodes < Application
def cookbooks
begin
@node = Chef::Node.cdb_load(params[:id])
- rescue Chef::Exceptions::CouchDBNotFound => e
+ rescue Chef::Exceptions::CouchDBNotFound => e
raise NotFound, "Cannot load node #{params[:id]}"
end
@@ -117,6 +117,26 @@ class Nodes < Application
end
end
+ def satisfy_all(cookbook, reqs=[])
+ vers = Array.new
+
+ if reqs.empty?
+ return Chef::CookbookVersion.cdb_load(cookbook, satisfy(cookbook).last)
+ end
+
+ reqs.each do |pat|
+ v = satisfy(cookbook, pat)
+ raise ArgumentError, "Can't satisfy dependency #{pat} for cookbook #{cookbook}" if v.empty?
+ if vers.empty?
+ vers = v
+ else
+ vers = vers & v
+ raise ArgumentError, "Conflicting dependencies for #{cookbook}" if vers.empty?
+ end
+ end
+ Chef::CookbookVersion.cdb_load(cookbook, vers.last)
+ end
+
def load_all_files
all_cookbooks = Chef::Environment.cdb_load_filtered_cookbook_versions(@node.chef_environment)