tunnel-vmc-plugin 0.1.6 → 0.1.7

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.
@@ -29,7 +29,8 @@ module VMCTunnel
29
29
  fail "No services available for tunneling." if instances.empty?
30
30
 
31
31
  instance = input[:instance, instances.sort_by(&:name)]
32
- clients = tunnel_clients[instance.vendor] || {}
32
+ vendor = v2? ? instance.service_plan.service.label : instance.vendor
33
+ clients = tunnel_clients[vendor] || {}
33
34
  client_name = input[:client, clients]
34
35
 
35
36
  tunnel = CFTunnel.new(client, instance)
@@ -19,7 +19,7 @@ class CFTunnel
19
19
  end
20
20
 
21
21
  def open!
22
- if helper.exists?
22
+ if helper
23
23
  auth = helper_auth
24
24
 
25
25
  unless helper_healthy?(auth)
@@ -79,7 +79,7 @@ class CFTunnel
79
79
  private
80
80
 
81
81
  def helper
82
- @helper ||= @client.app(HELPER_NAME)
82
+ @helper ||= @client.app_by_name(HELPER_NAME)
83
83
  end
84
84
 
85
85
  def create_helper
@@ -122,15 +122,31 @@ class CFTunnel
122
122
  def push_helper(token)
123
123
  target_base = @client.target.sub(/^[^\.]+\./, "")
124
124
 
125
- app = @client.app(HELPER_NAME)
126
- app.framework = "sinatra"
127
- app.url = "#{random_helper_url}.#{target_base}"
125
+ url = "#{random_helper_url}.#{target_base}"
126
+ is_v2 = @client.is_a?(CFoundry::V2::Client)
127
+
128
+ app = @client.app
129
+ app.name = HELPER_NAME
130
+ app.framework = @client.framework_by_name("sinatra")
131
+ app.runtime = @client.runtime_by_name("ruby19")
128
132
  app.total_instances = 1
129
133
  app.memory = 64
130
134
  app.env = { "CALDECOTT_AUTH" => token }
131
- app.services = [@service] if @service
135
+
136
+ if is_v2
137
+ app.space = @client.current_space
138
+ else
139
+ app.services = [@service] if @service
140
+ app.url = url
141
+ end
142
+
132
143
  app.create!
133
144
 
145
+ if is_v2
146
+ app.bind(@service)
147
+ app.create_route(url)
148
+ end
149
+
134
150
  begin
135
151
  app.upload(HELPER_APP)
136
152
  invalidate_tunnel_app_info
@@ -217,8 +233,10 @@ class CFTunnel
217
233
  raise "Remote tunnel helper is unaware of #{@service.name}!"
218
234
  end
219
235
 
236
+ is_v2 = @client.is_a?(CFoundry::V2::Client)
237
+
220
238
  info = JSON.parse(response)
221
- case @service.vendor
239
+ case (is_v2 ? @service.service_plan.service.label : @service.vendor)
222
240
  when "rabbitmq"
223
241
  uri = Addressable::URI.parse info["url"]
224
242
  info["hostname"] = uri.host
@@ -237,6 +255,9 @@ class CFTunnel
237
255
  # our "name" is irrelevant for redis
238
256
  when "redis"
239
257
  info.delete "name"
258
+
259
+ when "filesystem"
260
+ raise "Tunneling is not supported for this type of service"
240
261
  end
241
262
 
242
263
  ["hostname", "port", "password"].each do |k|
@@ -1,3 +1,3 @@
1
1
  module VMCTunnel
2
- VERSION = "0.1.6"
2
+ VERSION = "0.1.7"
3
3
  end
