foreman_ipam 0.0.11 → 0.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: 0c55538e48d175e816b53d10706a5279bd99c0d51d6a389a4e897844f4c841b2
4
- data.tar.gz: f6131ec6a0c5ed2db1834c5670f8bab4e0cc7a1ec8dec9c29926b12360c6034a
3
+ metadata.gz: d2d6195978d83bc1a5ab6485849833ab299c8df4d081f8ffc3cd272325225b12
4
+ data.tar.gz: ca5d8ac1087b01665f6b1d5b7c39dd46ecda8e15702040e11e07ca817750a1d6
5
5
  SHA512:
6
- metadata.gz: 5504492fd57853f8abe0530691a290b8ebb603de840dc97c8731b158c7cb99b2fdd3b25e9ae9a23b0498a60dbef4fae80d8a658af01c877d5e570e7ff780074f
7
- data.tar.gz: 14567c9ea0add4e8e10a55fff634f258f8824f9884da20fc2bf03cbf474e852b35617c978370e418fbcaf36c104af11428d65f36b9b8f4f3882b6f3c75775d67
6
+ metadata.gz: eae660a356f4368845ca9a73b3546a71adba235c1df533d054035cfb6f7dbf5a13772aec79f8d02126dcf6ebd8abb9d386bda9c7bc745b65595dd47f81c3f19e
7
+ data.tar.gz: fcc77ca57bacd49f2dee7a61f11f0262cb35b5e9180c4a9b9c67a289b33e20e00312217aab36fa50dcfdf006ebe0616aea4dcfeb11d56cf9a3c90bf61d9b3f76
data/README.md CHANGED
@@ -1,11 +1,6 @@
1
1
  # foreman_ipam
2
2
 
