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
@@ -0,0 +1,75 @@
1
+ require 'uri'
2
+ require 'net/http'
3
+ require 'openssl'
4
+
5
+ module OneviewSDK
6
+ # SSL Certificate helper
7
+ module SSLHelper
8
+ CERT_STORE = File.join(Dir.home, '/.oneview-sdk-ruby/trusted_certs.cer')
9
+
10
+ # Load any trusted certs and add them to the default SSL cert store.
11
+ # Looks for a file at ~/.oneview-sdk-ruby/trusted_certs.cer
12
+ # Note: File must be readable and parseable by X509::Store.add_file method
13
+ # @return [X509::Store] cert_store
14
+ def self.load_trusted_certs
15
+ store = OpenSSL::X509::Store.new
16
+ store.set_default_paths
17
+ begin
18
+ store.add_file(CERT_STORE) if File.file?(CERT_STORE)
19
+ rescue StandardError => e
20
+ puts "WARNING: Failed to load certificate store file at #{CERT_STORE} \n Message: #{e.message}"
21
+ end
22
+ store
23
+ rescue StandardError => e
24
+ puts "WARNING: Failure in #{self}##{__method__} \n Message: #{e.message}"
25
+ nil
26
+ end
27
+
28
+ # Check to see if a OneView instance's certificate is trusted
29
+ # @param [String] url URL of the OneView Instance to be added
30
+ # @return [Boolean] Whether or not certificate is trusted
31
+ # @raise [RuntimeError] if the url is invalid
32
+ def self.check_cert(url)
33
+ uri = URI.parse(URI.escape(url))
34
+ fail "Invalid url '#{url}'" unless uri.host
35
+ http = Net::HTTP.new(uri.host, uri.port)
36
+ http.use_ssl = true if uri.scheme == 'https'
37
+ trusted_certs = load_trusted_certs
38
+ http.cert_store = trusted_certs if trusted_certs
39
+ http.request(Net::HTTP::Get.new(uri.request_uri))
40
+ true
41
+ rescue OpenSSL::SSL::SSLError
42
+ false
43
+ end
44
+
45
+ # Fetch and add the ssl certificate of a OneView instance to the trusted certs store.
46
+ # Creates/modifies file at ~/.oneview-sdk-ruby/trusted_certs.cer
47
+ # @param [String] url URL of the OneView Instance to be added
48
+ # @raise [RuntimeError] if the url is invalid
49
+ def self.install_cert(url)
50
+ uri = URI.parse(URI.escape(url))
51
+ fail "Invalid url '#{url}'" unless uri.host
52
+ options = { use_ssl: true, verify_mode: OpenSSL::SSL::VERIFY_NONE }
53
+ pem = Net::HTTP.start(uri.host, uri.port, options) do |http|
54
+ http.peer_cert.to_pem
55
+ end
56
+ fail "Could not download cert from #{url}. You may have to do it manually, and append it to '#{CERT_STORE}'" if pem.nil?
57
+
58
+ name = "OneView at #{url}"
59
+ content = "\n#{name}\n"
60
+ content << "#{'=' * name.length}\n"
61
+ content << pem
62
+
63
+ cert_dir = File.dirname(CERT_STORE)
64
+ Dir.mkdir(cert_dir) unless File.directory?(cert_dir)
65
+ if File.file?(CERT_STORE) && File.read(CERT_STORE).include?(pem)
66
+ puts 'Cert store already contains this certificate. Skipped!'
67
+ false
68
+ else
69
+ File.open(CERT_STORE, 'a') { |f| f.write content }
70
+ puts "Cert added to '#{CERT_STORE}'. Cert Info: #{content}"
71
+ true
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,4 @@
1
+ # Gem version defined here
2
+ module OneviewSDK
3
+ VERSION = '1.0.0'.freeze
4
+ end
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ # http://guides.rubygems.org/specification-reference
3
+
4
+ require_relative './lib/oneview-sdk/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'oneview-sdk'
8
+ spec.version = OneviewSDK::VERSION
9
+ spec.authors = ['Henrique Diomede', 'Thiago Miotto', 'Jared Smartt', 'Ricardo Piantola']
10
+ spec.email = ['henrique.diomede@hpe.com', 'tmiotto@hpe.com', 'jared.smartt@hpe.com', 'piantola@hpe.com']
11
+ spec.summary = 'Gem to interact with oneview API'
12
+ spec.description = 'Gem to interact with oneview API'
13
+ spec.license = 'Apache-2.0'
14
+ spec.homepage = 'https://github.com/HewlettPackard/oneview-sdk-ruby'
15
+
16
+ all_files = `git ls-files -z`.split("\x0")
17
+ spec.files = all_files.reject { |f| f.match(%r{^(examples\/)|(spec\/)}) }
18
+ spec.executables = all_files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_runtime_dependency 'thor'
22
+ spec.add_runtime_dependency 'highline'
23
+ spec.add_runtime_dependency 'pry'
24
+
25
+ spec.add_development_dependency 'bundler'
26
+ spec.add_development_dependency 'rspec'
27
+ spec.add_development_dependency 'rake'
28
+ spec.add_development_dependency 'simplecov'
29
+ spec.add_development_dependency 'rubocop', '= 0.36.0'
30
+
31
+ end
metadata ADDED
@@ -0,0 +1,204 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: oneview-sdk
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Henrique Diomede
8
+ - Thiago Miotto
9
+ - Jared Smartt
10
+ - Ricardo Piantola
11
+ autorequire:
12
+ bindir: bin
13
+ cert_chain: []
14
+ date: 2016-04-29 00:00:00.000000000 Z
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: thor
18
+ requirement: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: highline
32
+ requirement: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: '0'
37
+ type: :runtime
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ - !ruby/object:Gem::Dependency
45
+ name: pry
46
+ requirement: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ type: :runtime
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ - !ruby/object:Gem::Dependency
59
+ name: bundler
60
+ requirement: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ type: :development
66
+ prerelease: false
67
+ version_requirements: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ - !ruby/object:Gem::Dependency
73
+ name: rspec
74
+ requirement: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ type: :development
80
+ prerelease: false
81
+ version_requirements: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ - !ruby/object:Gem::Dependency
87
+ name: rake
88
+ requirement: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ type: :development
94
+ prerelease: false
95
+ version_requirements: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ - !ruby/object:Gem::Dependency
101
+ name: simplecov
102
+ requirement: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ type: :development
108
+ prerelease: false
109
+ version_requirements: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ - !ruby/object:Gem::Dependency
115
+ name: rubocop
116
+ requirement: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - '='
119
+ - !ruby/object:Gem::Version
120
+ version: 0.36.0
121
+ type: :development
122
+ prerelease: false
123
+ version_requirements: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - '='
126
+ - !ruby/object:Gem::Version
127
+ version: 0.36.0
128
+ description: Gem to interact with oneview API
129
+ email:
130
+ - henrique.diomede@hpe.com
131
+ - tmiotto@hpe.com
132
+ - jared.smartt@hpe.com
133
+ - piantola@hpe.com
134
+ executables:
135
+ - oneview-sdk-ruby
136
+ extensions: []
137
+ extra_rdoc_files: []
138
+ files:
139
+ - ".gitattributes"
140
+ - ".gitignore"
141
+ - ".rubocop.yml"
142
+ - ".travis.yml"
143
+ - CHANGELOG.md
144
+ - Gemfile
145
+ - LICENSE
146
+ - README.md
147
+ - Rakefile
148
+ - bin/oneview-sdk-ruby
149
+ - lib/oneview-sdk.rb
150
+ - lib/oneview-sdk/cli.rb
151
+ - lib/oneview-sdk/client.rb
152
+ - lib/oneview-sdk/config_loader.rb
153
+ - lib/oneview-sdk/resource.rb
154
+ - lib/oneview-sdk/resource/enclosure.rb
155
+ - lib/oneview-sdk/resource/enclosure_group.rb
156
+ - lib/oneview-sdk/resource/ethernet_network.rb
157
+ - lib/oneview-sdk/resource/fc_network.rb
158
+ - lib/oneview-sdk/resource/fcoe_network.rb
159
+ - lib/oneview-sdk/resource/firmware_bundle.rb
160
+ - lib/oneview-sdk/resource/firmware_driver.rb
161
+ - lib/oneview-sdk/resource/interconnect.rb
162
+ - lib/oneview-sdk/resource/lig_uplink_set.rb
163
+ - lib/oneview-sdk/resource/logical_enclosure.rb
164
+ - lib/oneview-sdk/resource/logical_interconnect.rb
165
+ - lib/oneview-sdk/resource/logical_interconnect_group.rb
166
+ - lib/oneview-sdk/resource/server_hardware.rb
167
+ - lib/oneview-sdk/resource/server_hardware_type.rb
168
+ - lib/oneview-sdk/resource/server_profile.rb
169
+ - lib/oneview-sdk/resource/server_profile_template.rb
170
+ - lib/oneview-sdk/resource/storage_pool.rb
171
+ - lib/oneview-sdk/resource/storage_system.rb
172
+ - lib/oneview-sdk/resource/uplink_set.rb
173
+ - lib/oneview-sdk/resource/volume.rb
174
+ - lib/oneview-sdk/resource/volume_snapshot.rb
175
+ - lib/oneview-sdk/resource/volume_template.rb
176
+ - lib/oneview-sdk/rest.rb
177
+ - lib/oneview-sdk/ssl_helper.rb
178
+ - lib/oneview-sdk/version.rb
179
+ - oneview-sdk.gemspec
180
+ homepage: https://github.com/HewlettPackard/oneview-sdk-ruby
181
+ licenses:
182
+ - Apache-2.0
183
+ metadata: {}
184
+ post_install_message:
185
+ rdoc_options: []
186
+ require_paths:
187
+ - lib
188
+ required_ruby_version: !ruby/object:Gem::Requirement
189
+ requirements:
190
+ - - ">="
191
+ - !ruby/object:Gem::Version
192
+ version: '0'
193
+ required_rubygems_version: !ruby/object:Gem::Requirement
194
+ requirements:
195
+ - - ">="
196
+ - !ruby/object:Gem::Version
197
+ version: '0'
198
+ requirements: []
199
+ rubyforge_project:
200
+ rubygems_version: 2.5.2
201
+ signing_key:
202
+ specification_version: 4
203
+ summary: Gem to interact with oneview API
204
+ test_files: []