data/spec/Rakefile ADDED
@@ -0,0 +1,13 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ Bundler.require(:default, :development)
4
+
5
+ require 'rake/dsl_definition'
6
+ require 'rake'
7
+ require 'rspec'
8
+ require 'rspec/core/rake_task'
9
+
10
+ RSpec::Core::RakeTask.new do |t|
11
+ t.pattern = "*_spec.rb"
12
+ t.rspec_opts = ["--format", "documentation", "--colour"]
13
+ end
@@ -0,0 +1,71 @@
1
+ require "vmc/spec_helpers"
2
+ require "tunnel-vmc-plugin/plugin"
3
+
4
+ describe "VMCtunnel#tunnel" do
5
+ before(:all) do
6
+ instance_name = "postgres-#{random_str}"
7
+ client.service_instance_by_name(instance_name).should_not be
8
+ psql_service = client.services.find { |svc| svc.label == "postgresql" }
9
+
10
+ @instance = client.service_instance
11
+ @instance.name = instance_name
12
+
13
+ if client.is_a?(CFoundry::V2::Client)
14
+ @instance.service_plan = psql_service.service_plans.first
15
+ @instance.space = client.current_space
16
+ else
17
+ @instance.type = psql_service.type
18
+ @instance.vendor = psql_service.label
19
+ @instance.version = psql_service.version
20
+ @instance.tier = "free"
21
+ end
22
+
23
+ @instance.create!
24
+ end
25
+
26
+ after(:all) do
27
+ @instance.delete!
28
+ end
29
+
30
+ it "runs with no arguments" do
31
+ running(:tunnel) do
32
+ asks("Which service instance?")
33
+ given(@instance.name)
34
+ has_input(:instance, @instance)
35
+
36
+ asks("Which client would you like to start?")
37
+ given("none")
38
+ has_input(:client, "none")
39
+
40
+ does("Opening tunnel on port 10000")
41
+ kill
42
+ end
43
+ end
44
+
45
+ it "runs with args INSTANCE" do
46
+ running(:tunnel, :instance => @instance) do
47
+ asks("Which client would you like to start?")
48
+ given("none")
49
+ has_input(:client, "none")
50
+
51
+ does("Opening tunnel on port 10000")
52
+ kill
53
+ end
54
+ end
55
+
56
+ it "runs with args --port" do
57
+ port = "10024"
58
+ running(:tunnel, :port => port) do
59
+ asks("Which service instance?")
60
+ given(@instance.name)
61
+ has_input(:instance, @instance)
62
+
63
+ asks("Which client would you like to start?")
64
+ given("none")
65
+ has_input(:client, "none")
66
+
67
+ does("Opening tunnel on port #{port}")
68
+ kill
69
+ end
70
+ end
71
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tunnel-vmc-plugin
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 6
10
- version: 0.1.6
9
+ - 7
10
+ version: 0.1.7
11
11
  platform: ruby
12
12
  authors:
13
13
  - Alex Suraci
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-08-29 00:00:00 Z
18
+ date: 2012-09-18 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: cfoundry
@@ -57,7 +57,7 @@ dependencies:
57
57
  requirements:
58
58
  - - ~>
59
59
  - !ruby/object:Gem::Version
60
- hash: -818584907
60
+ hash: 1147517565
61
61
  segments:
62
62
  - 1
63
63
  - 0
@@ -82,6 +82,53 @@ dependencies:
82
82
  version: 0.0.5
83
83
  type: :runtime
84
84
  version_requirements: *id004
85
+ - !ruby/object:Gem::Dependency
86
+ name: rake
87
+ prerelease: false
88
+ requirement: &id005 !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ hash: 3
94
+ segments:
95
+ - 0
96
+ version: "0"
97
+ type: :development
98
+ version_requirements: *id005
99
+ - !ruby/object:Gem::Dependency
100
+ name: rspec
101
+ prerelease: false
102
+ requirement: &id006 !ruby/object:Gem::Requirement
103
+ none: false
104
+ requirements:
105
+ - - ~>
106
+ - !ruby/object:Gem::Version
107
+ hash: 3
108
+ segments:
109
+ - 2
110
+ - 0
111
+ version: "2.0"
112
+ type: :development
113
+ version_requirements: *id006
114
+ - !ruby/object:Gem::Dependency
115
+ name: vmc
116
+ prerelease: false
117
+ requirement: &id007 !ruby/object:Gem::Requirement
118
+ none: false
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ hash: 2295035119
123
+ segments:
124
+ - 0
125
+ - 4
126
+ - 0
127
+ - beta
128
+ - 42
129
+ version: 0.4.0.beta.42
130
+ type: :development
131
+ version_requirements: *id007
85
132
  description:
86
133
  email:
87
134
  - asuraci@vmware.com
@@ -100,6 +147,8 @@ files:
100
147
  - helper-app/Gemfile.lock
101
148
  - helper-app/server.rb
102
149
  - config/clients.yml
150
+ - spec/Rakefile
151
+ - spec/tunnel_spec.rb
103
152
  homepage: http://cloudfoundry.com/
104
153
  licenses: []
105
154
 
@@ -133,5 +182,6 @@ rubygems_version: 1.8.24
133
182
  signing_key:
134
183
  specification_version: 3
135
184
  summary: External access to your services on Cloud Foundry via a Caldecott HTTP tunnel.
136
- test_files: []
137
-
185
+ test_files:
186
+ - spec/Rakefile
187
+ - spec/tunnel_spec.rb