summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorelijah <elijah@riseup.net>2016-02-02 17:58:44 -0800
committerelijah <elijah@riseup.net>2016-02-23 09:50:58 -0800
commit8eec2d89983934868c9be07d55825cbe3bdcdaaf (patch)
treee0c02a4d625828132f482a1838306e20a4a8494e
parentda2c743faaccd26604c4c26fbb1557934688eb4a (diff)
added templates for `leap node add`, so that new nodes can get default values set in their initial .json file.
-rw-r--r--lib/leap_cli/commands/list.rb2
-rw-r--r--lib/leap_cli/commands/node.rb30
-rw-r--r--platform.rb2
-rw-r--r--provider_base/services/couchdb.json2
-rw-r--r--provider_base/templates/common.json3
-rw-r--r--provider_base/templates/couchdb.json5
-rw-r--r--provider_base/templates/openvpn.json7
7 files changed, 46 insertions, 5 deletions
diff --git a/lib/leap_cli/commands/list.rb b/lib/leap_cli/commands/list.rb
index c562b59b..aa425432 100644
--- a/lib/leap_cli/commands/list.rb
+++ b/lib/leap_cli/commands/list.rb
@@ -52,7 +52,7 @@ module LeapCli; module Commands
elsif prop_value == ""
"empty"
elsif prop_value.is_a? LeapCli::Config::Object
- node[prop].dump_json(:compact) # TODO: add option of getting pre-evaluation values.
+ node[prop].dump_json(:format => :compact) # TODO: add option of getting pre-evaluation values.
else
prop_value.to_s
end
diff --git a/lib/leap_cli/commands/node.rb b/lib/leap_cli/commands/node.rb
index ecd11f5e..cc352762 100644
--- a/lib/leap_cli/commands/node.rb
+++ b/lib/leap_cli/commands/node.rb
@@ -33,11 +33,13 @@ module LeapCli; module Commands
if options[:local]
node['ip_address'] = pick_next_vagrant_ip_address
end
- seed_node_data(node, args[1..-1])
+ seed_node_data_from_cmd_line(node, args[1..-1])
+ seed_node_data_from_template(node)
validate_ip_address(node)
begin
- write_file! [:node_config, name], node.dump_json + "\n"
node['name'] = name
+ json = node.dump_json(:exclude => ['name'])
+ write_file!([:node_config, name], json + "\n")
if file_exists? :ca_cert, :ca_key
generate_cert_for_node(manager.reload_node!(node))
end
@@ -91,7 +93,7 @@ module LeapCli; module Commands
node
end
- def seed_node_data(node, args)
+ def seed_node_data_from_cmd_line(node, args)
args.each do |seed|
key, value = seed.split(':', 2)
value = format_seed_value(value)
@@ -111,6 +113,23 @@ module LeapCli; module Commands
end
end
+ #
+ # load "new node template" information into the `node`, modifying `node`.
+ # values in the template will not override existing node values.
+ #
+ def seed_node_data_from_template(node)
+ return unless manager.respond_to?(:template)
+ node.inherit_from!(manager.template('common'))
+ [node['services']].flatten.each do |service|
+ if service
+ template = manager.template(service)
+ if template
+ node.inherit_from!(template)
+ end
+ end
+ end
+ end
+
def remove_node_files(node_name)
(Leap::Platform.node_files + [:node_files_dir]).each do |path|
remove_file! [path, node_name]
@@ -142,6 +161,11 @@ module LeapCli; module Commands
end
def validate_ip_address(node)
+ if node['ip_address'] == "REQUIRED"
+ bail! do
+ log :error, "ip_address is not set. Specify with `leap node add NAME ip_address:ADDRESS`."
+ end
+ end
IPAddr.new(node['ip_address'])
rescue ArgumentError
bail! do
diff --git a/platform.rb b/platform.rb
index 8433416e..323ba4ea 100644
--- a/platform.rb
+++ b/platform.rb
@@ -31,6 +31,7 @@ Leap::Platform.define do
:files_dir => 'files',
:nodes_dir => 'nodes',
:services_dir => 'services',
+ :templates_dir => 'templates',
:tags_dir => 'tags',
:node_files_dir => 'files/nodes/#{arg}',
@@ -41,6 +42,7 @@ Leap::Platform.define do
:node_config => 'nodes/#{arg}.json',
:service_config => 'services/#{arg}.json',
:tag_config => 'tags/#{arg}.json',
+ :template_config => 'templates/#{arg}.json',
# input config files, environmentally scoped
:provider_env_config => 'provider.#{arg}.json',
diff --git a/provider_base/services/couchdb.json b/provider_base/services/couchdb.json
index 30cb53d1..167bbf7d 100644
--- a/provider_base/services/couchdb.json
+++ b/provider_base/services/couchdb.json
@@ -9,7 +9,7 @@
},
"couch": {
"port": 5984,
- "mode": "plain",
+ "mode": "multimaster",
"users": {
"admin": {
"username": "admin",
diff --git a/provider_base/templates/common.json b/provider_base/templates/common.json
new file mode 100644
index 00000000..a7675b15
--- /dev/null
+++ b/provider_base/templates/common.json
@@ -0,0 +1,3 @@
+{
+ "ip_address": "REQUIRED"
+} \ No newline at end of file
diff --git a/provider_base/templates/couchdb.json b/provider_base/templates/couchdb.json
new file mode 100644
index 00000000..34b60915
--- /dev/null
+++ b/provider_base/templates/couchdb.json
@@ -0,0 +1,5 @@
+{
+ "couch": {
+ "mode": "plain"
+ }
+}
diff --git a/provider_base/templates/openvpn.json b/provider_base/templates/openvpn.json
new file mode 100644
index 00000000..cbe183e8
--- /dev/null
+++ b/provider_base/templates/openvpn.json
@@ -0,0 +1,7 @@
+{
+ "openvpn": {
+ "gateway_address": "REQUIRED",
+ "ports": ["443"],
+ "protocols": ["tcp"]
+ }
+}