hammer_cli_bluecat 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b92088eb6a5bbe78c9ce4cd2027e840d0eb91ad2
4
+ data.tar.gz: e4748449947a6a4cfea21e27cc4e8dab5d15fd84
5
+ SHA512:
6
+ metadata.gz: 412994e87bba2a0a1cedbbc399ad9b160993c70e6309b2af9692d304821d42d803633da69d3e8f8d2751eb77d07b72cba05d55eb9231a4fee6f6bbda224ab04b
7
+ data.tar.gz: 3df8048aca50b53ef57eec3a076dbf34e9d9d59391e666ae17153c8ed9a2c664877ce59cffb298d111386115c5ca5e01aa98197d7787e035f15d38b9cab602a6
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ /.idea/
2
+ /.bundle/
3
+ /.yardoc
4
+ /Gemfile.lock
5
+ /_yardoc/
6
+ /coverage/
7
+ /doc/
8
+ /pkg/
9
+ /spec/reports/
10
+ /tmp/
11
+ /vendor/
12
+ /bin/
13
+
14
+ # rspec failure tracking
15
+ .rspec_status
16
+
17
+ /*.gem
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.14.6
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in hammer_cli_bluecat-cli-bluecat.gemspec
4
+ gemspec
5
+
6
+ group :development do
7
+ gem 'bluecat', :git => 'git@github.com:mdwheele/bluecat.git'
8
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Dustin Wheeler
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,40 @@
1
+ # HammerCliBluecat
2
+
3
+ Adds a set of commands to synchronize data from Bluecat Address Manager to a Foreman instance.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'hammer_cli_bluecat'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install hammer-cli-bluecat
20
+
21
+ ## Usage
22
+
23
+ This Hammer CLI plugin relies on `hammer_cli_foreman` being installed and correctly configured. Additionally, you will need to configure this plugin (`~/.hammer/cli.modules.d/bluecat.yml`):
24
+
25
+ ```
26
+ :bluecat:
27
+ :enable_module: true
28
+ :wsdl: https://hostname/Services/API?wsdl
29
+ :username: api-user
30
+ :password: api-password
31
+ ```
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/mdwheele/hammer-cli-bluecat.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
40
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -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 'hammer_cli_bluecat/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "hammer_cli_bluecat"
8
+ spec.version = HammerCliBluecat::VERSION
9
+ spec.authors = ["Dustin Wheeler"]
10
+ spec.email = ["mdwheele@ncsu.edu"]
11
+
12
+ spec.summary = %q{Bluecat commands for Hammer}
13
+ spec.description = %q{Bluecat commands for Hammer CLI}
14
+ spec.homepage = "https://github.com/mdwheele/hammer_cli_bluecat"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "bin"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_dependency 'bluecat', '~> 0.1'
25
+ spec.add_dependency 'foreman_api', '~> 0.1'
26
+ spec.add_dependency 'netaddr', '~> 1.5'
27
+ spec.add_dependency 'hammer_cli', '~> 0.10'
28
+ spec.add_dependency 'hammer_cli_foreman', '~> 0.10'
29
+ spec.add_dependency 'apipie-bindings', '~> 0.2'
30
+
31
+ spec.add_development_dependency "bundler", "~> 1.14"
32
+ spec.add_development_dependency "rake", "~> 10.0"
33
+ spec.add_development_dependency "rspec", "~> 3.0"
34
+ end
@@ -0,0 +1,143 @@
1
+ require 'bluecat'
2
+ require 'hammer_cli'
3
+ require 'apipie_bindings'
4
+ require 'netaddr'
5
+ require 'pp'
6
+
7
+ module HammerCliBluecat
8
+ class BluecatCommand < HammerCLI::AbstractCommand
9
+ class SyncNetworkCommand < HammerCLI::AbstractCommand
10
+ include HammerCliBluecat
11
+
12
+ # TODO: Consider tftp_id as an option instead of magik-ing it.
13
+
14
+ def execute
15
+ # Get current domain identifiers...
16
+ @domain_ids = domain_ids
17
+ @tftp_id = tftp_id
18
+ @catalog = {}
19
+
20
+ # Build a list of subnet resources from Bluecat...
21
+ bluecat do |client|
22
+ client.ip4_networks(38537).map { |network| bluecat_to_foreman_catalog network }
23
+ .each { |entry| add_to_catalog entry }
24
+ end
25
+
26
+ # Gather current Foreman subnets
27
+ subnet_networks = foreman.resource(:subnets).call(:index, :per_page => 9999).map do |s|
28
+ {
29
+ :id => s['subnet']['id'],
30
+ :network => s['subnet']['network'],
31
+ }
32
+ end
33
+
34
+ # Mark catalog entries for update or deletion
35
+ subnet_networks.each do |network|
36
+ if @catalog.has_key?(network[:network])
37
+ if has_changed network
38
+ @catalog[network[:network]][:action] = 'update'
39
+ @catalog[network[:network]][:id] = network[:id]
40
+ end
41
+ else
42
+ @catalog[network[:network]] = {
43
+ :id => network[:id],
44
+ :action => 'delete'
45
+ }
46
+ end
47
+ end
48
+
49
+ process_catalog
50
+ HammerCLI::EX_OK
51
+ end
52
+
53
+ def process_catalog
54
+ @catalog.each do |network, entry|
55
+ case entry[:action]
56
+ when 'create'
57
+ puts "Creating #{entry}.\n"
58
+ foreman.resource(:subnets).call(:create, { :subnet => entry[:resource] })
59
+ when 'update'
60
+ puts "Updating #{entry}.\n"
61
+ foreman.resource(:subnets).call(:update, { :id => entry[:id], :subnet => entry[:resource] })
62
+ when 'delete'
63
+ puts "#{entry} marked for deletion, skipping.\n"
64
+ end
65
+ end
66
+ end
67
+
68
+ # Stub to determine whether an update is required
69
+ def has_changed(network)
70
+ true
71
+ end
72
+
73
+ # Foreman response from Bluecat into a unit of work.
74
+ def bluecat_to_foreman_catalog(network)
75
+ cidr = NetAddr::CIDR.create(network[:ip_range])
76
+
77
+ if network[:name]
78
+ name = "#{network[:name]} (#{network[:ip_range]})"
79
+ else
80
+ name = network[:ip_range]
81
+ end
82
+
83
+ {
84
+ :id => nil,
85
+ :action => 'create',
86
+ :resource => {
87
+ :name => name,
88
+ :network_type => 'IPv4',
89
+ :network => cidr.network,
90
+ :mask => cidr.wildcard_mask,
91
+ :gateway => cidr.nth(1),
92
+ :dns_primary => '152.1.14.14',
93
+ :dns_secondary => '152.1.14.21',
94
+ :ipam => 'None',
95
+ :domain_ids => @domain_ids,
96
+ :tftp_id => @tftp_id,
97
+ :boot_mode => 'DHCP'
98
+ }
99
+ }
100
+ end
101
+
102
+ def add_to_catalog(entry)
103
+ @catalog[entry[:resource][:network]] = entry
104
+ end
105
+ end
106
+
107
+ subcommand 'sync-networks', "Sync Bluecat networks to Foreman subnets", HammerCliBluecat::BluecatCommand::SyncNetworkCommand
108
+ end
109
+
110
+ HammerCLI::MainCommand.subcommand 'bluecat', "Bluecat Address Manager Tools", HammerCliBluecat::BluecatCommand
111
+
112
+ def bluecat
113
+ username = HammerCLI::Settings.get(:bluecat, :username)
114
+ password = HammerCLI::Settings.get(:bluecat, :password)
115
+
116
+ client = Bluecat::Client.new(wsdl: HammerCLI::Settings.get(:bluecat, :wsdl))
117
+ client.login(username, password)
118
+
119
+ yield client
120
+
121
+ client.logout
122
+ end
123
+
124
+ def foreman
125
+ uri = HammerCLI::Settings.get(:foreman, :host)
126
+ username = HammerCLI::Settings.get(:foreman, :username)
127
+ password = HammerCLI::Settings.get(:foreman, :password)
128
+
129
+ HammerCLI::Apipie::ApiConnection.new(
130
+ :uri => uri,
131
+ :username => username,
132
+ :password => password,
133
+ :api_version => '1')
134
+ end
135
+
136
+ def domain_ids
137
+ foreman.resource(:domains).call(:index).map { |e| e['domain']['id'] }
138
+ end
139
+
140
+ def tftp_id
141
+ 1
142
+ end
143
+ end
@@ -0,0 +1,3 @@
1
+ module HammerCliBluecat
2
+ VERSION = "0.1.1"
3
+ end
metadata ADDED
@@ -0,0 +1,180 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hammer_cli_bluecat
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Dustin Wheeler
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-04-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bluecat
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: foreman_api
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: netaddr
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.5'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.5'
55
+ - !ruby/object:Gem::Dependency
56
+ name: hammer_cli
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.10'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.10'
69
+ - !ruby/object:Gem::Dependency
70
+ name: hammer_cli_foreman
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.10'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.10'
83
+ - !ruby/object:Gem::Dependency
84
+ name: apipie-bindings
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.2'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.2'
97
+ - !ruby/object:Gem::Dependency
98
+ name: bundler
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '1.14'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '1.14'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rake
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '10.0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '10.0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rspec
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '3.0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '3.0'
139
+ description: Bluecat commands for Hammer CLI
140
+ email:
141
+ - mdwheele@ncsu.edu
142
+ executables: []
143
+ extensions: []
144
+ extra_rdoc_files: []
145
+ files:
146
+ - ".gitignore"
147
+ - ".rspec"
148
+ - ".travis.yml"
149
+ - Gemfile
150
+ - LICENSE.txt
151
+ - README.md
152
+ - Rakefile
153
+ - hammer_cli_bluecat.gemspec
154
+ - lib/hammer_cli_bluecat.rb
155
+ - lib/hammer_cli_bluecat/version.rb
156
+ homepage: https://github.com/mdwheele/hammer_cli_bluecat
157
+ licenses:
158
+ - MIT
159
+ metadata: {}
160
+ post_install_message:
161
+ rdoc_options: []
162
+ require_paths:
163
+ - lib
164
+ required_ruby_version: !ruby/object:Gem::Requirement
165
+ requirements:
166
+ - - ">="
167
+ - !ruby/object:Gem::Version
168
+ version: '0'
169
+ required_rubygems_version: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ requirements: []
175
+ rubyforge_project:
176
+ rubygems_version: 2.5.1
177
+ signing_key:
178
+ specification_version: 4
179
+ summary: Bluecat commands for Hammer
180
+ test_files: []