vmware-vra 2.4.0 → 2.5.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 11be1f053e0b79413a97f73d65dd7736e5da7c3c
4
- data.tar.gz: 5f034f6c50a4bd6a3ec8ee69a72672deb291747d
3
+ metadata.gz: 02e1b10df2a11fb1f980c90789893abd150206e9
4
+ data.tar.gz: 90be02ee5327c620bc60433006d0c793c9001669
5
5
  SHA512:
6
- metadata.gz: 12f97a5705101ab63b43212722a3501ac03ba76365f4cb856dfcbc39015ae86de6745c9090bd76c59dfd44362387964eff4e4a5b7cb55a4eab15bf8026aaeb19
7
- data.tar.gz: a6b900474a68a4b02064429cba79606423e34f085a46b86f3a73394d837cbf240433238e4b3cc87cb0efa1b5deab6a3c6376e30126e7cc6458cb967ce9786f28
6
+ metadata.gz: b090835fe0a8e5cf65efab244878adb1110430427d2e9eb3f2ea3768db1dedefe682c88e2318637b22f1bcb73cc896aa33138173bbec00147dfb0adabce8d9e4
7
+ data.tar.gz: e084aca8bf49456971c54844c7619c7465287b7f2b2657af6225558b95af0616697c18fcb92e498265355b6263e86fd71ec42e3c7951a7d90ac8e7a58a7c776b
@@ -1,7 +1,18 @@
1
1
  # Change Log
2
2
 
3
- ## [2.4.0](https://github.com/chef-partners/vmware-vra-gem/tree/2.4.0) (2017-09-19)
4
- [Full Changelog](https://github.com/chef-partners/vmware-vra-gem/compare/v2.3.0...2.4.0)
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
 
@@ -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.mkdir(dir_name) unless File.exist?(dir_name)
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
@@ -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
@@ -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
@@ -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
- def all_resources
29
- resources = []
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.each do |item|
33
- resources << Vra::Resource.new(client, data: item)
34
- end
33
+ items.map { |item| Vra::Resource.new(client, data: item) }
34
+ end
35
35
 
36
- resources
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)
@@ -18,5 +18,5 @@
18
18
  #
19
19
 
20
20
  module Vra
21
- VERSION = "2.4.0"
21
+ VERSION = "2.5.0"
22
22
  end
@@ -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)
@@ -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.0
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-09-19 00:00:00.000000000 Z
12
+ date: 2017-10-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ffi-yajl