vmware-vra 2.2.0 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 29d0f8225730f7665b5671e437ef655358a6de82
4
- data.tar.gz: 40d82c32de2a8f8b4678cb2b40a78cdbd6a0b53e
3
+ metadata.gz: 4206fd0351845613715dd83cc91a70b57067a025
4
+ data.tar.gz: 1ff2b3429cda1eb4f46cad5f9832cded71d60fde
5
5
  SHA512:
6
- metadata.gz: a2dec9201f3115b16a8e3f678a3daf50b9f9b1000993263960f589c229f21950543fd44b07991dd1b7e1716c4245c0e885eebd3d48aa6dacb880475d44fa69b8
7
- data.tar.gz: db317d1661507c16d7e72ceb2402794d8c84d94913a0a5fc13db5e26d8cf12ad1d9a620b7541564817bb6c6d9c6cf47f2611e56b7acda356df47628ea7695ce8
6
+ metadata.gz: 9f8e728e3be572a2d9094115702cc1ba4293ee92cebd5d43fb6430cfa80c48d378abde08d98013cf986c703ef126a05add06d955def8b407c30f017424de9dc4
7
+ data.tar.gz: ec94a0eec7d637ce06affef14c82aed642a520d5d8548a3e5288e501b87b6a78f93d5b671b601d6ccf3ef502949fc1b6633f46d2e16e5f3507166154d02813a4
data/CHANGELOG.md CHANGED
@@ -1,7 +1,20 @@
1
1
  # Change Log
2
2
 
