oneview-sdk 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +7 -0
  2. data/.gitattributes +2 -0
  3. data/.gitignore +29 -0
  4. data/.rubocop.yml +73 -0
  5. data/.travis.yml +8 -0
  6. data/CHANGELOG.md +39 -0
  7. data/Gemfile +2 -0
  8. data/LICENSE +201 -0
  9. data/README.md +317 -0
  10. data/Rakefile +90 -0
  11. data/bin/oneview-sdk-ruby +4 -0
  12. data/lib/oneview-sdk.rb +9 -0
  13. data/lib/oneview-sdk/cli.rb +407 -0
  14. data/lib/oneview-sdk/client.rb +163 -0
  15. data/lib/oneview-sdk/config_loader.rb +20 -0
  16. data/lib/oneview-sdk/resource.rb +313 -0
  17. data/lib/oneview-sdk/resource/enclosure.rb +169 -0
  18. data/lib/oneview-sdk/resource/enclosure_group.rb +98 -0
  19. data/lib/oneview-sdk/resource/ethernet_network.rb +60 -0
  20. data/lib/oneview-sdk/resource/fc_network.rb +31 -0
  21. data/lib/oneview-sdk/resource/fcoe_network.rb +25 -0
  22. data/lib/oneview-sdk/resource/firmware_bundle.rb +37 -0
  23. data/lib/oneview-sdk/resource/firmware_driver.rb +21 -0
  24. data/lib/oneview-sdk/resource/interconnect.rb +87 -0
  25. data/lib/oneview-sdk/resource/lig_uplink_set.rb +86 -0
  26. data/lib/oneview-sdk/resource/logical_enclosure.rb +84 -0
  27. data/lib/oneview-sdk/resource/logical_interconnect.rb +283 -0
  28. data/lib/oneview-sdk/resource/logical_interconnect_group.rb +92 -0
  29. data/lib/oneview-sdk/resource/server_hardware.rb +88 -0
  30. data/lib/oneview-sdk/resource/server_hardware_type.rb +27 -0
  31. data/lib/oneview-sdk/resource/server_profile.rb +37 -0
  32. data/lib/oneview-sdk/resource/server_profile_template.rb +24 -0
  33. data/lib/oneview-sdk/resource/storage_pool.rb +41 -0
  34. data/lib/oneview-sdk/resource/storage_system.rb +63 -0
  35. data/lib/oneview-sdk/resource/uplink_set.rb +119 -0
  36. data/lib/oneview-sdk/resource/volume.rb +188 -0
  37. data/lib/oneview-sdk/resource/volume_snapshot.rb +27 -0
  38. data/lib/oneview-sdk/resource/volume_template.rb +106 -0
  39. data/lib/oneview-sdk/rest.rb +163 -0
  40. data/lib/oneview-sdk/ssl_helper.rb +75 -0
  41. data/lib/oneview-sdk/version.rb +4 -0
  42. data/oneview-sdk.gemspec +31 -0
  43. metadata +204 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2f224fcb81143087867edc94a434b56d65a78659
