Class: Ridley::SandboxResource

Inherits:
Object
  • Object
show all
Includes:
Chozo::VariaModel
Defined in:
lib/ridley/resources/sandbox_resource.rb

Overview

Author:

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, new_attrs = {}) ⇒ SandboxResource

Returns a new instance of SandboxResource

Parameters:


49
50
51
52
# File 'lib/ridley/resources/sandbox_resource.rb', line 49

def initialize(client, new_attrs = {})
  @client = client
  mass_assign(new_attrs)
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client


45
46
47
# File 'lib/ridley/resources/sandbox_resource.rb', line 45

def client
  @client
end

Class Method Details

.create(client, checksums = []) ⇒ Array<Ridley::SandboxResource>

Create a new Sandbox on the client's Chef Server. A Sandbox requires an array of file checksums which lets the Chef Server know what the signature of the contents to be uploaded will look like.

Examples:

using the Ridley client to create a sandbox

client.sandbox.create([
  "385ea5490c86570c7de71070bce9384a",
  "f6f73175e979bd90af6184ec277f760c",
  "2e03dd7e5b2e6c8eab1cf41ac61396d5"
])

Parameters:

  • client (Ridley::Client)
  • checksums (Array) (defaults to: [])

    a hash of file checksums

Returns:


21
22
23
24
25
26
27
# File 'lib/ridley/resources/sandbox_resource.rb', line 21

def create(client, checksums = [])
  sumhash = { checksums: Hash.new }.tap do |chks|
    Array(checksums).each { |chk| chks[:checksums][chk] = nil }
  end

  new(client, client.connection.post("sandboxes", MultiJson.encode(sumhash)).body)
end

Instance Method Details

#checksum(chk_id) ⇒ Hash

Return information about the given checksum

Examples:

sandbox.checksum("e5a0f6b48d0712382295ff30bec1f9cc") => {
  needs_upload: true,
  url: "https://s3.amazonaws.com/opscode-platform-production-data/organization"
}

Parameters:

  • chk_id (#to_sym)

    checksum to retrieve information about

Returns:

  • (Hash)

    a hash containing the checksum information


67
68
69
# File 'lib/ridley/resources/sandbox_resource.rb', line 67

def checksum(chk_id)
  checksums[chk_id.to_sym]
end

#commitObject

Notify the Chef Server that uploading to this sandbox has completed


77
78
79
80
# File 'lib/ridley/resources/sandbox_resource.rb', line 77

def commit
  response = client.connection.put("sandboxes/#{sandbox_id}", MultiJson.encode(is_completed: true)).body
  set_attribute(:is_completed, response[:is_completed])
end

#to_sObject


82
83
84
# File 'lib/ridley/resources/sandbox_resource.rb', line 82

def to_s
  "#{sandbox_id}: #{checksums}"
end

#upload(checksums) ⇒ Object

Concurrently upload all of this sandboxes files into the checksum containers of the sandbox


72
73
74
# File 'lib/ridley/resources/sandbox_resource.rb', line 72

def upload(checksums)
  SandboxUploader.upload(self, checksums)
end