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
11
# File 'lib/mrsk/commander.rb', line 7

def initialize
  self.verbosity = :info
  self.holding_lock = false
  self.hold_lock_on_error = false
end

Instance Attribute Details

#hold_lock_on_errorObject

Returns the value of attribute hold_lock_on_error.



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

def hold_lock_on_error
  @hold_lock_on_error
end

#holding_lockObject

Returns the value of attribute holding_lock.



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

def holding_lock
  @holding_lock
end

#specific_hostsObject

Returns the value of attribute specific_hosts.



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

def specific_hosts
  @specific_hosts
end

#specific_rolesObject

Returns the value of attribute specific_roles.



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

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



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

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

#accessory_hostsObject



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

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

#accessory_namesObject



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

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

#app(role: nil) ⇒ Object



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

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

#auditor(**details) ⇒ Object



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

def auditor(**details)
  Mrsk::Commands::Auditor.new(config, **details)
end

#boot_strategyObject



54
55
56
57
58
59
60
# File 'lib/mrsk/commander.rb', line 54

def boot_strategy
  if config.boot.limit.present?
    { in: :groups, limit: config.boot.limit, wait: config.boot.wait }
  else
    {}
  end
end

#builderObject



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

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

#configObject



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

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

#configure(**kwargs) ⇒ Object



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

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

#dockerObject



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

def docker
  @docker ||= Mrsk::Commands::Docker.new(config)
end

#healthcheckObject



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

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

#hold_lock_on_error?Boolean

Returns:

  • (Boolean)


139
140
141
# File 'lib/mrsk/commander.rb', line 139

def hold_lock_on_error?
  self.hold_lock_on_error
end

#holding_lock?Boolean

Returns:

  • (Boolean)


135
136
137
# File 'lib/mrsk/commander.rb', line 135

def holding_lock?
  self.holding_lock
end

#hookObject



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

def hook
  @hook ||= Mrsk::Commands::Hook.new(config)
end

#hostsObject



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

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

#lockObject



107
108
109
# File 'lib/mrsk/commander.rb', line 107

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

#primary_hostObject



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

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

#pruneObject



111
112
113
# File 'lib/mrsk/commander.rb', line 111

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

#registryObject



115
116
117
# File 'lib/mrsk/commander.rb', line 115

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

#rolesObject



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

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

#roles_on(host) ⇒ Object



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

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

#specific_primary!Object



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

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

#traefikObject



119
120
121
# File 'lib/mrsk/commander.rb', line 119

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

#traefik_hostsObject



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

def traefik_hosts
  specific_hosts || config.traefik_hosts
end

#with_verbosity(level) ⇒ Object



123
124
125
126
127
128
129
130
131
132
133
# File 'lib/mrsk/commander.rb', line 123

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