4
+ data.tar.gz: 03a1ef013585d8f80554745aa9f2910b18dd797f
5
+ SHA512:
6
+ metadata.gz: 5d524a3027585fabc531bd9726b5780f71d92f84f17f0891824313d999124ecbbb43e4e9b2449408549816853e58be6a28df0a669f316d59c1525c3f68ffb3b5
7
+ data.tar.gz: cf2ec71583906adb14782aadaeb81da5e41063ac79529040918b537688011416781b60ac8771e03bc74924ec8cf62e3329b58890a118713fae54e3706fbde9e4
data/.gitattributes ADDED
@@ -0,0 +1,2 @@
1
+ # Convert all line endings to lf
2
+ * text eol=lf
data/.gitignore ADDED
@@ -0,0 +1,29 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ Berksfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
19
+ *.bundle
20
+ *.so
21
+ *.o
22
+ *.a
23
+ mkmf.log
24
+ *.sw*
25
+ examples/_client.rb
26
+ spec/integration/one_view_config.json
27
+ spec/integration/one_view_secrets.json
28
+ spec/system/one_view_config.json
29
+ spec/system/one_view_secrets.json
data/.rubocop.yml ADDED
@@ -0,0 +1,73 @@
1
+ # See default at https://github.com/bbatsov/rubocop/blob/master/config/default.yml
2
+
3
+ Metrics/ClassLength:
4
+ Max: 200
5
+ Exclude:
6
+ - 'lib/oneview-sdk/cli.rb'
7
+
8
+ Metrics/LineLength:
9
+ Max: 150
10
+
11
+ Metrics/ModuleLength:
12
+ Max: 150
13
+
14
+ Style/GlobalVars:
15
+ AllowedVariables: [$config, $secrets, $client, $client_120]
16
+
17
+ Style/IndentationWidth:
18
+ Width: 2
19
+
20
+ Style/VariableName:
21
+ EnforcedStyle: snake_case
22
+ Exclude:
23
+ - 'lib/oneview-sdk/resource/*'
24
+
25
+ Style/MethodName:
26
+ Exclude:
27
+ - 'lib/oneview-sdk/resource/*'
28
+
29
+ Style/FileName:
30
+ Exclude:
31
+ - 'lib/oneview-sdk.rb'
32
+ - 'bin/oneview-sdk'
33
+
34
+ Style/AlignParameters:
35
+ Exclude:
36
+ - 'lib/oneview-sdk/cli.rb'
37
+
38
+
39
+ Style/AccessorMethodName:
40
+ Enabled: false
41
+
42
+ Style/EmptyLines:
43
+ Enabled: false
44
+
45
+ Style/IndentArray:
46
+ Enabled: false
47
+
48
+ Style/MultilineOperationIndentation:
49
+ Enabled: false
50
+
51
+ Style/RescueModifier:
52
+ Enabled: false
53
+
54
+ Style/EmptyLinesAroundBlockBody:
55
+ Enabled: false
56
+
57
+ Style/EmptyLinesAroundClassBody:
58
+ Enabled: false
59
+
60
+ Metrics/AbcSize:
61
+ Enabled: false
62
+
63
+ Metrics/CyclomaticComplexity:
64
+ Enabled: false
65
+
66
+ Metrics/MethodLength:
67
+ Enabled: false
68
+
69
+ Metrics/PerceivedComplexity:
70
+ Enabled: false
71
+
72
+ Performance/Casecmp:
73
+ Enabled: false
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1
4
+
5
+ script:
6
+ - rake build
7
+ - rake test
8
+
data/CHANGELOG.md ADDED
@@ -0,0 +1,39 @@
1
+ # v1.0.0
2
+ ### Notes
3
+ This is the first release of the OneView SDK in Ruby and it adds full support to some core features listed bellow, with some execptions that are explicit.
4
+ This version of this SDK supports OneView appliances version 2.00.00 or higher, using the OneView Rest API version 200.
5
+ For now it only supports C7000 enclosure types.
6
+
7
+
8
+ ### Features supported
9
+ - Ethernet Network
10
+ - FC Network
11
+ - FCoE Network
12
+ - Interconnect
13
+ - Logical Interconnect
14
+ - Logical Interconnect Group
15
+ - Uplink Set
16
+ - Enclosure
17
+ - Logical Enclosure
18
+ - Enclosure Group
19
+ - Firmware Bundle
20
+ - Firmware Driver
21
+ - Storage System
22
+ - Storage Pool
23
+ - Volume
24
+ - Volume Template
25
+ - Server Profile (CRUD supported)
26
+ - Server Profile Template (CRUD supported)
27
+ - Server Hardware (CRUD Supported)
28
+
29
+ ### Know Issues
30
+ The integration tests may warn about 3 issues:
31
+
32
+ 1. OneviewSDK::LogicalInterconnect Firmware Updates perform the actions Stage
33
+ > The SDK cannot provide Firmware files for your OneView appliance. Please set a valid SPP in your appliance prior to running this test.
34
+
35
+ 2. OneviewSDK::VolumeTemplate#retrieve! retrieves the resource
36
+ > OneView 2.00.00 appliances may return the old type of Volume Template resource. Run it against a newer version of OneView and it should not happen.
37
+
38
+ 3. OneviewSDK::VolumeTemplate#update update volume name
39
+ > OneView 2.00.00 appliances may return the old type of Volume Template resource. Run it against a newer version of OneView and it should not happen.
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "{}"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2015-2016 Hewlett Packard Enterprise
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,317 @@
1
+ # oneview-sdk for Ruby
2
+ [![Gem Version](https://badge.fury.io/rb/oneview-sdk.svg)](https://badge.fury.io/rb/oneview-sdk)
3
+
4
+
5
+ The OneView SDK provides a Ruby library to easily interact with HPE OneView API. The Ruby SDK enables developers to easily build integration and scalable solutions with HPE OneView.
6
+
7
+ ## Installation
8
+ - Require the gem in your Gemfile:
9
+
10
+ ```ruby
11
+ gem 'oneview-sdk'
12
+ ```
13
+
14
+ Then run `$ bundle install`
15
+ - Or run the command:
16
+
17
+ ```bash
18
+ $ gem install oneview-sdk
19
+ ```
20
+
21
+
22
+ ## Configuration
23
+ The client has a few configuration options, which you can pass in during creation:
24
+
25
+ ```ruby
26
+ require 'oneview-sdk'
27
+ client = OneviewSDK::Client.new(
28
+ url: 'https://oneview.example.com',
29
+ user: 'Administrator', # This is the default
30
+ password: 'secret123',
31
+ ssl_enabled: true, # This is the default and strongly encouraged
32
+ logger: Logger.new(STDOUT), # This is the default
33
+ log_level: :info, # This is the default
34
+ api_version: 200, # Defaults to minimum of (200 and appliance API version)
35
+ token: 'xxxx...' # Set EITHER this or the user & password
36
+ )
37
+ ```
38
+
39
+ :lock: Tip: Check the file permissions because the password is stored in clear-text.
40
+
41
+ **Environment Variables**
42
+
43
+ You can also set the url and credentials or an authentication token using environment variables. For bash:
44
+
45
+ ```bash
46
+ export ONEVIEWSDK_URL='https://oneview.example.com'
47
+ export ONEVIEWSDK_SSL_ENABLED=false
48
+ # NOTE: Disabling SSL is strongly discouraged. Please see the CLI section for import instructions.
49
+
50
+ # Credentials
51
+ export ONEVIEWSDK_USER='Administrator'
52
+ export ONEVIEWSDK_PASSWORD='secret123'
53
+ # or auth token
54
+ export ONEVIEWSDK_TOKEN='xxxx...'
55
+ ```
56
+
57
+ :lock: Tip: Be sure nobody has access to your environment variables, as the password or token is stored in clear-text.
58
+
59
+ Then you can leave out these options from your config, enabling you to just do:
60
+
61
+ ```ruby
62
+ require 'oneview-sdk'
63
+ client = OneviewSDK::Client.new
64
+ ```
65
+ NOTE: Run `$ oneview-sdk-ruby env` to see a list of available environment variables and their current values.
66
+
67
+ **Configuration Files**
68
+
69
+ Configuration files can also be used to define client configuration (json or yaml formats). Here's an example json file:
70
+
71
+ ```json
72
+ {
73
+ "url": "https://oneview.example.com",
74
+ "user": "Administrator",
75
+ "password": "secret123"
76
+ }
77
+ ```
78
+
79
+ and load via:
80
+
81
+ ```ruby
82
+ config = OneviewSDK::Config.load("full_file_path.json")
83
+ client = OneviewSDK::Client.new(config)
84
+ ```
85
+
86
+ :lock: Tip: Check the file permissions because the password is stored in clear-text.
87
+
88
+ ### Custom logging
89
+ The default logger is a standard logger to STDOUT, but if you want to specify your own, you can. However, your logger must implement the following methods:
90
+
91
+ ```ruby
92
+ debug(String)
93
+ info(String)
94
+ warn(String)
95
+ error(String)
96
+ level=(Symbol, etc.) # The parameter here will be the log_level attribute
97
+ ```
98
+
99
+ ## Resources
100
+ Each OneView resource is exposed for usage with CRUD-like functionality.
101
+
102
+ For example, once you instantiate a resource object, you can call intuitive methods such as `resource.create`, `resource.udpate` and `resource.delete`. In addition, resources respond to helpful methods such as `.each`, `.eql?(other_resource)`, `.like(other_resource)`, `.retrieve!`, and many others.
103
+
104
+ Please see the [rubydoc.info](http://www.rubydoc.info/gems/oneview-sdk) documentation for the complete list and usage details, but here are a few examples to get you started:
105
+
106
+ - **Create a resource**
107
+
108
+ ```ruby
109
+ ethernet = OneviewSDK::EthernetNetwork.new(
110
+ client, { name: 'TestVlan', vlanId: 1001, purpose: 'General', smartLink: false, privateNetwork: false }
111
+ )
112
+ ethernet.create # Tells OneView to create this resource
113
+ ```
114
+
115
+ - **Access resource attributes**
116
+
117
+ ```ruby
118
+ ethernet['name'] # Returns 'TestVlan'
119
+
120
+ ethernet.data # Returns hash of all data
121
+
122
+ ethernet.each do |key, value|
123
+ puts "Attribute #{key} = #{value}"
124
+ end
125
+ ```
126
+
127
+ The resource's data is stored in its @data attribute. However, you can access the data directly using a hash-like syntax on the resource object (recommended). `resource['key']` functions a lot like `resource.data['key']`. The difference is that when using the data attribute, you must be cautious to use the correct key type (Hash vs Symbol).
128
+ The direct hash accessor on the resource converts all keys to strings, so `resource[:key]` and `resource['key']` access the same thing: `resource.data['key']`.
129
+
130
+ - **Update a resource**
131
+
132
+ Notice that there's a few different ways to do things, so pick your poison!
133
+ ```ruby
134
+ ethernet.set_all(name: 'newName', vlanId: 1002)
135
+ ethernet['purpose'] = 'General'
136
+ ethernet['ethernetNetworkType'] = 'Tagged'
137
+ ethernet.update # Saves current state to OneView
138
+
139
+ # Alternatively, you could do this in 1 step with:
140
+ ethernet.update(name: 'newName', vlanId: 1002, purpose: 'General', ethernetNetworkType: 'Tagged')
141
+ ```
142
+
143
+ - **Check resource equality**
144
+
145
+ You can use the `==` or `.eql?` method to compare resource equality, or `.like` to compare just a subset of attributes.
146
+ ```ruby
147
+ ethernet2 = OneviewSDK::EthernetNetwork.new(
148
+ client, { name: 'OtherVlan', vlanId: 1000, purpose: 'General', smartLink: false, privateNetwork: false }
149
+ )
150
+ ethernet == ethernet2 # Returns false
151
+ ethernet.eql?(ethernet2) # Returns false
152
+
153
+
154
+ # To compare a subset of attributes:
155
+ ethernet3 = OneviewSDK::EthernetNetwork.new(client, { purpose: 'General' })
156
+ ethernet.like?(ethernet3) # Returns true
157
+ ethernet.like?(name: TestVlan, purpose: 'General') # Returns true
158
+ ```
159
+
160
+
161
+ - **Find resources**
162
+
163
+ ```ruby
164
+ ethernet = OneviewSDK::EthernetNetwork.new(client, { name: 'OtherVlan' })
165
+ ethernet.retrieve! # Uses the name attribute to search for the resource on the server and update the data in this object.
166
+
167
+
168
+ # Each resource class also has a searching method (NOTE: class method, not instance method)
169
+ ethernet = OneviewSDK::EthernetNetwork.find_by(client, { name: 'OtherVlan' }).first
170
+
171
+ OneviewSDK::EthernetNetwork.find_by(client, { purpose: 'General' }).each do |network|
172
+ puts " #{network['name']}"
173
+ end
174
+
175
+ # Get all resources:
176
+ networks = client.get_all(:EthernetNetwork)
177
+ ```
178
+
179
+ - **Delete a resource**
180
+
181
+ ```ruby
182
+ ethernet = OneviewSDK::EthernetNetwork.find_by(client, { name: 'OtherVlan' }).first
183
+ ethernet.delete # Tells OneView to delete this resource
184
+ ```
185
+
186
+ ### Save/Load resources with files
187
+ Resources can be saved to files and loaded again very easily using the built-in `.to_file` & `.from_file` methods.
188
+
189
+ - To save a Resource to a file:
190
+
191
+ ```ruby
192
+ ethernet.to_file("full_file_path.json")
193
+ ```
194
+ - To load a Resource from a file: (note the class method, not instance method)
195
+
196
+ ```ruby
197
+ ethernet4 = OneviewSDK::Resource.from_file(client, "full_file_path.json")
198
+ ```
199
+
200
+
201
+ For more examples and test-scripts, see the [examples](examples/) directory and [rubydoc.info](http://www.rubydoc.info/gems/oneview-sdk) documentation.
202
+
203
+ ## Custom requests
204
+ In most cases, interacting with Resource objects is enough, but sometimes you need to make your own custom requests to OneView.
205
+ This project makes it extremely easy to do with some built-in methods for the Client object. Here are some examples:
206
+
207
+ ```ruby
208
+ # Get the appliance startup progress:
209
+ response = client.rest_api(:get, '/rest/appliance/progress')
210
+ # or even more simple:
211
+ response = client.rest_get('/rest/appliance/progress')
212
+
213
+ # Then we can validate the response and convert the response body into a hash...
214
+ data = client.response_handler(response)
215
+ ```
216
+
217
+ This example is about as basic as it gets, but you can make any type of OneView request.
218
+ If a resource does not do what you need, this will allow you to do it.
219
+ Please refer to the documentation and [code](lib/oneview-sdk/rest.rb) for complete list of methods and information about how to use them.
220
+
221
+
222
+ ## CLI
223
+ This gem also comes with a command-line interface to make interacting with OneView possible without the need to create a Ruby program or script.
224
+
225
+ Note: In order to use this, you will need to make sure your ruby `bin` directory is in your path.
226
+ Run `$ gem environment` to see where the executable paths are for your Ruby installation.
227
+
228
+ To get started, run `$ oneview-sdk-ruby --help`.
229
+
230
+ To communicate with an appliance, you will need to set up a few environment variables so it knows how to communicate. Run `$ oneview-sdk-ruby env` to see the available environment variables.
231
+
232
+ The CLI does not expose everything in the SDK, but it is great for doing simple tasks such as creating or deleting resources from files, listing resources, and searching. Here are a few examples:
233
+
234
+ - List ServerProfiles:
235
+ ```bash
236
+ $ oneview-sdk-ruby list ServerProfiles
237
+ # Or to show in yaml format (json is also supported):
238
+ $ oneview-sdk-ruby list ServerProfiles -f yaml
239
+ ```
240
+
241
+ - Show details for a specific resource:
242
+ ```bash
243
+ $ oneview-sdk-ruby show ServerProfile profile-1
244
+ # Or to show specific attributes only:
245
+ $ oneview-sdk-ruby show ServerProfile profile-1 -a name,uri,enclosureBay
246
+ ```
247
+
248
+ - Search by an attribute:
249
+ ```bash
250
+ $ oneview-sdk-ruby search ServerProfiles --filter state:Normal affinity:Bay
251
+ # By default, it will just show a list of names of matching resources,
252
+ # but again, you can show only certain attributes by using the -a option
253
+ # You can also chain keys together to search in nested hashes:
254
+ $ oneview-sdk-ruby search ServerProfiles --filter state:Normal boot.manageBoot:true
255
+ ```
256
+
257
+ - Create or delete resource by file:
258
+ ```bash
259
+ $ oneview-sdk-ruby create_from_file /my-server-profile.json
260
+ $ oneview-sdk-ruby delete_from_file /my-server-profile.json
261
+ ```
262
+
263
+ - Start an interactive console session with a OneView connection:
264
+ ```bash
265
+ $ oneview-sdk-ruby console
266
+ Console Connected to https://oneview.example.com
267
+ HINT: The @client object is available to you
268
+ >
269
+ ```
270
+
271
+ - Import a self-signed SSL certificate from your OneView instance:
272
+
273
+ Although you can disable ssl validation altogether for the client, this is strongly discouraged.
274
+ Instead, please import the certificate using the built-in cli cert command:
275
+ ```bash
276
+ # Check the certificate first:
277
+ $ oneview-sdk-ruby cert check https://oneview.example.com
278
+ Checking certificate for 'https://oneview.example.com' ...
279
+ ERROR: Certificate Validation Failed!
280
+
281
+ # Import the certificate:
282
+ $ oneview-sdk-ruby cert import https://oneview.example.com
283
+ Importing certificate for 'https://oneview.example.com' into '/home/users/user1/.oneview-sdk-ruby/trusted_certs.cer'...
284
+ Cert added to '/home/users/user1/.oneview-sdk-ruby/trusted_certs.cer'
285
+ ```
286
+
287
+ ## License
288
+ This project is licensed under the Apache 2.0 license. Please see [LICENSE](LICENSE) for more info.
289
+
290
+ ## Contributing and feature requests
291
+ **Contributing:** You know the drill. Fork it, branch it, change it, commit it, and pull-request it.
292
+ We are passionate about improving this project, and glad to accept help to make it better.
293
+
294
+ NOTE: We reserve the right to reject changes that we feel do not fit the scope of this project, so for feature additions, please open an issue to discuss your ideas before doing the work.
295
+
296
+ **Feature Requests:** If you have a need that is not met by the current implementation, please let us know (via a new issue).
297
+ This feedback is crucial for us to deliver a useful product. Do not assume we have already thought of everything, because we assure you that is not the case.
298
+
299
+ ### Building the Gem
300
+ First run `$ bundle` (requires the bundler gem), then...
301
+ - To build only, run `$ rake build`.
302
+ - To build and install the gem, run `$ rake install`.
303
+
304
+ ### Testing
305
+ - RuboCop: `$ rake rubocop`
306
+ - Unit: `$ rake spec`
307
+ - Integration: See the [spec/integration](spec/integration/) README
308
+ - All: Run `$ rake test:all` to run RuboCop, unit, & integration tests.
309
+ - Examples: See the [examples](examples/) README
310
+
311
+ Note: run `$ rake -T` to get a list of all the available rake tasks.
312
+
313
+ ## Authors
314
+ - Jared Smartt - [@jsmartt](https://github.com/jsmartt)
315
+ - Henrique Diomede - [@hdiomede](https://github.com/hdiomede)
316
+ - Thiago Miotto - [@tmiotto](https://github.com/tmiotto)
317
+ - Ricardo Piantola - [@piantola](https://github.com/piantola)