3
- Foreman plugin for IPAM integration with various IPAM providers.
4
-
5
- Currently supported Providers:
6
- 1. [phpIPAM](https://phpipam.net/).
7
-
8
- Provides a basic Dashboard for viewing phpIPAM sections and subnets. Also allows for obtaining of the next available IPv4 address for a given subnet(via [IPAM Smart Proxy Plugin](https://github.com/grizzthedj/smart_proxy_ipam)).
3
+ Foreman plugin for IPAM integration with External IPAM providers. Provides a basic Dashboard for viewing External IPAM groups and subnets via External IPAM Smart Proxy API's.
9
4
 
10
5
  ## Installation
11
6
 
@@ -14,10 +9,7 @@ for how to install Foreman plugins.
14
9
 
15
10
  ## Usage
16
11
 
17
- Once plugin is installed, you can look at the phpIPAM Dashboard(at Infrastructure --> phpIPAM Dashboard), for a simple view of sections, subnets etc. and/or use phpIPAM to get the next available IP address for a subnet:
18
-
19
- 1. Create a subnet in Foreman of IPAM type "IPAM". Click on the `Proxy` tab and associate the subnet with the IPAM proxy. _NOTE: This subnet must actually exist in phpIPAM. There is no phpIPAM integration on the subnet creation at this time._
20
- 2. Create a host in Foreman. When adding/editing interfaces, select the above subnet, and the next available IP(pulled from phpIPAM) for the selected subnet will be displayed in the IPv4 address field. _NOTE: This is not supported for IPv6._
12
+ Once plugin is installed, you can look at the External IPAM Dashboard at Infrastructure --> External IPAM, for a simple view of groups and subnets.
21
13
 
22
14
  ## Local development
23
15
 
@@ -31,38 +23,44 @@ git clone https://github.com/theforeman/smart-proxy
31
23
  ```
32
24
  3. Fork both the foreman plugin and smart proxy plugin repos, then clone
33
25
 
34
- foreman_phpipam repo: https://github.com/grizzthedj/smart_proxy_phpipam
35
- smart_proxy_phpipam repo: https://github.com/grizzthedj/smart_proxy_phpipam
26
+ foreman_ipam repo: https://github.com/grizzthedj/foreman_ipam
27
+ smart_proxy_ipam repo: https://github.com/grizzthedj/smart_proxy_ipam
36
28
 
37
29
  ```
38
- git clone https://github.com/<GITHUB_USER>/foreman_phpipam
39
- git clone https://github.com/<GITHUB_USER>/smart_proxy_phpipam
30
+ git clone https://github.com/<GITHUB_USER>/foreman_ipam
31
+ git clone https://github.com/<GITHUB_USER>/smart_proxy_ipam
40
32
  ```
41
- 4. Add the foreman_phpipam plugin to `Gemfile.local.rb` in the Foreman bundler.d directory
33
+ 4. Add the foreman_ipam plugin to `Gemfile.local.rb` in the Foreman bundler.d directory
42
34
  ```
43
- gem 'foreman_phpipam', :path => '/path/to/foreman_phpipam'
35
+ gem 'foreman_ipam', :path => '/path/to/foreman_ipam'
44
36
  ```
45
37
  5. From Foreman root directory run
46
38
  ```
47
39
  bundle install
48
40
  bundle exec rails db:migrate
49
- bundle exec rails db:seed # This adds 'phpIPAM' feature to Features table
41
+ bundle exec rails db:seed
50
42
  bundle exec foreman start
51
43
  ```
52
- 6. Add the smart_proxy_phpipam plugin to `Gemfile.local.rb` in Smart Proxy bundler.d directory
44
+ 6. Add the smart_proxy_ipam plugin to `Gemfile.local.rb` in Smart Proxy bundler.d directory
53
45
  ```
54
- gem 'smart_proxy_phpipam', :path => '/path/to/smart_proxy_phpipam'
46
+ gem 'smart_proxy_ipam', :path => '/path/to/smart_proxy_ipam'
55
47
  ```
56
- 7. Copy `config/settings.d/phpipam.yml.example` to `config/settings.d/phpipam.yml` and replace values with your phpIPAM URL and credentials.
57
- 8. From Smart Proxy root directory run ...
48
+
49
+ 7. Copy `config/settings.d/externalipam.yml.example` to `config/settings.d/externalipam.yml`, and set `enabled` to true, and `use_provider` to `externalipam_phpipam` or `externalipam_netbox`.
50
+
51
+ 8. Copy `config/settings.d/externalipam_phpipam.yml.example` to `config/settings.d/externalipam_phpipam.yml` and replace values with your phpIPAM URL and credentials.
52
+
53
+ 9. Copy `config/settings.d/externalipam_netbox.yml.example` to `config/settings.d/externalipam_netbox.yml` and replace values with your Netbox URL and API token.
54
+
55
+ 10. From Smart Proxy root directory run ...
58
56
  ```
59
57
  bundle install
60
58
  bundle exec smart-proxy start
61
59
  ```
62
- 9. Navigate to Foreman UI at http://localhost:5000
63
- 10. Add a Local Smart Proxy in the Foreman UI(Infrastructure => Smart Proxies)
64
- 11. Ensure that the `phpipam` feature is present on the proxy(http://proxy_url/features)
65
- 12. Create a Subnet, and associate the subnet to the `phpipam` proxy
60
+ 11. Navigate to Foreman UI at http://localhost:5000
61
+ 12. Add a Local Smart Proxy in the Foreman UI(Infrastructure => Smart Proxies)
62
+ 13. Ensure that the `External IPAM` feature is present on the proxy(http://proxy_url/features)
63
+ 14. Create a Subnet, and associate the subnet to the `External IPAM` proxy
66
64
 
67
65
  ## Run tests
68
66
 
@@ -72,15 +70,6 @@ From the Foreman core, run ...
72
70
  bundle exec rails test:foreman_ipam
73
71
  ```
74
72
 
75
- ## TODO
76
-
77
- - Support for ip ranges
78
- - Sync VLAN ID with phpIPAM
79
- - More functionality on phpIPAM Dashboard page
80
- * Create a subnet
81
- * List ips within a subnet
82
- - Better error handling in the case connectivity to phpIPAM is lost
83
-
84
73
  ## Contributing
85
74
 
86
75
  Fork and send a Pull Request. Thanks!
@@ -101,4 +90,3 @@ GNU General Public License for more details.
101
90
 
102
91
  You should have received a copy of the GNU General Public License
103
92
  along with this program. If not, see <http://www.gnu.org/licenses/>.
104
-
@@ -0,0 +1,32 @@
1
+ module ForemanIpam
2
+ class ExternalIpamController < ::DashboardController
3
+ def dashboard
4
+ begin
5
+ ipam_proxies = SmartProxy.with_features('External IPAM')
6
+ first_id = ipam_proxies.first.id
7
+ @response = {}
8
+ ipam_proxies.each do |proxy|
9
+ external_ipam_proxy = ProxyAPI::ExternalIpam.new({:url => proxy[:url]})
10
+ @response[proxy.name] = {
11
+ id: proxy.id,
12
+ first: proxy.id == first_id,
13
+ groups: external_ipam_proxy.get_groups
14
+ }
15
+ end
16
+ rescue => e
17
+ flash.now[:notice] = e.message
18
+ end
19
+ end
20
+
21
+ def subnets
22
+ begin
23
+ proxy = SmartProxy.find(params[:smart_proxy_id])
24
+ external_ipam_proxy = ProxyAPI::ExternalIpam.new({:url => proxy[:url]})
25
+ @subnets = external_ipam_proxy.get_subnets_by_group(params[:group])
26
+ rescue => e
27
+ flash.now[:notice] = e.message
28
+ end
29
+ render :json => @subnets.to_json, :status => :ok
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,106 @@
1
+ <h1>External IPAM Dashboard</h1>
2
+
3
+ <% if !flash.empty? %>
4
+ <div class="alert alert-warning ">
5
+ <span class="pficon pficon-warning-triangle-o "></span>
6
+ <span class="text"><%= _(flash.now[:notice]) %></span>
7
+ </div>
8
+ <% else %>
9
+ <ul class="nav nav-tabs" data-tabs="tabs">
10
+ <% @response.keys.each do |proxy| %>
11
+ <% proxy_name = proxy.downcase.gsub(' ','_') %>
12
+
13
+ <li class='<%= @response[proxy][:first] ? "active" : "" %>' onclick="clearSubnets('<%= proxy_name %>')">
14
+ <a href='#<%= proxy_name %>' data-toggle="tab"><%= _(proxy) %></a>
15
+ </li>
16
+ <% end %>
17
+ </ul>
18
+ <div class="tab-content">
19
+ <% @response.keys.each do |proxy| %>
20
+ <% proxy_name = proxy.downcase.gsub(' ','_') %>
21
+
22
+ <% if @response[proxy][:groups].length == 0 %>
23
+ <div class="alert alert-warning ">
24
+ <span class="pficon pficon-warning-triangle-o "></span>
25
+ <span class="text"><%= _("No groups found in External IPAM.") %></span>
26
+ </div>
27
+ <% else %>
28
+ <div class="tab-pane <%= "active" if @response[proxy][:first] %>" id='<%= proxy_name %>' >
29
+ <h3>Groups:</h3>
30
+ <table class="<%= table_css_classes 'table-fixed' %>">
31
+ <thead>
32
+ <tr>
33
+ <th class="col-md-2"><%= s_("Name") %></th>
34
+ <th class="col-md-6"><%= s_("Description") %></th>
35
+ </tr>
36
+ </thead>
37
+ <tbody>
38
+ <% @response[proxy][:groups].each do |group| %>
39
+ <tr>
40
+ <td class="ellipsis">
41
+ <a href="#" onclick="getSubnets('<%= group['name'] %>', '<%= @response[proxy][:id] %>', '<%= proxy_name %>')">
42
+ <%= group['name'] %>
43
+ </a>
44
+ </td>
45
+ <td class="ellipsis">
46
+ <%= group['description'] %>
47
+ </td>
48
+ </tr>
49
+ <% end %>
50
+ </tbody>
51
+ </table>
52
+
53
+ <div id="subnet_container_<%= proxy_name %>"></div>
54
+ </div>
55
+ <% end %>
56
+ <% end %>
57
+ </div>
58
+ <% end %>
59
+
60
+ <script>
61
+ function getSubnets(groupName, proxyId, proxyName) {
62
+ var subnetContainer = document.getElementById('subnet_container_' + proxyName);
63
+ subnetContainer.innerHTML = '<h2>Subnets for ' + groupName + '</h2>';
64
+
65
+ $.ajax({
66
+ type: "GET",
67
+ url: "/ipam/subnets?smart_proxy_id=" + proxyId + "&group=" + groupName,
68
+ success: function(data) {
69
+ if (!data) {
70
+ subnetContainer.innerHTML += 'Something went wrong';
71
+ }
72
+ else {
73
+ if (data.message === 'No subnets found')
74
+ subnetContainer.innerHTML += data.message;
75
+ else
76
+ displaySubnets(data, proxyName);
77
+ }
78
+ }
79
+ });
80
+ }
81
+
82
+ function clearSubnets(proxyName) {
83
+ document.getElementById('subnet_container_' + proxyName).innerHTML = '';
84
+ }
85
+
86
+ function displaySubnets(subnets, proxyName) {
87
+ var subnetContainer = document.getElementById('subnet_container_' + proxyName);
88
+
89
+ if (subnets.length == 0) {
90
+ subnetContainer.innerHTML += "<div class='col-md-3'><strong>No Subnets found</strong></div>"
91
+ }
92
+ else {
93
+ subnetContainer.innerHTML += `
94
+ <div class='col-md-3'><strong>Subnet</strong></div>
95
+ <div class='col-md-6'><strong>Description</strong></strong></div><br />
96
+ `;
97
+ }
98
+
99
+ subnets.forEach(function(item) {
100
+ subnetContainer.innerHTML += `
101
+ <div class='col-md-3'>` + item['subnet'] + `/` + item['mask'] + `</div>
102
+ <div class='col-md-6'>` + item['description'] + `</div><br />
103
+ `;
104
+ });
105
+ }
106
+ </script>
@@ -1,4 +1,4 @@
1
1
  Rails.application.routes.draw do
2
- get 'ipam', to: 'foreman_ipam/dashboard#ipam'
3
- get 'ipam/phpipam/subnets', to: 'foreman_ipam/dashboard#subnets'
2
+ get 'ipam', to: 'foreman_ipam/external_ipam#dashboard'
3
+ get 'ipam/subnets', to: 'foreman_ipam/external_ipam#subnets'
4
4
  end
@@ -16,23 +16,23 @@ module ForemanIpam
16
16
 
17
17
  initializer 'foreman_ipam.register_plugin', :before => :finisher_hook do |_app|
18
18
  Foreman::Plugin.register :foreman_ipam do
19
- requires_foreman '>= 1.16'
19
+ requires_foreman '>= 2.1'
20
20
 
21
21
  # Add permissions
22
22
  security_block :foreman_ipam do
23
- permission :view_foreman_ipam, :'foreman_ipam/dashboard' => [:ipam]
24
- permission :view_foreman_ipam_subnets, :'foreman_ipam/dashboard' => [:subnets]
23
+ permission :view_foreman_ipam, :'foreman_ipam/external_ipam' => [:dashboard]
24
+ permission :view_foreman_ipam_subnets, :'foreman_ipam/external_ipam' => [:subnets]
25
25
  end
26
26
 
27
27
  # Add a new role called 'ExternalIpam' if it doesn't exist
28
- role 'ExternalIpam', [:view_foreman_ipam, :view_foreman_ipam_subnets]
28
+ role 'ExternalIpam', [:view_foreman_ipam, :view_foreman_ipam_subnets] # , 'Role to allow for the viewing of Subnets and Sections from External IPAM']
29
29
 
30
30
  # Add menu entry to Infrastructure
31
31
  menu :top_menu, :template,
32
32
  url_hash: {
33
- controller: :'foreman_ipam/dashboard', action: :ipam
33
+ controller: :'foreman_ipam/external_ipam', action: :dashboard
34
34
  },
35
- caption: 'IPAM Dashboard',
35
+ caption: 'External IPAM',
36
36
  parent: :infrastructure_menu
37
37
  end
38
38
  end
@@ -1,3 +1,3 @@
1
1
  module ForemanIpam
2
- VERSION = '0.0.11'.freeze
2
+ VERSION = '0.1.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_ipam
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.11
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christopher Smith
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-01-03 00:00:00.000000000 Z
11
+ date: 2021-01-09 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Plugin for IPAM integration with various IPAM providers
14
14
  email:
@@ -20,17 +20,13 @@ files:
20
20
  - LICENSE
21
21
  - README.md
22
22
  - Rakefile
23
- - app/controllers/foreman_ipam/dashboard_controller.rb
23
+ - app/controllers/foreman_ipam/external_ipam_controller.rb
24
24
  - app/helpers/concerns/foreman_ipam/dashboard_helper_extensions.rb
25
25
  - app/models/concerns/foreman_ipam/dashboard_extensions.rb
26
- - app/views/dashboard/_foreman_ipam_widget.html.erb
27
- - app/views/foreman_ipam/dashboard/ipam.html.erb
28
- - config/initializers/phpipam.rb
26
+ - app/views/foreman_ipam/external_ipam/dashboard.html.erb
29
27
  - config/routes.rb
30
- - config/settings.yaml.example
31
28
  - lib/foreman_ipam.rb
32
29
  - lib/foreman_ipam/engine.rb
33
- - lib/foreman_ipam/phpipam.rb
34
30
  - lib/foreman_ipam/version.rb
35
31
  - lib/tasks/foreman_ipam_tasks.rake
36
32
  - locale/Makefile
@@ -44,7 +40,7 @@ homepage: https://github.com/grizzthedj/foreman_ipam
44
40
  licenses:
45
41
  - GPL-3.0
46
42
  metadata: {}
47
- post_install_message:
43
+ post_install_message:
48
44
  rdoc_options: []
49
45
  require_paths:
50
46
  - lib
@@ -60,7 +56,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
60
56
  version: '0'
61
57
  requirements: []
62
58
  rubygems_version: 3.0.6
63
- signing_key:
59
+ signing_key:
64
60
  specification_version: 4
65
61
  summary: Plugin for IPAM integration with various IPAM providers
66
62
  test_files:
@@ -1,21 +0,0 @@
1
-
2
- module ForemanIpam
3
- class DashboardController < ::DashboardController
4
- def ipam
5
- begin
6
- @response = Phpipam.proxy.get_sections
7
- rescue => e
8
- flash.now[:notice] = e.message
9
- end
10
- end
11
-
12
- def subnets
13
- begin
14
- @subnets = Phpipam.proxy.get_subnets_by_section(params[:section_name])
15
- rescue => e
16
- flash.now[:notice] = e.message
17
- end
18
- render :json => @subnets.to_json, :status => :ok
19
- end
20
- end
21
- end
@@ -1,2 +0,0 @@
1
- <h4 class="header ca"><%= _('ForemanIpam') %></h4>
2
- <%= _('Widget content') %>
@@ -1,82 +0,0 @@
1
- <h1>IPAM Integration Dashboard</h1>
2
-
3
- <% if !flash.empty? %>
4
- <div class="alert alert-warning ">
5
- <span class="pficon pficon-warning-triangle-o "></span>
6
- <span class="text"><%= _(flash.now[:notice]) %></span>
7
- </div>
8
- <% elsif @response['data'] && @response['data'].length == 0 %>
9
- <div class="alert alert-warning ">
10
- <span class="pficon pficon-warning-triangle-o "></span>
11
- <span class="text"><%= _("No sections found in External IPAM.") %></span>
12
- </div>
13
- <% elsif @response['data'] && @response['data'].length > 0 %>
14
- <h2>phpIPAM</h2>
15
- <h3>Sections:</h3>
16
- <table class="<%= table_css_classes 'table-fixed' %>">
17
- <thead>
18
- <tr>
19
- <th class="col-md-2"><%= s_("Name") %></th>
20
- <th class="col-md-6"><%= s_("Description") %></th>
21
- </tr>
22
- </thead>
23
- <tbody>
24
- <% @response['data'].each do |section| %>
25
- <tr>
26
- <td class="ellipsis">
27
- <a href="#" onclick="getSubnets('<%= section['id'] %>', '<%= section['name'] %>')"><%= section['name'] %></a>
28
- </td>
29
- <td class="ellipsis">
30
- <%= section['description'] %>
31
- </td>
32
- </tr>
33
- <% end %>
34
- </tbody>
35
- </table>
36
- <% end %>
37
-
38
- <div id="subnet_container"></div>
39
-
40
- <script>
41
- function getSubnets(section_id, section_name) {
42
- var subnet_container = document.getElementById('subnet_container');
43
- subnet_container.innerHTML = '<h2>Subnets for ' + section_name + '</h2>';
44
-
45
- $.ajax({
46
- type: "GET", url: "/ipam/phpipam/subnets",
47
- data: {"section_name": encodeURI(section_name)},
48
- success: function(data) {
49
- if (!data) {
50
- subnet_container.innerHTML += 'Cannot connect to External IPAM';
51
- }
52
- else {
53
- if (data.message === 'No subnets found')
54
- subnet_container.innerHTML += data.message;
55
- else
56
- displaySubnets(data);
57
- }
58
- }
59
- });
60
- }
61
-
62
- function displaySubnets(data) {
63
- var subnets = data;
64
-
65
- if (subnets['data'].length == 0) {
66
- subnet_container.innerHTML += "<div class='col-md-2'><strong>No Subnets</strong></div>"
67
- }
68
- else {
69
- subnet_container.innerHTML += `
70
- <div class='col-md-2'><strong>Subnet</strong></div>
71
- <div class='col-md-6'><strong>Description</strong></strong></div><br />
72
- `;
73
- }
74
-
75
- subnets['data'].forEach(function(item) {
76
- subnet_container.innerHTML += `
77
- <div class='col-md-2'>` + item['subnet'] + `/` + item['mask'] + `</div>
78
- <div class='col-md-6'>` + item['description'] + `</div><br />
79
- `;
80
- });
81
- }
82
- </script>
@@ -1 +0,0 @@
1
- require_relative '../../lib/foreman_ipam/phpipam'
@@ -1,10 +0,0 @@
1
-
2
- :ipam:
3
- :phpipam:
4
- :url: 'http://phpipam.example.com'
5
- :user: 'phpipam_api_user'
6
- :password: 'phpipam_password'
7
- :netbox:
8
- :url: 'http://netbox.example.com'
9
- :user: 'netbox_api_user'
10
- :password: 'netbox_password'
@@ -1,8 +0,0 @@
1
- module ForemanIpam
2
- class Phpipam
3
- def self.proxy
4
- external_ipam_proxy = SmartProxy.with_features('External IPAM').first
5
- ProxyAPI::ExternalIpam.new({:url => external_ipam_proxy[:url]})
6
- end
7
- end
8
- end