vmware-vra 3.1.0 → 3.1.3
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.
- checksums.yaml +4 -4
- data/.github/workflows/linters.yml +9 -0
- data/.markdownlint.yaml +5 -0
- data/.mdlrc +1 -0
- data/CHANGELOG.md +196 -143
- data/Gemfile +3 -0
- data/README.md +37 -26
- data/Rakefile +2 -2
- data/lib/vra/catalog.rb +6 -7
- data/lib/vra/catalog_base.rb +4 -4
- data/lib/vra/catalog_item.rb +12 -12
- data/lib/vra/catalog_source.rb +13 -13
- data/lib/vra/catalog_type.rb +6 -6
- data/lib/vra/client.rb +13 -13
- data/lib/vra/deployment.rb +21 -21
- data/lib/vra/deployment_request.rb +8 -9
- data/lib/vra/deployments.rb +1 -1
- data/lib/vra/http.rb +6 -6
- data/lib/vra/request.rb +6 -6
- data/lib/vra/request_parameters.rb +9 -9
- data/lib/vra/resource.rb +16 -16
- data/lib/vra/version.rb +1 -1
- data/lib/vra.rb +14 -14
- data/spec/catalog_item_spec.rb +50 -50
- data/spec/catalog_source_spec.rb +53 -53
- data/spec/catalog_spec.rb +45 -45
- data/spec/catalog_type_spec.rb +32 -32
- data/spec/client_spec.rb +202 -202
- data/spec/deployment_request_spec.rb +74 -74
- data/spec/deployment_spec.rb +70 -70
- data/spec/deployments_spec.rb +19 -19
- data/spec/http_spec.rb +59 -59
- data/spec/request_spec.rb +34 -34
- data/spec/resource_spec.rb +55 -55
- data/spec/spec_helper.rb +4 -4
- data/vmware-vra.gemspec +1 -1
- metadata +8 -7
- data/.github/ISSUE_TEMPLATE.md +0 -23
- data/.github/PULL_REQUEST_TEMPLATE.md +0 -14
data/lib/vra/deployment.rb
CHANGED
@@ -22,7 +22,7 @@ require "ffi_yajl" unless defined?(FFI_Yajl)
|
|
22
22
|
module Vra
|
23
23
|
# Class that represents the Deployment Object
|
24
24
|
class Deployment
|
25
|
-
INDEX_URL =
|
25
|
+
INDEX_URL = "/deployment/api/deployments"
|
26
26
|
|
27
27
|
attr_reader :id
|
28
28
|
|
@@ -35,40 +35,40 @@ module Vra
|
|
35
35
|
if @data.nil?
|
36
36
|
refresh
|
37
37
|
elsif @id.nil?
|
38
|
-
@id = @data[
|
38
|
+
@id = @data["id"]
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
42
|
def name
|
43
|
-
@data[
|
43
|
+
@data["name"]
|
44
44
|
end
|
45
45
|
|
46
46
|
def description
|
47
|
-
@data[
|
47
|
+
@data["description"]
|
48
48
|
end
|
49
49
|
|
50
50
|
def org_id
|
51
|
-
@data[
|
51
|
+
@data["orgId"]
|
52
52
|
end
|
53
53
|
|
54
54
|
def blueprint_id
|
55
|
-
@data[
|
55
|
+
@data["blueprintId"]
|
56
56
|
end
|
57
57
|
|
58
58
|
def owner
|
59
|
-
@data[
|
59
|
+
@data["ownedBy"]
|
60
60
|
end
|
61
61
|
|
62
62
|
def status
|
63
|
-
@data[
|
63
|
+
@data["status"]
|
64
64
|
end
|
65
65
|
|
66
66
|
def successful?
|
67
|
-
status ==
|
67
|
+
status == "CREATE_SUCCESSFUL"
|
68
68
|
end
|
69
69
|
|
70
70
|
def failed?
|
71
|
-
status ==
|
71
|
+
status == "CREATE_FAILED"
|
72
72
|
end
|
73
73
|
|
74
74
|
def completed?
|
@@ -80,16 +80,16 @@ module Vra
|
|
80
80
|
end
|
81
81
|
|
82
82
|
def action_id_by_name(action_name)
|
83
|
-
action = actions.find { |x| x[
|
83
|
+
action = actions.find { |x| x["name"] == action_name }
|
84
84
|
return if action.nil?
|
85
85
|
|
86
|
-
action[
|
86
|
+
action["id"]
|
87
87
|
end
|
88
88
|
|
89
89
|
def resources
|
90
90
|
response = client.get_parsed("/deployment/api/deployments/#{id}/resources")
|
91
91
|
|
92
|
-
response[
|
92
|
+
response["content"].map! { |x| Vra::Resource.new(client, id, data: x) }
|
93
93
|
end
|
94
94
|
|
95
95
|
def resource_by_id(res_id)
|
@@ -99,7 +99,7 @@ module Vra
|
|
99
99
|
def requests
|
100
100
|
response = client.get_parsed("/deployment/api/deployments/#{id}/requests")
|
101
101
|
|
102
|
-
response[
|
102
|
+
response["content"].map! { |x| Vra::Request.new(client, id, id: x["id"], data: x) }
|
103
103
|
end
|
104
104
|
|
105
105
|
def refresh
|
@@ -108,22 +108,22 @@ module Vra
|
|
108
108
|
raise Vra::Exception::NotFound, "deployment with ID #{id} does not exist"
|
109
109
|
end
|
110
110
|
|
111
|
-
def destroy(reason =
|
112
|
-
action_id = action_id_by_name(
|
111
|
+
def destroy(reason = "")
|
112
|
+
action_id = action_id_by_name("Delete")
|
113
113
|
raise Vra::Exception::NotFound, "No destroy action found for resource #{@id}" if action_id.nil?
|
114
114
|
|
115
115
|
submit_action_request(action_id, reason)
|
116
116
|
end
|
117
117
|
|
118
|
-
def power_off(reason =
|
119
|
-
action_id = action_id_by_name(
|
118
|
+
def power_off(reason = "")
|
119
|
+
action_id = action_id_by_name("PowerOff")
|
120
120
|
raise Vra::Exception::NotFound, "No power-off action found for resource #{@id}" if action_id.nil?
|
121
121
|
|
122
122
|
submit_action_request(action_id, reason)
|
123
123
|
end
|
124
124
|
|
125
125
|
def power_on(reason = nil)
|
126
|
-
action_id = action_id_by_name(
|
126
|
+
action_id = action_id_by_name("PowerOn")
|
127
127
|
raise Vra::Exception::NotFound, "No power-on action found for resource #{@id}" if action_id.nil?
|
128
128
|
|
129
129
|
submit_action_request(action_id, reason)
|
@@ -134,7 +134,7 @@ module Vra
|
|
134
134
|
attr_reader :client, :data
|
135
135
|
|
136
136
|
def validate!
|
137
|
-
raise ArgumentError,
|
137
|
+
raise ArgumentError, "must supply id or data hash" if @id.nil? && @data.nil?
|
138
138
|
end
|
139
139
|
|
140
140
|
def submit_action_request(action_id, reason)
|
@@ -148,7 +148,7 @@ module Vra
|
|
148
148
|
{
|
149
149
|
"actionId": action_id,
|
150
150
|
"inputs": {},
|
151
|
-
"reason": reason
|
151
|
+
"reason": reason,
|
152
152
|
}
|
153
153
|
end
|
154
154
|
end
|
@@ -16,7 +16,7 @@
|
|
16
16
|
# See the License for the specific language governing permissions and
|
17
17
|
# limitations under the License.
|
18
18
|
#
|
19
|
-
require
|
19
|
+
require "ffi_yajl" unless defined?(FFI_Yajl)
|
20
20
|
|
21
21
|
# Overriding the hash object to add the deep_merge method
|
22
22
|
class ::Hash
|
@@ -50,12 +50,12 @@ module Vra
|
|
50
50
|
begin
|
51
51
|
response = send_request!
|
52
52
|
rescue Vra::Exception::HTTPError => e
|
53
|
-
raise Vra::Exception::RequestError, "Unable to submit request: #{e.message}, trace: #{e.errors.join(
|
53
|
+
raise Vra::Exception::RequestError, "Unable to submit request: #{e.message}, trace: #{e.errors.join(", ")}"
|
54
54
|
rescue StandardError => e
|
55
55
|
raise e, e.message
|
56
56
|
end
|
57
57
|
|
58
|
-
request_id = FFI_Yajl::Parser.parse(response)[0][
|
58
|
+
request_id = FFI_Yajl::Parser.parse(response)[0]["deploymentId"]
|
59
59
|
Vra::Deployment.new(client, id: request_id)
|
60
60
|
end
|
61
61
|
|
@@ -85,21 +85,20 @@ module Vra
|
|
85
85
|
|
86
86
|
def validate!
|
87
87
|
missing_params = []
|
88
|
-
%i
|
88
|
+
%i{image_mapping flavor_mapping name project_id}.each do |arg|
|
89
89
|
missing_params << arg if send(arg).nil?
|
90
90
|
end
|
91
91
|
|
92
92
|
unless missing_params.empty?
|
93
|
-
raise ArgumentError, "Unable to submit request, required param(s) missing => #{missing_params.join(
|
93
|
+
raise ArgumentError, "Unable to submit request, required param(s) missing => #{missing_params.join(", ")}"
|
94
94
|
end
|
95
95
|
|
96
96
|
# If the user doesn't supply the catalog version, fetch the latest version and use it
|
97
97
|
# and if the API was unable to find a valid version, alert the user.
|
98
98
|
return unless @version.nil?
|
99
99
|
|
100
|
-
|
101
100
|
@version = CatalogItem.fetch_latest_version(client, catalog_id)
|
102
|
-
raise ArgumentError,
|
101
|
+
raise ArgumentError, "Unable to fetch a valid catalog version" if @version.nil?
|
103
102
|
end
|
104
103
|
|
105
104
|
def send_request!
|
@@ -117,8 +116,8 @@ module Vra
|
|
117
116
|
'inputs': {
|
118
117
|
'count': count,
|
119
118
|
'image': image_mapping,
|
120
|
-
'flavor': flavor_mapping
|
121
|
-
}
|
119
|
+
'flavor': flavor_mapping,
|
120
|
+
},
|
122
121
|
}.deep_merge(parameters)
|
123
122
|
end
|
124
123
|
end
|
data/lib/vra/deployments.rb
CHANGED
data/lib/vra/http.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
3
|
+
require "net/http" unless defined?(Net::HTTP)
|
4
|
+
require "openssl" unless defined?(OpenSSL)
|
5
|
+
require "ffi_yajl" unless defined?(FFI_Yajl)
|
6
|
+
require "json" unless defined?(JSON)
|
7
7
|
|
8
8
|
module Vra
|
9
9
|
module Http
|
@@ -64,7 +64,7 @@ module Vra
|
|
64
64
|
get: Net::HTTP::Get,
|
65
65
|
head: Net::HTTP::Head,
|
66
66
|
post: Net::HTTP::Post,
|
67
|
-
delete: Net::HTTP::Delete
|
67
|
+
delete: Net::HTTP::Delete,
|
68
68
|
}.fetch(method, nil)
|
69
69
|
|
70
70
|
raise "Unknown HTTP method #{method}!" unless type
|
@@ -150,7 +150,7 @@ module Vra
|
|
150
150
|
|
151
151
|
def self.from_response(http_response)
|
152
152
|
body = FFI_Yajl::Parser.parse(http_response.body) || {}
|
153
|
-
message = body[
|
153
|
+
message = body["message"] || body["serverMessage"]
|
154
154
|
new(message, http_response.code, body)
|
155
155
|
end
|
156
156
|
|
data/lib/vra/request.rb
CHANGED
@@ -31,16 +31,16 @@ module Vra
|
|
31
31
|
if @request_data.nil?
|
32
32
|
refresh
|
33
33
|
else
|
34
|
-
@id = @request_data[
|
34
|
+
@id = @request_data["id"]
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
38
|
def requested_by
|
39
|
-
request_data[
|
39
|
+
request_data["requestedBy"]
|
40
40
|
end
|
41
41
|
|
42
42
|
def name
|
43
|
-
request_data[
|
43
|
+
request_data["name"]
|
44
44
|
end
|
45
45
|
|
46
46
|
def refresh
|
@@ -61,7 +61,7 @@ module Vra
|
|
61
61
|
refresh_if_empty
|
62
62
|
return if request_empty?
|
63
63
|
|
64
|
-
request_data[
|
64
|
+
request_data["status"]
|
65
65
|
end
|
66
66
|
|
67
67
|
def completed?
|
@@ -69,11 +69,11 @@ module Vra
|
|
69
69
|
end
|
70
70
|
|
71
71
|
def successful?
|
72
|
-
status ==
|
72
|
+
status == "SUCCESSFUL"
|
73
73
|
end
|
74
74
|
|
75
75
|
def failed?
|
76
|
-
status ==
|
76
|
+
status == "FAILED"
|
77
77
|
end
|
78
78
|
|
79
79
|
private
|
@@ -93,7 +93,7 @@ module Vra
|
|
93
93
|
|
94
94
|
def to_vra
|
95
95
|
hash = {
|
96
|
-
'inputs': {}
|
96
|
+
'inputs': {},
|
97
97
|
}
|
98
98
|
|
99
99
|
@entries.each do |_, v|
|
@@ -120,7 +120,7 @@ module Vra
|
|
120
120
|
def to_h
|
121
121
|
hash = {}
|
122
122
|
|
123
|
-
if @children.count
|
123
|
+
if @children.count > 0
|
124
124
|
hash[@key] = {}
|
125
125
|
|
126
126
|
@children.each do |c|
|
@@ -135,13 +135,13 @@ module Vra
|
|
135
135
|
|
136
136
|
def to_vra
|
137
137
|
hash = {}
|
138
|
-
if @children.count
|
138
|
+
if @children.count > 0
|
139
139
|
hash[@key] = {}
|
140
140
|
|
141
|
-
hash[@key][
|
141
|
+
hash[@key]["inputs"] = {}
|
142
142
|
|
143
143
|
@children.each do |c|
|
144
|
-
hash[@key][
|
144
|
+
hash[@key]["inputs"].merge!(c.to_vra)
|
145
145
|
end
|
146
146
|
else
|
147
147
|
hash[@key] = format_value
|
@@ -152,12 +152,12 @@ module Vra
|
|
152
152
|
|
153
153
|
def format_value
|
154
154
|
case @type
|
155
|
-
when
|
155
|
+
when "integer"
|
156
156
|
@value.to_i
|
157
|
-
when
|
157
|
+
when "string"
|
158
158
|
@value
|
159
|
-
when
|
160
|
-
@value.to_s ==
|
159
|
+
when "boolean"
|
160
|
+
@value.to_s == "true"
|
161
161
|
else
|
162
162
|
@value
|
163
163
|
end
|
data/lib/vra/resource.rb
CHANGED
@@ -21,10 +21,10 @@ require "ffi_yajl" unless defined?(FFI_Yajl)
|
|
21
21
|
|
22
22
|
module Vra
|
23
23
|
class Resource
|
24
|
-
VM_TYPES = %w
|
24
|
+
VM_TYPES = %w{
|
25
25
|
Cloud.vSphere.Machine
|
26
26
|
Cloud.Machine
|
27
|
-
|
27
|
+
}.freeze
|
28
28
|
|
29
29
|
attr_reader :client, :deployment_id, :id, :resource_data
|
30
30
|
|
@@ -35,13 +35,13 @@ module Vra
|
|
35
35
|
@resource_data = opts[:data]
|
36
36
|
@resource_actions = []
|
37
37
|
|
38
|
-
raise ArgumentError,
|
39
|
-
raise ArgumentError,
|
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?
|
40
40
|
|
41
41
|
if @resource_data.nil?
|
42
42
|
fetch_resource_data
|
43
43
|
else
|
44
|
-
@id = @resource_data[
|
44
|
+
@id = @resource_data["id"]
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
@@ -54,40 +54,40 @@ module Vra
|
|
54
54
|
alias refresh fetch_resource_data
|
55
55
|
|
56
56
|
def name
|
57
|
-
resource_data[
|
57
|
+
resource_data["name"]
|
58
58
|
end
|
59
59
|
|
60
60
|
def status
|
61
|
-
resource_data[
|
61
|
+
resource_data["syncStatus"]
|
62
62
|
end
|
63
63
|
|
64
64
|
def properties
|
65
|
-
resource_data[
|
65
|
+
resource_data["properties"]
|
66
66
|
end
|
67
67
|
|
68
68
|
def vm?
|
69
|
-
VM_TYPES.include?(resource_data[
|
69
|
+
VM_TYPES.include?(resource_data["type"])
|
70
70
|
end
|
71
71
|
|
72
72
|
def owner_names
|
73
|
-
properties[
|
73
|
+
properties["Owner"]
|
74
74
|
end
|
75
75
|
|
76
76
|
def project_id
|
77
|
-
properties[
|
77
|
+
properties["project"]
|
78
78
|
end
|
79
79
|
|
80
80
|
def network_interfaces
|
81
81
|
return unless vm?
|
82
82
|
|
83
|
-
network_list = properties[
|
83
|
+
network_list = properties["networks"]
|
84
84
|
return if network_list.nil?
|
85
85
|
|
86
86
|
network_list.each_with_object([]) do |item, nics|
|
87
87
|
nics << {
|
88
|
-
|
89
|
-
|
90
|
-
|
88
|
+
"NETWORK_NAME" => item["name"],
|
89
|
+
"NETWORK_ADDRESS" => item["address"],
|
90
|
+
"NETWORK_MAC_ADDRESS" => item["mac_address"],
|
91
91
|
}
|
92
92
|
end
|
93
93
|
end
|
@@ -95,7 +95,7 @@ module Vra
|
|
95
95
|
def ip_address
|
96
96
|
return if !vm? || network_interfaces.nil?
|
97
97
|
|
98
|
-
properties[
|
98
|
+
properties["address"]
|
99
99
|
end
|
100
100
|
end
|
101
101
|
end
|
data/lib/vra/version.rb
CHANGED
data/lib/vra.rb
CHANGED
@@ -17,17 +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
|
31
|
-
require
|
32
|
-
require
|
33
|
-
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"
|
data/spec/catalog_item_spec.rb
CHANGED
@@ -17,142 +17,142 @@
|
|
17
17
|
# limitations under the License.
|
18
18
|
#
|
19
19
|
|
20
|
-
require
|
20
|
+
require "spec_helper"
|
21
21
|
|
22
22
|
describe Vra::CatalogItem do
|
23
23
|
let(:client) do
|
24
24
|
Vra::Client.new(
|
25
|
-
username:
|
26
|
-
password:
|
27
|
-
tenant:
|
28
|
-
base_url:
|
25
|
+
username: "user@corp.local",
|
26
|
+
password: "password",
|
27
|
+
tenant: "tenant",
|
28
|
+
base_url: "https://vra.corp.local"
|
29
29
|
)
|
30
30
|
end
|
31
31
|
|
32
|
-
let(:catalog_id) {
|
32
|
+
let(:catalog_id) { "123456" }
|
33
33
|
|
34
34
|
let(:catalog_item_payload) do
|
35
|
-
JSON.parse(File.read(
|
35
|
+
JSON.parse(File.read("spec/fixtures/resource/sample_catalog_item.json"))
|
36
36
|
end
|
37
37
|
|
38
38
|
let(:other_catalog_item_payload) do
|
39
|
-
JSON.parse(File.read(
|
39
|
+
JSON.parse(File.read("spec/fixtures/resource/sample_catalog_item_2.json"))
|
40
40
|
end
|
41
41
|
|
42
|
-
describe
|
43
|
-
it
|
42
|
+
describe "#initialize" do
|
43
|
+
it "raises an error if no ID or catalog item data have been provided" do
|
44
44
|
expect { Vra::CatalogItem.new(client) }.to raise_error(ArgumentError)
|
45
45
|
end
|
46
46
|
|
47
|
-
it
|
48
|
-
expect { Vra::CatalogItem.new(client, id: 123, data:
|
47
|
+
it "raises an error if an ID and catalog item data have both been provided" do
|
48
|
+
expect { Vra::CatalogItem.new(client, id: 123, data: "foo") }.to raise_error(ArgumentError)
|
49
49
|
end
|
50
50
|
|
51
|
-
context
|
52
|
-
it
|
51
|
+
context "when an ID is provided" do
|
52
|
+
it "fetches the catalog_item record" do
|
53
53
|
catalog_item = Vra::CatalogItem.allocate
|
54
54
|
expect(catalog_item).to receive(:fetch_catalog_item)
|
55
55
|
catalog_item.send(:initialize, client, id: catalog_id)
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
59
|
-
context
|
60
|
-
it
|
59
|
+
context "when catalog item data is provided" do
|
60
|
+
it "populates the ID correctly" do
|
61
61
|
catalog_item = Vra::CatalogItem.new(client, data: catalog_item_payload)
|
62
62
|
expect(catalog_item.id).to eq catalog_id
|
63
63
|
end
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
67
|
-
describe
|
68
|
-
context
|
69
|
-
let(:response) { double(
|
67
|
+
describe "#fetch_catalog_item" do
|
68
|
+
context "when the catalog item exists" do
|
69
|
+
let(:response) { double("response", code: 200, body: catalog_item_payload.to_json) }
|
70
70
|
|
71
|
-
it
|
72
|
-
expect(client).to receive(:http_get).with(
|
73
|
-
Vra::CatalogItem.new(client, id:
|
71
|
+
it "calls http_get against the catalog_service" do
|
72
|
+
expect(client).to receive(:http_get).with("/catalog/api/items/catalog-12345").and_return(response)
|
73
|
+
Vra::CatalogItem.new(client, id: "catalog-12345")
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
77
|
-
context
|
78
|
-
it
|
77
|
+
context "when the catalog item does not exist" do
|
78
|
+
it "raises an exception" do
|
79
79
|
allow(client)
|
80
80
|
.to receive(:http_get)
|
81
|
-
.with(
|
81
|
+
.with("/catalog/api/items/catalog-12345")
|
82
82
|
.and_raise(Vra::Exception::HTTPNotFound)
|
83
83
|
|
84
|
-
expect { Vra::CatalogItem.new(client, id:
|
84
|
+
expect { Vra::CatalogItem.new(client, id: "catalog-12345") }
|
85
85
|
.to raise_error(Vra::Exception::NotFound)
|
86
|
-
.with_message(
|
86
|
+
.with_message("catalog ID catalog-12345 does not exist")
|
87
87
|
end
|
88
88
|
end
|
89
89
|
end
|
90
90
|
|
91
|
-
describe
|
92
|
-
it
|
91
|
+
describe "#entitle!" do
|
92
|
+
it "should entitle the catalog item" do
|
93
93
|
allow(client).to receive(:authorized?).and_return(true)
|
94
|
-
stub_request(:get, client.full_url(
|
94
|
+
stub_request(:get, client.full_url("/catalog/api/items/123456"))
|
95
95
|
.to_return(status: 200, body: catalog_item_payload.to_json, headers: {})
|
96
96
|
|
97
|
-
response = double(
|
97
|
+
response = double("response", body: '{"message": "success"}', success?: true)
|
98
98
|
allow(client).to receive(:http_post).and_return(response)
|
99
99
|
|
100
|
-
entitle_response = described_class.entitle!(client,
|
100
|
+
entitle_response = described_class.entitle!(client, "123456")
|
101
101
|
expect(entitle_response).not_to be_nil
|
102
102
|
end
|
103
103
|
end
|
104
104
|
|
105
|
-
describe
|
106
|
-
it
|
105
|
+
describe "#attributes" do
|
106
|
+
it "should have the correct attributes" do
|
107
107
|
allow(client).to receive(:authorized?).and_return(true)
|
108
|
-
stub_request(:get, client.full_url(
|
108
|
+
stub_request(:get, client.full_url("/catalog/api/admin/sources/source-123456"))
|
109
109
|
.to_return(
|
110
110
|
status: 200,
|
111
|
-
body: File.read(
|
111
|
+
body: File.read("spec/fixtures/resource/sample_catalog_source.json"),
|
112
112
|
headers: {}
|
113
113
|
)
|
114
114
|
catalog_item = described_class.new(client, data: catalog_item_payload)
|
115
115
|
|
116
|
-
expect(catalog_item.name).to eq(
|
117
|
-
expect(catalog_item.description).to eq(
|
118
|
-
expect(catalog_item.source_id).to eq(
|
119
|
-
expect(catalog_item.source_name).to eq(
|
120
|
-
expect(catalog_item.icon_id).to eq(
|
116
|
+
expect(catalog_item.name).to eq("centos")
|
117
|
+
expect(catalog_item.description).to eq("Centos Cat")
|
118
|
+
expect(catalog_item.source_id).to eq("source-123456")
|
119
|
+
expect(catalog_item.source_name).to eq("Source 123")
|
120
|
+
expect(catalog_item.icon_id).to eq("1495b8d9")
|
121
121
|
expect(catalog_item.source).to be_a(Vra::CatalogSource)
|
122
122
|
expect(catalog_item.type).to be_a(Vra::CatalogType)
|
123
123
|
end
|
124
124
|
end
|
125
125
|
|
126
|
-
describe
|
126
|
+
describe "#versions" do
|
127
127
|
let(:versions_response) do
|
128
|
-
[{ id:
|
128
|
+
[{ id: "2", description: "v2.0" }, { id: "1", description: "v1.0" }]
|
129
129
|
end
|
130
130
|
|
131
131
|
before do
|
132
132
|
allow(client).to receive(:authorized?).and_return(true)
|
133
133
|
end
|
134
134
|
|
135
|
-
it
|
135
|
+
it "should call the api to fetch the versions" do
|
136
136
|
expect(client)
|
137
137
|
.to receive(:http_get_paginated_array!)
|
138
|
-
.with(
|
138
|
+
.with("/catalog/api/items/catalog-12345/versions")
|
139
139
|
.and_return(versions_response)
|
140
140
|
|
141
|
-
described_class.fetch_latest_version(client,
|
141
|
+
described_class.fetch_latest_version(client, "catalog-12345")
|
142
142
|
end
|
143
143
|
|
144
|
-
it
|
145
|
-
stub_request(:get, client.full_url(
|
144
|
+
it "should return the correct version" do
|
145
|
+
stub_request(:get, client.full_url("/catalog/api/items/catalog-12345/versions?$skip=0&$top=20"))
|
146
146
|
.to_return(
|
147
147
|
status: 200,
|
148
148
|
body: {
|
149
149
|
content: versions_response,
|
150
|
-
totalPages: 1
|
150
|
+
totalPages: 1,
|
151
151
|
}.to_json,
|
152
152
|
headers: {}
|
153
153
|
)
|
154
154
|
|
155
|
-
expect(described_class.fetch_latest_version(client,
|
155
|
+
expect(described_class.fetch_latest_version(client, "catalog-12345")).to eq("2")
|
156
156
|
end
|
157
157
|
end
|
158
158
|
end
|