Class: Cuoco::Uploader

Inherits:
Object
  • Object
show all
Defined in:
lib/cuoco/uploader.rb

Overview

This class handles uploading Cuoco and Chef scripts onto the remote machines

Instance Method Summary collapse

Constructor Details

#initialize(capistrano) ⇒ Uploader

Returns a new instance of Uploader.



7
8
9
10
11
12
13
14
# File 'lib/cuoco/uploader.rb', line 7

def initialize(capistrano)
  @cap = capistrano

  @chef_path = File.expand_path(@cap.fetch(:chef_path, 'config/chef'))
  @node_data = @cap.fetch(:chef_data, {})

  @cuoco_remote_path = '/tmp/cuoco'
end

Instance Method Details

#prepare_directory_structureObject



23
24
25
26
# File 'lib/cuoco/uploader.rb', line 23

def prepare_directory_structure
  @cap.run("mkdir -p #{@cuoco_remote_path}", :shell => '/bin/bash')
  @cap.sudo("mkdir -p /etc/chef", :shell => '/bin/bash')
end

#uploadObject



16
17
18
19
20
21
# File 'lib/cuoco/uploader.rb', line 16

def upload
  prepare_directory_structure
  upload_chef_config
  upload_chef_files
  upload_node_json
end

#upload_chef_configObject



28
29
30
31
32
# File 'lib/cuoco/uploader.rb', line 28

def upload_chef_config
  @config_contents = Cuoco::ConfigGenerator.chef_config(binding)
  @cap.put(@config_contents, @cuoco_remote_path+'/solo.rb')
  @cap.sudo("mv #{@cuoco_remote_path}/solo.rb /etc/chef/solo.rb", :shell => '/bin/bash')
end

#upload_chef_filesObject



34
35
36
37
38
# File 'lib/cuoco/uploader.rb', line 34

def upload_chef_files
  @cap.sudo("rm -rf #{@cuoco_remote_path}/chef", :shell => '/bin/bash')
  @cap.upload(@chef_path, @cuoco_remote_path+'/chef', :recursive => true)
  @cap.run("#{@cap.sudo} rm -rf /var/chef && #{@cap.sudo} mv #{@cuoco_remote_path}/chef /var/chef && #{@cap.sudo} chown -R root:root /var/chef", :shell => '/bin/bash')
end

#upload_node_jsonObject



40
41
42
# File 'lib/cuoco/uploader.rb', line 40

def upload_node_json
  @cap.put(@node_data.to_json, @cuoco_remote_path+'/node.json')
end