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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: edd8224440be0202f0981f08c84d41d96452ced1
4
- data.tar.gz: 22738c41f609c5a5975251c41aaf4405fb2a451b
3
+ metadata.gz: 6deb149a0997920f69ccdb20adbdabcbb923ebb4
4
+ data.tar.gz: 4e9c444f8d6beee298c37286998eb6e7a6517642
5
5
  SHA512:
6
- metadata.gz: 0afc168b4efdf3c99d69f8780061c0d4276873c03801ef49394d56922a73e23a15da02a1376c6ff136c90cb5eca7b71e029d9351200b20713b3c4f4b08ebb11e
7
- data.tar.gz: f737fd8a7ea09bdda40fffb1fc0e9165a3fe8369d7779a055b6c4b3b56be6ffd1568214e7996784cdbfd89db110138458bdb9e4e7e367492488bc0232eef52c5
6
+ metadata.gz: e69c2d0111708ed18d616419f10515bb06283841d561d97e9935064a2e0dce16d42e9c3c02aab7adf3ceec80769cf392e2cd3b66e8765bfdbb9fca7f939cf3f4
7
+ data.tar.gz: 6337545b1a1fb3d1d81517ff972d214e1c91c9b3ec3499169010eb156499e1b674e31cf36909b3b558e22be45a625e0768aa8254c01d9fa35a006bd8adde7912
@@ -1,5 +1,9 @@
1
1
  # Infrataster Changelog
2
2
 
3
+ ## v0.1.9
4
+
5
+ * Add "fuzzy IP address" feature which determine IP address by CIDR or netmask.
6
+
3
7
  ## v0.1.8
4
8
 
5
9
  * Use Poltergeist's header manipulation instead of BrowserMob Proxy. Remove BrowserMob Proxy dependency.
data/README.md CHANGED
@@ -63,15 +63,15 @@ $ rspec --init
63
63
  require 'infrataster/rspec'
64
64
 
65
65
  Infrataster::Server.define(
66
- :proxy, # name
67
- '192.168.33.10', # ip address
68
- vagrant: true # for vagrant VM
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, # name
72
- '172.16.33.11', # ip address
73
- vagrant: true, # for vagrant VM
74
- from: :proxy # access to this machine via SSH port forwarding 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.44.10',
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.44.11',
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:
@@ -1,3 +1,4 @@
1
+ require 'rspec'
1
2
  require 'infrataster/resources'
2
3
 
3
4
  module Infrataster
@@ -36,7 +36,8 @@ module Infrataster
36
36
  attr_reader :name, :address, :options
37
37
 
38
38
  def initialize(name, address, options = {})
39
- @name, @address, @options = name, address, options
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
 
@@ -1,3 +1,3 @@
1
1
  module Infrataster
2
- VERSION = "0.1.8"
2
+ VERSION = "0.1.9"
3
3
  end
@@ -2,12 +2,12 @@ require 'infrataster/rspec'
2
2
 
3
3
  Infrataster::Server.define(
4
4
  :proxy,
5
- '192.168.44.10',
5
+ '192.168.0.0/16',
6
6
  vagrant: true,
7
7
  )
8
8
  Infrataster::Server.define(
9
9
  :app,
10
- '172.16.44.11',
10
+ '172.16.0.0/16',
11
11
  vagrant: true,
12
12
  from: :proxy,
13
13
  )
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.8
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-17 00:00:00.000000000 Z
11
+ date: 2014-05-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec