train-vsphere 1.0.2 → 1.1.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
  SHA256:
3
- metadata.gz: 45a888e0295c41d0f029a3b2ac2c84a966086a271587e3d7356d908300ced712
4
- data.tar.gz: 9521236b5c908e91f98c7c5da50658deae442a67eaf93a9270b6792bb934702d
3
+ metadata.gz: d5a4dfe1f41d641b64ddfd74dcb679db53ab68df95e9886b50d7f99bba97b927
4
+ data.tar.gz: b6a248ca2c2b91bf48fb29a698a62a7d4c8236fa65bb471320b3088d1701fc38
5
5
  SHA512:
6
- metadata.gz: 23a03cfacc2dfe55348ee40b34d4954e3d5efddc08ca1ed58feabff92e176ea92fdd1a0023d653dc4817e9c7e14293a6b79c6f86465cce5bb67584461e2261fe
7
- data.tar.gz: 14de4e1f2e2756d0c9caaebae1d5b624ffe5ed0170601cf1025ac929b7340fe1fd8a4492dfef733aa15a3e132974b323cb3efb27b10becb77998238ef317c9a2
6
+ metadata.gz: fc81775655c57487849c65d3e8bbd76d949885a7f5723ab2c2e9b69f3261249eb18451dfff439879582a9c185bf74cb0f36293f7a864d11013c1c17e22bb50a2
7
+ data.tar.gz: eb04630f938006e85cf211a5a7045094926e000b02237d15263a01b20a06c82f57ea740f7f8f39000350b6f38ace59734c8bd26d84ef286504c003e7c0eb7afc
data/Gemfile CHANGED
File without changes
data/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  ## To Install this as a User
6
6
 
7
- You will need InSpec v3.9 or later.
7
+ You will need InSpec v3.9 or later. Note that while it will probably run on earlier releases this is what i built it on.
8
8
 
9
9
  Simply run:
10
10
 
@@ -30,14 +30,30 @@ export VC_PASSWORD='notVMware1!'
30
30
  inspec exec -t vsphere://
31
31
  ```
32
32
 
33
- When connected, you can retrieve your API token in your resources or profiles as such:
33
+ When connected, you can consume vsphere in the following ways:
34
34
 
35
35
  ```ruby
36
- #This retrieves an authentication token
37
- @authtoken = inspec.backend.authenticate
36
+ #This retrieves the class of name class
37
+ @api_client = inspec.backend.api_client(class)
38
+
39
+ #For example, the following will return the Console CLI status
40
+ @api_client = inspec.backend.api_client(VSphereAutomation::Appliance::AccessConsolecliApi)
41
+ status = @api_client.get.status
42
+
43
+ #Or directly
44
+
45
+ @status = inspec.backend.api_client(VSphereAutomation::Appliance::AccessConsolecliApi).get.status
46
+
47
+ #You can also use the rbvomi libraries by calling a method.
48
+
49
+ @vsphere_client = inspec.backend.vsphere_client(method)
50
+
51
+ #for example, the following will return the root folder which can then be consumed to find other objects such as VMs and hosts.
52
+
53
+ @dc = inspec.backend.vsphere_client(method).childEntity.grep(RbVmomi::VIM::Datacenter).find { |x| x.name == 'mydatacenter' }
54
+ @vm = dc.vmFolder.childEntity.grep(RbVmomi::VIM::VirtualMachine).find { |x| x.name == 'my_vm' }
55
+
38
56
 
