orca 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- orca (0.1.0)
4
+ orca (0.2.0)
5
5
  colored
6
6
  net-sftp
7
7
  net-ssh
data/README.md CHANGED
@@ -5,7 +5,7 @@ Orca
5
5
 
6
6
  Orca is a super simple way to build and configure servers.
7
7
 
8
- If you've found yourself stuck in the gap between deployment tools like Capistrano and full blown infrastructure tools like Puppet and Chef then Orca is probably for you.
8
+ If you've found yourself stuck in the gap between deployment tools like Capistrano and full blown infrastructure tools like Puppet and Chef then Orca is probably for you. This is especially the case if you choose to cycle machines and prefer baking from scratch when changes are required rather than attempting to converge system state (although you can build convergent systems using Orca if you wish).
9
9
 
10
10
 
11
11
  What problem does Orca try to solve?
@@ -42,7 +42,7 @@ Orca intentionally skirts around some important thengs that may or may not matte
42
42
  Orca doesn't...
43
43
 
44
44
  - try to scale beyond a smallish number of nodes
45
- - have any algorithyms that attempt to run periodically and converge divergent configurations
45
+ - have any algorithms that attempt to run periodically and converge divergent configurations
46
46
  - abstract the differences of different host OSes
47
47
  - provide a server to supervise infrastructure configuration
48
48
 
@@ -50,9 +50,13 @@ Orca doesn't...
50
50
  Installation
51
51
  ------------
52
52
 
53
- To install orca you will need to be running Ruby 1.9 or 2.0 and then install the orca gem from this repository...
53
+ To install orca you will need to be running Ruby 1.9 or 2.0 and then install the orca gem...
54
54
 
55
- gem 'orca', :git => 'git@github.com:andykent/orca.git'
55
+ gem install orca
56
+
57
+ or ideally add it to your gemfile...
58
+
59
+ gem 'orca'
56
60
 
57
61
 
58
62
  Command Line Usage
@@ -60,7 +64,7 @@ Command Line Usage
60
64
 
61
65
  To get started from within your projct you can run...
62
66
 
63
- bundle exec orca init .
67
+ orca init .
64
68
 
65
69
  This will create a config/orca.rb file for you to get started with.
66
70
 
@@ -107,3 +111,24 @@ Orca packages are written in a Ruby based DSL. It's really simple to learn in le
107
111
  trigger('gem:exists', 'bundler')
108
112
  end
109
113
  end
114
+
115
+
116
+
117
+ Extensions
118
+ ----------
119
+
120
+ The core of Orca doesn't have any platform specific logic but is designed to be a foundation to build apon. Extensions can be written in their own files, projects or gems, simply `require 'orca'` and then use the `Orca.extension` helper.
121
+
122
+ Some example extensions are included in this repo and can be required into your orca.rb file if you need them...
123
+
124
+ `require "orca/extensions/apt"` - Adds support for specifying aptitude dependancies with the `apt_package` helper.
125
+
126
+ `relative "orca/extensions/file_sync"` - Adds support for syncing and converging local/remove files with the `file` action.
127
+
128
+
129
+ Extras
130
+ ------
131
+
132
+ *Vagrant Provisioner Plugin*
133
+ https://github.com/andykent/vagrant-orca
134
+ Allows you to completely provision a machine with `vagrant up`
data/lib/orca.rb CHANGED
@@ -35,6 +35,7 @@ end
35
35
  require_relative "./orca/package"
36
36
  require_relative "./orca/package_index"
37
37
  require_relative "./orca/node"
38
+ require_relative "./orca/group"
38
39
  require_relative "./orca/runner"
39
40
  require_relative "./orca/resolver"
40
41
  require_relative "./orca/execution_context"
@@ -42,7 +43,4 @@ require_relative "./orca/local_file"
42
43
  require_relative "./orca/remote_file"
43
44
  require_relative "./orca/dsl"
44
45
  require_relative "./orca/suite"
