Class: Kaigara::Sysops

Inherits:
BaseController show all
Defined in:
app/controllers/sysops.rb

Overview

A plugin to manage system operations

Instance Method Summary collapse

Instance Method Details

#create(name) ⇒ Object

Creates a folder with kaigara project. It includes:

  • operations/ - directory for future kaigara scripts

  • resources/ - directory for any sources (scripts to template, etc.)

  • metadata.rb - file where you should store all your variables (including environment)

  • Vagrantfile - if you use Vagrant, you know what is it

  • Dockerfile - a template to generate Dockerfiles



22
23
24
25
26
27
28
29
30
31
32
# File 'app/controllers/sysops.rb', line 22

def create(name)
  package = Package.new(name)
  package.name = name
  package.version = '1.0.0'
  empty_directory(name)
  empty_directory(File.join(name, 'operations'))
  empty_directory(File.join(name, 'resources'))
  template('metadata.rb.erb', File.join(name, 'metadata.rb'))
  template('Vagrantfile.erb', File.join(name, 'Vagrantfile'))
  template('Dockerfile.erb', File.join(name, 'Dockerfile'))
end

#exec(*operations) ⇒ Object

Executes every script in operations/

-p [path]

set project path



56
57
58
59
60
61
# File 'app/controllers/sysops.rb', line 56

def exec(*operations)
  package = Package.new(options[:path])
  say "Executing #{package.full_name}...", :yellow
  package.load!
  package.run!(operations)
end

#generate(label) ⇒ Object

Generates new kaigara script in operations/ dir. You can use any ruby code in it.



38
39
40
41
42
43
44
45
46
47
48
# File 'app/controllers/sysops.rb', line 38

def generate(label)
  package = Package.new
  package.load!
  filename = File.join(package.operations_dir, package.operation_name(label))
  template('operation.rb.erb', filename)

rescue Package::MetadataNotFound
  say "#{package.script_path} not found", :red
  say "You may want to create a new sysops project first"
  exit 1
end