miq_dev_util 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +29 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/miq_dev_util/automate.rb +34 -0
- data/lib/miq_dev_util/code.rb +10 -0
- data/lib/miq_dev_util/ems.rb +20 -0
- data/lib/miq_dev_util/logger.rb +66 -0
- data/lib/miq_dev_util/version.rb +3 -0
- data/lib/miq_dev_util.rb +8 -0
- data/miq_dev_util.gemspec +34 -0
- metadata +103 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b23d75b67044ef97db93725264cbdacdd4eaf5f9
|
4
|
+
data.tar.gz: 6ba5859a40cab3b6378ef6622f3c570bb5833cd3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f90fe8f16a8e3973c904af770d495d0f8a6e4ca353d27c7320789c46a06e4b09896097d92186afc4726b95bd638631b87dd32611032bd45fa73f0c287a411f53
|
7
|
+
data.tar.gz: f6a08f6822e0709994576b47fb459248de002d7ba7b53a2eb5825d74656519b45ac49a30df50516352d2e7f05fcc9e6ee96229c299930ca55d12515e14111cfb
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Eric Wannemacher
|
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,29 @@
|
|
1
|
+
# MiqDevUtil
|
2
|
+
|
3
|
+
This is a set of helper classes to make developing in the ManageIQ automate
|
4
|
+
model less cumbersome. By putting helper code and commonly used methods in this
|
5
|
+
gem we can reduce the amount of code copied and pasted between methods.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
$ gem install miq_dev_util
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
|
13
|
+
require 'miq_dev_util'
|
14
|
+
|
15
|
+
## Development
|
16
|
+
|
17
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
18
|
+
|
19
|
+
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).
|
20
|
+
|
21
|
+
## Contributing
|
22
|
+
|
23
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/ewannema/miq_dev_util.
|
24
|
+
|
25
|
+
|
26
|
+
## License
|
27
|
+
|
28
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
29
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "miq_dev_util"
|
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,34 @@
|
|
1
|
+
# The Automate class is intended to hold methods that are useful when
|
2
|
+
# interacting with the ManageIQ automate system directly.
|
3
|
+
|
4
|
+
class MiqDevUtil::Automate
|
5
|
+
|
6
|
+
def initialize(evm)
|
7
|
+
@evm = evm
|
8
|
+
end
|
9
|
+
|
10
|
+
# Instantiate an automate instance at path or raise an exception with the
|
11
|
+
# message provided if the instantiation returns nil (not found).
|
12
|
+
def instantiate_or_raise(path, message)
|
13
|
+
object = @evm.instantiate(path)
|
14
|
+
if object.nil?
|
15
|
+
raise message
|
16
|
+
end
|
17
|
+
|
18
|
+
object
|
19
|
+
end
|
20
|
+
|
21
|
+
# This is a hacky workaround used to get an instance without executing the
|
22
|
+
# methods on it. It fails if a message is passed in the path or if the
|
23
|
+
# message field on the any of the methods are *.
|
24
|
+
def get_instance_with_attributes(path)
|
25
|
+
if path =~ /#/
|
26
|
+
raise "Does not work with messages in the path."
|
27
|
+
end
|
28
|
+
fake_message = "callingWithAFakeMessage"
|
29
|
+
empty_instance = @evm.instantiate("#{path}##{fake_message}")
|
30
|
+
instance_name = empty_instance.name
|
31
|
+
@evm.instance_get(instance_name)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# The Code class is a container for miscellaneous methods that a developer may
|
2
|
+
# find useful. The focus is on standard Ruby oriented tasks that could apply
|
3
|
+
# outside of the ManageIQ environment.
|
4
|
+
|
5
|
+
class MiqDevUtil::Code
|
6
|
+
# Perform a deep copy on objects that support marshalling.
|
7
|
+
def deep_copy(o)
|
8
|
+
Marshal.load(Marshal.dump(o))
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# The External Management System (EMS) class holds methods that apply to EMS
|
2
|
+
# objects in ManageIQ.
|
3
|
+
|
4
|
+
class MiqDevUtil::EMS
|
5
|
+
# Return a hash containing the attributes that are commonly used to connect
|
6
|
+
# directly to the EMS.
|
7
|
+
# * :host
|
8
|
+
# * :user
|
9
|
+
# * :password
|
10
|
+
# * :insecure
|
11
|
+
def self.get_credentials(ems, insecure=true)
|
12
|
+
{
|
13
|
+
host: ems['hostname'],
|
14
|
+
user: ems.authentication_userid,
|
15
|
+
password: ems.authentication_password,
|
16
|
+
insecure: insecure
|
17
|
+
}
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# A utility class to write information to the ManageIQ logs.
|
2
|
+
|
3
|
+
class MiqDevUtil::Logger
|
4
|
+
def initialize(evm, method_name)
|
5
|
+
@evm = evm
|
6
|
+
@method_name = method_name
|
7
|
+
@dump_log_level = :info
|
8
|
+
end
|
9
|
+
|
10
|
+
# Write message to the logging system with the given logging level.
|
11
|
+
def log(level, message)
|
12
|
+
@evm.log(level, "#{@_method_name} - #{message}")
|
13
|
+
end
|
14
|
+
|
15
|
+
# Write the attributes of the given object to the log with a prefix of
|
16
|
+
# my_object_name to make finding the entries a little easier.
|
17
|
+
def dump_attributes(my_object, my_object_name)
|
18
|
+
if my_object.respond_to?("attributes")
|
19
|
+
self.log(@dump_log_level, "Begin #{my_object_name}.attributes")
|
20
|
+
my_object.attributes.sort.each { |k, v| $evm.log(:info, "#{my_object_name} Attribute - #{k}: #{v}")}
|
21
|
+
self.log(@dump_log_level, "End #{my_object_name}.attributes")
|
22
|
+
self.log(@dump_log_level, "")
|
23
|
+
else
|
24
|
+
self.log(@dump_log_level, "No attributes for #{my_object_name}")
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# Write the associations of the given object to the log with a prefix of
|
29
|
+
# my_object_name to make finding the entries a little easier.
|
30
|
+
def dump_associations(my_object, my_object_name)
|
31
|
+
if my_object.respond_to?("associations")
|
32
|
+
self.log(@dump_log_level, "Begin #{my_object_name}.associations")
|
33
|
+
my_object.associations.sort.each { |a| $evm.log(:info, "#{my_object_name} Association - #{a}")}
|
34
|
+
self.log(@dump_log_level, "End #{my_object_name}.associations")
|
35
|
+
self.log(@dump_log_level, "")
|
36
|
+
else
|
37
|
+
self.log(@dump_log_level, "No associations for #{my_object_name}")
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
# Write the virtual columns of the given object to the log with a prefix of
|
42
|
+
# my_object_name to make finding the entries a little easier.
|
43
|
+
def dump_virtual_columns(my_object, my_object_name)
|
44
|
+
if my_object.respond_to?("virtual_columns")
|
45
|
+
self.log(@dump_log_level, "Begin #{my_object_name}.virtual_columns")
|
46
|
+
my_object.virtual_column_names.sort.each { |vcn| $evm.log(:info, "#{my_object_name} Virtual Column - #{vcn}")}
|
47
|
+
self.log(@dump_log_level, "End #{my_object_name}.virtual_columns")
|
48
|
+
self.log(@dump_log_level, "")
|
49
|
+
else
|
50
|
+
log(@dump_log_level, "No virtual_columns for #{my_object_name}")
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
# A shortcut for dumping multiple types of information about the given object.
|
55
|
+
def dump_info(my_object, my_object_name)
|
56
|
+
self.dump_attributes(my_object, my_object_name)
|
57
|
+
self.dump_associations(my_object, my_object_name)
|
58
|
+
self.dump_virtual_columns(my_object, my_object_name)
|
59
|
+
end
|
60
|
+
|
61
|
+
# A shortcut to dump the $evm.root object.
|
62
|
+
def dump_root()
|
63
|
+
self.dump_info(@evm.root, "$evm.root")
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
data/lib/miq_dev_util.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'miq_dev_util/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "miq_dev_util"
|
8
|
+
spec.version = MiqDevUtil::VERSION
|
9
|
+
spec.authors = ["Eric Wannemacher"]
|
10
|
+
spec.email = ["eric@wannemacher.us"]
|
11
|
+
|
12
|
+
spec.summary = %q{A set of helper classes to make ManageIQ automate
|
13
|
+
development easier and to try and eliminate copy and paste of commonly
|
14
|
+
used code.}
|
15
|
+
spec.homepage = "https://github.com/ewannema/miq_dev_util"
|
16
|
+
spec.license = "MIT"
|
17
|
+
|
18
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
19
|
+
# delete this section to allow pushing this gem to any host.
|
20
|
+
#if spec.respond_to?(:metadata)
|
21
|
+
# spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
|
22
|
+
#else
|
23
|
+
# raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
24
|
+
#end
|
25
|
+
|
26
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
27
|
+
spec.bindir = "exe"
|
28
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
29
|
+
spec.require_paths = ["lib"]
|
30
|
+
|
31
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
32
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
33
|
+
spec.add_development_dependency "rspec"
|
34
|
+
end
|
metadata
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: miq_dev_util
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Eric Wannemacher
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-07-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.10'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.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
|
+
description:
|
56
|
+
email:
|
57
|
+
- eric@wannemacher.us
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".rspec"
|
64
|
+
- ".travis.yml"
|
65
|
+
- Gemfile
|
66
|
+
- LICENSE.txt
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- bin/console
|
70
|
+
- bin/setup
|
71
|
+
- lib/miq_dev_util.rb
|
72
|
+
- lib/miq_dev_util/automate.rb
|
73
|
+
- lib/miq_dev_util/code.rb
|
74
|
+
- lib/miq_dev_util/ems.rb
|
75
|
+
- lib/miq_dev_util/logger.rb
|
76
|
+
- lib/miq_dev_util/version.rb
|
77
|
+
- miq_dev_util.gemspec
|
78
|
+
homepage: https://github.com/ewannema/miq_dev_util
|
79
|
+
licenses:
|
80
|
+
- MIT
|
81
|
+
metadata: {}
|
82
|
+
post_install_message:
|
83
|
+
rdoc_options: []
|
84
|
+
require_paths:
|
85
|
+
- lib
|
86
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
requirements: []
|
97
|
+
rubyforge_project:
|
98
|
+
rubygems_version: 2.2.2
|
99
|
+
signing_key:
|
100
|
+
specification_version: 4
|
101
|
+
summary: A set of helper classes to make ManageIQ automate development easier and
|
102
|
+
to try and eliminate copy and paste of commonly used code.
|
103
|
+
test_files: []
|