45
- require_relative "./orca/cli"
46
-
47
- require_relative "./orca/extensions/apt"
48
- require_relative "./orca/extensions/file_sync"
46
+ require_relative "./orca/cli"
data/lib/orca/cli.rb CHANGED
@@ -3,23 +3,24 @@ class Orca::Cli < Thor
3
3
 
4
4
  source_root File.join(File.dirname(__FILE__), *%w[.. .. config])
5
5
 
6
- class_option :demonstrate, :type => :boolean, :desc => "Don't actually run any commands on the node, just pretend."
6
+ class_option :demonstrate, :type => :boolean, :desc => "Don't actually run any commands on the group, just pretend."
7
7
  class_option :file, :banner => 'ORCA_FILE', :desc => "path to the orca.rb file to load, defaults to ./orca/orca.rb"
8
8
  class_option :throw, :type => :boolean, :desc => "Don't pretty print errors, raise with a stack trace."
9
+ class_option :sequential, :type => :boolean, :desc => "Don't run tasks in parrallel across nodes."
9
10
 
10
- desc "apply PACKAGE_NAME NODE_NAME", "apply the given package onto the given named node"
11
- def apply(package, node)
12
- run_command(package, node, :apply)
11
+ desc "apply PACKAGE_NAME GROUP_OR_NODE_NAME", "apply the given package onto the given named group"
12
+ def apply(package, group)
13
+ run_command(package, group, :apply)
13
14
  end
14
15
 
15
- desc "remove PACKAGE_NAME NODE_NAME", "remove the given package onto the given named node"
16
- def remove(package, node)
17
- run_command(package, node, :remove)
16
+ desc "remove PACKAGE_NAME GROUP_OR_NODE_NAME", "remove the given package onto the given named group"
17
+ def remove(package, group)
18
+ run_command(package, group, :remove)
18
19
  end
19
20
 
20
- desc "validate PACKAGE_NAME NODE_NAME", "run validation steps on the given named node"
21
- def validate(package, node)
22
- run_command(package, node, :validate)
21
+ desc "validate PACKAGE_NAME GROUP_OR_NODE_NAME", "run validation steps on the given named group"
22
+ def validate(package, group)
23
+ run_command(package, group, :validate)
23
24
  end
24
25
 
25
26
  desc "init", "initialize the current directory with a orca/orca.rb"
@@ -29,15 +30,11 @@ class Orca::Cli < Thor
29
30
 
30
31
  private
31
32
 
32
- def run_command(package, node, cmd)
33
+ def run_command(package, group, cmd)
33
34
  begin
34
- suite = Orca::Suite.new
35
+ suite = Orca::Suite.new(options)
35
36
  suite.load_file(orca_file)
36
- if options[:demonstrate]
37
- suite.demonstrate(node, package, cmd)
38
- else
39
- suite.execute(node, package, cmd)
40
- end
37
+ suite.run(group, package, cmd)
41
38
  rescue => e
42
39
  if options[:throw]
43
40
  raise e
data/lib/orca/dsl.rb CHANGED
@@ -14,5 +14,10 @@ module Orca
14
14
  def node(name, host, options={})
15
15
  Orca::Node.new(name, host, options)
16
16
  end
17
+
18
+ def group(name, nodes=[], &blk)
19
+ g = Orca::Group.new(name, nodes)
20
+ g.instance_eval(&blk) if block_given?
21
+ end
17
22
  end
18
23
  end