39
- #This authentication token can now be used to access all other APIs
40
- VSphereAutomation::Appliance::AccessConsolecliApi.new(@authtoken).get.value
41
57
  ```
42
58
 
43
59
  An example of a resource
@@ -47,18 +63,10 @@ class Vcsa < Inspec.resource(1)
47
63
  supports platform: 'vsphere'
48
64
  desc 'Use the vsphere audit resource to get information from the vSphere API'
49
65
 
50
- def initialize
51
- begin
52
- @auth_token = inspec.backend.authenticate
53
- rescue VSphereAutomation::ApiError => e
54
- fail Train::ClientError
55
- end
56
- end
57
66
 
58
67
  def ssh
59
68
  begin
60
- return VSphereAutomation::Appliance::AccessConsolecliApi.new(@auth_token).get.value
61
-
69
+ return inspec.backend.api_client(VSphereAutomation::Appliance::AccessConsolecliApi).get.value
62
70
  rescue VSphereAutomation::ApiError => e
63
71
  fail Train::ClientError
64
72
  end
@@ -108,7 +116,7 @@ Due to some unknown bug, libcurl4-gnutls-dev may be required on linux. I haven't
108
116
  1. Create your feature branch (git checkout -b my-new-feature)
109
117
  1. Commit your changes (git commit -sam 'Add some feature')
110
118
  1. Push to the branch (git push origin my-new-feature)
111
- 1. Create new Pull Request
119
+ 1. Create new Pull Request against the development branch
112
120
 
113
121
  ## License
114
122
 
data/lib/train-vsphere.rb CHANGED
File without changes
@@ -10,6 +10,7 @@ require 'vsphere-automation-appliance'
10
10
  require 'vsphere-automation-content'
11
11
  require 'vsphere-automation-vapi'
12
12
  require 'vsphere-automation-vcenter'
13
+ require 'rbvmomi'
13
14
 
14
15
  module TrainPlugins
15
16
  module Vsphere
@@ -21,20 +22,112 @@ module TrainPlugins
21
22
 
22
23
  options = validate_options(options)
23
24
  super(options)
25
+
26
+ #force enable caching
24
27
  enable_cache :api_call
25
28
 
26
29
  end
27
30
 
28
- def authenticate
31
+ def vsphere_client(function)
32
+ begin
33
+ if !defined? @vim
34
+ @vim = RbVmomi::VIM.connect(host: options[:host], user: options[:user], password: options[:password], insecure: options[:insecure])
35
+ end
36
+ content = @vim.serviceInstance.content
37
+ @cache[:api_call][function.to_s.to_sym] ||= content.public_send(function) if content.respond_to? function
38
+ rescue
39
+ fail Train::ClientError
40
+ end
41
+ end
29
42
 
30
- return api_client unless cache_enabled?(:api_call)
43
+ def api_client(klass)
44
+
45
+ configuration = VSphereAutomation::Configuration.new.tap do |c|
46
+ c.host = options[:host]
47
+ c.username = options[:user]
48
+ c.password = options[:password]
49
+ c.scheme = 'https'
50
+ c.verify_ssl = !options[:insecure]
51
+ c.verify_ssl_host = !options[:insecure]
52
+ end
53
+ begin
54
+ auth_token = VSphereAutomation::ApiClient.new(configuration)
55
+ auth_token.default_headers['Authorization'] = configuration.basic_auth_token
56
+ session_api = VSphereAutomation::CIS::SessionApi.new(auth_token)
57
+ session_id = session_api.create('').value
58
+ auth_token.default_headers['vmware-api-session-id'] = session_id
59
+
60
+ return klass.new(auth_token) unless cache_enabled?(:api_call)
61
+ @cache[:api_call][klass.to_s.to_sym] ||= klass.new(auth_token)
62
+
63
+ rescue VSphereAutomation::ApiError => e
64
+ fail Train::ClientError
31
65
 
32
- @cache[:api_call][api_client.to_s.to_sym] ||= api_client
66
+ #puts "Exception when calling AccessConsolecliApi->get: #{e}"
67
+ end
33
68
  end
34
69
 
35
70
 
36
71
 
37
72
 
73
+
74
+
75
+
76
+
77
+ # @cache[:api_call][resource.to_s.to_sym] ||= resource
78
+
79
+ # begin
80
+
81
+ # return vim
82
+ # rescue
83
+
84
+ # #puts "Exception when calling AccessConsolecliApi->get: #{e}"
85
+ # end
86
+
87
+ # end
88
+
89
+ # def
90
+
91
+ # def authenticate(authtype)
92
+
93
+ # if authtype == "rbvmomi"
94
+ # #Authenticates to the new open API using the vsphere automation SDK
95
+ # return api_client unless cache_enabled?(:api_call)
96
+
97
+ # configuration = VSphereAutomation::Configuration.new.tap do |c|
98
+ # c.host = options[:host]
99
+ # c.username = options[:user]
100
+ # c.password = options[:password]
101
+ # c.scheme = 'https'
102
+ # c.verify_ssl = !options[:insecure]
103
+ # c.verify_ssl_host = !options[:insecure]
104
+ # end
105
+ # begin
106
+ # api_client = VSphereAutomation::ApiClient.new(configuration)
107
+ # api_client.default_headers['Authorization'] = configuration.basic_auth_token
108
+ # session_api = VSphereAutomation::CIS::SessionApi.new(api_client)
109
+ # session_id = session_api.create('').value
110
+ # api_client.default_headers['vmware-api-session-id'] = session_id
111
+ # return api_client
112
+ # rescue VSphereAutomation::ApiError => e
113
+ # fail Train::ClientError
114
+ # #puts "Exception when calling AccessConsolecliApi->get: #{e}"
115
+ # end
116
+ # elseif authtype == "openapi"
117
+
118
+ # if
119
+ # @cache[:api_call][api_client.to_s.to_sym] ||= api_client
120
+ # end
121
+
122
+ # def auth_rbvmomi
123
+ # #Authenticates to the old API using rbvmomi
124
+ # return rest_client unless cache_enabled(:api_call)
125
+ # @cache[:api_call][api_client.to_s.to_sym] ||= rest_client
126
+
127
+
128
+
129
+
130
+
38
131
  def uri
39
132
  #Report vsphere URI
40
133
  "vsphere://#{options[:host]}"
@@ -47,30 +140,6 @@ module TrainPlugins
47
140
 
48
141
  private
49
142
 
50
- def api_client
51
-
52
-
53
-
54
- configuration = VSphereAutomation::Configuration.new.tap do |c|
55
- c.host = options[:host]
56
- c.username = options[:user]
57
- c.password = options[:password]
58
- c.scheme = 'https'
59
- c.verify_ssl = !options[:insecure]
60
- c.verify_ssl_host = !options[:insecure]
61
- end
62
- begin
63
- api_client = VSphereAutomation::ApiClient.new(configuration)
64
- api_client.default_headers['Authorization'] = configuration.basic_auth_token
65
- session_api = VSphereAutomation::CIS::SessionApi.new(api_client)
66
- session_id = session_api.create('').value
67
- api_client.default_headers['vmware-api-session-id'] = session_id
68
- return api_client
69
- rescue VSphereAutomation::ApiError => e
70
- fail Train::ClientError
71
- #puts "Exception when calling AccessConsolecliApi->get: #{e}"
72
- end
73
- end
74
143
 
75
144
  def validate_options(options)
76
145
  if options[:user].nil?
File without changes
File without changes
@@ -2,6 +2,6 @@
2
2
 
3
3
  module TrainPlugins
4
4
  module Vsphere
5
- VERSION = '1.0.2'
5
+ VERSION = '1.1.0'
6
6
  end
7
7
  end
@@ -6,10 +6,9 @@ require 'train-vsphere/version'
6
6
 
7
7
  Gem::Specification.new do |spec|
8
8
  # Importantly, all Train plugins must be prefixed with `train-`
9
- spec.name = 'train-aws'
9
+ spec.name = 'train-vsphere'
10
10
 
11
11
  # It is polite to namespace your plugin under InspecPlugins::YourPluginInCamelCase
12
- spec.name = 'train-vsphere'
13
12
  spec.version = TrainPlugins::Vsphere::VERSION
14
13
  spec.authors = ['Sjors Robroek']
15
14
  spec.email = ['s.robroek@vxsan.com']
@@ -31,4 +30,5 @@ Gem::Specification.new do |spec|
31
30
 
32
31
  spec.add_dependency 'train', '~> 1.4'
33
32
  spec.add_dependency 'vsphere-automation-sdk', '~> 0.1.0'
33
+ spec.add_dependency 'rbvmomi', '~> 2.1.0'
34
34
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: train-vsphere
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sjors Robroek
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: 0.1.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: rbvmomi
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 2.1.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 2.1.0
41
55
  description: Allows applications using Train to speak to vSphere
42
56
  email:
43
57
  - s.robroek@vxsan.com
@@ -72,7 +86,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
72
86
  - !ruby/object:Gem::Version
73
87
  version: '0'
74
88
  requirements: []
75
- rubygems_version: 3.0.1
89
+ rubygems_version: 3.0.3
76
90
  signing_key:
77
91
  specification_version: 4
78
92
  summary: Train Transport for vSphere