vmware-vra 2.4.0 → 2.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +13 -2
- data/lib/vra/catalog_item.rb +1 -1
- data/lib/vra/request.rb +1 -8
- data/lib/vra/resource.rb +9 -0
- data/lib/vra/resources.rb +9 -7
- data/lib/vra/version.rb +1 -1
- data/spec/resource_spec.rb +18 -0
- data/spec/resources_spec.rb +11 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 02e1b10df2a11fb1f980c90789893abd150206e9
|
4
|
+
data.tar.gz: 90be02ee5327c620bc60433006d0c793c9001669
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b090835fe0a8e5cf65efab244878adb1110430427d2e9eb3f2ea3768db1dedefe682c88e2318637b22f1bcb73cc896aa33138173bbec00147dfb0adabce8d9e4
|
7
|
+
data.tar.gz: e084aca8bf49456971c54844c7619c7465287b7f2b2657af6225558b95af0616697c18fcb92e498265355b6263e86fd71ec42e3c7951a7d90ac8e7a58a7c776b
|
data/CHANGELOG.md
CHANGED
@@ -1,7 +1,18 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
-
## [2.
|
4
|
-
[Full Changelog](https://github.com/chef-partners/vmware-vra-gem/compare/v2.
|
3
|
+
## [2.5.0](https://github.com/chef-partners/vmware-vra-gem/tree/2.5.0) (2017-10-17)
|
4
|
+
[Full Changelog](https://github.com/chef-partners/vmware-vra-gem/compare/v2.4.0...2.5.0)
|
5
|
+
|
6
|
+
**Closed issues:**
|
7
|
+
|
8
|
+
- Use mkdir\_p when creating template directory [\#60](https://github.com/chef-partners/vmware-vra-gem/issues/60)
|
9
|
+
|
10
|
+
**Merged pull requests:**
|
11
|
+
|
12
|
+
- Adds ability to lookup resource by name [\#62](https://github.com/chef-partners/vmware-vra-gem/pull/62) ([logicminds](https://github.com/logicminds))
|
13
|
+
|
14
|
+
## [v2.4.0](https://github.com/chef-partners/vmware-vra-gem/tree/v2.4.0) (2017-09-19)
|
15
|
+
[Full Changelog](https://github.com/chef-partners/vmware-vra-gem/compare/v2.3.0...v2.4.0)
|
5
16
|
|
6
17
|
**Closed issues:**
|
7
18
|
|
data/lib/vra/catalog_item.rb
CHANGED
@@ -118,7 +118,7 @@ module Vra
|
|
118
118
|
# @param [Boolean] - set to true if you wish the file name to be the id of the catalog item
|
119
119
|
# @return [Array[String]] - a array of all the files that were generated
|
120
120
|
def self.dump_templates(client, dir_name = "vra_templates", use_id = false)
|
121
|
-
FileUtils.
|
121
|
+
FileUtils.mkdir_p(dir_name) unless File.exist?(dir_name)
|
122
122
|
client.catalog.entitled_items.map do |c|
|
123
123
|
id = use_id ? c.id : c.name.tr(" ", "_")
|
124
124
|
filename = File.join(dir_name, "#{id}.json").downcase
|
data/lib/vra/request.rb
CHANGED
@@ -80,19 +80,12 @@ module Vra
|
|
80
80
|
end
|
81
81
|
|
82
82
|
def resources
|
83
|
-
resources = []
|
84
|
-
|
85
83
|
begin
|
86
84
|
request_resources = client.http_get_paginated_array!("/catalog-service/api/consumer/requests/#{@id}/resources")
|
87
85
|
rescue Vra::Exception::HTTPNotFound
|
88
86
|
raise Vra::Exception::NotFound, "resources for request ID #{@id} are not found"
|
89
87
|
end
|
90
|
-
|
91
|
-
request_resources.each do |resource|
|
92
|
-
resources << Vra::Resource.new(client, data: resource)
|
93
|
-
end
|
94
|
-
|
95
|
-
resources
|
88
|
+
request_resources.map { |resource| Vra::Resource.new(client, data: resource) }
|
96
89
|
end
|
97
90
|
end
|
98
91
|
end
|
data/lib/vra/resource.rb
CHANGED
@@ -44,6 +44,15 @@ module Vra
|
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
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.find { |r| r.name.downcase =~ /#{name.downcase}/ }
|
54
|
+
end
|
55
|
+
|
47
56
|
def fetch_resource_data
|
48
57
|
@resource_data = client.get_parsed("/catalog-service/api/consumer/resources/#{@id}")
|
49
58
|
rescue Vra::Exception::HTTPNotFound
|
data/lib/vra/resources.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
#
|
3
4
|
# Author:: Chef Partner Engineering (<partnereng@chef.io>)
|
4
5
|
# Copyright:: Copyright (c) 2015 Chef Software, Inc.
|
@@ -25,15 +26,16 @@ module Vra
|
|
25
26
|
@client = client
|
26
27
|
end
|
27
28
|
|
28
|
-
|
29
|
-
|
30
|
-
|
29
|
+
# @return [Array[Vra::Resource]] - returns an array of all the resources owned by the user
|
30
|
+
# @param [Vra::Client]
|
31
|
+
def self.all(client)
|
31
32
|
items = client.http_get_paginated_array!("/catalog-service/api/consumer/resources")
|
32
|
-
items.
|
33
|
-
|
34
|
-
end
|
33
|
+
items.map { |item| Vra::Resource.new(client, data: item) }
|
34
|
+
end
|
35
35
|
|
36
|
-
|
36
|
+
# @return [Array[Vra::Resource]] - returns an array of all the resources owned by the user
|
37
|
+
def all_resources
|
38
|
+
self.class.all(client)
|
37
39
|
end
|
38
40
|
|
39
41
|
def by_id(id)
|
data/lib/vra/version.rb
CHANGED
data/spec/resource_spec.rb
CHANGED
@@ -67,6 +67,24 @@ describe Vra::Resource do
|
|
67
67
|
"non_vm_resource.json")))
|
68
68
|
end
|
69
69
|
|
70
|
+
describe "#by_name" do
|
71
|
+
it "can lookup and return resource" do
|
72
|
+
resource = Vra::Resource.allocate
|
73
|
+
allow(resource).to receive(:name).and_return("host1234")
|
74
|
+
name = resource.name
|
75
|
+
allow(Vra::Resources).to receive(:all).and_return([resource])
|
76
|
+
expect(Vra::Resource.by_name(client, name)).to eq(resource)
|
77
|
+
end
|
78
|
+
|
79
|
+
it "returns nil if nothing found" do
|
80
|
+
resource = Vra::Resource.allocate
|
81
|
+
allow(resource).to receive(:name).and_return("host1234")
|
82
|
+
name = "somethingelse1234"
|
83
|
+
allow(Vra::Resources).to receive(:all).and_return([resource])
|
84
|
+
expect(Vra::Resource.by_name(client, name)).to be nil
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
70
88
|
describe "#initialize" do
|
71
89
|
it "raises an error if no ID or resource data have been provided" do
|
72
90
|
expect { Vra::Resource.new }.to raise_error(ArgumentError)
|
data/spec/resources_spec.rb
CHANGED
@@ -29,6 +29,17 @@ describe Vra::Resources do
|
|
29
29
|
|
30
30
|
let(:resources) { Vra::Resources.new(client) }
|
31
31
|
|
32
|
+
it "#all" do
|
33
|
+
allow(client).to receive(:http_get_paginated_array!)
|
34
|
+
.with("/catalog-service/api/consumer/resources")
|
35
|
+
.and_return([ { "id" => "1" }, { "id" => "2" } ])
|
36
|
+
|
37
|
+
items = resources.all_resources
|
38
|
+
|
39
|
+
expect(items[0]).to be_an_instance_of(Vra::Resource)
|
40
|
+
expect(items[1]).to be_an_instance_of(Vra::Resource)
|
41
|
+
end
|
42
|
+
|
32
43
|
describe "#all_resources" do
|
33
44
|
it "calls the resources API endpoint" do
|
34
45
|
expect(client).to receive(:http_get_paginated_array!)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vmware-vra
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Leff
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2017-
|
12
|
+
date: 2017-10-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: ffi-yajl
|