data/lib/orca/group.rb ADDED
@@ -0,0 +1,38 @@
1
+ class Orca::Group
2
+ class << self
3
+ def register(group)
4
+ @groups ||= {}
5
+ @groups[group.name] = group
6
+ end
7
+
8
+ def from_node(node)
9
+ new(node.name, [node])
10
+ end
11
+
12
+ def find(name)
13
+ return name if name.is_a?(Orca::Group)
14
+ return nil unless @groups
15
+ @groups[name]
16
+ end
17
+ end
18
+
19
+ attr_reader :name, :nodes
20
+
21
+ def initialize(name, nodes=[])
22
+ @name = name
23
+ @nodes = nodes
24
+ Orca::Group.register(self)
25
+ end
26
+
27
+ def node(name, host, options={})
28
+ add_node( Orca::Node.new(name, host, options) )
29
+ end
30
+
31
+ def add_node(node)
32
+ @nodes << node
33
+ end
34
+
35
+ def includes(group)
36
+ Orca::Group.find(group).nodes.each {|n| add_node(n) }
37
+ end
38
+ end
data/lib/orca/node.rb CHANGED
@@ -11,6 +11,7 @@ class Orca::Node
11
11
 
12
12
  def self.register(node)
13
13
  @nodes ||= {}
14
+ Orca::Group.from_node(node)
14
15
  @nodes[node.name] = node
15
16
  end
16
17
 
@@ -69,7 +70,7 @@ class Orca::Node
69
70
  end
70
71
 
71
72
  def log(context, msg)
72
- puts "#{self.to_s} [#{context.to_s.bold}] #{msg}"
73
+ Thread.exclusive { puts "#{self.to_s} [#{context.to_s.bold}] #{msg}" }
73
74
  end
74
75
 
75
76
  def connection
data/lib/orca/suite.rb CHANGED
@@ -1,18 +1,31 @@
1
1
  class Orca::Suite
2
2
 
3
+ def initialize(options={})
4
+ @sequential = options[:sequential]
5
+ @demonstrate = options[:demonstrate]
6
+ end
7
+
3
8
  def load_file(file)
4
9
  Orca::DSL.module_eval(File.read(file))
5
10
  end
6
11
 
7
- def execute(node_name, pkg_name, command)
8
- node = Orca::Node.find(node_name)
12
+ def run(group_name, pkg_name, command, sequential=false)
13
+ group = Orca::Group.find(group_name)
9
14
  pkg = Orca::PackageIndex.default.get(pkg_name)
10
- Orca::Runner.new(node, pkg).execute(command)
15
+ runners = group.nodes.map { |node| Orca::Runner.new(node, pkg) }
16
+ if @sequential
17
+ runners.each {|runner| exec(runner, command) }
18
+ else
19
+ threads = runners.map {|runner| Thread.new { exec(runner, command) } }
20
+ threads.each {|t| t.join }
21
+ end
11
22
  end
12
23
 
13
- def demonstrate(node_name, pkg_name, command)
14
- node = Orca::Node.find(node_name)
15
- pkg = Orca::PackageIndex.default.get(pkg_name)
16
- Orca::Runner.new(node, pkg).demonstrate(command)
24
+ def exec(runner, command)
25
+ if @demonstrate
26
+ runner.demonstrate(command)
27
+ else
28
+ runner.execute(command)
29
+ end
17
30
  end
18
31
  end
data/orca.gemspec CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |gem|
10
10
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
11
11
  gem.name = "orca"
12
12
  gem.require_paths = ["lib"]
13
- gem.version = '0.1.0'
13
+ gem.version = '0.2.0'
14
14
  gem.add_dependency('colored')
15
15
  gem.add_dependency('net-ssh')
16
16
  gem.add_dependency('net-sftp')
data/test/dsl_test.rb CHANGED
@@ -32,4 +32,20 @@ describe Orca::DSL do
32
32
  node.host.must_equal 'node-host'
33
33
  end
34
34
  end
35
+
36
+ describe "'group' command" do
37
+ it "creates a group" do
38
+ Orca::DSL.group('group-name')
39
+ group = Orca::Group.find('group-name')
40
+ group.must_be_instance_of Orca::Group
41
+ group.name.must_equal 'group-name'
42
+ end
43
+
44
+ it "evals in the group context" do
45
+ node = mock
46
+ Orca::DSL.group('group-name') { add_node(node) }
47
+ group = Orca::Group.find('group-name')
48
+ group.nodes.must_equal [node]
49
+ end
50
+ end
35
51
  end
