Class: Beyond::Tenant

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/beyond/tenant.rb

Instance Method Summary collapse

Instance Method Details

#configsObject



11
12
13
# File 'app/models/beyond/tenant.rb', line 11

def configs
  YAML.load_file(File.join(ENV['tenants_configs_dir'], name + '.yml'))
end

#deployObject



31
32
33
34
35
36
# File 'app/models/beyond/tenant.rb', line 31

def deploy
  unless Kernel.system("#{ENV['kamino_bin']} deploy -name='#{name}'")
    throw 'Error creating tenant'
  end
  PLUGINS.notify :on_deploy, self
end

#startObject



45
46
47
48
49
50
# File 'app/models/beyond/tenant.rb', line 45

def start
  unless Kernel.system("docker start #{name}")
    throw 'Error starting tenant'
  end
  PLUGINS.notify :on_start, self
end

#stopObject



38
39
40
41
42
43
# File 'app/models/beyond/tenant.rb', line 38

def stop
  unless Kernel.system("docker stop #{name}")
    throw 'Error stoping tenant'
  end
  PLUGINS.notify :on_stop, self
end

#update_configs(changes) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/models/beyond/tenant.rb', line 15

def update_configs changes
  conf = configs
  changes.each do |k, v|
    if conf[k]['type'] == 'bool'
      conf[k]['value'] = (v == 'true')
    else
      conf[k]['value'] = v
    end
  end
  file = File.join(ENV['tenants_configs_dir'], name + '.yml')
  File.open file, 'w' do |f|
    f.print conf.to_yaml
  end
  PLUGINS.notify :on_update_configs, self
end

#working?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'app/models/beyond/tenant.rb', line 52

def working?
  !!(`docker top #{name}`.match /\d+/)
end