vcenter_lib 0.0.1
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 +7 -0
- data/.gitignore +11 -0
- data/.rubocop.yml +106 -0
- data/.travis.yml +22 -0
- data/Gemfile +12 -0
- data/LICENSE.txt +21 -0
- data/README.md +70 -0
- data/Rakefile +18 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/vcenter_lib/logging.rb +43 -0
- data/lib/vcenter_lib/vcenter.rb +54 -0
- data/lib/vcenter_lib/version.rb +3 -0
- data/lib/vcenter_lib/vm_converter.rb +102 -0
- data/lib/vcenter_lib.rb +18 -0
- data/scripts/deploy_gem.sh +87 -0
- data/spec/classes/spec_helper.rb +4 -0
- data/spec/classes/vcenter_spec.rb +29 -0
- data/vcenter_lib.gemspec +28 -0
- metadata +148 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 183c9b6df0f9435d8dc54acb0bbbef438b1906ba
|
4
|
+
data.tar.gz: f3eb1ac505a72d18b354f49c462f4e2633a7a137
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4a9539cc4c08d9153b72118122765f84da118a017c6725c5eb21d8ac50d75e8db340cde103769b5db44ddce128525dbe023cb1d7e11cefbc8db28faa687d3158
|
7
|
+
data.tar.gz: e1ed62bfafdb5bab1455dd1d3b0c3b600611ab9373edbc7be37bc8837e0e45f72fd010c7c1cf3d7fbd39081186200e54031f44c047f7c798eeccc98779968bb3
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
# This yaml file describes which files are excluded in rubocop run.
|
2
|
+
# It can be in the project home directory or in the $HOME folder.
|
3
|
+
|
4
|
+
# Common configuration.
|
5
|
+
AllCops:
|
6
|
+
Include:
|
7
|
+
- 'lib/**/'
|
8
|
+
- 'exe/*'
|
9
|
+
|
10
|
+
Exclude:
|
11
|
+
- 'scripts/**/*'
|
12
|
+
- 'vendor/**/*'
|
13
|
+
- 'bin/**/*'
|
14
|
+
- 'bundle/**/*'
|
15
|
+
- 'local-gems/**/*'
|
16
|
+
- '**/*.sh'
|
17
|
+
- 'tester.rb'
|
18
|
+
- 'test/**/*'
|
19
|
+
- 'toaster.rb'
|
20
|
+
|
21
|
+
# --- XXXLength-Section --------------------------------------------------------------------
|
22
|
+
# too long lines, methods and classes are annoying,
|
23
|
+
LineLength:
|
24
|
+
Enabled: true
|
25
|
+
Max: 100
|
26
|
+
|
27
|
+
MethodLength:
|
28
|
+
Enabled: true
|
29
|
+
Max: 35
|
30
|
+
|
31
|
+
Metrics/AbcSize:
|
32
|
+
Max: 40
|
33
|
+
|
34
|
+
ClassLength:
|
35
|
+
Enabled: true
|
36
|
+
Max: 140
|
37
|
+
|
38
|
+
# --- Style Cops - Section -----------------------------------------------------------------
|
39
|
+
# Don't be so dogmatic about Hash-Style! Both are fine for us
|
40
|
+
HashSyntax:
|
41
|
+
Enabled: true
|
42
|
+
|
43
|
+
# From Ruby 2.x on there is no need for this anymore, so why bothering now?
|
44
|
+
Encoding:
|
45
|
+
Enabled: false
|
46
|
+
|
47
|
+
# Ensable following message: Documentation: Missing top-level class documentation comment.
|
48
|
+
Documentation:
|
49
|
+
Enabled: true
|
50
|
+
|
51
|
+
# check filename conventions
|
52
|
+
FileName:
|
53
|
+
Enabled: false
|
54
|
+
|
55
|
+
# this 3-digit thing for portnumbers? oh, come on!
|
56
|
+
NumericLiterals:
|
57
|
+
Enabled: false
|
58
|
+
|
59
|
+
# ok, one should avoid global vars, but from time to time we need them
|
60
|
+
Style/GlobalVars:
|
61
|
+
Enabled: true
|
62
|
+
|
63
|
+
Style/RegexpLiteral:
|
64
|
+
Enabled: true
|
65
|
+
|
66
|
+
Style/AlignParameters:
|
67
|
+
EnforcedStyle: "with_fixed_indentation"
|
68
|
+
|
69
|
+
Style/BracesAroundHashParameters:
|
70
|
+
EnforcedStyle: "context_dependent"
|
71
|
+
|
72
|
+
Style/EachWithObject:
|
73
|
+
Enabled: false
|
74
|
+
|
75
|
+
# we don't want be forced to use %i
|
76
|
+
Style/SymbolArray:
|
77
|
+
Enabled: false
|
78
|
+
|
79
|
+
# we know the special global variables by heart
|
80
|
+
Style/SpecialGlobalVars:
|
81
|
+
Enabled: false
|
82
|
+
|
83
|
+
# we don't care about quoting style
|
84
|
+
Style/StringLiterals:
|
85
|
+
Enabled: false
|
86
|
+
|
87
|
+
# for easier line moving
|
88
|
+
Style/TrailingCommaInLiteral:
|
89
|
+
Enabled: false
|
90
|
+
|
91
|
+
|
92
|
+
# --- Complexity - Section -----------------------------------------------------------------
|
93
|
+
# as old McCabe says:
|
94
|
+
#
|
95
|
+
# Cyclomatic Complexity Risk Evaluation...
|
96
|
+
# 1-10 A simple module without much risk
|
97
|
+
# 11-20 A more complex module with moderate risk
|
98
|
+
# 21-50 A complex module of high risk
|
99
|
+
# 51 and greater An untestable program of very high risk
|
100
|
+
CyclomaticComplexity:
|
101
|
+
Max: 10
|
102
|
+
|
103
|
+
# Lint-Section -----------------------------------------------------------------------------
|
104
|
+
# what is soooo bad about blablubb.match /..../ compared to blablubb.match(/..../)?
|
105
|
+
Lint/AmbiguousRegexpLiteral:
|
106
|
+
Enabled: true
|
data/.travis.yml
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
sudo: false
|
2
|
+
language: ruby
|
3
|
+
cache: bundler
|
4
|
+
before_install: gem install bundler
|
5
|
+
install: bundle install --jobs=3 --retry=3
|
6
|
+
rvm:
|
7
|
+
- 1.9.3
|
8
|
+
- 2.0.0
|
9
|
+
- 2.1.10
|
10
|
+
- 2.2.6
|
11
|
+
- 2.3.3
|
12
|
+
- 2.4.0
|
13
|
+
- ruby-head
|
14
|
+
- jruby-9.1.5.0
|
15
|
+
- jruby-19mode
|
16
|
+
- jruby-head
|
17
|
+
matrix:
|
18
|
+
fast_finish: true
|
19
|
+
allow_failures:
|
20
|
+
- rvm: jruby-head
|
21
|
+
- rvm: ruby-head
|
22
|
+
|
data/Gemfile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
gemspec
|
4
|
+
|
5
|
+
# only for local testing but not needed for spec tests
|
6
|
+
group :test do
|
7
|
+
gem 'rake'
|
8
|
+
gem 'rubocop' if RUBY_VERSION !~ /^1\./
|
9
|
+
# rubocop:disable Bundler/DuplicatedGem
|
10
|
+
gem 'rubocop', '=0.39.0' if RUBY_VERSION =~ /^1\./
|
11
|
+
# rubocop:enable Bundler/DuplicatedGem
|
12
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Michael Meyling
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
# vcenter library
|
2
|
+
|
3
|
+
Use your vCenter credentials to ask for properties of any VM.
|
4
|
+
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'vcenter_lib'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install vcenter_lib
|
21
|
+
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
require 'pp'
|
26
|
+
require 'benchmark'
|
27
|
+
require_relative 'lib/vcenter_lib'
|
28
|
+
|
29
|
+
options = {}
|
30
|
+
options[:username] = 'my_user@vcenter'
|
31
|
+
options[:password] = 'my_secret_password'
|
32
|
+
options[:vcenter_url] = 'vcenter01.ds.my_vcenter.com'
|
33
|
+
options[:insecure] = true # you might need this
|
34
|
+
|
35
|
+
@vcenter = VcenterLib::Vcenter.new(options)
|
36
|
+
@vm_converter = VcenterLib::VmConverter.new(@vcenter)
|
37
|
+
|
38
|
+
puts 'get properties for certain VM'
|
39
|
+
vm = nil
|
40
|
+
time = Benchmark.realtime do
|
41
|
+
pp vm = @vcenter.find_vm('my_server.my_company.com')
|
42
|
+
pp @vm_converter.convert_vm_mor_to_h(vm)
|
43
|
+
end
|
44
|
+
|
45
|
+
puts "run for #{time} seconds"
|
46
|
+
|
47
|
+
puts 'get properties for all VMs'
|
48
|
+
vms = nil
|
49
|
+
time = Benchmark.realtime do
|
50
|
+
pp (vms = @vm_converter.convert_vm_mobs_to_attr_hash(@vcenter.vms)).size
|
51
|
+
end
|
52
|
+
|
53
|
+
pp vms
|
54
|
+
puts "run for #{time} seconds"
|
55
|
+
|
56
|
+
|
57
|
+
## Development
|
58
|
+
|
59
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
60
|
+
|
61
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
62
|
+
|
63
|
+
## Contributing
|
64
|
+
|
65
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/m-31/vcenter_lib.
|
66
|
+
|
67
|
+
|
68
|
+
## License
|
69
|
+
|
70
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require "bundler/gem_tasks"
|
3
|
+
require "rubocop/rake_task"
|
4
|
+
require 'rspec/core/rake_task'
|
5
|
+
|
6
|
+
desc "Run RuboCop on the lib directory"
|
7
|
+
RuboCop::RakeTask.new(:rubocop) do |task|
|
8
|
+
task.formatters = ["fuubar"]
|
9
|
+
task.options = ["-D"]
|
10
|
+
task.options = task.options + ["--fail-level", "E"] if RUBY_VERSION =~ /^1\./
|
11
|
+
task.fail_on_error = true
|
12
|
+
end
|
13
|
+
|
14
|
+
RSpec::Core::RakeTask.new(:spec) do |t|
|
15
|
+
t.pattern = 'spec/**/*_spec.rb'
|
16
|
+
end
|
17
|
+
|
18
|
+
task default: %w[spec rubocop]
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "vcenter_lib.gemspec"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'logger'
|
2
|
+
|
3
|
+
module VcenterLib
|
4
|
+
# for logger access just include this module
|
5
|
+
module Logging
|
6
|
+
class << self
|
7
|
+
attr_writer :logger
|
8
|
+
|
9
|
+
def logger
|
10
|
+
unless @logger
|
11
|
+
@logger = Logger.new($stdout)
|
12
|
+
@logger.level = (ENV['LOG_LEVEL'] || Logger::INFO).to_i
|
13
|
+
end
|
14
|
+
@logger
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
# addition
|
19
|
+
def self.included(base)
|
20
|
+
class << base
|
21
|
+
def logger
|
22
|
+
# :nocov:
|
23
|
+
Logging.logger
|
24
|
+
# :nocov:
|
25
|
+
end
|
26
|
+
|
27
|
+
def logger=(logger)
|
28
|
+
# :nocov:
|
29
|
+
Logging.logger = logger
|
30
|
+
# :nocov:
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def logger
|
36
|
+
Logging.logger
|
37
|
+
end
|
38
|
+
|
39
|
+
def logger=(logger)
|
40
|
+
Logging.logger = logger
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'rbvmomi'
|
2
|
+
|
3
|
+
module VcenterLib
|
4
|
+
# central access point
|
5
|
+
class Vcenter
|
6
|
+
include Logging
|
7
|
+
|
8
|
+
def initialize(options = {})
|
9
|
+
@username = options[:username]
|
10
|
+
@password = options[:password]
|
11
|
+
@vcenter = options[:vcenter]
|
12
|
+
@insecure = options[:insecure]
|
13
|
+
end
|
14
|
+
|
15
|
+
# get array of all datacenters
|
16
|
+
def dcs
|
17
|
+
vim.rootFolder.childEntity.grep(RbVmomi::VIM::Datacenter)
|
18
|
+
end
|
19
|
+
|
20
|
+
# get all vms in all datacenters
|
21
|
+
def vms
|
22
|
+
dcs.inject([]) do |result, dc|
|
23
|
+
result + serviceContent.viewManager.CreateContainerView(
|
24
|
+
container: dc.vmFolder,
|
25
|
+
type: ['VirtualMachine'],
|
26
|
+
recursive: true
|
27
|
+
).view
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
# find vm
|
32
|
+
def find_vm_by_name(vm_name)
|
33
|
+
logger.debug("search for #{vm_name}")
|
34
|
+
serviceContent.propertyCollector.collectMultiple(vms, 'name').find do |_k, v|
|
35
|
+
v['name'] == vm_name
|
36
|
+
end[0]
|
37
|
+
end
|
38
|
+
|
39
|
+
# rubocop:disable Style/MethodName
|
40
|
+
def serviceContent
|
41
|
+
vim.serviceContent
|
42
|
+
end
|
43
|
+
# rubocop:enable Style/MethodName
|
44
|
+
|
45
|
+
def vim
|
46
|
+
@vim || @vim = RbVmomi::VIM.connect(
|
47
|
+
host: @vcenter,
|
48
|
+
user: @username,
|
49
|
+
password: @password,
|
50
|
+
insecure: @insecure
|
51
|
+
)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
require 'rbvmomi'
|
2
|
+
|
3
|
+
module VcenterLib
|
4
|
+
# convert VMware managed object into a simple hash
|
5
|
+
class VmConverter
|
6
|
+
include Logging
|
7
|
+
|
8
|
+
# see http://vijava.sourceforge.net/vSphereAPIDoc/ver51/ReferenceGuide/vim.vm.ConfigInfo.html
|
9
|
+
ATTRIBUTES = [
|
10
|
+
'name',
|
11
|
+
'config.annotation',
|
12
|
+
'config.cpuHotAddEnabled',
|
13
|
+
'config.instanceUuid',
|
14
|
+
'config.firmware',
|
15
|
+
'config.memoryHotAddEnabled',
|
16
|
+
'config.template',
|
17
|
+
'config.uuid',
|
18
|
+
'config.hardware.numCoresPerSocket',
|
19
|
+
'config.hardware.numCPU',
|
20
|
+
'config.hardware.memoryMB',
|
21
|
+
'config.guestFullName',
|
22
|
+
'config.guestId',
|
23
|
+
'config.version',
|
24
|
+
'guest.guestState',
|
25
|
+
'guest.ipAddress',
|
26
|
+
'guest.toolsStatus',
|
27
|
+
'guest.toolsVersionStatus',
|
28
|
+
'overallStatus',
|
29
|
+
'runtime.bootTime',
|
30
|
+
'runtime.connectionState',
|
31
|
+
'runtime.maxCpuUsage',
|
32
|
+
'runtime.maxMemoryUsage',
|
33
|
+
'runtime.powerState',
|
34
|
+
'summary.config.numEthernetCards',
|
35
|
+
'summary.config.numVirtualDisks',
|
36
|
+
'summary.guest.guestFullName',
|
37
|
+
'summary.guest.hostName',
|
38
|
+
|
39
|
+
'runtime.host',
|
40
|
+
# 'resourcePool',
|
41
|
+
# 'parent',
|
42
|
+
# 'summary.quickStats',
|
43
|
+
|
44
|
+
# summary: 'summary',
|
45
|
+
# storage: 'storage',
|
46
|
+
# devices: 'config.hardware.device',
|
47
|
+
].freeze
|
48
|
+
|
49
|
+
def initialize(vcenter)
|
50
|
+
@vcenter = vcenter
|
51
|
+
end
|
52
|
+
|
53
|
+
# convert a VMware RbVmomi::VIM::ManagedObject into a simple hash.
|
54
|
+
def vm_mo_to_h(vm_mo, attributes = ATTRIBUTES)
|
55
|
+
return nil unless vm_mo
|
56
|
+
props2h(vm_mo.collect!(*attributes))
|
57
|
+
end
|
58
|
+
|
59
|
+
def vm_mos_to_h(vm_mobs, attributes = ATTRIBUTES)
|
60
|
+
vms = @vcenter.serviceContent.propertyCollector.collectMultiple(vm_mobs, *attributes)
|
61
|
+
hosts = {} # cache already known hosts here
|
62
|
+
vms.map do |_vm, props|
|
63
|
+
extra = {}
|
64
|
+
props.delete_if do |_k, v|
|
65
|
+
if v.is_a? RbVmomi::VIM::HostSystem
|
66
|
+
extra = hosts[v] || {}
|
67
|
+
if extra.empty?
|
68
|
+
# rubocop:disable Style/RescueModifier
|
69
|
+
extra['datacenter'] = attribute(v.path, RbVmomi::VIM::Datacenter) rescue nil
|
70
|
+
extra['cluster'] = attribute(v.path, RbVmomi::VIM::ClusterComputeResource) rescue nil
|
71
|
+
extra['hypervisor'] = v.name rescue nil
|
72
|
+
# rubocop:enable Style/RescueModifier
|
73
|
+
hosts[v] = extra
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
props.merge!(extra)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
private
|
82
|
+
|
83
|
+
def props2h(props)
|
84
|
+
extra = {}
|
85
|
+
props.delete_if do |_k, v|
|
86
|
+
if v.is_a? RbVmomi::VIM::HostSystem
|
87
|
+
# rubocop:disable Style/RescueModifier
|
88
|
+
extra['datacenter'] = attribute(v.path, RbVmomi::VIM::Datacenter) rescue nil
|
89
|
+
extra['cluster'] = attribute(v.path, RbVmomi::VIM::ClusterComputeResource) rescue nil
|
90
|
+
extra['hypervisor'] = v.name rescue nil
|
91
|
+
# rubocop:enable Style/RescueModifier
|
92
|
+
end
|
93
|
+
end
|
94
|
+
props.merge!(extra)
|
95
|
+
end
|
96
|
+
|
97
|
+
# return parent object based on class provides name of RbVmomi object.
|
98
|
+
def attribute(path, type)
|
99
|
+
path.select { |x| x[0].is_a? type }[0][1]
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
data/lib/vcenter_lib.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'logger'
|
2
|
+
|
3
|
+
# library for easy acces to vcenter informations
|
4
|
+
module VcenterLib
|
5
|
+
require_relative 'vcenter_lib/logging'
|
6
|
+
require_relative 'vcenter_lib/version'
|
7
|
+
require_relative 'vcenter_lib/vcenter'
|
8
|
+
require_relative 'vcenter_lib/vm_converter'
|
9
|
+
|
10
|
+
def logger
|
11
|
+
unless @logger
|
12
|
+
@logger = Logger.new(STDOUT)
|
13
|
+
@logger.level = Logger::INFO
|
14
|
+
end
|
15
|
+
|
16
|
+
@logger
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
|
3
|
+
# release gem to rubygems
|
4
|
+
|
5
|
+
# exit on any error
|
6
|
+
set -e
|
7
|
+
|
8
|
+
#############################################################################
|
9
|
+
## defaults
|
10
|
+
|
11
|
+
readonly progname=$(basename $0)
|
12
|
+
readonly script_dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
|
13
|
+
readonly main_dir=$( cd "${script_dir}" && cd .. && pwd )
|
14
|
+
readonly application=$(basename ${main_dir})
|
15
|
+
readonly module_version=$( cd "${main_dir}" && grep spec.version *.gemspec | grep -o '[=].*[^ ]' | tr -d "= ")
|
16
|
+
|
17
|
+
#############################################################################
|
18
|
+
## functions
|
19
|
+
|
20
|
+
## write green message with time stamp to stdout
|
21
|
+
function puts () {
|
22
|
+
echo -e "\033[0;32m"$(date +"%Y-%m-%d %T") $*"\033[0m"
|
23
|
+
}
|
24
|
+
|
25
|
+
## bump version, must be in main git directory
|
26
|
+
function bump_version () {
|
27
|
+
puts "bump ${application} gem version"
|
28
|
+
|
29
|
+
old_version=$( ruby -I lib/${application} -e "require 'version'; puts Gem::Version.new(${module_version})" )
|
30
|
+
puts "gem version currently:" ${old_version}
|
31
|
+
|
32
|
+
new_version=$( ruby -I lib/${application} -e "require 'version'; puts Gem::Version.new(${module_version} + '.1').bump" )
|
33
|
+
puts "we will change it into:" ${new_version}
|
34
|
+
|
35
|
+
cat lib/${application}/version.rb | sed "s/$old_version/$new_version/" > lib/${application}/version.rb.new
|
36
|
+
mv lib/${application}/version.rb.new lib/${application}/version.rb
|
37
|
+
}
|
38
|
+
|
39
|
+
## commit and push version, must be in main git directory
|
40
|
+
function commit_and_push_version () {
|
41
|
+
puts "commit and push ${application} gem version"
|
42
|
+
git add lib/${application}/version.rb
|
43
|
+
git commit -m "m31's version bumper"
|
44
|
+
git push
|
45
|
+
}
|
46
|
+
|
47
|
+
#############################################################################
|
48
|
+
## main processsing
|
49
|
+
|
50
|
+
cd ${main_dir}
|
51
|
+
|
52
|
+
puts "trying to release ${application} gem to rubygems"
|
53
|
+
puts
|
54
|
+
|
55
|
+
puts "updating git repository"
|
56
|
+
git pull -r
|
57
|
+
|
58
|
+
puts "build new Gemfile.lock with bundle install"
|
59
|
+
rm Gemfile.lock
|
60
|
+
bundle install
|
61
|
+
|
62
|
+
puts "check and test"
|
63
|
+
bundle exec rake spec
|
64
|
+
|
65
|
+
bump_version
|
66
|
+
commit_and_push_version
|
67
|
+
|
68
|
+
puts "build gem"
|
69
|
+
result=$( gem build ${application}.gemspec )
|
70
|
+
puts " ${result}"
|
71
|
+
|
72
|
+
# get gem file name
|
73
|
+
set +e
|
74
|
+
gem_file=$( echo $result | grep -o "${application}-[.0-9]*\.gem$" )
|
75
|
+
set -e
|
76
|
+
puts " gem file:" $gem_file
|
77
|
+
|
78
|
+
## check if group was specified
|
79
|
+
if [ -z "${gem_file}" ]; then
|
80
|
+
echo "generated gem file not found" >&2
|
81
|
+
exit 1
|
82
|
+
fi
|
83
|
+
|
84
|
+
puts "push gem to rubygems"
|
85
|
+
gem push ${gem_file} --host https://rubygems.org
|
86
|
+
|
87
|
+
echo -e "\033[0;34mThe lioness has rejoined her cub, and all is right in the jungle...\033[0m"
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require_relative 'spec_helper'
|
2
|
+
|
3
|
+
describe VcenterLib::Vcenter do
|
4
|
+
subject do
|
5
|
+
options = {
|
6
|
+
username: 'my_user@vcenter',
|
7
|
+
password: 'my_secret_password',
|
8
|
+
vcenter: 'vcenter01.ds.my_vcenter.com'
|
9
|
+
}
|
10
|
+
described_class.new(options)
|
11
|
+
end
|
12
|
+
|
13
|
+
context '#initialize' do
|
14
|
+
it 'should create a RbVmomi::VIM' do
|
15
|
+
expect(RbVmomi::VIM).to receive(:connect)
|
16
|
+
.with(host: 'vcenter01.ds.my_vcenter.com',
|
17
|
+
user: 'my_user@vcenter',
|
18
|
+
password: 'my_secret_password',
|
19
|
+
insecure: nil) do
|
20
|
+
Class.new do
|
21
|
+
def vim
|
22
|
+
self
|
23
|
+
end
|
24
|
+
end.new
|
25
|
+
end
|
26
|
+
subject.send(:vim)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/vcenter_lib.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require File.expand_path('../lib/vcenter_lib/version', __FILE__)
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'vcenter_lib'
|
7
|
+
spec.version = VcenterLib::VERSION
|
8
|
+
spec.authors = ['Michael Meyling']
|
9
|
+
spec.email = ['search@meyling.com']
|
10
|
+
spec.summary = 'easy access to vcenter informations'
|
11
|
+
spec.description = 'We will see what we can do.'
|
12
|
+
spec.homepage = 'https://github.com/m-31/vcenter_lib'
|
13
|
+
spec.license = 'MIT'
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
17
|
+
spec.bindir = 'exe'
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_dependency 'rbvmomi', '~> 1.11.2'
|
22
|
+
|
23
|
+
spec.add_development_dependency 'bundler'
|
24
|
+
spec.add_development_dependency 'rspec'
|
25
|
+
spec.add_development_dependency 'pry'
|
26
|
+
spec.add_development_dependency 'webmock'
|
27
|
+
spec.add_development_dependency 'simplecov', '~> 0.9.0'
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,148 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: vcenter_lib
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Michael Meyling
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-05-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rbvmomi
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.11.2
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.11.2
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: webmock
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: simplecov
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.9.0
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.9.0
|
97
|
+
description: We will see what we can do.
|
98
|
+
email:
|
99
|
+
- search@meyling.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".gitignore"
|
105
|
+
- ".rubocop.yml"
|
106
|
+
- ".travis.yml"
|
107
|
+
- Gemfile
|
108
|
+
- LICENSE.txt
|
109
|
+
- README.md
|
110
|
+
- Rakefile
|
111
|
+
- bin/console
|
112
|
+
- bin/setup
|
113
|
+
- lib/vcenter_lib.rb
|
114
|
+
- lib/vcenter_lib/logging.rb
|
115
|
+
- lib/vcenter_lib/vcenter.rb
|
116
|
+
- lib/vcenter_lib/version.rb
|
117
|
+
- lib/vcenter_lib/vm_converter.rb
|
118
|
+
- scripts/deploy_gem.sh
|
119
|
+
- spec/classes/spec_helper.rb
|
120
|
+
- spec/classes/vcenter_spec.rb
|
121
|
+
- vcenter_lib.gemspec
|
122
|
+
homepage: https://github.com/m-31/vcenter_lib
|
123
|
+
licenses:
|
124
|
+
- MIT
|
125
|
+
metadata: {}
|
126
|
+
post_install_message:
|
127
|
+
rdoc_options: []
|
128
|
+
require_paths:
|
129
|
+
- lib
|
130
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
131
|
+
requirements:
|
132
|
+
- - ">="
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: '0'
|
135
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - ">="
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '0'
|
140
|
+
requirements: []
|
141
|
+
rubyforge_project:
|
142
|
+
rubygems_version: 2.6.8
|
143
|
+
signing_key:
|
144
|
+
specification_version: 4
|
145
|
+
summary: easy access to vcenter informations
|
146
|
+
test_files:
|
147
|
+
- spec/classes/spec_helper.rb
|
148
|
+
- spec/classes/vcenter_spec.rb
|