Class: Prepd::Workspace

Inherits:
Base
  • Object
show all
Defined in:
lib/prepd/models/workspace.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#create

Instance Attribute Details

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/prepd/models/workspace.rb', line 3

def name
  @name
end

Instance Method Details

#create_workspaceObject



19
20
21
22
23
24
# File 'lib/prepd/models/workspace.rb', line 19

def create_workspace
  Dir.chdir(Prepd.config.working_dir) do
    FileUtils.rm_rf(name) if Prepd.config.force
    FileUtils.mkdir_p(name)
  end
end

#directory_cannot_existObject



10
11
12
13
# File 'lib/prepd/models/workspace.rb', line 10

def directory_cannot_exist
  return if Prepd.config.force
  errors.add(:directory_exists, requested_dir) if Dir.exists?(requested_dir)
end

#initialize_workspaceObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/prepd/models/workspace.rb', line 26

def initialize_workspace
  Dir.chdir(requested_dir) do
    File.open('prepd-workspace.yml', 'w') { |f| f.write("---\nname: #{name}\n") }
    Prepd.register_workspace(Dir.pwd)
    FileUtils.cp_r("#{Prepd.files_dir}/workspace/.", '.')
    Dir.chdir('developer') do
      File.open('vars.yml', 'w') do |f|
        f.puts("---\ngit_user:")
        f.puts("  name: #{`git config --get user.name`.chomp}")
        f.puts("  email: #{`git config --get user.email`.chomp}")
      end
      Prepd.write_password_file('vault-password.txt')
      FileUtils.touch('vault.yml')
      system('ansible-vault encrypt vault.yml')
    end
    # NOTE: remove after testing
    # Dir.chdir('machines') do
    #   FileUtils.mkdir('packer_cache')
    #   Dir.chdir('packer_cache') do
    #     FileUtils.cp('/tmp/50e697ab8edda5b0ac5ba2482c07003d2ff037315c7910af66efd3c28d23ed51.iso', '.')
    #   end
    # end
  end
end

#requested_dirObject



15
16
17
# File 'lib/prepd/models/workspace.rb', line 15

def requested_dir
  "#{Prepd.config.working_dir}/#{name}"
end