summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/leap/platform.rb2
-rw-r--r--lib/leap_cli/config/manager.rb13
-rw-r--r--lib/leap_cli/config/object.rb23
-rw-r--r--lib/leap_cli/remote/tasks.rb4
4 files changed, 34 insertions, 8 deletions
diff --git a/lib/leap/platform.rb b/lib/leap/platform.rb
index 36a13f8..9112ef3 100644
--- a/lib/leap/platform.rb
+++ b/lib/leap/platform.rb
@@ -14,6 +14,7 @@ module Leap
attr_accessor :monitor_username
attr_accessor :reserved_usernames
+ attr_accessor :hiera_dir
attr_accessor :hiera_path
attr_accessor :files_dir
attr_accessor :leap_dir
@@ -24,6 +25,7 @@ module Leap
def define(&block)
# some defaults:
@reserved_usernames = []
+ @hiera_dir = '/etc/leap'
@hiera_path = '/etc/leap/hiera.yaml'
@leap_dir = '/srv/leap'
@files_dir = '/srv/leap/files'
diff --git a/lib/leap_cli/config/manager.rb b/lib/leap_cli/config/manager.rb
index 2013217..ca739c3 100644
--- a/lib/leap_cli/config/manager.rb
+++ b/lib/leap_cli/config/manager.rb
@@ -331,6 +331,19 @@ module LeapCli
@partials[partial_path]
end
+ #
+ # Loads a json template file as a Hash (used only when creating a new node .json
+ # file for the first time).
+ #
+ def template(template)
+ path = Path.named_path([:template_config, template], Path.provider_base)
+ if File.exists?(path)
+ return load_json(path, Config::Object)
+ else
+ return nil
+ end
+ end
+
private
def load_all_json(pattern, object_class, options={})
diff --git a/lib/leap_cli/config/object.rb b/lib/leap_cli/config/object.rb
index 869c331..0f7376f 100644
--- a/lib/leap_cli/config/object.rb
+++ b/lib/leap_cli/config/object.rb
@@ -85,12 +85,23 @@ module LeapCli
#
# export JSON
#
- def dump_json(*options)
+ def dump_json(options={})
evaluate(@node)
- if options.include? :compact
- self.to_json
+ if options[:format] == :compact
+ return self.to_json
else
- JSON.sorted_generate(self)
+ excluded = {}
+ if options[:exclude]
+ options[:exclude].each do |key|
+ excluded[key] = self[key]
+ self.delete(key)
+ end
+ end
+ json_str = JSON.sorted_generate(self)
+ if excluded.any?
+ self.merge!(excluded)
+ end
+ return json_str
end
end
@@ -286,7 +297,7 @@ module LeapCli
keys.each do |key|
obj = fetch_value(key, context)
if is_required_value_not_set?(obj)
- Util::log 0, :warning, "required key \"#{key}\" is not set in node \"#{node.name}\"."
+ Util::log 0, :warning, "required property \"#{key}\" is not set in node \"#{node.name}\"."
elsif obj.is_a? Config::Object
obj.evaluate_everything(context)
end
@@ -301,7 +312,7 @@ module LeapCli
@late_eval_list.each do |key, value|
self[key] = context.evaluate_ruby(key, value)
if is_required_value_not_set?(self[key])
- Util::log 0, :warning, "required key \"#{key}\" is not set in node \"#{node.name}\"."
+ Util::log 0, :warning, "required property \"#{key}\" is not set in node \"#{node.name}\"."
end
end
end
diff --git a/lib/leap_cli/remote/tasks.rb b/lib/leap_cli/remote/tasks.rb
index 928d026..9d4587e 100644
--- a/lib/leap_cli/remote/tasks.rb
+++ b/lib/leap_cli/remote/tasks.rb
@@ -60,8 +60,8 @@ task :install_prerequisites, :max_hosts => MAX_HOSTS do
run %[#{apt_get} install $( (egrep -q '(^wheezy|^7\.)' /etc/debian_version && echo #{leap.required_wheezy_packages}) || echo #{leap.required_packages} )]
end
#run "locale-gen"
- leap.mkdirs("/etc/leap", "/srv/leap")
- run "chmod 0755 /etc/leap"
+ leap.mkdirs Leap::Platform.hiera_dir
+ run "chmod 0755 #{Leap::Platform.hiera_dir}"
leap.mark_initialized
end