Class: Mrsk::Commander

Inherits:
Object
  • Object
show all
Defined in:
lib/mrsk/commander.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCommander

Returns a new instance of Commander.



7
8
9
10
# File 'lib/mrsk/commander.rb', line 7

def initialize
  self.verbosity = :info
  self.lock_count = 0
end

Instance Attribute Details

#lock_countObject

Returns the value of attribute lock_count.



5
6
7
# File 'lib/mrsk/commander.rb', line 5

def lock_count
  @lock_count
end

#specific_hostsObject

Returns the value of attribute specific_hosts.



23
24
25
# File 'lib/mrsk/commander.rb', line 23

def specific_hosts
  @specific_hosts
end

#specific_rolesObject

Returns the value of attribute specific_roles.



23
24
25
# File 'lib/mrsk/commander.rb', line 23

def specific_roles
  @specific_roles
end

#verbosityObject

Returns the value of attribute verbosity.



5
6
7
# File 'lib/mrsk/commander.rb', line 5

def verbosity
  @verbosity
end

Instance Method Details

#accessory(name) ⇒ Object



74
75
76
# File 'lib/mrsk/commander.rb', line 74

def accessory(name)
  Mrsk::Commands::Accessory.new(config, name: name)
end

#accessory_hostsObject



61
62
63
# File 'lib/mrsk/commander.rb', line 61

def accessory_hosts
  specific_hosts || config.accessories.flat_map(&:hosts)
end

#accessory_namesObject



65
66
67
# File 'lib/mrsk/commander.rb', line 65

def accessory_names
  config.accessories&.collect(&:name) || []
end

#app(role: nil) ⇒ Object



70
71
72
# File 'lib/mrsk/commander.rb', line 70

def app(role: nil)
  Mrsk::Commands::App.new(config, role: role)
end

#auditor(role: nil) ⇒ Object



78
79
80
# File 'lib/mrsk/commander.rb', line 78

def auditor(role: nil)
  Mrsk::Commands::Auditor.new(config, role: role)
end

#builderObject



82
83
84
# File 'lib/mrsk/commander.rb', line 82

def builder
  @builder ||= Mrsk::Commands::Builder.new(config)
end

#configObject



12
13
14
15
16
17
# File 'lib/mrsk/commander.rb', line 12

def config
  @config ||= Mrsk::Configuration.create_from(**@config_kwargs).tap do |config|
    @config_kwargs = nil
    configure_sshkit_with(config)
  end
end

#configure(**kwargs) ⇒ Object



19
20
21
# File 'lib/mrsk/commander.rb', line 19

def configure(**kwargs)
  @config, @config_kwargs = nil, kwargs
end

#healthcheckObject



86
87
88
# File 'lib/mrsk/commander.rb', line 86

def healthcheck
  @healthcheck ||= Mrsk::Commands::Healthcheck.new(config)
end

#hostsObject



47
48
49
50
51
# File 'lib/mrsk/commander.rb', line 47

def hosts
  (specific_hosts || config.all_hosts).select do |host|
    (specific_roles || config.roles).flat_map(&:hosts).include?(host)
  end
end

#lockObject



102
103
104
# File 'lib/mrsk/commander.rb', line 102

def lock
  @lock ||= Mrsk::Commands::Lock.new(config)
end

#primary_hostObject



37
38
39
# File 'lib/mrsk/commander.rb', line 37

def primary_host
  specific_hosts&.first || config.primary_web_host
end

#pruneObject



90
91
92
# File 'lib/mrsk/commander.rb', line 90

def prune
  @prune ||= Mrsk::Commands::Prune.new(config)
end

#registryObject



94
95
96
# File 'lib/mrsk/commander.rb', line 94

def registry
  @registry ||= Mrsk::Commands::Registry.new(config)
end

#rolesObject



41
42
43
44
45
# File 'lib/mrsk/commander.rb', line 41

def roles
  (specific_roles || config.roles).select do |role|
    ((specific_hosts || config.all_hosts) & role.hosts).any?
  end
end

#roles_on(host) ⇒ Object



53
54
55
# File 'lib/mrsk/commander.rb', line 53

def roles_on(host)
  roles.select { |role| role.hosts.include?(host.to_s) }.map(&:name)
end

#specific_primary!Object



25
26
27
# File 'lib/mrsk/commander.rb', line 25

def specific_primary!
  self.specific_hosts = [ config.primary_web_host ]
end

#traefikObject



98
99
100
# File 'lib/mrsk/commander.rb', line 98

def traefik
  @traefik ||= Mrsk::Commands::Traefik.new(config)
end

#traefik_hostsObject



57
58
59
# File 'lib/mrsk/commander.rb', line 57

def traefik_hosts
  specific_hosts || config.traefik_hosts
end

#with_verbosity(level) ⇒ Object



106
107
108
109
110
111
112
113
114
115
116
# File 'lib/mrsk/commander.rb', line 106

def with_verbosity(level)
  old_level = self.verbosity

  self.verbosity = level
  SSHKit.config.output_verbosity = level

  yield
ensure
  self.verbosity = old_level
  SSHKit.config.output_verbosity = old_level
end