chef-provisioning-oneview 1.2.1 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +119 -65
  3. data/chef-provisioning-oneview.gemspec +39 -0
  4. data/lib/chef/provisioning/create_machine.rb +43 -46
  5. data/lib/chef/provisioning/customize_machine.rb +50 -48
  6. data/lib/chef/provisioning/helpers.rb +18 -0
  7. data/lib/chef/provisioning/icsp/api_v104.rb +3 -2
  8. data/lib/chef/provisioning/icsp/icsp_helper.rb +288 -0
  9. data/lib/chef/provisioning/icsp/rest.rb +50 -0
  10. data/lib/chef/provisioning/oneview/oneview_helper.rb +53 -0
  11. data/lib/chef/provisioning/oneview/san_storage.rb +69 -69
  12. data/lib/chef/provisioning/oneview_driver.rb +124 -105
  13. data/lib/chef/provisioning/version.rb +1 -1
  14. metadata +23 -61
  15. data/Rakefile +0 -19
  16. data/lib/chef/provisioning/icsp/icsp_api.rb +0 -284
  17. data/lib/chef/provisioning/oneview/oneview_api.rb +0 -186
  18. data/lib/chef/provisioning/oneview/v1.2/api.rb +0 -3
  19. data/lib/chef/provisioning/oneview/v2.0/api.rb +0 -3
  20. data/lib/chef/provisioning/rest.rb +0 -52
  21. data/spec/shared_context.rb +0 -78
  22. data/spec/spec_helper.rb +0 -23
  23. data/spec/support/fake_action_handler.rb +0 -6
  24. data/spec/support/fake_icsp.rb +0 -73
  25. data/spec/support/fake_machine_spec.rb +0 -18
  26. data/spec/support/fake_oneview.rb +0 -148
  27. data/spec/support/fixtures/icsp/v102/error_404.json +0 -14
  28. data/spec/support/fixtures/icsp/v102/login.json +0 -5
  29. data/spec/support/fixtures/icsp/v102/os-deployment-build-plans.json +0 -99
  30. data/spec/support/fixtures/icsp/v102/os-deployment-servers.json +0 -179
  31. data/spec/support/fixtures/icsp/v102/os-deployment-servers_1670001.json +0 -83
  32. data/spec/support/fixtures/icsp/v102/os-deployment-servers_fakesn.json +0 -9
  33. data/spec/support/fixtures/icsp/v102/server_by_sn_VCGE9KB041.json +0 -45
  34. data/spec/support/fixtures/icsp/v102/server_by_sn_empty.json +0 -16
  35. data/spec/support/fixtures/icsp/v102/version.json +0 -4
  36. data/spec/support/fixtures/oneview/v120/error_404.json +0 -14
  37. data/spec/support/fixtures/oneview/v120/login.json +0 -5
  38. data/spec/support/fixtures/oneview/v120/server-hardware.json +0 -1476
  39. data/spec/support/fixtures/oneview/v120/server-hardware_Template-WebServer.json +0 -468
  40. data/spec/support/fixtures/oneview/v120/server-hardware_specific.json +0 -151
  41. data/spec/support/fixtures/oneview/v120/server-profiles.json +0 -369
  42. data/spec/support/fixtures/oneview/v120/server-profiles_invalid_filter.json +0 -14
  43. data/spec/support/fixtures/oneview/v120/server-profiles_name_Template-WebServer.json +0 -133
  44. data/spec/support/fixtures/oneview/v120/server-profiles_name_Template-WebServerWithSAN.json +0 -200
  45. data/spec/support/fixtures/oneview/v120/server-profiles_name_chef-web01.json +0 -133
  46. data/spec/support/fixtures/oneview/v120/server-profiles_name_chef-web03.json +0 -133
  47. data/spec/support/fixtures/oneview/v120/server-profiles_name_empty.json +0 -15
  48. data/spec/support/fixtures/oneview/v120/server-profiles_sn_VCGE9KB041.json +0 -133
  49. data/spec/support/fixtures/oneview/v120/server-profiles_sn_VCGE9KB042.json +0 -206
  50. data/spec/support/fixtures/oneview/v120/server-profiles_sn_empty.json +0 -15
  51. data/spec/support/fixtures/oneview/v120/storage-volumes_1B5D3CA2-6C5B-41C2-8B97-1821F1883F22.json +0 -26
  52. data/spec/support/fixtures/oneview/v120/tasks_fake_active.json +0 -5
  53. data/spec/support/fixtures/oneview/v120/tasks_fake_complete.json +0 -5
  54. data/spec/support/fixtures/oneview/v120/version.json +0 -4
  55. data/spec/support/fixtures/oneview/v200/server-profile-templates_WebServerTemplate.json +0 -109
  56. data/spec/support/fixtures/oneview/v200/server-profile-templates_WebServerTemplateWithSAN.json +0 -144
  57. data/spec/support/fixtures/oneview/v200/server-profile-templates_invalid.json +0 -16
  58. data/spec/support/fixtures/oneview/v200/server-profile-templates_new-profile_WebServerTemplate.json +0 -125
  59. data/spec/support/fixtures/oneview/v200/server-profile-templates_new-profile_WebServerTemplateWithSAN.json +0 -178
  60. data/spec/support/fixtures/oneview/v200/version.json +0 -4
  61. data/spec/unit/create_machine_spec.rb +0 -78
  62. data/spec/unit/destroy_spec.rb +0 -26
  63. data/spec/unit/icsp_nic_teams_spec.rb +0 -38
  64. data/spec/unit/icsp_search_spec.rb +0 -25
  65. data/spec/unit/oneview_driver_spec.rb +0 -79
  66. data/spec/unit/oneview_login_spec.rb +0 -17
  67. data/spec/unit/oneview_power_spec.rb +0 -51
  68. data/spec/unit/oneview_san_spec.rb +0 -86
  69. data/spec/unit/oneview_search_spec.rb +0 -63
  70. data/spec/unit/rest_api_spec.rb +0 -115
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1d3cd5a3b65cb69035f944b55366db63824b0a98
4
- data.tar.gz: 094924c5feaea2aef5283e5a2b09a57a15d852c2
3
+ metadata.gz: 11de8d1ced349e47d834f7027c6fe84a67d625c6
4
+ data.tar.gz: 29db709224300d4b08603b4b6f000ef7d938468a
5
5
  SHA512:
