bosh_aws_cpi 0.6.0 → 0.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/cloud/aws/cloud.rb +16 -0
- data/lib/cloud/aws/dynamic_network.rb +2 -2
- data/lib/cloud/aws/network_configurator.rb +14 -8
- data/lib/cloud/aws/version.rb +1 -1
- data/spec/spec_helper.rb +6 -1
- data/spec/unit/configure_networks_spec.rb +23 -2
- data/spec/unit/create_vm_spec.rb +10 -5
- data/spec/unit/network_configurator_spec.rb +4 -4
- metadata +8 -8
data/lib/cloud/aws/cloud.rb
CHANGED
@@ -261,6 +261,10 @@ module Bosh::AwsCloud
|
|
261
261
|
end
|
262
262
|
end
|
263
263
|
|
264
|
+
# Configures network for a running instance
|
265
|
+
# @param [String] instance_id instance identifier
|
266
|
+
# @param [Hash] network_spec network properties
|
267
|
+
# @raises [Bosh::Clouds:NotSupported] if the security groups change
|
264
268
|
def configure_networks(instance_id, network_spec)
|
265
269
|
with_thread_name("configure_networks(#{instance_id}, ...)") do
|
266
270
|
@logger.info("Configuring `#{instance_id}' to use the following " \
|
@@ -269,6 +273,18 @@ module Bosh::AwsCloud
|
|
269
273
|
network_configurator = NetworkConfigurator.new(network_spec)
|
270
274
|
instance = @ec2.instances[instance_id]
|
271
275
|
|
276
|
+
actual = instance.security_groups.collect {|sg| sg.name }.sort
|
277
|
+
new = network_configurator.security_groups(@default_security_groups)
|
278
|
+
|
279
|
+
# If the security groups change, we need to recreate the VM
|
280
|
+
# as you can't change the security group of a running instance,
|
281
|
+
# we need to send the InstanceUpdater a request to do it for us
|
282
|
+
unless actual == new
|
283
|
+
raise Bosh::Clouds::NotSupported,
|
284
|
+
"security groups change requires VM recreation: %s to %s" %
|
285
|
+
[actual.join(", "), new.join(", ")]
|
286
|
+
end
|
287
|
+
|
272
288
|
network_configurator.configure(@ec2, instance)
|
273
289
|
|
274
290
|
update_agent_settings(instance) do |settings|
|
@@ -17,8 +17,8 @@ module Bosh::AwsCloud
|
|
17
17
|
##
|
18
18
|
# Configures EC2 dynamic network. Right now it's a no-op,
|
19
19
|
# as dynamic networks are completely managed by EC2
|
20
|
-
# @param [AWS:EC2] instance EC2 client
|
21
|
-
# @param [AWS::EC2::Instance] EC2 instance to configure
|
20
|
+
# @param [AWS:EC2] ec2 instance EC2 client
|
21
|
+
# @param [AWS::EC2::Instance] instance EC2 instance to configure
|
22
22
|
def configure(ec2, instance)
|
23
23
|
end
|
24
24
|
|
@@ -37,14 +37,14 @@ module Bosh::AwsCloud
|
|
37
37
|
cloud_error("More than one dynamic network for `#{name}'")
|
38
38
|
else
|
39
39
|
@dynamic_network = DynamicNetwork.new(name, spec)
|
40
|
-
|
41
|
-
extract_security_groups(spec)
|
40
|
+
@security_groups += extract_security_groups(spec)
|
42
41
|
end
|
43
42
|
when "vip"
|
44
43
|
if @vip_network
|
45
44
|
cloud_error("More than one vip network for `#{name}'")
|
46
45
|
else
|
47
46
|
@vip_network = VipNetwork.new(name, spec)
|
47
|
+
@security_groups += extract_security_groups(spec)
|
48
48
|
end
|
49
49
|
else
|
50
50
|
cloud_error("Invalid network type `#{network_type}': AWS CPI " \
|
@@ -58,6 +58,9 @@ module Bosh::AwsCloud
|
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
61
|
+
# Applies network configuration to the vm
|
62
|
+
# @param [AWS:EC2] ec2 instance EC2 client
|
63
|
+
# @param [AWS::EC2::Instance] instance EC2 instance to configure
|
61
64
|
def configure(ec2, instance)
|
62
65
|
@dynamic_network.configure(ec2, instance)
|
63
66
|
|
@@ -84,27 +87,30 @@ module Bosh::AwsCloud
|
|
84
87
|
# @return [Array] security groups
|
85
88
|
def security_groups(default)
|
86
89
|
if @security_groups.empty? && default
|
87
|
-
|
90
|
+
default.sort
|
88
91
|
else
|
89
|
-
|
92
|
+
@security_groups.sort
|
90
93
|
end
|
91
94
|
end
|
92
95
|
|
96
|
+
private
|
97
|
+
|
93
98
|
##
|
94
99
|
# Extracts the security groups from the network configuration
|
95
100
|
# @param [Hash] network_spec Network specification
|
96
101
|
# @raise [ArgumentError] if the security groups in the network_spec
|
97
102
|
# is not an Array
|
98
|
-
def extract_security_groups(
|
99
|
-
if
|
100
|
-
cloud_properties =
|
103
|
+
def extract_security_groups(network_spec)
|
104
|
+
if network_spec && network_spec["cloud_properties"]
|
105
|
+
cloud_properties = network_spec["cloud_properties"]
|
101
106
|
if cloud_properties && cloud_properties["security_groups"]
|
102
107
|
unless cloud_properties["security_groups"].is_a?(Array)
|
103
108
|
raise ArgumentError, "security groups must be an Array"
|
104
109
|
end
|
105
|
-
|
110
|
+
return cloud_properties["security_groups"]
|
106
111
|
end
|
107
112
|
end
|
113
|
+
[]
|
108
114
|
end
|
109
115
|
|
110
116
|
end
|
data/lib/cloud/aws/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -8,9 +8,28 @@ describe Bosh::AwsCloud::Cloud do
|
|
8
8
|
@registry = mock_registry
|
9
9
|
end
|
10
10
|
|
11
|
+
it "forces recreation when security groups differ" do
|
12
|
+
sec_grp = double("security_group", :name => "newgroup")
|
13
|
+
instance = double("instance",
|
14
|
+
:id => "i-foobar",
|
15
|
+
:security_groups => [sec_grp])
|
16
|
+
|
17
|
+
cloud = mock_cloud do |ec2|
|
18
|
+
ec2.instances.stub(:[]).
|
19
|
+
with("i-foobar").
|
20
|
+
and_return(instance)
|
21
|
+
end
|
22
|
+
|
23
|
+
lambda {
|
24
|
+
cloud.configure_networks("i-foobar", combined_network_spec)
|
25
|
+
}.should raise_error Bosh::Clouds::NotSupported
|
26
|
+
end
|
27
|
+
|
11
28
|
it "adds elastic ip from to the instance for vip network" do
|
29
|
+
sec_grp = double("security_group", :name => "default")
|
12
30
|
instance = double("instance",
|
13
|
-
:id => "i-foobar"
|
31
|
+
:id => "i-foobar",
|
32
|
+
:security_groups => [sec_grp])
|
14
33
|
|
15
34
|
cloud = mock_cloud do |ec2|
|
16
35
|
ec2.instances.stub(:[]).
|
@@ -33,8 +52,10 @@ describe Bosh::AwsCloud::Cloud do
|
|
33
52
|
end
|
34
53
|
|
35
54
|
it "removes elastic ip from the instance if vip network is gone" do
|
55
|
+
sec_grp = double("security_group", :name => "default")
|
36
56
|
instance = double("instance",
|
37
|
-
:id => "i-foobar"
|
57
|
+
:id => "i-foobar",
|
58
|
+
:security_groups => [sec_grp])
|
38
59
|
|
39
60
|
cloud = mock_cloud do |ec2|
|
40
61
|
ec2.instances.stub(:[]).
|
data/spec/unit/create_vm_spec.rb
CHANGED
@@ -54,14 +54,16 @@ describe Bosh::AwsCloud::Cloud, "create_vm" do
|
|
54
54
|
}
|
55
55
|
}
|
56
56
|
|
57
|
+
sec_grp = double("security_group", :name => "default")
|
57
58
|
instance = double("instance",
|
58
59
|
:id => "i-test",
|
59
|
-
:elastic_ip => nil
|
60
|
+
:elastic_ip => nil,
|
61
|
+
:security_groups => [sec_grp])
|
60
62
|
client = double("client", :describe_images => fake_image_set)
|
61
63
|
|
62
64
|
cloud = mock_cloud do |ec2|
|
63
65
|
ec2.instances.should_receive(:create).
|
64
|
-
with(ec2_params(user_data)).
|
66
|
+
with(ec2_params(user_data, %w[default])).
|
65
67
|
and_return(instance)
|
66
68
|
ec2.should_receive(:client).and_return(client)
|
67
69
|
end
|
@@ -90,10 +92,11 @@ describe Bosh::AwsCloud::Cloud, "create_vm" do
|
|
90
92
|
|
91
93
|
instance = double("instance",
|
92
94
|
:id => "i-test",
|
93
|
-
:elastic_ip => nil
|
95
|
+
:elastic_ip => nil,
|
96
|
+
:security_groups => [])
|
94
97
|
client = double("client", :describe_images => fake_image_set)
|
95
98
|
|
96
|
-
security_groups = %w[foo
|
99
|
+
security_groups = %w[bar foo]
|
97
100
|
network_spec = dynamic_network_spec
|
98
101
|
network_spec["cloud_properties"] = {
|
99
102
|
"security_groups" => security_groups
|
@@ -120,9 +123,11 @@ describe Bosh::AwsCloud::Cloud, "create_vm" do
|
|
120
123
|
end
|
121
124
|
|
122
125
|
it "associates instance with elastic ip if vip network is provided" do
|
126
|
+
sec_grp = double("security_group", :name => "default")
|
123
127
|
instance = double("instance",
|
124
128
|
:id => "i-test",
|
125
|
-
:elastic_ip => nil
|
129
|
+
:elastic_ip => nil,
|
130
|
+
:security_groups => [sec_grp])
|
126
131
|
client = double("client", :describe_images => fake_image_set)
|
127
132
|
|
128
133
|
cloud = mock_cloud do |ec2|
|
@@ -17,7 +17,7 @@ describe Bosh::AwsCloud::NetworkConfigurator do
|
|
17
17
|
end
|
18
18
|
|
19
19
|
describe "security groups" do
|
20
|
-
it "should
|
20
|
+
it "should be extracted from both dynamic and vip network" do
|
21
21
|
spec = {}
|
22
22
|
spec["network_a"] = dynamic_network_spec
|
23
23
|
set_security_groups(spec["network_a"], %w[foo])
|
@@ -25,12 +25,12 @@ describe Bosh::AwsCloud::NetworkConfigurator do
|
|
25
25
|
set_security_groups(spec["network_b"], %w[bar])
|
26
26
|
|
27
27
|
nc = Bosh::AwsCloud::NetworkConfigurator.new(spec)
|
28
|
-
nc.security_groups(nil).should == %w[foo]
|
28
|
+
nc.security_groups(nil).should == %w[bar foo]
|
29
29
|
end
|
30
30
|
|
31
31
|
it "should return the default groups if none are extracted" do
|
32
32
|
spec = {}
|
33
|
-
spec["network_a"] =
|
33
|
+
spec["network_a"] = {"type" => "dynamic"}
|
34
34
|
|
35
35
|
nc = Bosh::AwsCloud::NetworkConfigurator.new(spec)
|
36
36
|
nc.security_groups(%w[foo]).should == %w[foo]
|
@@ -38,7 +38,7 @@ describe Bosh::AwsCloud::NetworkConfigurator do
|
|
38
38
|
|
39
39
|
it "should return an empty list if no default group is set" do
|
40
40
|
spec = {}
|
41
|
-
spec["network_a"] =
|
41
|
+
spec["network_a"] = {"type" => "dynamic"}
|
42
42
|
|
43
43
|
nc = Bosh::AwsCloud::NetworkConfigurator.new(spec)
|
44
44
|
nc.security_groups(nil).should == []
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bosh_aws_cpi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.2
|
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: 2012-
|
12
|
+
date: 2012-08-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: aws-sdk
|
@@ -34,7 +34,7 @@ dependencies:
|
|
34
34
|
requirements:
|
35
35
|
- - ! '>='
|
36
36
|
- !ruby/object:Gem::Version
|
37
|
-
version: 0.
|
37
|
+
version: 0.5.0
|
38
38
|
type: :runtime
|
39
39
|
prerelease: false
|
40
40
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -42,7 +42,7 @@ dependencies:
|
|
42
42
|
requirements:
|
43
43
|
- - ! '>='
|
44
44
|
- !ruby/object:Gem::Version
|
45
|
-
version: 0.
|
45
|
+
version: 0.5.0
|
46
46
|
- !ruby/object:Gem::Dependency
|
47
47
|
name: bosh_cpi
|
48
48
|
requirement: !ruby/object:Gem::Requirement
|
@@ -50,7 +50,7 @@ dependencies:
|
|
50
50
|
requirements:
|
51
51
|
- - ! '>='
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
version: 0.4.
|
53
|
+
version: 0.4.4
|
54
54
|
type: :runtime
|
55
55
|
prerelease: false
|
56
56
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -58,7 +58,7 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - ! '>='
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 0.4.
|
61
|
+
version: 0.4.4
|
62
62
|
- !ruby/object:Gem::Dependency
|
63
63
|
name: httpclient
|
64
64
|
requirement: !ruby/object:Gem::Requirement
|
@@ -158,7 +158,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
158
158
|
version: '0'
|
159
159
|
segments:
|
160
160
|
- 0
|
161
|
-
hash:
|
161
|
+
hash: -2760126620918151960
|
162
162
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
163
163
|
none: false
|
164
164
|
requirements:
|
@@ -167,7 +167,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
167
167
|
version: '0'
|
168
168
|
segments:
|
169
169
|
- 0
|
170
|
-
hash:
|
170
|
+
hash: -2760126620918151960
|
171
171
|
requirements: []
|
172
172
|
rubyforge_project:
|
173
173
|
rubygems_version: 1.8.24
|