hiera-vcenter 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/hiera/backend/vcenter_backend.rb +73 -0
- metadata +45 -0
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'RbVviews'
|
2
|
+
|
3
|
+
class Hiera
|
4
|
+
module Backend
|
5
|
+
class Vcenter_backend
|
6
|
+
def initialize
|
7
|
+
Hiera.debug("Hiera VMware vCenter backend initialized")
|
8
|
+
end
|
9
|
+
|
10
|
+
def lookup(key, scope, order_override, resolution_type)
|
11
|
+
Hiera.debug("Looking up \"#{key}\" in vCenter")
|
12
|
+
Hiera.debug("Scope of \"#{scope}\"")
|
13
|
+
Hiera.debug("Order_override of \"#{order_override}\"")
|
14
|
+
Hiera.debug("Resolution_type: #{resolution_type}")
|
15
|
+
|
16
|
+
|
17
|
+
#Establishc onnection to VC
|
18
|
+
config = Config[:vcenter]
|
19
|
+
vc_view = RbVviews.new(config[:server],config[:username],config[:password])
|
20
|
+
vc_view.connect
|
21
|
+
vim = vc_view.instance_variable_get(:@vim)
|
22
|
+
|
23
|
+
#Lookup custom field names and keys
|
24
|
+
propSet = [ { :type => 'CustomFieldsManager', :pathSet => ['field'], :all => false } ]
|
25
|
+
filterSpec = RbVmomi::VIM.PropertyFilterSpec(
|
26
|
+
:objectSet => [ :obj => vim.serviceContent.customFieldsManager ],
|
27
|
+
:propSet => propSet
|
28
|
+
)
|
29
|
+
|
30
|
+
result = vim.propertyCollector.RetrieveProperties(:specSet => [filterSpec])
|
31
|
+
$hashCustomField = Hash.new
|
32
|
+
result[0].obj.field.each {|cf| $hashCustomField[cf.key] = cf.name }
|
33
|
+
|
34
|
+
|
35
|
+
# Search list of domains specified in the hierarchy section in hiera.yaml
|
36
|
+
Backend.datasources(scope, order_override) do |source|
|
37
|
+
Hiera.debug("Looking for vCenter vminstanceuuid #{source}")
|
38
|
+
@source = source
|
39
|
+
vm = vc_view.get_view('VirtualMachine','config.instanceUuid',source)
|
40
|
+
|
41
|
+
#doesn't work with array lookup yet
|
42
|
+
results = []
|
43
|
+
|
44
|
+
#Create hash of key,value for custom values
|
45
|
+
$hashCustomValue = Hash.new
|
46
|
+
vm.select {|vm| vm.obj['config.instanceUuid'] == @source.chomp}.each {|vm|
|
47
|
+
vm.obj.customValue.each {|cv|
|
48
|
+
$hashCustomValue[cv.key] = cv.value
|
49
|
+
}
|
50
|
+
}
|
51
|
+
|
52
|
+
|
53
|
+
#Create array of actual field names and values
|
54
|
+
$arrOut = []
|
55
|
+
$hashCustomValue.each {|key,value|
|
56
|
+
$classes = value if $hashCustomField[key] == "puppet.classes"
|
57
|
+
$arrOut << "#{$hashCustomField[key]}=#{value}"
|
58
|
+
}
|
59
|
+
|
60
|
+
Hiera.debug("answer: #{$classes}")
|
61
|
+
classes = $classes.to_s.split(',')
|
62
|
+
classes = [] unless $classes
|
63
|
+
answer = classes
|
64
|
+
Hiera.debug("returning: #{answer}")
|
65
|
+
vc_view.close
|
66
|
+
|
67
|
+
return answer
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
metadata
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hiera-vcenter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Clinton Kitson
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-07-05 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: ''
|
15
|
+
email: clinton.kitson@emc.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/hiera/backend/vcenter_backend.rb
|
21
|
+
homepage: http://rubygems.org/gems/hiera-vcenter
|
22
|
+
licenses: []
|
23
|
+
post_install_message:
|
24
|
+
rdoc_options: []
|
25
|
+
require_paths:
|
26
|
+
- lib
|
27
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
none: false
|
35
|
+
requirements:
|
36
|
+
- - ! '>='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
requirements: []
|
40
|
+
rubyforge_project:
|
41
|
+
rubygems_version: 1.8.23
|
42
|
+
signing_key:
|
43
|
+
specification_version: 3
|
44
|
+
summary: Provides a vCenter lookup for VM custom values to Hiera
|
45
|
+
test_files: []
|