@@ -0,0 +1,53 @@
1
+ require_relative 'test_helper'
2
+
3
+ describe Orca::Group do
4
+ describe "#from_node" do
5
+ it "creates a new group based on a node name" do
6
+ node = mock(:name => 'test-node')
7
+ Orca::Group.from_node(node)
8
+ group = Orca::Group.find('test-node')
9
+ group.must_be_instance_of(Orca::Group)
10
+ group.name.must_equal('test-node')
11
+ group.nodes.must_equal [node]
12
+ end
13
+ end
14
+
15
+ describe ".node(name, host, options)" do
16
+ it "adds a new node from parameters" do
17
+ group = Orca::Group.new('test')
18
+ group.node('mynode', 'myhost')
19
+ group.nodes.size.must_equal 1
20
+ group.nodes.first.name.must_equal 'mynode'
21
+ group.nodes.first.host.must_equal 'myhost'
22
+ end
23
+ end
24
+
25
+ describe ".add_node(node)" do
26
+ it "adds a new node by object" do
27
+ group = Orca::Group.new('test')
28
+ node = mock
29
+ group.add_node(node)
30
+ group.nodes.must_equal [node]
31
+ end
32
+ end
33
+
34
+ describe ".includes(other_group)" do
35
+ it "copied the nodes from another group" do
36
+ node = mock
37
+ group = Orca::Group.new('test-a', [node])
38
+ group2 = Orca::Group.new('test-b')
39
+ group2.nodes.must_equal []
40
+ group2.includes(group)
41
+ group2.nodes.must_equal [node]
42
+ end
43
+
44
+ it "copied the nodes from another group by name" do
45
+ node = mock
46
+ group = Orca::Group.new('test-a', [node])
47
+ group2 = Orca::Group.new('test-b')
48
+ group2.nodes.must_equal []
49
+ group2.includes('test-a')
50
+ group2.nodes.must_equal [node]
51
+ end
52
+ end
53
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: orca
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-18 00:00:00.000000000 Z
12
+ date: 2013-06-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: colored
@@ -98,6 +98,7 @@ files:
98
98
  - lib/orca/execution_context.rb
99
99
  - lib/orca/extensions/apt.rb
100
100
  - lib/orca/extensions/file_sync.rb
101
+ - lib/orca/group.rb
101
102
  - lib/orca/local_file.rb
102
103
  - lib/orca/node.rb
103
104
  - lib/orca/package.rb
@@ -109,6 +110,7 @@ files:
109
110
  - orca.gemspec
110
111
  - test/dsl_test.rb
111
112
  - test/fixtures/example.txt
113
+ - test/group_test.rb
112
114
  - test/local_file_test.rb
113
115
  - test/package_index_test.rb
114
116
  - test/package_test.rb
@@ -127,12 +129,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
127
129
  - - ! '>='
128
130
  - !ruby/object:Gem::Version
129
131
  version: '0'
132
+ segments:
133
+ - 0
134
+ hash: 1672503668912245797
130
135
  required_rubygems_version: !ruby/object:Gem::Requirement
131
136
  none: false
132
137
  requirements:
133
138
  - - ! '>='
134
139
  - !ruby/object:Gem::Version
135
140
  version: '0'
141
+ segments:
142
+ - 0
143
+ hash: 1672503668912245797
136
144
  requirements: []
137
145
  rubyforge_project:
138
146
  rubygems_version: 1.8.23
@@ -142,6 +150,7 @@ summary: Simplified Machine Building
142
150
  test_files:
143
151
  - test/dsl_test.rb
144
152
  - test/fixtures/example.txt
153
+ - test/group_test.rb
145
154
  - test/local_file_test.rb
146
155
  - test/package_index_test.rb
147
156
  - test/package_test.rb