vmware-vra 2.7.0 → 3.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -1
- data/CHANGELOG.md +27 -1
- data/README.md +91 -141
- data/Rakefile +1 -12
- data/lib/vra/catalog.rb +39 -8
- data/lib/vra/catalog_base.rb +62 -0
- data/lib/vra/catalog_item.rb +29 -75
- data/lib/vra/catalog_source.rb +116 -0
- data/lib/vra/catalog_type.rb +56 -0
- data/lib/vra/client.rb +72 -53
- data/lib/vra/deployment.rb +155 -0
- data/lib/vra/deployment_request.rb +117 -0
- data/lib/vra/{resources.rb → deployments.rb} +26 -17
- data/lib/vra/exceptions.rb +2 -2
- data/lib/vra/http.rb +20 -7
- data/lib/vra/request.rb +28 -36
- data/lib/vra/request_parameters.rb +12 -10
- data/lib/vra/resource.rb +33 -203
- data/lib/vra/version.rb +2 -2
- data/lib/vra.rb +15 -12
- data/spec/catalog_item_spec.rb +64 -222
- data/spec/catalog_source_spec.rb +178 -0
- data/spec/catalog_spec.rb +112 -72
- data/spec/catalog_type_spec.rb +114 -0
- data/spec/client_spec.rb +287 -228
- data/spec/deployment_request_spec.rb +192 -0
- data/spec/deployment_spec.rb +227 -0
- data/spec/deployments_spec.rb +80 -0
- data/spec/fixtures/resource/sample_catalog_item.json +18 -0
- data/spec/fixtures/resource/sample_catalog_item_2.json +18 -0
- data/spec/fixtures/resource/sample_catalog_source.json +20 -0
- data/spec/fixtures/resource/sample_catalog_type.json +49 -0
- data/spec/fixtures/resource/sample_dep_actions.json +58 -0
- data/spec/fixtures/resource/sample_dep_request.json +19 -0
- data/spec/fixtures/resource/sample_dep_resource.json +112 -0
- data/spec/fixtures/resource/sample_deployment.json +26 -0
- data/spec/fixtures/resource/sample_entitlements.json +25 -0
- data/spec/http_spec.rb +63 -61
- data/spec/request_spec.rb +62 -68
- data/spec/resource_spec.rb +71 -390
- data/spec/spec_helper.rb +10 -4
- data/vmware-vra.gemspec +2 -4
- metadata +42 -32
- data/.travis.yml +0 -14
- data/lib/vra/catalog_request.rb +0 -127
- data/lib/vra/requests.rb +0 -41
- data/spec/catalog_request_spec.rb +0 -265
- data/spec/requests_spec.rb +0 -60
- data/spec/resources_spec.rb +0 -71
data/lib/vra/resource.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
#
|
3
3
|
# Author:: Chef Partner Engineering (<partnereng@chef.io>)
|
4
|
-
# Copyright:: Copyright (c)
|
4
|
+
# Copyright:: Copyright (c) 2022 Chef Software, Inc.
|
5
5
|
# License:: Apache License, Version 2.0
|
6
6
|
#
|
7
7
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -17,255 +17,85 @@
|
|
17
17
|
# limitations under the License.
|
18
18
|
#
|
19
19
|
|
20
|
-
require "ffi_yajl"
|
20
|
+
require "ffi_yajl" unless defined?(FFI_Yajl)
|
21
21
|
|
22
22
|
module Vra
|
23
23
|
class Resource
|
24
|
-
|
24
|
+
VM_TYPES = %w[
|
25
|
+
Cloud.vSphere.Machine
|
26
|
+
Cloud.Machine
|
27
|
+
].freeze
|
25
28
|
|
26
|
-
|
29
|
+
attr_reader :client, :deployment_id, :id, :resource_data
|
30
|
+
|
31
|
+
def initialize(client, deployment_id, opts = {})
|
27
32
|
@client = client
|
33
|
+
@deployment_id = deployment_id
|
28
34
|
@id = opts[:id]
|
29
35
|
@resource_data = opts[:data]
|
30
36
|
@resource_actions = []
|
31
37
|
|
32
|
-
if @id.nil? && @resource_data.nil?
|
33
|
-
|
34
|
-
end
|
35
|
-
|
36
|
-
if !@id.nil? && !@resource_data.nil?
|
37
|
-
raise ArgumentError, "must supply an id OR a resource data hash, not both"
|
38
|
-
end
|
38
|
+
raise ArgumentError, 'must supply an id or a resource data hash' if @id.nil? && @resource_data.nil?
|
39
|
+
raise ArgumentError, 'must supply an id OR a resource data hash, not both' if !@id.nil? && !@resource_data.nil?
|
39
40
|
|
40
41
|
if @resource_data.nil?
|
41
42
|
fetch_resource_data
|
42
43
|
else
|
43
|
-
@id = @resource_data[
|
44
|
+
@id = @resource_data['id']
|
44
45
|
end
|
45
46
|
end
|
46
47
|
|
47
|
-
# @param client [Vra::Client]
|
48
|
-
# @param name [String] - the hostname of the client you wish to lookup
|
49
|
-
# @preturn [Vra::Resource] - return nil if not found, otherwise the resource associated with the name
|
50
|
-
def self.by_name(client, name)
|
51
|
-
raise ArgumentError.new("name cannot be nil") if name.nil?
|
52
|
-
raise ArgumentError.new("client cannot be nil") if client.nil?
|
53
|
-
Resources.all(client).find { |r| r.name.downcase =~ /#{name.downcase}/ }
|
54
|
-
end
|
55
|
-
|
56
48
|
def fetch_resource_data
|
57
|
-
@resource_data = client.get_parsed("/
|
49
|
+
@resource_data = client.get_parsed("/deployment/api/deployments/#{deployment_id}/resources/#{id}")
|
58
50
|
rescue Vra::Exception::HTTPNotFound
|
59
51
|
raise Vra::Exception::NotFound, "resource ID #{@id} does not exist"
|
60
52
|
end
|
53
|
+
|
61
54
|
alias refresh fetch_resource_data
|
62
55
|
|
63
56
|
def name
|
64
|
-
resource_data[
|
65
|
-
end
|
66
|
-
|
67
|
-
def description
|
68
|
-
resource_data["description"]
|
57
|
+
resource_data['name']
|
69
58
|
end
|
70
59
|
|
71
60
|
def status
|
72
|
-
resource_data[
|
73
|
-
end
|
74
|
-
|
75
|
-
def vm?
|
76
|
-
%w{Infrastructure.Virtual Infrastructure.Cloud}.include?(resource_data["resourceTypeRef"]["id"])
|
77
|
-
end
|
78
|
-
|
79
|
-
def organization
|
80
|
-
return {} if resource_data["organization"].nil?
|
81
|
-
|
82
|
-
resource_data["organization"]
|
83
|
-
end
|
84
|
-
|
85
|
-
def tenant_id
|
86
|
-
organization["tenantRef"]
|
87
|
-
end
|
88
|
-
|
89
|
-
def tenant_name
|
90
|
-
organization["tenantLabel"]
|
91
|
-
end
|
92
|
-
|
93
|
-
def subtenant_id
|
94
|
-
organization["subtenantRef"]
|
95
|
-
end
|
96
|
-
|
97
|
-
def subtenant_name
|
98
|
-
organization["subtenantLabel"]
|
99
|
-
end
|
100
|
-
|
101
|
-
def catalog_item
|
102
|
-
return {} if resource_data["catalogItem"].nil?
|
103
|
-
|
104
|
-
resource_data["catalogItem"]
|
105
|
-
end
|
106
|
-
|
107
|
-
def catalog_id
|
108
|
-
catalog_item["id"]
|
61
|
+
resource_data['syncStatus']
|
109
62
|
end
|
110
63
|
|
111
|
-
def
|
112
|
-
|
64
|
+
def properties
|
65
|
+
resource_data['properties']
|
113
66
|
end
|
114
67
|
|
115
|
-
def
|
116
|
-
resource_data[
|
68
|
+
def vm?
|
69
|
+
VM_TYPES.include?(resource_data['type'])
|
117
70
|
end
|
118
71
|
|
119
72
|
def owner_names
|
120
|
-
|
121
|
-
end
|
122
|
-
|
123
|
-
def machine_status
|
124
|
-
status = resource_data["resourceData"]["entries"].find { |x| x["key"] == "MachineStatus" }
|
125
|
-
raise "No MachineStatus entry available for resource" if status.nil?
|
126
|
-
|
127
|
-
status["value"]["value"]
|
128
|
-
end
|
129
|
-
|
130
|
-
def machine_on?
|
131
|
-
machine_status == "On"
|
132
|
-
end
|
133
|
-
|
134
|
-
def machine_off?
|
135
|
-
machine_status == "Off"
|
73
|
+
properties['Owner']
|
136
74
|
end
|
137
75
|
|
138
|
-
def
|
139
|
-
|
140
|
-
end
|
141
|
-
|
142
|
-
def machine_turning_off?
|
143
|
-
%w{TurningOff ShuttingDown}.include?(machine_status)
|
144
|
-
end
|
145
|
-
|
146
|
-
def machine_in_provisioned_state?
|
147
|
-
machine_status == "MachineProvisioned"
|
76
|
+
def project_id
|
77
|
+
properties['project']
|
148
78
|
end
|
149
79
|
|
150
80
|
def network_interfaces
|
151
81
|
return unless vm?
|
152
82
|
|
153
|
-
network_list =
|
83
|
+
network_list = properties['networks']
|
154
84
|
return if network_list.nil?
|
155
85
|
|
156
|
-
network_list
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
end
|
163
|
-
|
164
|
-
nics << nic
|
86
|
+
network_list.each_with_object([]) do |item, nics|
|
87
|
+
nics << {
|
88
|
+
'NETWORK_NAME' => item['name'],
|
89
|
+
'NETWORK_ADDRESS' => item['address'],
|
90
|
+
'NETWORK_MAC_ADDRESS' => item['mac_address']
|
91
|
+
}
|
165
92
|
end
|
166
93
|
end
|
167
94
|
|
168
|
-
def
|
95
|
+
def ip_address
|
169
96
|
return if !vm? || network_interfaces.nil?
|
170
97
|
|
171
|
-
|
172
|
-
|
173
|
-
request_id = @resource_data["requestId"]
|
174
|
-
|
175
|
-
print "Waiting For vRA to collect the IP"
|
176
|
-
|
177
|
-
loop do
|
178
|
-
resource_views = @client.http_get("/catalog-service/api/consumer/requests/#{request_id}/resourceViews")
|
179
|
-
|
180
|
-
JSON.parse(resource_views.body)["content"].each do |content|
|
181
|
-
if content.key?("data") &&
|
182
|
-
!(content["data"]["ip_address"].nil? ||
|
183
|
-
content["data"]["ip_address"] == "")
|
184
|
-
addrs << content["data"]["ip_address"]
|
185
|
-
end
|
186
|
-
end
|
187
|
-
|
188
|
-
break unless addrs.empty?
|
189
|
-
|
190
|
-
sleep 10
|
191
|
-
end
|
192
|
-
|
193
|
-
addrs
|
194
|
-
end
|
195
|
-
|
196
|
-
def actions
|
197
|
-
# if this Resource instance was created with data from a "all_resources" fetch,
|
198
|
-
# it is likely missing operations data because the vRA API is not pleasant sometimes.
|
199
|
-
fetch_resource_data if resource_data["operations"].nil?
|
200
|
-
|
201
|
-
resource_data["operations"]
|
202
|
-
end
|
203
|
-
|
204
|
-
def action_id_by_name(name)
|
205
|
-
return if actions.nil?
|
206
|
-
|
207
|
-
action = actions.find { |x| x["name"] == name }
|
208
|
-
return if action.nil?
|
209
|
-
|
210
|
-
action["id"]
|
211
|
-
end
|
212
|
-
|
213
|
-
def destroy
|
214
|
-
action_id = action_id_by_name("Destroy")
|
215
|
-
raise Vra::Exception::NotFound, "No destroy action found for resource #{@id}" if action_id.nil?
|
216
|
-
|
217
|
-
submit_action_request(action_id)
|
218
|
-
end
|
219
|
-
|
220
|
-
def shutdown
|
221
|
-
action_id = action_id_by_name("Shutdown")
|
222
|
-
raise Vra::Exception::NotFound, "No shutdown action found for resource #{@id}" if action_id.nil?
|
223
|
-
|
224
|
-
submit_action_request(action_id)
|
225
|
-
end
|
226
|
-
|
227
|
-
def poweroff
|
228
|
-
action_id = action_id_by_name("Power Off")
|
229
|
-
raise Vra::Exception::NotFound, "No power-off action found for resource #{@id}" if action_id.nil?
|
230
|
-
|
231
|
-
submit_action_request(action_id)
|
232
|
-
end
|
233
|
-
|
234
|
-
def poweron
|
235
|
-
action_id = action_id_by_name("Power On")
|
236
|
-
raise Vra::Exception::NotFound, "No power-on action found for resource #{@id}" if action_id.nil?
|
237
|
-
|
238
|
-
submit_action_request(action_id)
|
239
|
-
end
|
240
|
-
|
241
|
-
def action_request_payload(action_id)
|
242
|
-
{
|
243
|
-
"@type" => "ResourceActionRequest",
|
244
|
-
"resourceRef" => {
|
245
|
-
"id" => @id,
|
246
|
-
},
|
247
|
-
"resourceActionRef" => {
|
248
|
-
"id" => action_id,
|
249
|
-
},
|
250
|
-
"organization" => {
|
251
|
-
"tenantRef" => tenant_id,
|
252
|
-
"tenantLabel" => tenant_name,
|
253
|
-
"subtenantRef" => subtenant_id,
|
254
|
-
"subtenantLabel" => subtenant_name,
|
255
|
-
},
|
256
|
-
"state" => "SUBMITTED",
|
257
|
-
"requestNumber" => 0,
|
258
|
-
"requestData" => {
|
259
|
-
"entries" => [],
|
260
|
-
},
|
261
|
-
}
|
262
|
-
end
|
263
|
-
|
264
|
-
def submit_action_request(action_id)
|
265
|
-
payload = action_request_payload(action_id).to_json
|
266
|
-
response = client.http_post("/catalog-service/api/consumer/requests", payload)
|
267
|
-
request_id = response.location.split("/")[-1]
|
268
|
-
Vra::Request.new(client, request_id)
|
98
|
+
properties['address']
|
269
99
|
end
|
270
100
|
end
|
271
101
|
end
|
data/lib/vra/version.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
#
|
3
3
|
# Author:: Chef Partner Engineering (<partnereng@chef.io>)
|
4
|
-
# Copyright:: Copyright (c)
|
4
|
+
# Copyright:: Copyright (c) 2022 Chef Software, Inc.
|
5
5
|
# License:: Apache License, Version 2.0
|
6
6
|
#
|
7
7
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -18,5 +18,5 @@
|
|
18
18
|
#
|
19
19
|
|
20
20
|
module Vra
|
21
|
-
VERSION = "
|
21
|
+
VERSION = "3.0.1"
|
22
22
|
end
|
data/lib/vra.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
#
|
3
3
|
# Author:: Chef Partner Engineering (<partnereng@chef.io>)
|
4
|
-
# Copyright:: Copyright (c)
|
4
|
+
# Copyright:: Copyright (c) 2022 Chef Software, Inc.
|
5
5
|
# License:: Apache License, Version 2.0
|
6
6
|
#
|
7
7
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -17,14 +17,17 @@
|
|
17
17
|
# limitations under the License.
|
18
18
|
#
|
19
19
|
|
20
|
-
require
|
21
|
-
require
|
22
|
-
require
|
23
|
-
require
|
24
|
-
require
|
25
|
-
require
|
26
|
-
require
|
27
|
-
require
|
28
|
-
require
|
29
|
-
require
|
30
|
-
require
|
20
|
+
require 'vra/catalog_base'
|
21
|
+
require 'vra/catalog'
|
22
|
+
require 'vra/catalog_item'
|
23
|
+
require 'vra/catalog_source'
|
24
|
+
require 'vra/catalog_type'
|
25
|
+
require 'vra/deployment_request'
|
26
|
+
require 'vra/deployment'
|
27
|
+
require 'vra/deployments'
|
28
|
+
require 'vra/client'
|
29
|
+
require 'vra/exceptions'
|
30
|
+
require 'vra/request'
|
31
|
+
require 'vra/request_parameters'
|
32
|
+
require 'vra/resource'
|
33
|
+
require 'vra/version'
|