vagrant-cloudcenter 0.2.0 → 0.3.0

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.
@@ -31,53 +31,128 @@ module VagrantPlugins
31
31
  end
32
32
 
33
33
  access_key = env[:machine].provider_config.access_key
34
- host_ip = env[:machine].provider_config.host_ip
34
+ host = env[:machine].provider_config.host
35
35
  username = env[:machine].provider_config.username
36
36
 
37
+ use_https = env[:machine].provider_config.use_https
38
+ ssl_ca_file = env[:machine].provider_config.ssl_ca_file
39
+
37
40
  begin
38
- encoded = URI.encode("https://#{username}:#{access_key}@#{host_ip}/v2/jobs?search=[deploymentEntity.name,fle,#{env[:machine_name]}]");
41
+ encoded = URI.encode("https://#{username}:#{access_key}@#{host}/v2/jobs?search=[deploymentEntity.name,fle,#{env[:machine_name]}]");
39
42
 
40
- response = JSON.parse(RestClient::Request.execute(
43
+ if !use_https
44
+ response = JSON.parse(RestClient::Request.execute(
41
45
  :method => :get,
42
46
  :url => encoded,
43
47
  :verify_ssl => false,
44
48
  :accept => "json",
45
49
  :headers => {"Content-Type" => "application/json"}
46
-
47
50
  ));
51
+ else
52
+ if ssl_ca_file.to_s.empty?
53
+ response = JSON.parse(RestClient::Request.execute(
54
+ :method => :get,
55
+ :url => encoded,
56
+ :accept => "json",
57
+ :headers => {"Content-Type" => "application/json"}
58
+ ));
59
+ else
60
+ response = JSON.parse(RestClient::Request.execute(
61
+ :method => :get,
62
+ :url => encoded,
63
+ :ssl_ca_file => ssl_ca_file.to_s,
64
+ :accept => "json",
65
+ :headers => {"Content-Type" => "application/json"}
66
+ ));
67
+ end
68
+
69
+ end
70
+
48
71
  if !response["jobs"].empty?
49
72
  jobID = response["jobs"][0]["id"]
50
73
  end
51
74
 
52
75
  rescue => e
53
- error = JSON.parse(e.response)
54
- code = error["errors"][0]["code"]
76
+ if e.to_s == "SSL_connect returned=1 errno=0 state=error: certificate verify failed"
77
+ puts "\n ERROR: Failed to verify certificate\n\n"
78
+ exit
79
+ elsif e.to_s == "hostname \"#{host}\" does not match the server certificate"
80
+ puts "\n ERROR: Hostname \"#{host}\" does not match the server certificate\n\n"
81
+ exit
82
+ elsif e.to_s.include? "No route to host"
83
+ puts "\n ERROR: No route to host. Check connectivity and try again\n\n"
84
+ exit
85
+ elsif e.to_s.== "Timed out connecting to server"
86
+ puts "\n ERROR: Timed out connecting to server. Check connectivity and try again\n\n"
87
+ exit
88
+ elsif e.to_s.== "getaddrinfo: nodename nor servname provided, or not known"
89
+ puts "\n ERROR: Unable to connect to \"#{host}\" \n\n"
90
+ exit
91
+ else
92
+ error = JSON.parse(e.response)
93
+ code = error["errors"][0]["code"]
55
94
 
56
- puts "\n Error code: #{error['errors'][0]['code']}\n"
57
- puts "\n #{error['errors'][0]['message']}\n\n"
95
+ puts "\n Error code: #{error['errors'][0]['code']}\n"
96
+ puts "\n #{error['errors'][0]['message']}\n\n"
58
97
 
59
- exit
98
+ exit
99
+ end
60
100
  end
61
101
 
62
102
  if !jobID.nil?
63
103
  begin
64
- encoded = URI.encode("https://#{username}:#{access_key}@#{host_ip}/v2/jobs/#{jobID}");
65
-
66
- response = JSON.parse(RestClient::Request.execute(
67
- :method => :delete,
68
- :url => encoded,
69
- :verify_ssl => false,
70
- :accept => "json"
71
- ));
104
+ encoded = URI.encode("https://#{username}:#{access_key}@#{host}/v2/jobs/#{jobID}");
105
+
106
+ if !use_https
107
+ response = JSON.parse(RestClient::Request.execute(
108
+ :method => :delete,
109
+ :url => encoded,
110
+ :verify_ssl => false,
111
+ :accept => "json"
112
+ ));
113
+ else
114
+ if ssl_ca_file.to_s.empty?
115
+ response = JSON.parse(RestClient::Request.execute(
116
+ :method => :delete,
117
+ :url => encoded,
118
+ :accept => "json"
119
+ ));
120
+ else
121
+ response = JSON.parse(RestClient::Request.execute(
122
+ :method => :delete,
123
+ :url => encoded,
124
+ :accept => "json",
125
+ :ssl_ca_file => ssl_ca_file.to_s
126
+ ));
127
+ end
128
+
129
+ end
72
130
 
73
131
  rescue => e
74
- error = JSON.parse(e.response)
75
- code = error["errors"][0]["code"]
76
-
77
- puts "\n Error code: #{error['errors'][0]['code']}\n"
78
- puts "\n #{error['errors'][0]['message']}\n\n"
79
-
80
- exit
132
+ if e.to_s == "SSL_connect returned=1 errno=0 state=error: certificate verify failed"
133
+ puts "\n ERROR: Failed to verify certificate\n\n"
134
+ exit
135
+ elsif e.to_s == "hostname \"#{host}\" does not match the server certificate"
136
+ puts "\n ERROR: Hostname \"#{host}\" does not match the server certificate\n\n"
137
+ exit
138
+ elsif e.to_s.include? "No route to host"
139
+ puts "\n ERROR: No route to host. Check connectivity and try again\n\n"
140
+ exit
141
+ elsif e.to_s.== "Timed out connecting to server"
142
+ puts "\n ERROR: Timed out connecting to server. Check connectivity and try again\n\n"
143
+ exit
144
+ elsif e.to_s.== "getaddrinfo: nodename nor servname provided, or not known"
145
+ puts "\n ERROR: Unable to connect to \"#{host}\" \n\n"
146
+ exit
147
+ else
148
+ error = JSON.parse(e.response)
149
+ code = error["errors"][0]["code"]
150
+
151
+ puts "\n Error code: #{error['errors'][0]['code']}\n"
152
+ puts "\n #{error['errors'][0]['message']}\n\n"
153
+
154
+ exit
155
+ end
81
156
 
82
157
  end
83
158
 
@@ -86,24 +161,61 @@ module VagrantPlugins
86
161
  countdown -= 1
87
162
 
88
163
  begin
89
- encoded = URI.encode("https://#{username}:#{access_key}@#{host_ip}/v2/jobs?search=[deploymentEntity.name,fle,#{env[:machine_name]}]");
164
+ encoded = URI.encode("https://#{username}:#{access_key}@#{host}/v2/jobs?search=[deploymentEntity.name,fle,#{env[:machine_name]}]");
90
165
 
91
- response = JSON.parse(RestClient::Request.execute(
166
+ if !use_https
167
+ response = JSON.parse(RestClient::Request.execute(
92
168
  :method => :get,
93
169
  :url => encoded,
94
170
  :verify_ssl => false,
95
171
  :accept => "json",
96
172
  :headers => {"Content-Type" => "application/json"}
97
173
  ));
174
+ else
175
+ if ssl_ca_file.to_s.empty?
176
+ response = JSON.parse(RestClient::Request.execute(
177
+ :method => :get,
178
+ :url => encoded,
179
+ :accept => "json",
180
+ :headers => {"Content-Type" => "application/json"}
181
+ ));
182
+ else
183
+ response = JSON.parse(RestClient::Request.execute(
184
+ :method => :get,
185
+ :url => encoded,
186
+ :ssl_ca_file => ssl_ca_file.to_s,
187
+ :accept => "json",
188
+ :headers => {"Content-Type" => "application/json"}
189
+ ));
190
+ end
191
+
192
+ end
98
193
 
99
194
  rescue => e
100
- error = JSON.parse(e.response)
101
- code = error["errors"][0]["code"]
102
-
103
- puts "\n Error code: #{error['errors'][0]['code']}\n"
104
- puts "\n #{error['errors'][0]['message']}\n\n"
105
-
106
- exit
195
+ if e.to_s == "SSL_connect returned=1 errno=0 state=error: certificate verify failed"
196
+ puts "\n ERROR: Failed to verify certificate\n\n"
197
+ exit
198
+ elsif e.to_s == "hostname \"#{host}\" does not match the server certificate"
199
+ puts "\n ERROR: Hostname \"#{host}\" does not match the server certificate\n\n"
200
+ exit
201
+ elsif e.to_s.include? "No route to host"
202
+ puts "\n ERROR: No route to host. Check connectivity and try again\n\n"
203
+ exit
204
+ elsif e.to_s.== "Timed out connecting to server"
205
+ puts "\n ERROR: Timed out connecting to server. Check connectivity and try again\n\n"
206
+ exit
207
+ elsif e.to_s.== "getaddrinfo: nodename nor servname provided, or not known"
208
+ puts "\n ERROR: Unable to connect to \"#{host}\" \n\n"
209
+ exit
210
+ else
211
+ error = JSON.parse(e.response)
212
+ code = error["errors"][0]["code"]
213
+
214
+ puts "\n Error code: #{error['errors'][0]['code']}\n"
215
+ puts "\n #{error['errors'][0]['message']}\n\n"
216
+
217
+ exit
218
+ end
107
219
 
108
220
  end
109
221
 
@@ -12,7 +12,7 @@ module VagrantPlugins
12
12
  # Get the rest API key for authentication
13
13
 
14
14
 
15
- host_ip = ENV['host_ip']
15
+ host = ENV['host']
16
16
  access_key = ENV['access_key']
17
17
  username = ENV['username']
18
18
 
@@ -34,12 +34,12 @@ module VagrantPlugins
34
34
 
35
35
  if argv[0] && argv[0].match(/\A\d+\z/)
36
36
 
37
- encoded = URI.encode("https://#{username}:#{access_key}@#{host_ip}/v1/apps/#{argv[0]}");
37
+ encoded = URI.encode("https://#{username}:#{access_key}@#{host}/v1/apps/#{argv[0]}");
38
38
 
39
39
  catalog = JSON.parse(RestClient::Request.execute(
40
40
  :method => :get,
41
41
  :url => encoded,
42
- :verify_ssl => false,
42
+ #:verify_ssl => false,
43
43
  :content_type => "json",
44
44
  :accept => "json"
45
45
  ));
@@ -48,18 +48,30 @@ module VagrantPlugins
48
48
  end
49
49
  rescue => e
50
50
 
51
- if e.inspect == "Timed out connecting to server"
52
- puts "\n#ConnectionError - Unable to connnect to CloudCenter Manager \n"
53
- exit
54
- else
55
- error = JSON.parse(e.response)
56
- code = error["errors"][0]["code"]
51
+ if e.to_s == "SSL_connect returned=1 errno=0 state=error: certificate verify failed"
52
+ puts "\n ERROR: Failed to verify certificate\n\n"
53
+ exit
54
+ elsif e.to_s == "hostname \"#{host}\" does not match the server certificate"
55
+ puts "\n ERROR: Hostname \"#{host}\" does not match the server certificate\n\n"
56
+ exit
57
+ elsif e.to_s.include? "No route to host"
58
+ puts "\n ERROR: No route to host. Check connectivity and try again\n\n"
59
+ exit
60
+ elsif e.to_s.== "Timed out connecting to server"
61
+ puts "\n ERROR: Timed out connecting to server. Check connectivity and try again\n\n"
62
+ exit
63
+ elsif e.to_s.== "getaddrinfo: nodename nor servname provided, or not known"
64
+ puts "\n ERROR: Unable to connect to \"#{host}\" \n\n"
65
+ exit
66
+ else
67
+ error = JSON.parse(e.response)
68
+ code = error["errors"][0]["code"]
57
69
 
58
- puts "\n Error code: #{error['errors'][0]['code']}\n"
70
+ puts "\n Error code: #{error['errors'][0]['code']}\n"
59
71
  puts "\n #{error['errors'][0]['message']}\n\n"
60
72
 
61
- exit
62
- end
73
+ exit
74
+ end
63
75
  end
64
76
 
65
77
 
@@ -10,7 +10,7 @@ module VagrantPlugins
10
10
 
11
11
  access_key = ""
12
12
  username = ""
13
- host_ip = ""
13
+ host = ""
14
14
 
15
15
  if File.exists?("VagrantFile")
16
16
  File.readlines("VagrantFile").grep(/cloudcenter.access_key/) do |line|
@@ -24,9 +24,9 @@ module VagrantPlugins
24
24
 
25
25
  end
26
26
  end
27
- File.readlines("VagrantFile").grep(/cloudcenter.host_ip/) do |line|
27
+ File.readlines("VagrantFile").grep(/cloudcenter.host/) do |line|
28
28
  unless line.empty?
29
- host_ip = line.scan(/["']([^"']*)["']/)[0][0]
29
+ host = line.scan(/["']([^"']*)["']/)[0][0]
30
30
 
31
31
  end
32
32
  end
@@ -38,8 +38,8 @@ module VagrantPlugins
38
38
  if username.empty?
39
39
  username = ENV["username"]
40
40
  end
41
- if host_ip.empty?
42
- host_ip = ENV["host_ip"]
41
+ if host.empty?
42
+ host = ENV["host"]
43
43
  end
44
44
 
45
45
  if access_key.nil?
@@ -48,19 +48,19 @@ module VagrantPlugins
48
48
  if username.nil?
49
49
  puts "Username missing. Please enter into VagrantFile or environmental variable 'export username= '"
50
50
  end
51
- if host_ip.nil?
52
- puts "Host IP missing. Please enter into VagrantFile or environmental variable 'export host_ip= '"
51
+ if host.nil?
52
+ puts "Host IP missing. Please enter into VagrantFile or environmental variable 'export host= '"
53
53
  end
54
54
 
55
- if !(access_key.nil? or username.nil? or host_ip.nil?)
55
+ if !(access_key.nil? or username.nil? or host.nil?)
56
56
  begin
57
57
 
58
- encoded = URI.encode("https://#{username}:#{access_key}@#{host_ip}/v1/apps");
58
+ encoded = URI.encode("https://#{username}:#{access_key}@#{host}/v1/apps");
59
59
 
60
60
  catalog = JSON.parse(RestClient::Request.execute(
61
61
  :method => :get,
62
62
  :url => encoded,
63
- :verify_ssl => false,
63
+ #:verify_ssl => false,
64
64
  :content_type => "json",
65
65
  :accept => "json"
66
66
  ));
@@ -91,18 +91,30 @@ module VagrantPlugins
91
91
 
92
92
  rescue => e
93
93
 
94
- if e.inspect == "Timed out connecting to server"
95
- puts "\n#ConnectionError - Unable to connnect to CloudCenter Manager \n"
96
- exit
97
- else
98
- error = JSON.parse(e.response)
99
- code = error["errors"][0]["code"]
94
+ if e.to_s == "SSL_connect returned=1 errno=0 state=error: certificate verify failed"
95
+ puts "\n ERROR: Failed to verify certificate\n\n"
96
+ exit
97
+ elsif e.to_s == "hostname \"#{host}\" does not match the server certificate"
98
+ puts "\n ERROR: Hostname \"#{host}\" does not match the server certificate\n\n"
99
+ exit
100
+ elsif e.to_s.include? "No route to host"
101
+ puts "\n ERROR: No route to host. Check connectivity and try again\n\n"
102
+ exit
103
+ elsif e.to_s.== "Timed out connecting to server"
104
+ puts "\n ERROR: Timed out connecting to server. Check connectivity and try again\n\n"
105
+ exit
106
+ elsif e.to_s.== "getaddrinfo: nodename nor servname provided, or not known"
107
+ puts "\n ERROR: Unable to connect to \"#{host}\" \n\n"
108
+ exit
109
+ else
110
+ error = JSON.parse(e.response)
111
+ code = error["errors"][0]["code"]
100
112
 
101
- puts "\n Error code: #{error['errors'][0]['code']}\n"
113
+ puts "\n Error code: #{error['errors'][0]['code']}\n"
102
114
  puts "\n #{error['errors'][0]['message']}\n\n"
103
115
 
104
- exit
105
- end
116
+ exit
117
+ end
106
118
  end
107
119
  end
108
120
 
@@ -24,10 +24,16 @@ Vagrant.configure(2) do |config|
24
24
  config.ssh.insert_key = false
25
25
 
26
26
  config.vm.provider :cloudcenter do |cloudcenter|
27
+
27
28
  cloudcenter.username = 'my_username'
28
29
  cloudcenter.access_key = 'my_access_key'
29
- cloudcenter.host_ip = 'cloudcenter_host_ip_address'
30
+
31
+ cloudcenter.host = 'cloudcenter_host_address'
30
32
  cloudcenter.deployment_config = 'sample_deployment_config.json'
33
+
34
+ cloudcenter.use_https = true
35
+ cloudcenter.ssl_ca_file = '/path/to/ca_file'
36
+
31
37
  end
32
38
 
33
39
  config.vm.synced_folder '.', '/opt/my_files/', type: 'rsync'
@@ -10,7 +10,7 @@ module VagrantPlugins
10
10
 
11
11
  access_key = ""
12
12
  username = ""
13
- host_ip = ""
13
+ host = ""
14
14
 
15
15
 
16
16
  if File.exists?("VagrantFile")
@@ -25,9 +25,9 @@ module VagrantPlugins
25
25
 
26
26
  end
27
27
  end
28
- File.readlines("VagrantFile").grep(/cloudcenter.host_ip/) do |line|
28
+ File.readlines("VagrantFile").grep(/cloudcenter.host/) do |line|
29
29
  unless line.empty?
30
- host_ip = line.scan(/["']([^"']*)["']/)[0][0]
30
+ host = line.scan(/["']([^"']*)["']/)[0][0]
31
31
 
32
32
  end
33
33
  end
@@ -39,8 +39,8 @@ module VagrantPlugins
39
39
  if username.empty?
40
40
  username = ENV["username"]
41
41
  end
42
- if host_ip.empty?
43
- host_ip = ENV["host_ip"]
42
+ if host.empty?
43
+ host = ENV["host"]
44
44
  end
45
45
 
46
46
 
@@ -50,19 +50,19 @@ module VagrantPlugins
50
50
  if username.nil?
51
51
  puts "Username missing. Please enter into VagrantFile or environmental variable 'export username= '"
52
52
  end
53
- if host_ip.nil?
54
- puts "Host IP missing. Please enter into VagrantFile or environmental variable 'export host_ip= '"
53
+ if host.nil?
54
+ puts "Host address missing. Please enter into VagrantFile or environmental variable 'export host= '"
55
55
  end
56
56
 
57
- if !(access_key.nil? or username.nil? or host_ip.nil?)
57
+ if !(access_key.nil? or username.nil? or host.nil?)
58
58
  begin
59
59
 
60
- encoded = URI.encode("https://#{username}:#{access_key}@#{host_ip}/v2/jobs");
60
+ encoded = URI.encode("https://#{username}:#{access_key}@#{host}/v2/jobs");
61
61
 
62
62
  catalog = JSON.parse(RestClient::Request.execute(
63
63
  :method => :get,
64
64
  :url => encoded,
65
- :verify_ssl => false,
65
+ #:verify_ssl => false,
66
66
  :content_type => "json",
67
67
  :accept => "json"
68
68
  ));
@@ -95,18 +95,30 @@ module VagrantPlugins
95
95
 
96
96
  rescue => e
97
97
 
98
- if e.inspect == "Timed out connecting to server"
99
- puts "\n#ConnectionError - Unable to connnect to CloudCenter Manager \n"
100
- exit
101
- else
102
- error = JSON.parse(e.response)
103
- code = error["errors"][0]["code"]
98
+ if e.to_s == "SSL_connect returned=1 errno=0 state=error: certificate verify failed"
99
+ puts "\n ERROR: Failed to verify certificate\n\n"
100
+ exit
101
+ elsif e.to_s == "hostname \"#{host}\" does not match the server certificate"
102
+ puts "\n ERROR: Hostname \"#{host}\" does not match the server certificate\n\n"
103
+ exit
104
+ elsif e.to_s.include? "No route to host"
105
+ puts "\n ERROR: No route to host. Check connectivity and try again\n\n"
106
+ exit
107
+ elsif e.to_s.== "Timed out connecting to server"
108
+ puts "\n ERROR: Timed out connecting to server. Check connectivity and try again\n\n"
109
+ exit
110
+ elsif e.to_s.== "getaddrinfo: nodename nor servname provided, or not known"
111
+ puts "\n ERROR: Unable to connect to \"#{host}\" \n\n"
112
+ exit
113
+ else
114
+ error = JSON.parse(e.response)
115
+ code = error["errors"][0]["code"]
104
116
 
105
- puts "\n Error code: #{error['errors'][0]['code']}\n"
117
+ puts "\n Error code: #{error['errors'][0]['code']}\n"
106
118
  puts "\n #{error['errors'][0]['message']}\n\n"
107
119
 
108
- exit
109
- end
120
+ exit
121
+ end
110
122
  end
111
123
  end
112
124
 
@@ -8,10 +8,10 @@ module VagrantPlugins
8
8
  # @return [String]
9
9
  attr_accessor :access_key
10
10
 
11
- # The Catalog Name for the VM to be provisioned from
11
+ # The address of the host
12
12
  #
13
13
  # @return [String]
14
- attr_accessor :host_ip
14
+ attr_accessor :host
15
15
 
16
16
  # Comment to use when provisioning the VM
17
17
  #
@@ -23,13 +23,23 @@ module VagrantPlugins
23
23
  # @return [String]
24
24
  attr_accessor :deployment_config
25
25
 
26
-
26
+ # Whether or not to use HTTPS
27
+ #
28
+ # @return [boolean]
29
+ attr_accessor :use_https
30
+
31
+ # Path to the SSL CA file
32
+ #
33
+ # @return [String]
34
+ attr_accessor :ssl_ca_file
35
+
27
36
  def initialize()
28
- @access_key = UNSET_VALUE
29
- @host_ip = UNSET_VALUE
30
- @host_port = UNSET_VALUE
31
- @username = UNSET_VALUE
32
- @deployment_config = UNSET_VALUE
37
+ @access_key = UNSET_VALUE
38
+ @host = UNSET_VALUE
39
+ @username = UNSET_VALUE
40
+ @deployment_config = UNSET_VALUE
41
+ @use_https = true
42
+ @ssl_ca_file = ''
33
43
  end
34
44
  end
35
45
  end
@@ -1,3 +1,3 @@
1
1
  module Cloudcenter
2
- VERSION = "0.1.0"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-cloudcenter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Conor Murphy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-27 00:00:00.000000000 Z
11
+ date: 2017-07-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: highline