3
- ## [2.2.0](https://github.com/chef-partners/vmware-vra-gem/tree/2.2.0) (2017-06-08)
4
- [Full Changelog](https://github.com/chef-partners/vmware-vra-gem/compare/v2.1.3...2.2.0)
3
+ ## [2.3.0](https://github.com/chef-partners/vmware-vra-gem/tree/2.3.0) (2017-06-30)
4
+ [Full Changelog](https://github.com/chef-partners/vmware-vra-gem/compare/v2.2.0...2.3.0)
5
+
6
+ **Closed issues:**
7
+
8
+ - catalog\_request SSLError [\#30](https://github.com/chef-partners/vmware-vra-gem/issues/30)
9
+ - Incompatible with vagrant 1.8+ \(at least\) [\#26](https://github.com/chef-partners/vmware-vra-gem/issues/26)
10
+
11
+ **Merged pull requests:**
12
+
13
+ - Extra parameters [\#50](https://github.com/chef-partners/vmware-vra-gem/pull/50) ([lloydsmithjr03](https://github.com/lloydsmithjr03))
14
+ - Initial Jenkinsfile for integration tests [\#49](https://github.com/chef-partners/vmware-vra-gem/pull/49) ([jjasghar](https://github.com/jjasghar))
15
+
16
+ ## [v2.2.0](https://github.com/chef-partners/vmware-vra-gem/tree/v2.2.0) (2017-06-08)
17
+ [Full Changelog](https://github.com/chef-partners/vmware-vra-gem/compare/v2.1.3...v2.2.0)
5
18
 
6
19
  **Closed issues:**
7
20
 
data/Jenkinsfile ADDED
@@ -0,0 +1,31 @@
1
+ pipeline {
2
+ agent {
3
+ docker {
4
+ args '-u root'
5
+ image 'localhost:5000/jjkeysv3'
6
+ }
7
+
8
+ }
9
+ triggers {
10
+ pollSCM('H * * * *')
11
+ }
12
+ stages {
13
+ stage('Pull down the ChefDK') {
14
+ steps {
15
+ sh '''apt-get update
16
+ apt-get install -y curl sudo git build-essential
17
+ curl -L https://chef.io/chef/install.sh | sudo bash -s -- -P chefdk -c current'''
18
+ }
19
+ }
20
+ stage('Bundle') {
21
+ steps {
22
+ sh 'chef exec bundle install'
23
+ }
24
+ }
25
+ stage('Rake') {
26
+ steps {
27
+ sh 'chef exec bundle exec rake '
28
+ }
29
+ }
30
+ }
31
+ }
data/README.md CHANGED
@@ -96,6 +96,12 @@ If your catalog blueprint item requires additional parameters to successfully su
96
96
  catalog_request.set_parameter('my_parameter', 'string', 'my value')
97
97
  ```
98
98
 
99
+ If you need to set a parameter on a child object in the blueprint, you can add them by using a ~:
100
+
101
+ ```
102
+ catalog_request.set_parameter('object~my_parameter', 'string', 'my value')
103
+ ```
104
+
99
105
  ### Creating a request from a yaml or json payload
100
106
  Should you want to create a request ahead of time you can create the parameters up front by
101
107
  reading from a file or a hard coded payload you use every time. This is not required by any means but allows
@@ -41,12 +41,16 @@ module Vra
41
41
  @additional_params.set(key, type, value)
42
42
  end
43
43
 
44
+ def set_parameters(key, value_data)
45
+ @additional_params.set_parameters(key, value_data)
46
+ end
47
+
44
48
  def delete_parameter(key)
45
49
  @additional_params.delete(key)
46
50
  end
47
51
 
48
52
  def parameters
49
- @additional_params.all_entries
53
+ @additional_params.to_vra
50
54
  end
51
55
 
52
56
  def subtenant_id
@@ -72,15 +76,7 @@ module Vra
72
76
  hash_payload["data"]["_leaseDays"] = @lease_days
73
77
  hash_payload["description"] = @notes
74
78
 
75
- parameters.each do |param|
76
- if hash_payload["data"].key? param.key
77
- hash_payload["data"][param.key] = param.value
78
- else
79
- hash_payload["data"][blueprint_name]["data"][param.key] = param.value
80
- end
81
- end
82
-
83
- JSON.pretty_generate(hash_payload)
79
+ JSON.pretty_generate(deep_merge(hash_payload, parameters))
84
80
  end
85
81
 
86
82
  def submit
@@ -98,5 +94,22 @@ module Vra
98
94
  request_id = JSON.parse(post_response.body)["id"]
99
95
  Vra::Request.new(client, request_id)
100
96
  end
97
+
98
+ def deep_merge(first, second)
99
+ merger = proc do |key, v1, v2|
100
+ if Hash === v1 && Hash === v2
101
+ v1.merge(v2, &merger)
102
+ elsif Array === v1 && Array === v2
103
+ v1 | v2
104
+ elsif [:undefined, nil, :nil].include?(v2)
105
+ v1
106
+ else
107
+ v2
108
+ end
109
+ end
110
+ first.merge(second.to_h, &merger)
111
+ end
112
+
113
+ private :deep_merge
101
114
  end
102
115
  end
@@ -16,15 +16,55 @@
16
16
  # See the License for the specific language governing permissions and
17
17
  # limitations under the License.
18
18
  #
19
-
20
19
  module Vra
21
20
  class RequestParameters
22
21
  def initialize
23
22
  @entries = {}
24
23
  end
25
24
 
25
+ def set_parameters(key, value_data, parent = nil)
26
+ if value_data.key?(:type)
27
+ if parent.nil?
28
+ set(key, value_data[:type], value_data[:value])
29
+ else
30
+ parent.add_child(Vra::RequestParameter.new(key, value_data[:type], value_data[:value]))
31
+ end
32
+ else
33
+ if parent.nil?
34
+ p = set(key, nil, nil)
35
+ else
36
+ p = Vra::RequestParameter.new(key, nil, nil)
37
+ parent.add_child(p)
38
+ end
39
+
40
+ value_data.each do |k, data|
41
+ set_parameters(k, data, p)
42
+ end
43
+ end
44
+ end
45
+
26
46
  def set(key, type, value)
27
- @entries[key] = Vra::RequestParameter.new(key, type, value)
47
+ if key.to_s.include? "~"
48
+ split_key = key.split("~")
49
+ parent = nil
50
+ split_key.each_with_index do |item, index|
51
+ if index == 0
52
+ if @entries[item].nil?
53
+ @entries[item] = Vra::RequestParameter.new(item, nil, nil)
54
+ end
55
+ parent = @entries[item]
56
+ elsif index == (split_key.count - 1)
57
+ c = Vra::RequestParameter.new(item, type, value)
58
+ parent.add_child(c)
59
+ else
60
+ p = Vra::RequestParameter.new(item, nil, nil)
61
+ parent.add_child(p)
62
+ parent = p
63
+ end
64
+ end
65
+ else
66
+ @entries[key] = Vra::RequestParameter.new(key, type, value)
67
+ end
28
68
  end
29
69
 
30
70
  def delete(key)
@@ -34,24 +74,75 @@ module Vra
34
74
  def all_entries
35
75
  @entries.values
36
76
  end
77
+
78
+ def to_h
79
+ hash = {}
80
+
81
+ @entries.each do |k, v|
82
+ hash.merge!(v.to_h)
83
+ end
84
+
85
+ hash
86
+ end
87
+
88
+ def to_vra
89
+ hash = {
90
+ "data" => {},
91
+ }
92
+
93
+ @entries.each do |k, v|
94
+ hash["data"].merge!(v.to_vra)
95
+ end
96
+
97
+ hash
98
+ end
37
99
  end
38
100
 
39
101
  class RequestParameter
40
- attr_accessor :key, :type, :value
102
+ attr_accessor :key, :type, :value, :children
41
103
  def initialize(key, type, value)
42
104
  @key = key
43
105
  @type = type
44
106
  @value = value
107
+ @children = []
108
+ end
109
+
110
+ def add_child(child)
111
+ @children.push(child)
45
112
  end
46
113
 
47
114
  def to_h
48
- {
49
- "key" => @key,
50
- "value" => {
51
- "type" => @type,
52
- "value" => format_value,
53
- },
54
- }
115
+ hash = {}
116
+
117
+ if @children.count > 0
118
+ hash[@key] = {}
119
+
120
+ @children.each do |c|
121
+ hash[@key].merge!(c.to_h)
122
+ end
123
+ else
124
+ hash[@key] = format_value
125
+ end
126
+
127
+ hash
128
+ end
129
+
130
+ def to_vra
131
+ hash = {}
132
+
133
+ if @children.count > 0
134
+ hash[@key] = {}
135
+
136
+ hash[@key]["data"] = {}
137
+
138
+ @children.each do |c|
139
+ hash[@key]["data"].merge!(c.to_vra)
140
+ end
141
+ else
142
+ hash[@key] = format_value
143
+ end
144
+
145
+ hash
55
146
  end
56
147
 
57
148
  def format_value
@@ -59,9 +150,9 @@ module Vra
59
150
  when "integer"
60
151
  @value.to_i
61
152
  when "string"
62
- @value.to_s
153
+ @value
63
154
  else
64
- @value.to_s
155
+ @value
65
156
  end
66
157
  end
67
158
  end
data/lib/vra/version.rb CHANGED
@@ -18,5 +18,5 @@
18
18
  #
19
19
 
20
20
  module Vra
21
- VERSION = "2.2.0".freeze
21
+ VERSION = "2.3.0".freeze
22
22
  end
@@ -95,13 +95,59 @@ describe Vra::CatalogRequest do
95
95
 
96
96
  template = File.read("spec/fixtures/resource/catalog_request.json")
97
97
  payload = JSON.parse(request.merge_payload(template))
98
- param1 = payload["data"]["my_blueprint"]["data"]["param1"]
99
- param2 = payload["data"]["my_blueprint"]["data"]["param2"]
98
+ param1 = payload["data"]["param1"]
99
+ param2 = payload["data"]["param2"]
100
100
 
101
101
  expect(param1).to be_a(String)
102
- expect(param2).to be_a(String)
102
+ expect(param2).to be_a(Integer)
103
103
  expect(param1).to eq "my string"
104
- expect(param2).to eq "2468"
104
+ expect(param2).to eq 2468
105
+ end
106
+
107
+ it "properly handles additional nested parameters" do
108
+ request.set_parameter("BP1~param1", "string", "my string")
109
+ request.set_parameter("BP1~BP2~param2", "integer", 2468)
110
+
111
+ template = File.read("spec/fixtures/resource/catalog_request.json")
112
+ payload = JSON.parse(request.merge_payload(template))
113
+ param1 = payload["data"]["BP1"]["data"]["param1"]
114
+ param2 = payload["data"]["BP1"]["data"]["BP2"]["data"]["param2"]
115
+
116
+ expect(param1).to be_a(String)
117
+ expect(param2).to be_a(Integer)
118
+ expect(param1).to eq "my string"
119
+ expect(param2).to eq 2468
120
+ end
121
+
122
+ it "properly handles nested parameters" do
123
+ parameters = {
124
+ "BP1" => {
125
+ "param1" => {
126
+ type: "string",
127
+ value: "my string",
128
+ },
129
+ "BP2" => {
130
+ "param2" => {
131
+ type: "integer",
132
+ value: 2468,
133
+ },
134
+ },
135
+ },
136
+ }
137
+
138
+ parameters.each do |k, v|
139
+ request.set_parameters(k, v)
140
+ end
141
+
142
+ template = File.read("spec/fixtures/resource/catalog_request.json")
143
+ payload = JSON.parse(request.merge_payload(template))
144
+ param1 = payload["data"]["BP1"]["data"]["param1"]
145
+ param2 = payload["data"]["BP1"]["data"]["BP2"]["data"]["param2"]
146
+
147
+ expect(param1).to be_a(String)
148
+ expect(param2).to be_a(Integer)
149
+ expect(param1).to eq "my string"
150
+ expect(param2).to eq 2468
105
151
  end
106
152
  end
107
153
 
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.2.0
4
+ version: 2.3.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-06-08 00:00:00.000000000 Z
12
+ date: 2017-06-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ffi-yajl
@@ -151,6 +151,7 @@ files:
151
151
  - ".travis.yml"
152
152
  - CHANGELOG.md
153
153
  - Gemfile
154
+ - Jenkinsfile
154
155
  - LICENSE.txt
155
156
  - README.md
156
157
  - Rakefile