summaryrefslogtreecommitdiff
path: root/lib/leap_cli/config
diff options
context:
space:
mode:
authorelijah <elijah@riseup.net>2016-07-21 00:55:12 -0700
committerelijah <elijah@riseup.net>2016-08-23 13:37:34 -0700
commit205b61dfe721e6d88fc06b050a0497eeb35f4e02 (patch)
tree518b5799f56d9e224d7ca2d85b3d29ef0c01b3c6 /lib/leap_cli/config
parent6fab56fb40256fb2e541ee3ad61490f03254d38e (diff)
added 'leap vm' command
Diffstat (limited to 'lib/leap_cli/config')
-rw-r--r--lib/leap_cli/config/cloud.rb64
-rw-r--r--lib/leap_cli/config/environment.rb10
-rw-r--r--lib/leap_cli/config/filter.rb7
-rw-r--r--lib/leap_cli/config/manager.rb23
-rw-r--r--lib/leap_cli/config/node.rb13
5 files changed, 99 insertions, 18 deletions
diff --git a/lib/leap_cli/config/cloud.rb b/lib/leap_cli/config/cloud.rb
new file mode 100644
index 00000000..e3e5c1f1
--- /dev/null
+++ b/lib/leap_cli/config/cloud.rb
@@ -0,0 +1,64 @@
+# encoding: utf-8
+#
+# A class for the cloud.json file
+#
+# Example format:
+#
+# {
+# "my_aws": {
+# "api": "aws",
+# "vendor": "aws",
+# "auth": {
+# "region": "us-west-2",
+# "aws_access_key_id": "xxxxxxxxxxxxxxx",
+# "aws_secret_access_key": "xxxxxxxxxxxxxxxxxxxxxxxxxx"
+# },
+# "default_image": "ami-98e114f8",
+# "default_options": {
+# "InstanceType": "t2.nano"
+# }
+# }
+# }
+#
+
+module LeapCli; module Config
+
+ # http://fog.io/about/supported_services.html
+ VM_APIS = {
+ 'aws' => 'fog-aws',
+ 'google' => 'fog-google',
+ 'libvirt' => 'fog-libvirt',
+ 'openstack' => 'fog-openstack',
+ 'rackspace' => 'fog-rackspace'
+ }
+
+ class Cloud < Hash
+ def initialize(env=nil)
+ end
+
+ #
+ # returns hash, each key is the name of an API that is
+ # needed and the value is the name of the gem.
+ #
+ # only provider APIs that are required because they are present
+ # in cloud.json are included.
+ #
+ def required_gems
+ required = {}
+ self.each do |name, conf|
+ api = conf["api"]
+ required_gems[api] = VM_APIS[api]
+ end
+ return required
+ end
+
+ #
+ # returns an array of all possible providers
+ #
+ def possible_apis
+ VM_APIS.keys
+ end
+
+ end
+
+end; end
diff --git a/lib/leap_cli/config/environment.rb b/lib/leap_cli/config/environment.rb
index 398fd023..dadd9eaf 100644
--- a/lib/leap_cli/config/environment.rb
+++ b/lib/leap_cli/config/environment.rb
@@ -30,10 +30,12 @@ module LeapCli; module Config
# shared, non-inheritable
def nodes; @@nodes; end
def secrets; @@secrets; end
+ def cloud; @@cloud; end
def initialize(manager, name, search_dir, parent, options={})
@@nodes ||= nil
@@secrets ||= nil
+ @@cloud ||= nil
@manager = manager
@name = name
@@ -64,6 +66,7 @@ module LeapCli; module Config
@partials = Config::ObjectList.new
@provider = Config::Provider.new
@common = Config::Object.new
+ @cloud = Config::Cloud.new
return
end
@@ -89,7 +92,9 @@ module LeapCli; module Config
@partials.values.each {|partial| partial.delete('name'); }
#
- # shared: currently non-inheritable
+ # shared
+ #
+ # shared configs are also non-inheritable
# load the first ones we find, and only those.
#
if @@nodes.nil? || @@nodes.empty?
@@ -98,6 +103,9 @@ module LeapCli; module Config
if @@secrets.nil? || @@secrets.empty?
@@secrets = load_json(Path.named_path(:secrets_config, search_dir), Config::Secrets, options)
end
+ if @@cloud.nil? || @@cloud.empty?
+ @@cloud = load_json(Path.named_path(:cloud_config, search_dir), Config::Cloud)
+ end
end
#
diff --git a/lib/leap_cli/config/filter.rb b/lib/leap_cli/config/filter.rb
index 27502577..07424894 100644
--- a/lib/leap_cli/config/filter.rb
+++ b/lib/leap_cli/config/filter.rb
@@ -29,6 +29,7 @@ module LeapCli
# options -- hash, possible keys include
# :nopin -- disregard environment pinning
# :local -- if false, disallow local nodes
+ # :warning -- if false, don't print a warning when no nodes are found.
#
# A nil value in the filters array indicates
# the default environment. This is in order to support
@@ -139,9 +140,11 @@ module LeapCli
return @manager.env('_all_').services[name].node_list
elsif @manager.tags[name]
return @manager.env('_all_').tags[name].node_list
- else
+ elsif @options[:warning] != false
LeapCli.log :warning, "filter '#{name}' does not match any node names, tags, services, or environments."
return Config::ObjectList.new
+ else
+ return Config::ObjectList.new
end
else
node_list = Config::ObjectList.new
@@ -153,7 +156,7 @@ module LeapCli
@environments.each do |env|
node_list.merge!(@manager.env(env).tags[name].node_list)
end
- else
+ elsif @options[:warning] != false
LeapCli.log :warning, "filter '#{name}' does not match any node names, tags, services, or environments."
end
return node_list
diff --git a/lib/leap_cli/config/manager.rb b/lib/leap_cli/config/manager.rb
index 62eaa894..b42f1ae0 100644
--- a/lib/leap_cli/config/manager.rb
+++ b/lib/leap_cli/config/manager.rb
@@ -315,19 +315,20 @@ module LeapCli
end
# inherit from tags
+ node['tags'] = (node['tags'] || []).to_a
if node.vagrant?
- node['tags'] = (node['tags'] || []).to_a + ['local']
+ node['tags'] << 'local'
+ elsif node['vm']
+ node['tags'] << 'vm'
end
- if node['tags']
- node['tags'].to_a.each do |node_tag|
- tag = node_env.tags[node_tag]
- if tag.nil?
- msg = 'in node "%s": the tag "%s" does not exist.' % [node['name'], node_tag]
- log 0, :error, msg
- raise LeapCli::ConfigError.new(node, "error " + msg) if throw_exceptions
- else
- new_node.deep_merge!(tag)
- end
+ node['tags'].each do |node_tag|
+ tag = node_env.tags[node_tag]
+ if tag.nil?
+ msg = 'in node "%s": the tag "%s" does not exist.' % [node['name'], node_tag]
+ log 0, :error, msg
+ raise LeapCli::ConfigError.new(node, "error " + msg) if throw_exceptions
+ else
+ new_node.deep_merge!(tag)
end
end
diff --git a/lib/leap_cli/config/node.rb b/lib/leap_cli/config/node.rb
index 2d76b814..23abdee3 100644
--- a/lib/leap_cli/config/node.rb
+++ b/lib/leap_cli/config/node.rb
@@ -9,11 +9,8 @@ module LeapCli; module Config
class Node < Object
attr_accessor :file_paths
- def initialize(environment=nil) #, name=nil)
+ def initialize(environment=nil)
super(environment)
- #if name
- # self['name'] = name
- #end
@node = self
@file_paths = []
end
@@ -38,6 +35,14 @@ module LeapCli; module Config
return vagrant_range.include?(ip_addr)
end
+ def vm?
+ self['vm']
+ end
+
+ def vm_id?
+ self['vm.id'] && !self['vm.id'].empty?
+ end
+
#
# Return a hash table representation of ourselves, with the key equal to the @node.name,
# and the value equal to the fields specified in *keys.