blimpy 0.3.4 → 0.3.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,7 @@
1
1
  require 'blimpy/helpers/state'
2
2
  require 'blimpy/livery'
3
3
  require 'blimpy/keys'
4
+ require 'blimpy/securitygroups'
4
5
  require 'blimpy/boxes'
5
6
 
6
7
  module Blimpy
@@ -8,7 +9,7 @@ module Blimpy
8
9
  include Blimpy::Helpers::State
9
10
 
10
11
  attr_reader :allowed_regions, :region
11
- attr_accessor :image_id, :flavor, :group
12
+ attr_accessor :image_id, :flavor, :group, :ports
12
13
  attr_accessor :name, :tags, :fleet_id, :username, :livery
13
14
 
14
15
 
@@ -33,6 +34,7 @@ module Blimpy
33
34
  @group = nil
34
35
  @name = 'Unnamed Box'
35
36
  @tags = {}
37
+ @ports = []
36
38
  @server = server
37
39
  @fleet_id = 0
38
40
  @ssh_connected = false
@@ -46,10 +46,12 @@ module Blimpy::Boxes
46
46
  tags = @tags.merge({:Name => @name, :CreatedBy => 'Blimpy', :BlimpyFleetId => @fleet_id})
47
47
 
48
48
  Blimpy::Keys.import_key(fog)
49
+ generated_group = Blimpy::SecurityGroups.ensure_group(fog, @ports + [22])
50
+ groups = [@group, generated_group].compact
49
51
  fog.servers.create(:image_id => @image_id,
50
52
  :flavor_id => @flavor,
51
53
  :key_name => Blimpy::Keys.key_name,
52
- :groups => [@group],
54
+ :groups => groups,
53
55
  :tags => tags)
54
56
  end
55
57
  end
@@ -116,7 +116,7 @@ module Blimpy
116
116
  Blimpy.fleet do |fleet|
117
117
  fleet.add(:aws) do |ship|
118
118
  ship.name = 'Excelsior'
119
- ship.group = 'default'
119
+ ship.ports = [22, 8080]
120
120
  end
121
121
  end
122
122
  """)
@@ -0,0 +1,37 @@
1
+ require 'set'
2
+ require 'zlib'
3
+
4
+ module Blimpy
5
+ module SecurityGroups
6
+ def self.group_id(ports)
7
+ if ports.nil? or ports.empty?
8
+ return nil
9
+ end
10
+
11
+ ports = Set.new(ports)
12
+ # Lolwut, #hash is inconsistent between ruby processes
13
+ "Blimpy-#{Zlib.crc32(ports.inspect)}"
14
+ end
15
+
16
+ def self.ensure_group(fog, ports)
17
+ name = group_id(ports)
18
+ ports = Set.new(ports)
19
+
20
+ exists = fog.security_groups.get(name)
21
+
22
+ if exists.nil?
23
+ create_group(fog, ports)
24
+ end
25
+ name
26
+ end
27
+
28
+ def self.create_group(fog, ports)
29
+ name = group_id(ports)
30
+ group = fog.security_groups.create(:name => name,
31
+ :description => "Custom Blimpy security group for #{ports.to_a}")
32
+ ports.each do |port|
33
+ group.authorize_port_range(port .. port)
34
+ end
35
+ end
36
+ end
37
+ end
@@ -1,3 +1,3 @@
1
1
  module Blimpy
2
- VERSION = "0.3.4"
2
+ VERSION = "0.3.5"
3
3
  end
@@ -0,0 +1,55 @@
1
+ require 'spec_helper'
2
+ require 'blimpy/securitygroups'
3
+
4
+ describe Blimpy::SecurityGroups do
5
+ let(:fog) { mock('Fog object') }
6
+ let(:ports) { [22, 8080] }
7
+
8
+ describe '#group_id' do
9
+ it 'should return nil for an empty port Array' do
10
+ subject.group_id([]).should be_nil
11
+ end
12
+
13
+ context 'with a known ID' do
14
+ let(:known_id) { 3548764514 }
15
+
16
+ it 'should generate the right string for [1, 2]' do
17
+ subject.group_id([1, 2]).should == "Blimpy-#{known_id}"
18
+ end
19
+
20
+ it 'should generate the identical string for [1, 2, 1]' do
21
+ subject.group_id([1, 2, 1]).should == "Blimpy-#{known_id}"
22
+ end
23
+ end
24
+ end
25
+
26
+ describe '#ensure_group' do
27
+ context 'for a group that exists' do
28
+ it 'should bail and not try to create the group' do
29
+ fog.stub_chain(:security_groups, :get).and_return(true)
30
+ subject.should_receive(:create_group).never
31
+ subject.should_receive(:group_id).and_return('fake-id')
32
+ name = subject.ensure_group(fog, ports)
33
+ name.should == 'fake-id'
34
+ end
35
+ end
36
+
37
+ context "for a group that doesn't exist" do
38
+ it 'should create the group' do
39
+ fog.stub_chain(:security_groups, :get).and_return(nil)
40
+ subject.should_receive(:create_group).once
41
+ subject.ensure_group(fog, ports)
42
+ end
43
+ end
44
+ end
45
+
46
+ describe '#create_group' do
47
+ let(:group) { mock('Fog SecurityGroup') }
48
+ it 'should authorize the port ranges for every port' do
49
+ fog.stub_chain(:security_groups, :create).and_return(group)
50
+ group.should_receive(:authorize_port_range).with(22..22)
51
+ group.should_receive(:authorize_port_range).with(8080..8080)
52
+ subject.create_group(fog, ports)
53
+ end
54
+ end
55
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blimpy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.3.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-05-20 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: fog
16
- requirement: &13269540 !ruby/object:Gem::Requirement
16
+ requirement: &7711400 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *13269540
24
+ version_requirements: *7711400
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: thor
27
- requirement: &13269100 !ruby/object:Gem::Requirement
27
+ requirement: &7710980 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *13269100
35
+ version_requirements: *7710980
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: minitar
38
- requirement: &13268640 !ruby/object:Gem::Requirement
38
+ requirement: &7710540 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *13268640
46
+ version_requirements: *7710540
47
47
  description: Blimpy is a tool for managing a fleet of machines in the CLOUD!
48
48
  email:
49
49
  - tyler@monkeypox.org
@@ -79,6 +79,7 @@ files:
79
79
  - lib/blimpy/helpers/state.rb
80
80
  - lib/blimpy/keys.rb
81
81
  - lib/blimpy/livery.rb
82
+ - lib/blimpy/securitygroups.rb
82
83
  - lib/blimpy/version.rb
83
84
  - spec/blimpy/box_spec.rb
84
85
  - spec/blimpy/boxes/aws_spec.rb
@@ -88,6 +89,7 @@ files:
88
89
  - spec/blimpy/helpers/state_spec.rb
89
90
  - spec/blimpy/keys_spec.rb
90
91
  - spec/blimpy/livery_spec.rb
92
+ - spec/blimpy/securitygroups_spec.rb
91
93
  - spec/blimpy_spec.rb
92
94
  - spec/spec_helper.rb
93
95
  homepage: https://github.com/rtyler/blimpy
@@ -132,5 +134,6 @@ test_files:
132
134
  - spec/blimpy/helpers/state_spec.rb
133
135
  - spec/blimpy/keys_spec.rb
134
136
  - spec/blimpy/livery_spec.rb
137
+ - spec/blimpy/securitygroups_spec.rb
135
138
  - spec/blimpy_spec.rb
136
139
  - spec/spec_helper.rb