Class: Kaigara::Package

Inherits:
Object
  • Object
show all
Defined in:
app/models/sysops/package.rb

Defined Under Namespace

Classes: MetadataNotFound

Constant Summary collapse

METADATA_FILE_NAME =

The base project files and directories

'metadata.rb'
VAGRANT_FILE_NAME =
'Vagrantfile'
OPERATIONS_DIR_NAME =
'operations'
RESOURCES_DIR_NAME =
'resources'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path = '.') ⇒ Package

Returns a new instance of Package.



25
26
27
28
29
30
31
32
# File 'app/models/sysops/package.rb', line 25

def initialize(path = '.')
  @options = {}
  @work_dir = path ? File.expand_path(path) : '.'

  @operations_dir = File.join(@work_dir, OPERATIONS_DIR_NAME)
  @script_path = File.expand_path(File.join(@work_dir, METADATA_FILE_NAME))
  @spec = Spec.new(self)
end

Instance Attribute Details

#dependenciesObject

Returns the value of attribute dependencies.



19
20
21
# File 'app/models/sysops/package.rb', line 19

def dependencies
  @dependencies
end

#nameObject

Returns the value of attribute name.



21
22
23
# File 'app/models/sysops/package.rb', line 21

def name
  @name
end

#operations_dirObject

Returns the value of attribute operations_dir.



18
19
20
# File 'app/models/sysops/package.rb', line 18

def operations_dir
  @operations_dir
end

#script_pathObject

metadata.rb path



16
17
18
# File 'app/models/sysops/package.rb', line 16

def script_path
  @script_path
end

#versionObject

Returns the value of attribute version.



20
21
22
# File 'app/models/sysops/package.rb', line 20

def version
  @version
end

#work_dirObject

Project directory



13
14
15
# File 'app/models/sysops/package.rb', line 13

def work_dir
  @work_dir
end

Instance Method Details

#execute_operation!(path) ⇒ Object



60
61
62
63
64
65
# File 'app/models/sysops/package.rb', line 60

def execute_operation!(path)
  context = Operation.new path
  context.work_dir = @work_dir
  context.environment = @spec.environment
  context.apply!
end

#full_nameObject



34
35
36
# File 'app/models/sysops/package.rb', line 34

def full_name
  @full_name ||= [name, version].compact.join("/")
end

#load!Object

Read and execute metadata.rb

Raises:



39
40
41
42
43
# File 'app/models/sysops/package.rb', line 39

def load!
  raise MetadataNotFound.new unless File.exist?(@script_path)
  script = File.read(@script_path)
  @spec.instance_eval(script)
end

#operation_name(name) ⇒ Object

Create an empty operation in ./operations



46
47
48
49
# File 'app/models/sysops/package.rb', line 46

def operation_name(name)
  ts = DateTime.now.strftime('%Y%m%d%H%M%S')
  return "%s_%s.rb" % [ts, name]
end

#run!(operations) ⇒ Object

Execute operations in the operations directory one by one



52
53
54
55
56
57
58
# File 'app/models/sysops/package.rb', line 52

def run!(operations)
  Dir[File.join(@operations_dir, '*.rb')].sort.each do |x|
    if operations.empty? or operations.find { |op| x.include?(op) }
      execute_operation!(x)
    end
  end
end