Module: Charmkit::DSL

Defined in:
lib/charmkit/fs.rb,
lib/charmkit/runner.rb,
lib/charmkit/package.rb,
lib/charmkit/template.rb,
lib/charmkit/hook-tools.rb

Defined Under Namespace

Classes: TemplateRenderer

Instance Method Summary collapse

Instance Method Details

#action(item) ⇒ Object



26
27
28
29
# File 'lib/charmkit/hook-tools.rb', line 26

def action(item)
  out, err = run "action-get #{item}"
  return out.chomp
end

#action=(item) ⇒ Object



31
32
33
34
# File 'lib/charmkit/hook-tools.rb', line 31

def action=(item)
  out, err = run "action-set #{item}"
  return out.chomp
end

#config(item) ⇒ Object



11
12
13
14
# File 'lib/charmkit/hook-tools.rb', line 11

def config(item)
  out, err = run "config-get #{item}"
  return out.chomp
end

#is_dir?(path) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/charmkit/fs.rb', line 11

def is_dir?(path)
  return Dir.exists? path
end

#is_file?(path) ⇒ Boolean

Returns:

  • (Boolean)


8
9
10
# File 'lib/charmkit/fs.rb', line 8

def is_file?(path)
  return File.exists? path
end

#is_installed?(package) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
14
15
16
17
# File 'lib/charmkit/package.rb', line 11

def is_installed?(package)
  begin
    run "dpkg -s #{package}" and return true
  rescue
    return false
  end
end

#log(msg) ⇒ Object



36
37
38
# File 'lib/charmkit/hook-tools.rb', line 36

def log(msg)
  run "juju-log #{msg}"
end

#package(packages, *opts) ⇒ Object

installs apt packages



4
5
6
7
8
9
# File 'lib/charmkit/package.rb', line 4

def package(packages, *opts)
  if opts.include?(:update_cache)
    run "apt-get update"
  end
  run "apt-get install -qyf #{packages.join(' ')}"
end

#resource(item) ⇒ Object



16
17
18
19
# File 'lib/charmkit/hook-tools.rb', line 16

def resource(item)
  out, err = run "resource-get #{item}"
  return out.chomp
end

#run(data) ⇒ Object



5
6
7
8
9
10
11
12
# File 'lib/charmkit/runner.rb', line 5

def run(data)
  if ENV['DRYRUN']
    puts "DRYRUN: #{data}"
  else
    cmd = TTY::Command.new(printer: :null)
    return cmd.run(data)
  end
end

#status(level = :maintenance, msg = "") ⇒ Object

calls status-set in juju environment



5
6
7
8
9
# File 'lib/charmkit/hook-tools.rb', line 5

def status(level=:maintenance, msg="")
  levels = [:maintenance, :active, :blocked]
  raise unless levels.include?(level)
  run "status-set #{level.to_s} #{msg}"
end

#template(src, dst, **context) ⇒ Object



17
18
19
20
# File 'lib/charmkit/template.rb', line 17

def template(src, dst, **context)
  rendered = TemplateRenderer.render(File.read(src), context)
  File.write(dst, rendered)
end

#unit(item) ⇒ Object



21
22
23
24
# File 'lib/charmkit/hook-tools.rb', line 21

def unit(item)
  out, err = run "unit-get #{item}"
  return out.chomp
end