infrataster 0.1.8 → 0.1.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +30 -9
- data/lib/infrataster/helpers/resource_helper.rb +1 -0
- data/lib/infrataster/server.rb +40 -1
- data/lib/infrataster/version.rb +1 -1
- data/spec/integration/spec_helper.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6deb149a0997920f69ccdb20adbdabcbb923ebb4
|
4
|
+
data.tar.gz: 4e9c444f8d6beee298c37286998eb6e7a6517642
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e69c2d0111708ed18d616419f10515bb06283841d561d97e9935064a2e0dce16d42e9c3c02aab7adf3ceec80769cf392e2cd3b66e8765bfdbb9fca7f939cf3f4
|
7
|
+
data.tar.gz: 6337545b1a1fb3d1d81517ff972d214e1c91c9b3ec3499169010eb156499e1b674e31cf36909b3b558e22be45a625e0768aa8254c01d9fa35a006bd8adde7912
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -63,15 +63,15 @@ $ rspec --init
|
|
63
63
|
require 'infrataster/rspec'
|
64
64
|
|
65
65
|
Infrataster::Server.define(
|
66
|
-
:proxy,
|
67
|
-
'192.168.
|
68
|
-
vagrant: true
|
66
|
+
:proxy, # name
|
67
|
+
'192.168.0.0/16', # ip address
|
68
|
+
vagrant: true # for vagrant VM
|
69
69
|
)
|
70
70
|
Infrataster::Server.define(
|
71
|
-
:app,
|
72
|
-
'172.16.
|
73
|
-
vagrant: true,
|
74
|
-
from: :proxy
|
71
|
+
:app, # name
|
72
|
+
'172.16.0.0/16', # ip address
|
73
|
+
vagrant: true, # for vagrant VM
|
74
|
+
from: :proxy # access to this machine via SSH port forwarding from proxy
|
75
75
|
)
|
76
76
|
|
77
77
|
# Code generated by `rspec --init` is following...
|
@@ -117,7 +117,7 @@ Infrataster::Server.define(
|
|
117
117
|
# Name of the server, this will be used in the spec files.
|
118
118
|
:proxy,
|
119
119
|
# IP address of the server
|
120
|
-
'192.168.
|
120
|
+
'192.168.0.0/16',
|
121
121
|
# If the server is provided by vagrant and this option is true,
|
122
122
|
# SSH configuration to connect to this server is got from `vagrant ssh-config` command automatically.
|
123
123
|
vagrant: true,
|
@@ -127,7 +127,7 @@ Infrataster::Server.define(
|
|
127
127
|
# Name of the server, this will be used in the spec files.
|
128
128
|
:app,
|
129
129
|
# IP address of the server
|
130
|
-
'172.16.
|
130
|
+
'172.16.0.0/16',
|
131
131
|
# If the server is provided by vagrant and this option is true,
|
132
132
|
# SSH configuration to connect to this server is got from `vagrant ssh-config` command automatically.
|
133
133
|
vagrant: true,
|
@@ -147,6 +147,27 @@ Infrataster::Server.define(
|
|
147
147
|
)
|
148
148
|
```
|
149
149
|
|
150
|
+
### fuzzy IP address
|
151
|
+
|
152
|
+
Infrataster has "fuzzy IP address" feature. You can pass IP address which has netmask (= CIDR) to `Infrataster::Server#define`. This needs `vagrant` option or `ssh` option which has `host_name` because this fetches all IP address via SSH and find the matching one.
|
153
|
+
|
154
|
+
```ruby
|
155
|
+
Infrataster::Server.define(
|
156
|
+
:app,
|
157
|
+
# find IP address matching 172.16.0.0 ~ 172.16.255.255
|
158
|
+
'172.16.0.0/16',
|
159
|
+
```
|
160
|
+
|
161
|
+
Of course, you can set fully-specified IP address too.
|
162
|
+
|
163
|
+
```ruby
|
164
|
+
Infrataster::Server.define(
|
165
|
+
:app,
|
166
|
+
'172.16.11.22',
|
167
|
+
# or
|
168
|
+
'172.16.11.22/32',
|
169
|
+
```
|
170
|
+
|
150
171
|
### #ssh_exec
|
151
172
|
|
152
173
|
You can execute a command on the server like the following:
|
data/lib/infrataster/server.rb
CHANGED
@@ -36,7 +36,8 @@ module Infrataster
|
|
36
36
|
attr_reader :name, :address, :options
|
37
37
|
|
38
38
|
def initialize(name, address, options = {})
|
39
|
-
@name, @
|
39
|
+
@name, @options = name, options
|
40
|
+
@address = determine_address(address)
|
40
41
|
end
|
41
42
|
|
42
43
|
def from
|
@@ -134,6 +135,44 @@ module Infrataster
|
|
134
135
|
|
135
136
|
config
|
136
137
|
end
|
138
|
+
|
139
|
+
def fetch_all_addresses
|
140
|
+
result = []
|
141
|
+
ssh_exec('ip addr').each_line do |line|
|
142
|
+
#inet 10.0.2.15/24 brd 10.0.2.255 scope global eth0
|
143
|
+
if %r{inet ([^/]+)} =~ line
|
144
|
+
result << $1
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
result
|
149
|
+
end
|
150
|
+
|
151
|
+
def determine_address(address)
|
152
|
+
Logger.debug("Determining ip address...")
|
153
|
+
|
154
|
+
ipaddr = IPAddr.new(address)
|
155
|
+
if ipaddr.to_range.begin == ipaddr.to_range.end
|
156
|
+
# subnet mask is 255.255.255.255
|
157
|
+
return ipaddr.to_s
|
158
|
+
end
|
159
|
+
|
160
|
+
all_addresses = fetch_all_addresses
|
161
|
+
Logger.debug(all_addresses)
|
162
|
+
|
163
|
+
matched = all_addresses.select do |a|
|
164
|
+
ipaddr.include?(a)
|
165
|
+
end
|
166
|
+
Logger.debug(matched)
|
167
|
+
|
168
|
+
if matched.empty?
|
169
|
+
raise Error, "No IP address matching #{ipaddr} is not found."
|
170
|
+
elsif matched.size > 1
|
171
|
+
raise Error, "Multiple IP addresses matching #{ipaddr} are found."
|
172
|
+
end
|
173
|
+
|
174
|
+
matched.first
|
175
|
+
end
|
137
176
|
end
|
138
177
|
end
|
139
178
|
|
data/lib/infrataster/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: infrataster
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryota Arai
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-05-
|
11
|
+
date: 2014-05-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|