bosh_openstack_cpi 0.0.7 → 1.5.0.pre.1113
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +0 -5
- data/USAGE.md +55 -27
- data/bin/bosh_openstack_console +2 -10
- data/lib/bosh_openstack_cpi.rb +1 -0
- data/lib/cloud/openstack.rb +7 -2
- data/lib/cloud/openstack/cloud.rb +345 -261
- data/lib/cloud/openstack/dynamic_network.rb +1 -0
- data/lib/cloud/openstack/helpers.rb +77 -19
- data/lib/cloud/openstack/manual_network.rb +35 -0
- data/lib/cloud/openstack/network.rb +1 -0
- data/lib/cloud/openstack/network_configurator.rb +76 -37
- data/lib/cloud/openstack/tag_manager.rb +17 -0
- data/lib/cloud/openstack/version.rb +2 -1
- data/lib/cloud/openstack/vip_network.rb +15 -12
- metadata +40 -75
- data/Rakefile +0 -62
- data/bosh_cpi.md +0 -82
- data/lib/cloud/openstack/registry_client.rb +0 -127
- data/spec/assets/sample_config.yml +0 -14
- data/spec/integration/cpi_test.rb +0 -119
- data/spec/spec_helper.rb +0 -146
- data/spec/unit/attach_disk_spec.rb +0 -111
- data/spec/unit/cloud_spec.rb +0 -31
- data/spec/unit/configure_networks_spec.rb +0 -106
- data/spec/unit/create_disk_spec.rb +0 -82
- data/spec/unit/create_stemcell_spec.rb +0 -315
- data/spec/unit/create_vm_spec.rb +0 -252
- data/spec/unit/delete_disk_spec.rb +0 -37
- data/spec/unit/delete_stemcell_spec.rb +0 -80
- data/spec/unit/delete_vm_spec.rb +0 -25
- data/spec/unit/detach_disk_spec.rb +0 -78
- data/spec/unit/helpers_spec.rb +0 -74
- data/spec/unit/network_configurator_spec.rb +0 -57
- data/spec/unit/reboot_vm_spec.rb +0 -32
- data/spec/unit/set_vm_metadata_spec.rb +0 -34
- data/spec/unit/validate_deployment_spec.rb +0 -17
@@ -1,37 +0,0 @@
|
|
1
|
-
# Copyright (c) 2012 Piston Cloud Computing, Inc.
|
2
|
-
|
3
|
-
require File.expand_path("../../spec_helper", __FILE__)
|
4
|
-
|
5
|
-
describe Bosh::OpenStackCloud::Cloud do
|
6
|
-
|
7
|
-
it "deletes an OpenStack volume" do
|
8
|
-
volume = double("volume", :id => "v-foobar")
|
9
|
-
|
10
|
-
cloud = mock_cloud do |openstack|
|
11
|
-
openstack.volumes.should_receive(:get).
|
12
|
-
with("v-foobar").and_return(volume)
|
13
|
-
end
|
14
|
-
|
15
|
-
volume.should_receive(:status).and_return(:available)
|
16
|
-
volume.should_receive(:destroy).and_return(true)
|
17
|
-
cloud.should_receive(:wait_resource).with(volume, :deleted, :status, true)
|
18
|
-
|
19
|
-
cloud.delete_disk("v-foobar")
|
20
|
-
end
|
21
|
-
|
22
|
-
it "doesn't delete an OpenStack volume unless it's state is `available'" do
|
23
|
-
volume = double("volume", :id => "v-foobar")
|
24
|
-
|
25
|
-
cloud = mock_cloud do |openstack|
|
26
|
-
openstack.volumes.should_receive(:get).with("v-foobar").and_return(volume)
|
27
|
-
end
|
28
|
-
|
29
|
-
volume.should_receive(:status).and_return(:busy)
|
30
|
-
|
31
|
-
expect {
|
32
|
-
cloud.delete_disk("v-foobar")
|
33
|
-
}.to raise_error(Bosh::Clouds::CloudError,
|
34
|
-
"Cannot delete volume `v-foobar', state is busy")
|
35
|
-
end
|
36
|
-
|
37
|
-
end
|
@@ -1,80 +0,0 @@
|
|
1
|
-
# Copyright (c) 2012 Piston Cloud Computing, Inc.
|
2
|
-
|
3
|
-
require File.expand_path("../../spec_helper", __FILE__)
|
4
|
-
|
5
|
-
describe Bosh::OpenStackCloud::Cloud do
|
6
|
-
|
7
|
-
it "deletes stemcell (only image)" do
|
8
|
-
image = double("image", :id => "i-foo", :name => "i-foo",
|
9
|
-
:properties => {})
|
10
|
-
|
11
|
-
cloud = mock_glance do |glance|
|
12
|
-
glance.images.stub(:find_by_id).with("i-foo").and_return(image)
|
13
|
-
end
|
14
|
-
|
15
|
-
image.should_receive(:destroy)
|
16
|
-
|
17
|
-
cloud.delete_stemcell("i-foo")
|
18
|
-
end
|
19
|
-
|
20
|
-
it "deletes stemcell (image, kernel and ramdisk)" do
|
21
|
-
image = double("image", :id => "i-foo", :name => "i-foo",
|
22
|
-
:properties => {"kernel_id" => "k-id",
|
23
|
-
"ramdisk_id" => "r-id"})
|
24
|
-
kernel = double("image", :id => "k-id",
|
25
|
-
:properties => {"stemcell" => "i-foo"})
|
26
|
-
ramdisk = double("image", :id => "r-id",
|
27
|
-
:properties => {"stemcell" => "i-foo"})
|
28
|
-
|
29
|
-
cloud = mock_glance do |glance|
|
30
|
-
glance.images.stub(:find_by_id).with("i-foo").and_return(image)
|
31
|
-
glance.images.stub(:find_by_id).with("k-id").and_return(kernel)
|
32
|
-
glance.images.stub(:find_by_id).with("r-id").and_return(ramdisk)
|
33
|
-
end
|
34
|
-
|
35
|
-
kernel.should_receive(:destroy)
|
36
|
-
ramdisk.should_receive(:destroy)
|
37
|
-
image.should_receive(:destroy)
|
38
|
-
|
39
|
-
cloud.delete_stemcell("i-foo")
|
40
|
-
end
|
41
|
-
|
42
|
-
it "deletes stemcell (kernel and ramdisk not uploaded by the CPI)" do
|
43
|
-
image = double("image", :id => "i-foo", :name => "i-foo",
|
44
|
-
:properties => {"kernel_id" => "k-id",
|
45
|
-
"ramdisk_id" => "r-id"})
|
46
|
-
kernel = double("image", :id => "k-id", :properties => {})
|
47
|
-
ramdisk = double("image", :id => "r-id", :properties => {})
|
48
|
-
|
49
|
-
cloud = mock_glance do |glance|
|
50
|
-
glance.images.stub(:find_by_id).with("i-foo").and_return(image)
|
51
|
-
glance.images.stub(:find_by_id).with("k-id").and_return(kernel)
|
52
|
-
glance.images.stub(:find_by_id).with("r-id").and_return(ramdisk)
|
53
|
-
end
|
54
|
-
|
55
|
-
image.should_receive(:destroy)
|
56
|
-
|
57
|
-
cloud.delete_stemcell("i-foo")
|
58
|
-
end
|
59
|
-
|
60
|
-
it "deletes stemcell (kernel and ramdisk that do not belong to stemcell)" do
|
61
|
-
image = double("image", :id => "i-foo", :name => "i-foo",
|
62
|
-
:properties => {"kernel_id" => "k-id",
|
63
|
-
"ramdisk_id" => "r-id"})
|
64
|
-
kernel = double("image", :id => "k-id",
|
65
|
-
:properties => {"stemcell" => "i-bar"})
|
66
|
-
ramdisk = double("image", :id => "r-id",
|
67
|
-
:properties => {"stemcell" => "i-bar"})
|
68
|
-
|
69
|
-
cloud = mock_glance do |glance|
|
70
|
-
glance.images.stub(:find_by_id).with("i-foo").and_return(image)
|
71
|
-
glance.images.stub(:find_by_id).with("k-id").and_return(kernel)
|
72
|
-
glance.images.stub(:find_by_id).with("r-id").and_return(ramdisk)
|
73
|
-
end
|
74
|
-
|
75
|
-
image.should_receive(:destroy)
|
76
|
-
|
77
|
-
cloud.delete_stemcell("i-foo")
|
78
|
-
end
|
79
|
-
|
80
|
-
end
|
data/spec/unit/delete_vm_spec.rb
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
# Copyright (c) 2012 Piston Cloud Computing, Inc.
|
2
|
-
|
3
|
-
require File.expand_path("../../spec_helper", __FILE__)
|
4
|
-
|
5
|
-
describe Bosh::OpenStackCloud::Cloud do
|
6
|
-
|
7
|
-
before(:each) do
|
8
|
-
@registry = mock_registry
|
9
|
-
end
|
10
|
-
|
11
|
-
it "deletes an OpenStack server" do
|
12
|
-
server = double("server", :id => "i-foobar", :name => "i-foobar")
|
13
|
-
|
14
|
-
cloud = mock_cloud do |openstack|
|
15
|
-
openstack.servers.should_receive(:get).with("i-foobar").and_return(server)
|
16
|
-
end
|
17
|
-
|
18
|
-
server.should_receive(:destroy).and_return(true)
|
19
|
-
cloud.should_receive(:wait_resource).with(server, :terminated, :state, true)
|
20
|
-
|
21
|
-
@registry.should_receive(:delete_settings).with("i-foobar")
|
22
|
-
|
23
|
-
cloud.delete_vm("i-foobar")
|
24
|
-
end
|
25
|
-
end
|
@@ -1,78 +0,0 @@
|
|
1
|
-
# Copyright (c) 2012 Piston Cloud Computing, Inc.
|
2
|
-
|
3
|
-
require File.expand_path("../../spec_helper", __FILE__)
|
4
|
-
|
5
|
-
describe Bosh::OpenStackCloud::Cloud do
|
6
|
-
|
7
|
-
before(:each) do
|
8
|
-
@registry = mock_registry
|
9
|
-
end
|
10
|
-
|
11
|
-
it "detaches an OpenStack volume from a server" do
|
12
|
-
server = double("server", :id => "i-test", :name => "i-test")
|
13
|
-
volume = double("volume", :id => "v-foobar")
|
14
|
-
volume_attachments = double("body", :body => {"volumeAttachments" =>
|
15
|
-
[{"volumeId" => "v-foobar"},
|
16
|
-
{"volumeId" => "v-barfoo"}]})
|
17
|
-
|
18
|
-
cloud = mock_cloud do |openstack|
|
19
|
-
openstack.servers.should_receive(:get).
|
20
|
-
with("i-test").and_return(server)
|
21
|
-
openstack.volumes.should_receive(:get).
|
22
|
-
with("v-foobar").and_return(volume)
|
23
|
-
openstack.should_receive(:get_server_volumes).
|
24
|
-
and_return(volume_attachments)
|
25
|
-
end
|
26
|
-
|
27
|
-
volume.should_receive(:detach).with(server.id, "v-foobar").and_return(true)
|
28
|
-
cloud.should_receive(:wait_resource).with(volume, :available)
|
29
|
-
|
30
|
-
old_settings = {
|
31
|
-
"foo" => "bar",
|
32
|
-
"disks" => {
|
33
|
-
"persistent" => {
|
34
|
-
"v-foobar" => "/dev/vdc",
|
35
|
-
"v-barfoo" => "/dev/vdd"
|
36
|
-
}
|
37
|
-
}
|
38
|
-
}
|
39
|
-
|
40
|
-
new_settings = {
|
41
|
-
"foo" => "bar",
|
42
|
-
"disks" => {
|
43
|
-
"persistent" => {
|
44
|
-
"v-barfoo" => "/dev/vdd"
|
45
|
-
}
|
46
|
-
}
|
47
|
-
}
|
48
|
-
|
49
|
-
@registry.should_receive(:read_settings).
|
50
|
-
with("i-test").and_return(old_settings)
|
51
|
-
@registry.should_receive(:update_settings).
|
52
|
-
with("i-test", new_settings)
|
53
|
-
|
54
|
-
cloud.detach_disk("i-test", "v-foobar")
|
55
|
-
end
|
56
|
-
|
57
|
-
it "raises an error when volume is not attached to a server" do
|
58
|
-
server = double("server", :id => "i-test", :name => "i-test")
|
59
|
-
volume = double("volume", :id => "v-barfoo")
|
60
|
-
volume_attachments = double("body",
|
61
|
-
:body => {"volumeAttachments" =>
|
62
|
-
[{"volumeId" => "v-foobar"}]})
|
63
|
-
|
64
|
-
cloud = mock_cloud do |openstack|
|
65
|
-
openstack.servers.should_receive(:get).
|
66
|
-
with("i-test").and_return(server)
|
67
|
-
openstack.volumes.should_receive(:get).
|
68
|
-
with("v-barfoo").and_return(volume)
|
69
|
-
openstack.should_receive(:get_server_volumes).
|
70
|
-
and_return(volume_attachments)
|
71
|
-
end
|
72
|
-
|
73
|
-
expect {
|
74
|
-
cloud.detach_disk("i-test", "v-barfoo")
|
75
|
-
}.to raise_error(Bosh::Clouds::CloudError, /is not attached to server/)
|
76
|
-
end
|
77
|
-
|
78
|
-
end
|
data/spec/unit/helpers_spec.rb
DELETED
@@ -1,74 +0,0 @@
|
|
1
|
-
# Copyright (c) 2012 Piston Cloud Computing, Inc.
|
2
|
-
|
3
|
-
require File.expand_path("../../spec_helper", __FILE__)
|
4
|
-
|
5
|
-
describe Bosh::OpenStackCloud::Helpers do
|
6
|
-
before(:each) do
|
7
|
-
Bosh::Clouds::Config.stub(:task_checkpoint)
|
8
|
-
end
|
9
|
-
|
10
|
-
it "should time out" do
|
11
|
-
cloud = mock_cloud
|
12
|
-
|
13
|
-
resource = double("resource")
|
14
|
-
resource.stub(:id).and_return("foobar")
|
15
|
-
resource.stub(:reload).and_return(cloud)
|
16
|
-
resource.stub(:status).and_return(:start)
|
17
|
-
cloud.stub(:sleep)
|
18
|
-
|
19
|
-
expect {
|
20
|
-
cloud.wait_resource(resource, :stop, :status, false, 0.1)
|
21
|
-
}.to raise_error Bosh::Clouds::CloudError, /Timed out/
|
22
|
-
end
|
23
|
-
|
24
|
-
it "should not time out" do
|
25
|
-
cloud = mock_cloud
|
26
|
-
|
27
|
-
resource = double("resource")
|
28
|
-
resource.stub(:id).and_return("foobar")
|
29
|
-
resource.stub(:reload).and_return(cloud)
|
30
|
-
resource.stub(:status).and_return(:start, :stop)
|
31
|
-
cloud.stub(:sleep)
|
32
|
-
|
33
|
-
cloud.wait_resource(resource, :stop, :status, false, 0.1)
|
34
|
-
end
|
35
|
-
|
36
|
-
it "should raise Bosh::Clouds::CloudError if state is error" do
|
37
|
-
cloud = mock_cloud
|
38
|
-
|
39
|
-
resource = double("resource")
|
40
|
-
resource.stub(:id).and_return("foobar")
|
41
|
-
resource.stub(:reload).and_return(cloud)
|
42
|
-
resource.stub(:status).and_return(:error)
|
43
|
-
cloud.stub(:sleep)
|
44
|
-
|
45
|
-
expect {
|
46
|
-
cloud.wait_resource(resource, :stop, :status, false, 0.1)
|
47
|
-
}.to raise_error Bosh::Clouds::CloudError, /state is error/
|
48
|
-
end
|
49
|
-
|
50
|
-
it "should raise Bosh::Clouds::CloudError if resource not found" do
|
51
|
-
cloud = mock_cloud
|
52
|
-
|
53
|
-
resource = double("resource")
|
54
|
-
resource.stub(:id).and_return("foobar")
|
55
|
-
resource.stub(:reload).and_return(nil)
|
56
|
-
cloud.stub(:sleep)
|
57
|
-
|
58
|
-
expect {
|
59
|
-
cloud.wait_resource(resource, :deleted, :status, false, 0.1)
|
60
|
-
}.to raise_error Bosh::Clouds::CloudError, /Resource not found/
|
61
|
-
end
|
62
|
-
|
63
|
-
it "should not raise and exception if resource not found" do
|
64
|
-
cloud = mock_cloud
|
65
|
-
|
66
|
-
resource = double("resource")
|
67
|
-
resource.stub(:id).and_return("foobar")
|
68
|
-
resource.stub(:reload).and_return(nil)
|
69
|
-
resource.stub(:status).and_return(:deleted)
|
70
|
-
cloud.stub(:sleep)
|
71
|
-
|
72
|
-
cloud.wait_resource(resource, :deleted, :status, true, 0.1)
|
73
|
-
end
|
74
|
-
end
|
@@ -1,57 +0,0 @@
|
|
1
|
-
# Copyright (c) 2012 Piston Cloud Computing, Inc.
|
2
|
-
|
3
|
-
require File.expand_path("../../spec_helper", __FILE__)
|
4
|
-
|
5
|
-
describe Bosh::OpenStackCloud::NetworkConfigurator do
|
6
|
-
|
7
|
-
def set_security_groups(spec, security_groups)
|
8
|
-
spec["cloud_properties"] = {
|
9
|
-
"security_groups" => security_groups
|
10
|
-
}
|
11
|
-
end
|
12
|
-
|
13
|
-
it "should raise an error if the spec isn't a hash" do
|
14
|
-
expect {
|
15
|
-
Bosh::OpenStackCloud::NetworkConfigurator.new("foo")
|
16
|
-
}.to raise_error ArgumentError
|
17
|
-
end
|
18
|
-
|
19
|
-
describe "security groups" do
|
20
|
-
it "should be extracted from both dynamic and vip network" do
|
21
|
-
spec = {}
|
22
|
-
spec["network_a"] = dynamic_network_spec
|
23
|
-
set_security_groups(spec["network_a"], %w[foo])
|
24
|
-
spec["network_b"] = vip_network_spec
|
25
|
-
set_security_groups(spec["network_b"], %w[bar])
|
26
|
-
|
27
|
-
nc = Bosh::OpenStackCloud::NetworkConfigurator.new(spec)
|
28
|
-
nc.security_groups(nil).should == %w[bar foo]
|
29
|
-
end
|
30
|
-
|
31
|
-
it "should return the default groups if none are extracted" do
|
32
|
-
spec = {}
|
33
|
-
spec["network_a"] = {"type" => "dynamic"}
|
34
|
-
|
35
|
-
nc = Bosh::OpenStackCloud::NetworkConfigurator.new(spec)
|
36
|
-
nc.security_groups(%w[foo]).should == %w[foo]
|
37
|
-
end
|
38
|
-
|
39
|
-
it "should return an empty list if no default group is set" do
|
40
|
-
spec = {}
|
41
|
-
spec["network_a"] = {"type" => "dynamic"}
|
42
|
-
|
43
|
-
nc = Bosh::OpenStackCloud::NetworkConfigurator.new(spec)
|
44
|
-
nc.security_groups(nil).should == []
|
45
|
-
end
|
46
|
-
|
47
|
-
it "should raise an error when it isn't an array" do
|
48
|
-
spec = {}
|
49
|
-
spec["network_a"] = dynamic_network_spec
|
50
|
-
set_security_groups(spec["network_a"], "foo")
|
51
|
-
|
52
|
-
expect {
|
53
|
-
Bosh::OpenStackCloud::NetworkConfigurator.new(spec)
|
54
|
-
}.to raise_error ArgumentError, "security groups must be an Array"
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
data/spec/unit/reboot_vm_spec.rb
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
# Copyright (c) 2012 Piston Cloud Computing, Inc.
|
2
|
-
|
3
|
-
require File.expand_path("../../spec_helper", __FILE__)
|
4
|
-
|
5
|
-
describe Bosh::OpenStackCloud::Cloud do
|
6
|
-
|
7
|
-
before :each do
|
8
|
-
@server = double("server", :id => "i-foobar")
|
9
|
-
|
10
|
-
@cloud = mock_cloud(mock_cloud_options) do |openstack|
|
11
|
-
openstack.servers.stub(:get).with("i-foobar").and_return(@server)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
it "reboots an OpenStack server (CPI call picks soft reboot)" do
|
16
|
-
@cloud.should_receive(:soft_reboot).with(@server)
|
17
|
-
@cloud.reboot_vm("i-foobar")
|
18
|
-
end
|
19
|
-
|
20
|
-
it "soft reboots an OpenStack server" do
|
21
|
-
@server.should_receive(:reboot)
|
22
|
-
@cloud.should_receive(:wait_resource).with(@server, :active, :state)
|
23
|
-
@cloud.send(:soft_reboot, @server)
|
24
|
-
end
|
25
|
-
|
26
|
-
it "hard reboots an OpenStack server" do
|
27
|
-
@server.should_receive(:reboot)
|
28
|
-
@cloud.should_receive(:wait_resource).with(@server, :active, :state)
|
29
|
-
@cloud.send(:hard_reboot, @server)
|
30
|
-
end
|
31
|
-
|
32
|
-
end
|
@@ -1,34 +0,0 @@
|
|
1
|
-
# Copyright (c) 2009-2012 VMware, Inc.
|
2
|
-
|
3
|
-
require File.expand_path("../../spec_helper", __FILE__)
|
4
|
-
|
5
|
-
describe Bosh::OpenStackCloud::Cloud do
|
6
|
-
before :each do
|
7
|
-
@server = double("server", :id => "i-foobar")
|
8
|
-
@metadata = double("metadata")
|
9
|
-
|
10
|
-
@cloud = mock_cloud do |openstack|
|
11
|
-
openstack.servers.should_receive(:get).
|
12
|
-
with("i-foobar").and_return(@server)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
it "should set metadata" do
|
17
|
-
metadata = {:job => "job", :index => "index"}
|
18
|
-
|
19
|
-
@server.should_receive(:metadata).and_return(@metadata, @metadata)
|
20
|
-
@metadata.should_receive(:update).with(:job => "job")
|
21
|
-
@metadata.should_receive(:update).with(:index => "index")
|
22
|
-
|
23
|
-
@cloud.set_vm_metadata("i-foobar", metadata)
|
24
|
-
end
|
25
|
-
|
26
|
-
it "should set metadata with a nil value" do
|
27
|
-
metadata = {:deployment => nil}
|
28
|
-
|
29
|
-
@server.should_receive(:metadata).and_return(@metadata)
|
30
|
-
@metadata.should_receive(:update).with(:deployment => "")
|
31
|
-
|
32
|
-
@cloud.set_vm_metadata("i-foobar", metadata)
|
33
|
-
end
|
34
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
# Copyright (c) 2012 Piston Cloud Computing, Inc.
|
2
|
-
|
3
|
-
require File.expand_path("../../spec_helper", __FILE__)
|
4
|
-
|
5
|
-
describe Bosh::OpenStackCloud::Cloud do
|
6
|
-
|
7
|
-
it "doesn't implement `validate_deployment'" do
|
8
|
-
Fog::Compute.stub(:new)
|
9
|
-
Fog::Image.stub(:new)
|
10
|
-
cloud = make_cloud
|
11
|
-
expect {
|
12
|
-
cloud.validate_deployment({}, {})
|
13
|
-
}.to raise_error(Bosh::Clouds::NotImplemented,
|
14
|
-
"`validate_deployment' is not implemented by Bosh::OpenStackCloud::Cloud")
|
15
|
-
end
|
16
|
-
|
17
|
-
end
|