6
- metadata.gz: 0d867cc5a82453fca8430a2ad7a772d1fc286c85dd54595144bd47cbe65e46205bbd74a8fe6307aa71a36ca3757bec04d3a4bfb765a4314a04aca8bf055dd218
7
- data.tar.gz: 492474abfa48306e3376377698abfb92e386ec3571253c0d8be3aad724aaeb46f978f0bd49f35a66646ae06455bc13a1a1265d900c0913fd6b50515d2ada6107
6
+ metadata.gz: 17c2c3f0a1dfa71dddb30d57792a395f064a458e2017205a36769c9006cae60a043b3074a15fcb5c6bb77b6af4f9496697036775c709bac5f7e391274b9b8ff1
7
+ data.tar.gz: 673f473fd1cdeedc70c859b8f932dfcada3d6dbbcad415399eec091dbc2d8ea6a03122e8a6b245e936ca8198dc7f310500ee76e6572ba6e653f1fb5026f0d7ba
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # chef-provisioning-oneview
2
- Chef Provisioning driver for HPE OneView
3
2
 
3
+ Chef Provisioning driver for HPE OneView
4
4
 
5
5
  [![Build Status](https://travis-ci.org/HewlettPackard/chef-provisioning-oneview.svg?branch=master)](https://travis-ci.org/HewlettPackard/chef-provisioning-oneview)
6
6
  [![Gem Version](https://badge.fury.io/rb/chef-provisioning-oneview.svg)](https://badge.fury.io/rb/chef-provisioning-oneview)
@@ -8,40 +8,65 @@ Chef Provisioning driver for HPE OneView
8
8
  Questions or comments? Join the Gitter room [![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/HewlettPackard/chef-provisioning-oneview?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
9
9
 
10
10
 
11
- Currently supports:
11
+ Verified on (may support other versions too, but no guarantees):
12
12
  - OneView v1.2.0 - 2.0.0
13
13
  - ICsp v7.4.0 - 7.5.0
14
14
 
15
15
  # Installation
16
16
 
17
- - This program is meant to run inside the chef-client, so to install it, add the following to a Chef recipe and run it:
17
+ - This program is meant to run inside the chef-client. To install it, add the following to a Chef recipe and run it:
18
+
18
19
  ```ruby
19
20
  chef_gem 'chef-provisioning-oneview'
20
21
  ```
21
-
22
- - To install it on your system Ruby for development purposes:
23
- - Install Ruby and the `ruby-devel` or `ruby-dev` package for your system.
24
-
25
- - Option 1: Require the gem in your Gemfile: `gem 'chef-provisioning-oneview'`, then run `$ bundle install`
26
- - Option 2: Run the command: `$ gem install chef-provisioning-oneview`
27
22
 
28
23
 
29
- # Prerequisites
30
- - Set up your `knife.rb` file with the information the driver needs to connect to OneView and Insight Control Server Provisioning
24
+ # Credentials & Configuration
25
+
26
+ There are a few different ways to provide credentials and configuration for this driver.
27
+
28
+ - In a recipe using the `with_driver` method:
29
+
30
+ ```ruby
31
+ # The basic usage is:
32
+ # with_driver canonical_url, driver_options
33
+
34
+ with_driver 'oneview:https://oneview.example.com', {
35
+ oneview: {
36
+ url: 'https://oneview2.example.com' # Will be overridden by the canonical url above
37
+ user: 'Administrator',
38
+ password: 'secret123',
39
+ token: 'token123', # Optional. Use EITHER this or the username & password
40
+ ssl_enabled: true, # Optional. Defaults to true
41
+ timeout: 10 # Optional. In seconds
42
+ },
43
+ icsp: {
44
+ url: 'https://icsp.example.com'
45
+ user: 'Admin',
46
+ password: 'secret456',
47
+ ssl_enabled: true, # Optional. Defaults to true
48
+ timeout: 20 # Optional. In seconds
49
+ }
50
+ }
51
+ ```
52
+
53
+ - You can also use the following options in your `knife.rb` file:
31
54
 
32
55
  ```ruby
33
56
  # (knife.rb)
34
57
  # (in addition to all the normal stuff like node_name, client_key, validation_client_name, validation_key, chef_server_url, etc.)
35
- knife[:oneview_url] = 'https://my-oneview.my-domain.com'
58
+ knife[:oneview_url] = 'https://oneview.example.com'
36
59
  knife[:oneview_username] = 'Administrator'
37
60
  knife[:oneview_password] = 'password123'
38
- knife[:oneview_ignore_ssl] = true # For self-signed certs
39
- knife[:oneview_timeout] = 10 # Optional. 10 (seconds) is the default
61
+ knife[:oneview_token] = 'token123' # Use EITHER this or the username & password
62
+ knife[:oneview_ignore_ssl] = true # For self-signed certs (discouraged)
63
+ knife[:oneview_timeout] = 10 # Optional. In seconds
40
64
 
41
- knife[:icsp_url] = 'https://my-icsp.my-domain.com'
65
+ knife[:icsp_url] = 'https://icsp.example.com'
42
66
  knife[:icsp_username] = 'Administrator'
43
67
  knife[:icsp_password] = 'password123'
44
- knife[:icsp_ignore_ssl] = true # For self-signed certs
68
+ knife[:icsp_ignore_ssl] = true # For self-signed certs (discouraged)
69
+ knife[:icsp_timeout] = 20 # Optional. In seconds
45
70
 
46
71
  knife[:node_root_password] = 'password123'
47
72
 
@@ -50,69 +75,84 @@ Currently supports:
50
75
  ssl_verify_mode :verify_none
51
76
  ```
52
77
 
78
+ - Finally, there are a few environment variables that you can set:
79
+
80
+ ```bash
81
+ export ONEVIEWSDK_USER='Administrator'
82
+ export ONEVIEWSDK_PASSWORD='secret123'
83
+ export ONEVIEWSDK_TOKEN='token123'
84
+ ```
85
+
86
+ Since there are a few diferent ways of providing the same config values, here's the order of evaluation:
87
+ - **OneView URL:** canonical_url (ie `oneview:https://oneview.example.com`), driver_options[:oneview][:url], knife[:oneview_url], ENV['ONEVIEWSDK_URL']
88
+ - **OneView user, password, & token:** driver_options, knife, environment variable
89
+ - **ICSP url, user, & password:** driver_options, knife
90
+
91
+ Note: ICSP is not required, so if you don't want to use it, you can leave out those config options and it will be ignored.
92
+
93
+ ### Additional Setup
94
+
53
95
  - Your OneView, Insight Controll Server Provisioning(ICSP), and Chef server must be trusted by your certificate stores. See [examples/ssl_issues.md](examples/ssl_issues.md) for more info on how to do this.
96
+ - You can also use the OneView SDK cli tool to import your OneView cert. See [this](https://github.com/HewlettPackard/oneview-sdk-ruby#cli).
54
97
  - Your OneView and ICSP servers must be set up beforehand. Unfortunately, this driver doesn't do that for you too.
55
98
 
56
- Note: ICSP is no longer required, so if you don't want to use it, you can leave those config options from your knife.rb.
57
-
58
99
  # Usage
59
100
 
60
101
  Example recipe:
61
102
  ```ruby
62
103
  require 'chef/provisioning'
63
104
 
64
- with_driver 'oneview'
65
-
66
- with_chef_server "https://my-chef.my-domain.com/organizations/my-org",
67
- :client_name => Chef::Config[:node_name], # NOTE: This must have node & client creation privileges (ie admin group)
68
- :signing_key_filename => Chef::Config[:client_key] # NOTE: This must have node & client creation privileges (ie admin group)
105
+ with_driver 'oneview:https://oneview.example.com', {
106
+ oneview: { user: 'Administrator', password: 'secret123' },
107
+ icsp: { url: 'https://icsp.example.com' user: 'Admin', password: 'secret456' }
108
+ }
69
109
 
70
110
  machine 'web01' do
71
111
  recipe 'my_server_cookbook::default'
72
112
 
73
- machine_options :driver_options => {
74
- :server_template => 'Web Server Template', # Name of Template OR Server Profile
75
- :os_build => 'CHEF-RHEL-6.5-x64', # Name of OS Build Plan on ICSP. Supports array of strings also.
76
- :server_location => 'Encl1, bay 16', # Optional. Use to provision a specific server
113
+ machine_options driver_options: {
114
+ server_template: 'Web Server Template', # Name of Template OR Server Profile
115
+ os_build: 'CHEF-RHEL-6.5-x64', # Name of OS Build Plan on ICSP. Supports array of strings also.
116
+ server_location: 'Encl1, bay 16', # Optional. Use to provision a specific server
77
117
 
78
- :host_name => 'chef-web01',
79
- :ip_address => 'xx.xx.xx.xx', # For bootstrapping. Deprecated in favor of { bootstrap: true } in connection; see below
80
- :domainType => 'workgroup',
81
- :domainName => 'sub.domain.com',
82
- :mask => '255.255.255.0', # Can set here or in individual connections below
83
- :dhcp => false, # Can set here or in individual connections below
84
- :gateway => 'xx.xx.xx.1', # Can set here or in individual connections below
85
- :dns => 'xx.xx.xx.xx,xx.xx.xx.xx,xx.xx.xx.xx', # Can set here or in individual connections below
86
- :connections => {
118
+ host_name: 'chef-web01',
119
+ ip_address: 'xx.xx.xx.xx', # For bootstrapping. Deprecated in favor of { bootstrap: true } in connection; see below
120
+ domainType: 'workgroup',
121
+ domainName: 'sub.domain.com',
122
+ mask: '255.255.255.0', # Can set here or in individual connections below
123
+ dhcp: false, # Can set here or in individual connections below
124
+ gateway: 'xx.xx.xx.1', # Can set here or in individual connections below
125
+ dns: 'xx.xx.xx.xx,xx.xx.xx.xx,xx.xx.xx.xx', # Can set here or in individual connections below
126
+ connections: {
87
127
  #1 => { ... } (Reserved for PXE on our setup)
88
128
  2 => {
89
- :ip4Address => 'xx.xx.xx.xx',
90
- :mask => '255.255.254.0', # Optional. Overrides mask property above
91
- :dhcp => false # Optional. Overrides dhcp property above
92
- :gateway => 'xx.xx.xx.1' # Optional. Overrides gateway property above
93
- :dns => 'xx.xx.xx.xx' # Optional. Overrides dns property above
94
- :bootstrap => true # Set this on 1 connection only. Tells Chef which connection to use to bootstrap.
129
+ ip4Address: 'xx.xx.xx.xx',
130
+ mask: '255.255.254.0', # Optional. Overrides mask property above
131
+ dhcp: false # Optional. Overrides dhcp property above
132
+ gateway: 'xx.xx.xx.1' # Optional. Overrides gateway property above
133
+ dns: 'xx.xx.xx.xx' # Optional. Overrides dns property above
134
+ bootstrap: true # Set this on 1 connection only. Tells Chef which connection to use to bootstrap.
95
135
  },
96
136
  3 => {
97
- :dhcp => true # Optional. Overrides dhcp property above
98
- :gateway => :none # Optional. Overrides gateway property above
99
- :dns => :none # Optional. Overrides dns property above
137
+ dhcp: true # Optional. Overrides dhcp property above
138
+ gateway: :none # Optional. Overrides gateway property above
139
+ dns: :none # Optional. Overrides dns property above
100
140
  }
101
141
  },
102
- :skip_network_configuration => false, # Default. Set to true for EXSi hosts, etc.
103
- :custom_attributes => {
104
- :chefCert => 'ssh-rsa AA...' # Optional
142
+ skip_network_configuration: false, # Default. Set to true for EXSi hosts, etc.
143
+ custom_attributes: {
144
+ chefCert: 'ssh-rsa AA...' # Optional
105
145
  }
106
146
  },
107
- :transport_options => {
108
- :user => 'root', # Optional. Defaults to 'root'
109
- :ssh_options => {
110
- :password => Chef::Config.knife[:node_root_password]
147
+ transport_options: {
148
+ user: 'root', # Optional. Defaults to 'root'
149
+ ssh_options: {
150
+ password: Chef::Config.knife[:node_root_password]
111
151
  }
112
152
  },
113
- :convergence_options => {
114
- :ssl_verify_mode => :verify_none, # Optional. For Chef servers with self-signed certs
115
- :bootstrap_proxy => 'http://proxy.domain.com:8080' # Optional
153
+ convergence_options: {
154
+ ssl_verify_mode: :verify_none, # Optional. For Chef servers with self-signed certs
155
+ bootstrap_proxy: 'http://proxy.example.com:8080' # Optional
116
156
  }
117
157
 
118
158
  chef_environment '_default'
@@ -125,11 +165,12 @@ See https://github.com/chef/chef-provisioning-ssh for more transport_options.
125
165
  NOTE: Some basic connection settings such as :ip4Address and :dhcp are shown in the example recipe, but you can pass in any interface/nic options that exist in the ICsp api for POST requests to /rest/os-deployment-jobs
126
166
 
127
167
  ### Custom Attributes
168
+
128
169
  Insided the custom attributes hash, you can specify any data that you would like to pass into your ICsp build plan scripts or configuration files. For example, to specify a list of trusted public keys to be placed into the node's .ssh/authorized_keys file, add a custom attribute to the machine resource definition:
129
170
 
130
171
  ```ruby
131
- :custom_attributes => {
132
- :chefCert => 'ssh-rsa AA...'
172
+ custom_attributes: {
173
+ chefCert: 'ssh-rsa AA...'
133
174
  }
134
175
  ```
135
176
 
@@ -144,13 +185,14 @@ fi
144
185
  ```
145
186
 
146
187
  ### SSH Keys
188
+
147
189
  To use SSH keys insead of passwords to connect to nodes, you'll need to modify your transport_options to look something like:
148
190
 
149
191
  ```ruby
150
- :transport_options => {
151
- :ssh_options => {
152
- :auth_methods => ['publickey'],
153
- :keys => ['~/.ssh/id_rsa']
192
+ transport_options: {
193
+ ssh_options: {
194
+ auth_methods: ['publickey'],
195
+ keys: ['~/.ssh/id_rsa']
154
196
  }
155
197
  }
156
198
  ```
@@ -158,42 +200,54 @@ To use SSH keys insead of passwords to connect to nodes, you'll need to modify y
158
200
  You'll also need to put the corresponding public key(s) into the node's authorized_keys file during the OS setup. See the Custom Attributes section above for one way to do this.
159
201
 
160
202
  ### Behind a proxy
161
- Add `:bootstrap_proxy => 'http://proxy.domain.com:8080'` to your convergence_options hash.
203
+
204
+ Add `bootstrap_proxy: 'http://proxy.example.com:8080'` to your convergence_options hash.
162
205
  Also, make sure your OS build plans set up the proxy configuration in a post OS install script.
163
206
 
164
207
  ### SAN Storage
208
+
165
209
  In order to attach a SAN volume as a bootable volume, the volume name must start with 'boot'; it will be appended with the the profile name on creation.
166
210
 
167
211
  ### Switching to a different network after provisioning
168
- Add `1 => {:net => "Deadnetwork", :deployNet => "PXE Network", :dhcp => true}` to your connections hash.
212
+
213
+ Add `1 => {net: "Deadnetwork", deployNet: "PXE Network", dhcp: true}` to your connections hash.
169
214
  This will flip the first connection of the newly provisioned machine off of your pxe network to your Deadnetwork right after provisioning. This is helpful for taking the newly provisioned machine off the PXE network as soon as possible.
170
215
 
171
216
  ### Adding Nic Teams
172
- Add `:team => 'TeamName'` into a connection in your connections hash. Make sure that you have 2 connections in a team and the name does not include hyphens. This information will be passed to ISCP as the 'teams' custom attribute in the format: `"TeamName1-mac1,mac2|TeamName2-mac6,mac7,mac8"` to be consumed in a custom build plan script.
217
+
218
+ Add `team: 'TeamName'` into a connection in your connections hash. Make sure that you have 2 connections in a team and the name does not include hyphens. This information will be passed to ISCP as the 'teams' custom attribute in the format: `"TeamName1-mac1,mac2|TeamName2-mac6,mac7,mac8"` to be consumed in a custom build plan script.
173
219
 
174
220
  # Doing a test run
221
+
175
222
  This repo contains everything you need to get started, including example recipes and knife configuration files. See the README in the [examples](examples/) directory for how to begin provisioning.
176
223
 
177
224
 
178
225
  # Troubleshooting
226
+
179
227
  See the [Trouleshooting wiki page](https://github.com/HewlettPackard/chef-provisioning-oneview/wiki/Troubleshooting)
180
228
 
181
229
 
182
230
  # Contributing
231
+
183
232
  You know the drill. Fork it, branch it, change it, commit it, pull-request it. We're passionate about improving this driver, and glad to accept help to make it better.
184
233
 
185
234
  ### Building the Gem
235
+
186
236
  To build this gem, run `$ rake build` or `gem build chef-provisioning-oneview.gemspec`.
187
237
 
188
238
  Then once it's built you can install it by running `$ rake install` or `$ gem install ./chef-provisioning-oneview-<VERSION>.gem`.
189
239
 
240
+ Note: You may need to first install the `ruby-devel` or `ruby-dev` package for your system.
241
+
190
242
  ### Testing
243
+
191
244
  - RuboCop: `$ rake rubocop` or `$ rubocop .`
192
245
  - Rspec: `$ rake spec` or `$ rspec`
193
246
  - Both: Run `$ rake test` to run both RuboCop and Rspec tests.
194
247
 
195
248
  # Authors
249
+
196
250
  - Jared Smartt - [@jsmartt](https://github.com/jsmartt)
197
- - Gunjan Kamle - [@kgunjan](https://github.com/kgunjan)
198
251
  - Matthew Frahry - [@mbfrahry](https://github.com/mbfrahry)
199
252
  - Andy Claiborne - [@veloandy](https://github.com/veloandy)
253
+ - Gunjan Kamle - [@kgunjan](https://github.com/kgunjan)
@@ -0,0 +1,39 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__) + '/lib')
2
+ require 'chef/provisioning/version'
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = 'chef-provisioning-oneview'
6
+ s.version = Chef::Provisioning::ONEVIEW_DRIVER_VERSION
7
+ s.platform = Gem::Platform::RUBY
8
+ s.extra_rdoc_files = ['README.md', 'LICENSE']
9
+ s.summary = 'Chef Provisioning driver for OneView'
10
+ s.description = 'Chef Provisioning driver for creating and managing OneView infrastructure.'
11
+ s.author = 'Hewlett Packard Enterprise'
12
+ s.email = ['jared.smartt@hpe.com', 'gunjan.kamle@hpe.com']
13
+ s.homepage = 'https://github.com/HewlettPackard/chef-provisioning-oneview'
14
+ s.license = 'Apache-2.0'
15
+
16
+ case RUBY_VERSION
17
+ when /^2\.0/
18
+ s.add_dependency 'chef', '~> 12.0', '< 12.9'
19
+ when /^2\.(1|2\.[01])/
20
+ s.add_dependency 'chef', '~> 12.0', '< 12.14'
21
+ else
22
+ s.add_dependency 'chef', '~> 12.0'
23
+ end
24
+ s.add_dependency 'oneview-sdk', '~> 2.1'
25
+ s.add_dependency 'chef-provisioning', '~> 1.0'
26
+
27
+ s.add_development_dependency 'rspec', '~> 3.0'
28
+ s.add_development_dependency 'rake'
29
+ s.add_development_dependency 'sinatra'
30
+ s.add_development_dependency 'webmock'
31
+ s.add_development_dependency 'simplecov'
32
+ s.add_development_dependency 'rubocop', '= 0.40.0'
33
+ s.add_development_dependency 'pry'
34
+
35
+ s.require_path = 'lib'
36
+
37
+ all_files = `git ls-files -z`.split("\x0")
38
+ s.files = Dir['LICENSE', 'README.md', '*.gemspec', 'lib/**/*'].reject { |f| !all_files.include?(f) }
39
+ end
@@ -1,51 +1,48 @@
1
- module CreateMachine
2
- private
3
-
4
- # Chef oneview provisioning
5
- def create_machine(action_handler, machine_spec, machine_options)
6
- host_name = machine_options[:driver_options][:host_name]
7
-
8
- # Check if profile exists first
9
- matching_profiles = rest_api(:oneview, :get, "/rest/server-profiles?filter=name matches '#{host_name}'&sort=name:asc")
10
- if matching_profiles['count'] > 0
11
- profile = matching_profiles['members'].first
12
- return profile
13
- end
14
-
15
- # Search for OneView Template by name
16
- template = get_oneview_template(machine_options[:driver_options][:server_template])
17
-
18
- # Get first availabe (and compatible) HP OV server blade
19
- # If a server_location has been specified, uses that
20
- chosen_blade = available_hardware_for_template(template, machine_options[:driver_options][:server_location])
21
-
22
- power_off(action_handler, machine_spec, chosen_blade['uri'])
23
-
24
- # Create new profile instance from template
25
- action_handler.perform_action "Initialize creation of server profile for #{machine_spec.name}" do
26
- action_handler.report_progress "INFO: Initializing creation of server profile for #{machine_spec.name}"
27
-
28
- # Add name & hardware uri to template
29
- template['name'] = host_name
30
- template['serverHardwareUri'] = chosen_blade['uri']
31
-
32
- update_san_info(machine_spec, template)
1
+ module OneviewChefProvisioningDriver
2
+ # Handles allocation of OneView ServerProfile
3
+ module CreateMachine
4
+ # Allocate OneView server profile
5
+ def create_machine(action_handler, machine_name, machine_options)
6
+ host_name = machine_options[:driver_options][:host_name] || machine_name
7
+ profile_name = machine_options[:driver_options][:profile_name] || host_name
8
+
9
+ # Check if profile exists first
10
+ matching_profile = OneviewSDK::ServerProfile.find_by(@ov, name: host_name).first
11
+ return matching_profile if matching_profile
12
+
13
+ # Search for OneView Template or Profile by name
14
+ template_name = machine_options[:driver_options][:server_template]
15
+ profile = profile_from_template(template_name, profile_name)
16
+
17
+ # Get first availabe (and compatible) OneView server blade.
18
+ # If a server_location has been specified, uses that
19
+ hw = available_hardware_for_profile(profile, machine_options[:driver_options][:server_location])
20
+
21
+ action_handler.perform_action "Power off server #{hw['name']} for machine '#{machine_name}'" do
22
+ action_handler.report_progress "INFO: Powering off server #{hw['name']} for machine '#{machine_name}'"
23
+ hw.power_off
24
+ end
33
25
 
34
- # Post back to /rest/server-profiles
35
- options = { 'body' => template }
36
- options['X-API-Version'] = 200 if @current_oneview_api_version >= 200 && template['type'] == 'ServerProfileV5'
37
- task = rest_api(:oneview, :post, '/rest/server-profiles', options)
38
- task_uri = task['uri']
39
- raise "Failed to create OneView server profile #{host_name}. Details: " unless task_uri
40
- # Wait for profile to appear
41
- 60.times do # Wait for up to 5 min
42
- matching_profiles = rest_api(:oneview, :get, "/rest/server-profiles?filter=name matches '#{host_name}'&sort=name:asc")
43
- return matching_profiles['members'].first if matching_profiles['members'].first
44
- print '.'
45
- sleep 5
26
+ # Create new ServerProfile from the template
27
+ action_handler.perform_action "Create server profile for #{machine_name}" do
28
+ action_handler.report_progress "INFO: Creating server profile for #{machine_name}"
29
+ profile.set_server_hardware(hw)
30
+ update_san_info(machine_name, profile)
31
+ response = @ov.rest_post(profile.class::BASE_URI, { 'body' => profile.data }, profile.api_version)
32
+ unless response.code.to_i == 202
33
+ task = JSON.parse(response.body)
34
+ raise "Server profile couldn't be created! #{task['taskStatus']}. #{task['taskErrors'].first['message'] rescue nil}"
35
+ end
36
+ 60.times do # Wait for up to 5 min for profile to appear in OneView
37
+ return profile if profile.retrieve!
38
+ task = @ov.response_handler(@ov.rest_get(response.header['location'] || JSON.parse(response.body)['uri']))
39
+ break if task['taskState'] == 'Error'
40
+ print '.'
41
+ sleep 5
42
+ end
43
+ raise "Server profile couldn't be created! #{task['taskStatus']}. #{task['taskErrors'].first['message'] rescue nil}"
46
44
  end
47
- task = rest_api(:oneview, :get, task_uri)
48
- raise "Server profile couldn't be created! #{task['taskStatus']}. #{task['taskErrors'].first['message']}"
45
+ profile
49
46
  end
50
47
  end
51
48
  end