Class | Chef::CookbookVersion
In: | lib/chef/cookbook_version.rb
Parent: | Object

## Chef::CookbookVersion

CookbookVersion is a model object encapsulating the data about a Chef cookbook. Chef supports maintaining multiple versions of a cookbook on a single server; each version is represented by a distinct instance of this class.

### Methods

<=> attribute_filenames= attribute_files= available_versions cache cdb_by_name cdb_destroy cdb_list cdb_list_latest cdb_list_latest_ids cdb_load cdb_save checksum_cookbook_file checksums chef_server_rest chef_server_rest cleanup_file_cache clear_obsoleted_cookbooks couchdb_id= create_design_document destroy force_save_url freeze_version frozen_version? full_name fully_qualified_recipe_names generate_manifest_with_urls json_create latest_cookbooks list load load_recipe manifest manifest= manifest_records_by_path metadata_json_file metadata_rb_file new preferred_filename_on_disk_location preferred_manifest_record preferred_manifest_records_for_directory purge recipe_filenames= recipe_files= relative_filenames_in_preferred_directory reload_metadata! reset_cache_validity save_url segment_filenames sync_cookbook_file_cache sync_cookbooks to_hash to_json valid_cache_entries version version=

### Included Modules

Chef::IndexQueue::Indexable Comparable

### Constants

COOKBOOK_SEGMENTS | = | [ :resources, :providers, :recipes, :definitions, :libraries, :attributes, :files, :templates, :root_files ]
DESIGN_DOCUMENT | = | { "version" => 8, "language" => "javascript", "views" => { "all" => { "map" => <<-EOJS function(doc) { if (doc.chef_type == "cookbook_version") { emit(doc.name, doc); } } EOJS

### External Aliases

attribute_filenames | -> | attribute_files
| BACKCOMPAT/DEPRECATED - Remove these and fix breakage before release [DAN - 5/20/2010]##
recipe_filenames | -> | recipe_files
| BACKCOMPAT/DEPRECATED - Remove these and fix breakage before release [DAN - 5/20/2010]##

### Attributes

attribute_filenames | [R] | attribute_filenames also has a setter that has non-default functionality.
attribute_filenames_by_short_filename | [R] |
couchdb | [RW] |
couchdb_id | [R] |
couchdb_rev | [RW] |
definition_filenames | [RW] |
file_filenames | [RW] |
library_filenames | [RW] |
metadata | [RW] |
metadata_filenames | [RW] |
name | [RW] |
provider_filenames | [RW] |
recipe_filenames | [R] | recipe_filenames also has a setter that has non-default functionality.
recipe_filenames_by_name | [R] |
resource_filenames | [RW] |
root_dir | [RW] |
root_filenames | [RW] |
status | [RW] |
template_filenames | [RW] |

### Public Class methods

available_versions(cookbook_name)

Given a `cookbook_name`, get a list of all versions that exist on the server.

### Returns

String]:
  Array of cookbook versions, which are strings like ‘x.y.z‘

nil: | if the cookbook doesn‘t exist. an error will also be logged.

cache()
cdb_by_name(cookbook_name, couchdb=nil)

Couchdb

cdb_list(inflate=false, couchdb=nil)
cdb_list_latest(inflate=false, couchdb=nil)
cdb_list_latest_ids(inflate=false, couchdb=nil)
cdb_load(name, version='latest', couchdb=nil)
checksum_cookbook_file(filepath)

This is the one and only method that knows how cookbook files’ checksums are generated.

chef_server_rest()

REST API

cleanup_file_cache()
clear_obsoleted_cookbooks(cookbook_hash)

Iterates over cached cookbooks’ files, removing files belonging to cookbooks that don‘t appear in `cookbook_hash`

create_design_document(couchdb=nil)
json_create(o)
latest_cookbooks()

Get the newest version of all cookbooks

list()
load(name, version="_latest")
new(name, couchdb=nil)

Creates a new Chef::CookbookVersion object.

### Returns

object<Chef::CookbookVersion>: | Duh. :)

reset_cache_validity()
sync_cookbook_file_cache(cookbook)

Update the file caches for a given cache segment. Takes a segment name and a hash that matches one of the cookbooks/_attribute_files style remote file listings.

### Parameters

cookbook<Chef::Cookbook>: | The cookbook to update
valid_cache_entries<Hash>: | Out-param; Added to this hash are the files that

were referred to by this cookbook

sync_cookbooks(cookbook_hash)

Synchronizes all the cookbooks from the chef-server.

### Returns

true: | Always returns true

valid_cache_entries()

Keep track of the filenames that we use in both eager cookbook downloading (during sync_cookbooks) and lazy (during the run itself, through FileVendor). After the run is over, clean up the cache.

### Public Instance methods

<=>(o)
attribute_filenames=(*filenames)
attribute_files=(*filenames)

Alias for attribute_filenames=

cdb_destroy()
cdb_save()
checksums()

Returns a hash of checksums to either nil or the on disk path (which is done by generate_manifest).

chef_server_rest()
couchdb_id=(value)
destroy()
force_save_url()

Adds the `force=true` parameter to the upload URL. This allows the user to overwrite a frozen cookbook (a PUT against the normal save_url raises a 409 Conflict in this case).

freeze_version()
frozen_version?()

Indicates if this version is frozen or not. Freezing a coobkook version indicates that a new cookbook with the same name and version number shoule

full_name()
fully_qualified_recipe_names()

Return recipe names in the form of cookbook_name::recipe_name

generate_manifest_with_urls(&url_generator)
load_recipe(recipe_name, run_context)

called from DSL

manifest()

A manifest is a Mash that maps segment names to arrays of manifest records (see preferred_manifest_record for format of manifest records), as well as describing cookbook metadata. The manifest follows a form like the following:

      {
        :cookbook_name = "apache2",
        :version = "1.0",
        :name = "Apache 2"
        :metadata = ???TODO: timh/cw: 5-24-2010: describe this format,

        :files => [
          {
            :name => "afile.rb",
            :path => "files/ubuntu-9.10/afile.rb",
            :checksum => "2222",
            :specificity => "ubuntu-9.10"
          },
        ],
        :templates => [ manifest_record1, ... ],
        ...
      }

manifest=(new_manifest)
manifest_records_by_path()
metadata_json_file()
metadata_rb_file()
preferred_filename_on_disk_location(node, segment, filename, current_filepath=nil)
preferred_manifest_record(node, segment, filename)

Determine the most specific manifest record for the given segment/filename, given information in the node. Throws FileNotFound if there is no such segment and filename in the manifest.

A manifest record is a Mash that follows the following form: {

      :name => "example.rb",
      :path => "files/default/example.rb",
      :specificity => "default",
      :checksum => "1234"

}

preferred_manifest_records_for_directory(node, segment, dirname)

Determine the manifest records from the most specific directory for the given node. See preferred_manifest_record for a description of entries of the returned Array.

purge()

Runs on Chef Server (API); deletes the cookbook from couchdb and also destroys associated checksum documents

recipe_filenames=(*filenames)
recipe_files=(*filenames)

Alias for recipe_filenames=

relative_filenames_in_preferred_directory(node, segment, dirname)
reload_metadata!()
save_url()

Return the URL to save (PUT) this object to the server via the REST api. If there is an existing document on the server and it is marked frozen, a PUT will result in a 409 Conflict.

segment_filenames(segment)
to_hash()
to_json(*a)
version()
version=(new_version)

[Validate]