Class: Fleet::Controller

Inherits:
Object
  • Object
show all
Defined in:
lib/fleet/controller.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeController

Returns a new instance of Controller.



6
7
8
# File 'lib/fleet/controller.rb', line 6

def initialize
  @cluster = Fleet::Cluster.new(controller: self)
end

Instance Attribute Details

#clusterObject

Returns the value of attribute cluster.



4
5
6
# File 'lib/fleet/controller.rb', line 4

def cluster
  @cluster
end

#unitsObject

returns an array of Fleet::Unit instances



16
17
18
19
20
21
# File 'lib/fleet/controller.rb', line 16

def units
  return @units.to_a if @units
  machines
  fetch_units
  @units.to_a
end

Instance Method Details

#[](unit_name) ⇒ Object

find a unitfile of a specific name



31
32
33
# File 'lib/fleet/controller.rb', line 31

def [](unit_name)
  units.detect { |u| u.name == unit_name }
end

#destroy(*unit_names) ⇒ Object



59
60
61
62
63
# File 'lib/fleet/controller.rb', line 59

def destroy(*unit_names)
  runner = Fleetctl::Command.run('destroy', unit_names)
  clear_units
  runner.exit_code == 0
end

#load(*unit_file_or_files) ⇒ Object

accepts one or more File objects, or an array of File objects



52
53
54
55
56
57
# File 'lib/fleet/controller.rb', line 52

def load(*unit_file_or_files)
  unitfiles = [*unit_file_or_files].flatten
  out = unitfile_operation(:load, unitfiles)
  clear_units
  out
end

#machinesObject

returns an array of Fleet::Machine instances



11
12
13
# File 'lib/fleet/controller.rb', line 11

def machines
  cluster.machines
end

#start(*unit_file_or_files) ⇒ Object

accepts one or more File objects, or an array of File objects



36
37
38
39
40
41
# File 'lib/fleet/controller.rb', line 36

def start(*unit_file_or_files)
  unitfiles = [*unit_file_or_files].flatten
  out = unitfile_operation(:start, unitfiles)
  clear_units
  out
end

#submit(*unit_file_or_files) ⇒ Object

accepts one or more File objects, or an array of File objects



44
45
46
47
48
49
# File 'lib/fleet/controller.rb', line 44

def submit(*unit_file_or_files)
  unitfiles = [*unit_file_or_files].flatten
  out = unitfile_operation(:submit, unitfiles)
  clear_units
  out
end

#syncObject

refreshes local state to match the fleet cluster



24
25
26
27
28
# File 'lib/fleet/controller.rb', line 24

def sync
  build_fleet
  fetch_units
  true
end