Class: Superhosting::Base

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/superhosting/base.rb

Instance Method Summary collapse

Methods included from Helpers

#create_conf, #erb, #instance_variables_to_hash, #remove_line_from_file, #write_if_not_exist

Constructor Details

#initialize(config_path: '/etc/sx', lib_path: '/var/lib/sx', logger: nil, docker_socket: nil) ⇒ Base

Returns a new instance of Base.



5
6
7
8
9
10
11
12
13
# File 'lib/superhosting/base.rb', line 5

def initialize(config_path: '/etc/sx', lib_path: '/var/lib/sx', logger: nil, docker_socket: nil)
  @config_path = Pathname.new(config_path)
  @lib_path = Pathname.new(lib_path)
  @config = PathMapper.new(config_path)
  @lib = PathMapper.new(lib_path)
  @logger = logger

  @docker_api = DockerApi.new(socket: docker_socket)
end

Instance Method Details

#command(*command_args) ⇒ Object



30
31
32
33
34
35
# File 'lib/superhosting/base.rb', line 30

def command(*command_args)
  cmd = Mixlib::ShellOut.new(*command_args)
  cmd.run_command
  debug([cmd.stdout, cmd.stderr].join("\n"))
  cmd
end

#command!(*command_args) ⇒ Object



19
20
21
22
23
24
25
26
27
28
# File 'lib/superhosting/base.rb', line 19

def command!(*command_args)
  cmd = Mixlib::ShellOut.new(*command_args)
  cmd.run_command
  if cmd.status.success?
    debug([cmd.stdout, cmd.stderr].join("\n"))
    cmd
  else
    raise NetStatus::Exception.new(error: :error, message: [cmd.stdout, cmd.stderr].join("\n"))
  end
end

#debug(*a, &b) ⇒ Object



15
16
17
# File 'lib/superhosting/base.rb', line 15

def debug(*a, &b)
  @logger.debug(*a, &b) unless @logger.nil?
end