/usr/lib/python2.7/dist-packages/charmtools/templates/chef/files/cookbooks/juju-helpers/libraries/juju/juju_helpers.rb is in charm-tools 2.1.2-0ubuntu4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | module JujuHelpers
HOOK_ENVIRONMENT = %w(juju_unit_name juju_relation juju_remote_unit)
COMMANDS = ''
HOOK_ENVIRONMENT.each do |method|
define_method method do
ENV[method.upcase]
end
end
def relation_ids(relation_name = nil)
commands = ['relation-ids --fromat=json']
commands << relation_name if relation_name
run(commands.join(' ')).try { |relations| JSON.load(relations) }
end
def relation_list(relation_id = nil)
commands = ['relation-list --format=json']
commands << "-r #{relation_id}" if relation_id
run(commands.join(' ')).try { |relations| JSON.load(relations) }
end
def relation_get(unit_name = nil, relation_id = nil)
commands = ['relation-get --format=json']
commands << "-r #{relation_id}" if relation_id
commands << '-'
commands << unit_name if unit_name
run(commands.join(' ')).try { |relation| JSON.load(relation) }
end
def config_get
run("config-get --format=json").try { |relation| JSON.load(relation) }
end
def unit_get(key)
run("unit-get #{key}")
end
def juju_log(text)
run("juju-log #{text}")
end
private
def run(command)
value = %x{ #{command} 2>&1 }.strip
value.empty? ? nil : value
end
end
|