bosh_openstack_registry 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +80 -0
- data/lib/openstack_registry/api_controller.rb +1 -1
- data/lib/openstack_registry/config.rb +2 -1
- data/lib/openstack_registry/runner.rb +1 -1
- data/lib/openstack_registry/server_manager.rb +29 -1
- data/lib/openstack_registry/version.rb +1 -1
- data/spec/assets/sample_config.yml +2 -1
- data/spec/spec_helper.rb +2 -1
- data/spec/unit/api_controller_spec.rb +2 -2
- data/spec/unit/server_manager_spec.rb +50 -6
- metadata +6 -11
- data/README +0 -3
data/README.md
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
# BOSH OpenStack Registry
|
2
|
+
Copyright (c) 2009-2012 VMware, Inc.
|
3
|
+
|
4
|
+
For online documentation see: http://rubydoc.info/gems/bosh_openstack_registry/
|
5
|
+
|
6
|
+
## Usage
|
7
|
+
|
8
|
+
bin/migrate [<options>]
|
9
|
+
-c, --config FILE OpenStack Registry configuration file
|
10
|
+
|
11
|
+
bin/openstack_registry [<options>]
|
12
|
+
-c, --config FILE OpenStack Registry configuration file
|
13
|
+
|
14
|
+
## Configuration
|
15
|
+
|
16
|
+
These options are passed to the OpenStack Registry when it is instantiated.
|
17
|
+
|
18
|
+
### Registry options
|
19
|
+
|
20
|
+
These are the options for the Registry HTTP server (by default server is
|
21
|
+
bound to address 0.0.0.0):
|
22
|
+
|
23
|
+
* `port` (required)
|
24
|
+
Registry port
|
25
|
+
* `user` (required)
|
26
|
+
Registry user (for HTTP Basic authentication)
|
27
|
+
* `password` (required)
|
28
|
+
Registry password (for HTTP Basic authentication)
|
29
|
+
|
30
|
+
### Database options
|
31
|
+
|
32
|
+
These are the options for the database connection where registry will store
|
33
|
+
server properties:
|
34
|
+
|
35
|
+
* `database` (required)
|
36
|
+
DB connection URI
|
37
|
+
* `max_connections` (required)
|
38
|
+
Maximum size of the connection pool
|
39
|
+
* `pool_timeout` (required)
|
40
|
+
Number of seconds to wait if a connection cannot be acquired before
|
41
|
+
raising an error
|
42
|
+
|
43
|
+
### OpenStack options
|
44
|
+
|
45
|
+
These are the credentials to connect to OpenStack services:
|
46
|
+
|
47
|
+
* `auth_url` (required)
|
48
|
+
URL of the OpenStack Identity endpoint to connect to
|
49
|
+
* `username` (required)
|
50
|
+
OpenStack user name
|
51
|
+
* `api_key` (required)
|
52
|
+
OpenStack API key
|
53
|
+
* `tenant` (required)
|
54
|
+
OpenStack tenant name
|
55
|
+
* `region` (optional)
|
56
|
+
OpenStack region
|
57
|
+
|
58
|
+
## Example
|
59
|
+
|
60
|
+
This is a sample of an OpenStack Registry configuration file:
|
61
|
+
|
62
|
+
---
|
63
|
+
loglevel: debug
|
64
|
+
|
65
|
+
http:
|
66
|
+
port: 25695
|
67
|
+
user: admin
|
68
|
+
password: admin
|
69
|
+
|
70
|
+
db:
|
71
|
+
database: "sqlite:///:memory:"
|
72
|
+
max_connections: 32
|
73
|
+
pool_timeout: 10
|
74
|
+
|
75
|
+
openstack:
|
76
|
+
auth_url: "http://127.0.0.1:5000/v2.0/tokens"
|
77
|
+
username: foo
|
78
|
+
api_key: bar
|
79
|
+
tenant: foo
|
80
|
+
region:
|
@@ -17,7 +17,7 @@ module Bosh::OpenstackRegistry
|
|
17
17
|
|
18
18
|
get "/servers/:server_id/settings" do
|
19
19
|
ip_check = authorized? ? nil : request.ip
|
20
|
-
settings = @server_manager.read_settings(params[:server_id])
|
20
|
+
settings = @server_manager.read_settings(params[:server_id], ip_check)
|
21
21
|
json(:status => "ok", :settings => settings)
|
22
22
|
end
|
23
23
|
|
@@ -32,7 +32,8 @@ module Bosh::OpenstackRegistry
|
|
32
32
|
:openstack_auth_url => @openstack_properties["auth_url"],
|
33
33
|
:openstack_username => @openstack_properties["username"],
|
34
34
|
:openstack_api_key => @openstack_properties["api_key"],
|
35
|
-
:openstack_tenant => @openstack_properties["tenant"]
|
35
|
+
:openstack_tenant => @openstack_properties["tenant"],
|
36
|
+
:openstack_region => @openstack_properties["region"]
|
36
37
|
}
|
37
38
|
|
38
39
|
@db = connect_db(config["db"])
|
@@ -27,7 +27,12 @@ module Bosh::OpenstackRegistry
|
|
27
27
|
##
|
28
28
|
# Reads server settings
|
29
29
|
# @param [String] server_id OpenStack server id
|
30
|
-
|
30
|
+
# @param [optional, String] remote_ip If this IP is provided, check will
|
31
|
+
# be performed to see if the server id actually has this IP address
|
32
|
+
# according to OpenStack.
|
33
|
+
def read_settings(server_id, remote_ip = nil)
|
34
|
+
check_instance_ips(remote_ip, server_id) if remote_ip
|
35
|
+
|
31
36
|
get_server(server_id).settings
|
32
37
|
end
|
33
38
|
|
@@ -37,6 +42,16 @@ module Bosh::OpenstackRegistry
|
|
37
42
|
|
38
43
|
private
|
39
44
|
|
45
|
+
def check_instance_ips(ip, server_id)
|
46
|
+
return if ip == "127.0.0.1"
|
47
|
+
actual_ips = server_ips(server_id)
|
48
|
+
unless actual_ips.include?(ip)
|
49
|
+
raise ServerError, "Server IP mismatch, expected IP is " \
|
50
|
+
"`%s', actual IP(s): `%s'" %
|
51
|
+
[ ip, actual_ips.join(", ") ]
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
40
55
|
def get_server(server_id)
|
41
56
|
server = Models::OpenstackServer[:server_id => server_id]
|
42
57
|
|
@@ -47,6 +62,19 @@ module Bosh::OpenstackRegistry
|
|
47
62
|
server
|
48
63
|
end
|
49
64
|
|
65
|
+
# Get the list of IPs belonging to this server
|
66
|
+
def server_ips(server_id)
|
67
|
+
server = @openstack.servers.get(server_id)
|
68
|
+
raise ServerNotFound, "Server `#{server_id}' not found" unless server
|
69
|
+
ips = []
|
70
|
+
server.addresses.each do |network, addresses|
|
71
|
+
addresses.each do |addr|
|
72
|
+
ips.push(addr.kind_of?(Hash) ? addr["addr"] : addr)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
ips
|
76
|
+
end
|
77
|
+
|
50
78
|
end
|
51
79
|
|
52
80
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -22,7 +22,7 @@ describe Bosh::OpenstackRegistry::ApiController do
|
|
22
22
|
|
23
23
|
it "returns settings for given OpenStack server (IP check)" do
|
24
24
|
@server_manager.should_receive(:read_settings).
|
25
|
-
with("foo").and_return("bar")
|
25
|
+
with("foo", "127.0.0.1").and_return("bar")
|
26
26
|
|
27
27
|
@session.get("/servers/foo/settings")
|
28
28
|
|
@@ -32,7 +32,7 @@ describe Bosh::OpenstackRegistry::ApiController do
|
|
32
32
|
|
33
33
|
it "returns settings (authorized user, no IP check)" do
|
34
34
|
@server_manager.should_receive(:read_settings).
|
35
|
-
with("foo").and_return("bar")
|
35
|
+
with("foo", nil).and_return("bar")
|
36
36
|
|
37
37
|
@session.basic_authorize("admin", "admin")
|
38
38
|
@session.get("/servers/foo/settings")
|
@@ -5,10 +5,10 @@ require File.expand_path("../../spec_helper", __FILE__)
|
|
5
5
|
describe Bosh::OpenstackRegistry::ServerManager do
|
6
6
|
|
7
7
|
before(:each) do
|
8
|
-
|
9
|
-
Fog::Compute.stub(:new).and_return(
|
10
|
-
|
11
|
-
Bosh::OpenstackRegistry.openstack =
|
8
|
+
@compute = double(Fog::Compute)
|
9
|
+
Fog::Compute.stub(:new).and_return(@compute)
|
10
|
+
openstack = mock("openstack")
|
11
|
+
Bosh::OpenstackRegistry.openstack = openstack
|
12
12
|
end
|
13
13
|
|
14
14
|
let(:manager) do
|
@@ -19,18 +19,62 @@ describe Bosh::OpenstackRegistry::ServerManager do
|
|
19
19
|
Bosh::OpenstackRegistry::Models::OpenstackServer.create(params)
|
20
20
|
end
|
21
21
|
|
22
|
+
def actual_ip_is(private_ip, floating_ip = nil)
|
23
|
+
servers = mock("servers")
|
24
|
+
server = mock("server", :addresses => {
|
25
|
+
"private" => [{"version" => 4, "addr" => private_ip}],
|
26
|
+
"public" => [floating_ip]
|
27
|
+
})
|
28
|
+
|
29
|
+
@compute.should_receive(:servers).and_return(servers)
|
30
|
+
servers.should_receive(:get).with("foo").and_return(server)
|
31
|
+
end
|
32
|
+
|
22
33
|
describe "reading settings" do
|
23
|
-
it "returns settings" do
|
34
|
+
it "returns settings after verifying IP address" do
|
35
|
+
create_server(:server_id => "foo", :settings => "bar")
|
36
|
+
actual_ip_is("10.0.0.1")
|
37
|
+
manager.read_settings("foo", "10.0.0.1").should == "bar"
|
38
|
+
end
|
39
|
+
|
40
|
+
it "returns settings after verifying floating IP address" do
|
41
|
+
create_server(:server_id => "foo", :settings => "bar")
|
42
|
+
actual_ip_is("10.0.0.1", "10.0.1.1")
|
43
|
+
manager.read_settings("foo", "10.0.1.1").should == "bar"
|
44
|
+
end
|
45
|
+
|
46
|
+
it "raises an error if IP cannot be verified" do
|
47
|
+
create_server(:server_id => "foo", :settings => "bar")
|
48
|
+
actual_ip_is("10.0.0.1", "10.0.1.1")
|
49
|
+
expect {
|
50
|
+
manager.read_settings("foo", "10.0.2.1")
|
51
|
+
}.to raise_error(Bosh::OpenstackRegistry::ServerError,
|
52
|
+
"Server IP mismatch, expected IP is `10.0.2.1', " \
|
53
|
+
"actual IP(s): `10.0.0.1, 10.0.1.1'")
|
54
|
+
end
|
55
|
+
|
56
|
+
it "doesn't check remote IP if it's not provided" do
|
24
57
|
create_server(:server_id => "foo", :settings => "bar")
|
25
58
|
manager.read_settings("foo").should == "bar"
|
26
59
|
end
|
27
60
|
|
28
|
-
it "raises an error if server not found" do
|
61
|
+
it "raises an error if server not found in registry" do
|
29
62
|
expect {
|
30
63
|
manager.read_settings("foo")
|
31
64
|
}.to raise_error(Bosh::OpenstackRegistry::ServerNotFound,
|
32
65
|
"Can't find server `foo'")
|
33
66
|
end
|
67
|
+
|
68
|
+
it "raises an error if server not found in OpenStack" do
|
69
|
+
expect {
|
70
|
+
servers = mock("servers")
|
71
|
+
@compute.should_receive(:servers).and_return(servers)
|
72
|
+
servers.should_receive(:get).with("foo").and_return(nil)
|
73
|
+
create_server(:server_id => "foo", :settings => "bar")
|
74
|
+
manager.read_settings("foo", "10.0.0.1")
|
75
|
+
}.to raise_error(Bosh::OpenstackRegistry::ServerNotFound,
|
76
|
+
"Server `foo' not found")
|
77
|
+
end
|
34
78
|
end
|
35
79
|
|
36
80
|
describe "updating settings" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bosh_openstack_registry
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
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-10
|
12
|
+
date: 2012-12-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: sequel
|
@@ -80,7 +80,7 @@ dependencies:
|
|
80
80
|
requirement: !ruby/object:Gem::Requirement
|
81
81
|
none: false
|
82
82
|
requirements:
|
83
|
-
- -
|
83
|
+
- - ! '>='
|
84
84
|
- !ruby/object:Gem::Version
|
85
85
|
version: 1.6.0
|
86
86
|
type: :runtime
|
@@ -88,7 +88,7 @@ dependencies:
|
|
88
88
|
version_requirements: !ruby/object:Gem::Requirement
|
89
89
|
none: false
|
90
90
|
requirements:
|
91
|
-
- -
|
91
|
+
- - ! '>='
|
92
92
|
- !ruby/object:Gem::Version
|
93
93
|
version: 1.6.0
|
94
94
|
description: BOSH OpenStack registry
|
@@ -110,7 +110,7 @@ files:
|
|
110
110
|
- lib/openstack_registry/server_manager.rb
|
111
111
|
- lib/openstack_registry/version.rb
|
112
112
|
- lib/openstack_registry/yaml_helper.rb
|
113
|
-
- README
|
113
|
+
- README.md
|
114
114
|
- Rakefile
|
115
115
|
- spec/assets/sample_config.yml
|
116
116
|
- spec/spec_helper.rb
|
@@ -130,18 +130,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
130
130
|
- - ! '>='
|
131
131
|
- !ruby/object:Gem::Version
|
132
132
|
version: '0'
|
133
|
-
segments:
|
134
|
-
- 0
|
135
|
-
hash: -1388648985805055139
|
136
133
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
137
134
|
none: false
|
138
135
|
requirements:
|
139
136
|
- - ! '>='
|
140
137
|
- !ruby/object:Gem::Version
|
141
138
|
version: '0'
|
142
|
-
segments:
|
143
|
-
- 0
|
144
|
-
hash: -1388648985805055139
|
145
139
|
requirements: []
|
146
140
|
rubyforge_project:
|
147
141
|
rubygems_version: 1.8.24
|
@@ -155,3 +149,4 @@ test_files:
|
|
155
149
|
- spec/unit/config_spec.rb
|
156
150
|
- spec/unit/runner_spec.rb
|
157
151
|
- spec/unit/server_manager_spec.rb
|
152
|
+
has_rdoc:
|
data/README
DELETED