-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switching over to using rails engines
- Loading branch information
Paul Kelly
committed
Oct 3, 2010
1 parent
6a354e6
commit 47c2f21
Showing
12 changed files
with
176 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
ActionController::Routing::Routes.draw do |map| | ||
map.resources :subnets | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,23 @@ | ||
Dir.glob(File.join(File.dirname(__FILE__), "db", "migrate", "*")).each do |file| | ||
FileUtils.cp file, File.join(Rails.root, "db", "migrate"), :verbose => true | ||
#!/usr/bin/ruby | ||
require 'fileutils' | ||
root = File.join(File.dirname(__FILE__),"..", "..", "..") | ||
Dir.glob(File.join(File.dirname(__FILE__), "lib", "db", "migrate", "*")).each do |file| | ||
FileUtils.cp file, File.join(root, "db", "migrate"), :verbose => true | ||
end | ||
puts "********************************************************************" | ||
puts "Please run rake db:migrate from the root of your installation" | ||
puts "This will add support for vendors, servertypes and network databases" | ||
puts "********************************************************************" | ||
|
||
routes = File.join(root, "config", "routes") | ||
new_routes = File.join(root, "config", "routes.new") | ||
unless `grep subnets #{routes}` | ||
File.open(routes, "r") do |src| | ||
File.open(new_routes, "w") do |dst| | ||
line = src.readline | ||
dst.write("map.NetdbManagers") if line.match(/Routes.draw/) | ||
dst.write line | ||
end | ||
end | ||
FileUtils.mv src, dst | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,41 @@ | ||
class SubnetsController < ApplicationController | ||
layout 'standard' | ||
def index | ||
@search = Subnet.search params[:search] | ||
@subnets = @search.paginate(:page => params[:page]) | ||
end | ||
|
||
def new | ||
@subnet = Subnet.new | ||
end | ||
|
||
active_scaffold :subnet do |config| | ||
config.columns = [:domain, :name, :number, :mask, :ranges, :dhcp, :vlanid] | ||
config.create.columns = [:domain, :name, :number, :mask, :ranges, :dhcp, :priority, :vlanid] | ||
config.columns[:domain].label = "Site" | ||
config.columns[:vlanid].label = "VLAN id" | ||
columns[:dhcp].label = "DHCP Server" | ||
columns[:ranges].label = "Address ranges" | ||
config.columns[:ranges].description = "A list of comma separated single IPs or start-end couples." | ||
columns[:mask].label = "Netmask" | ||
config.columns[:domain].form_ui = :select | ||
config.columns[:dhcp].form_ui = :select | ||
list.columns.exclude :created_at, :updated_at | ||
list.sorting = {:domain => 'DESC' } | ||
columns['domain'].sort_by :sql | ||
def create | ||
@subnet = Subnet.new(params[:subnet]) | ||
if @subnet.save | ||
flash[:foreman_notice] = "Successfully created subnet." | ||
redirect_to subnets_url | ||
else | ||
render :action => 'new' | ||
end | ||
end | ||
|
||
# Deletes require a page update so as to show error messsages | ||
config.delete.link.inline = false | ||
def edit | ||
@subnet = Subnet.find(params[:id]) | ||
end | ||
|
||
def update | ||
@subnet = Subnet.find(params[:id]) | ||
if @subnet.update_attributes(params[:subnet]) | ||
flash[:foreman_notice] = "Successfully updated subnet." | ||
redirect_to subnets_url | ||
else | ||
render :action => 'edit' | ||
end | ||
end | ||
|
||
config.nested.add_link "Hosts", [:hosts] | ||
def destroy | ||
@subnet = Subnet.find(params[:id]) | ||
@subnet.destroy | ||
flash[:foreman_notice] = "Successfully destroyed subnet." | ||
redirect_to subnets_url | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class Servertype < ActiveRecord::Base | ||
has_many :netdbs | ||
|
||
validates_uniqueness_of :name | ||
validates_presence_of :name | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
class Vendor < ActiveRecord::Base | ||
has_many :netdbs | ||
|
||
validates_uniqueness_of :name | ||
validates_presence_of :name | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<% form_for @subnet do |f| %> | ||
<%= f.error_messages %> | ||
<p> | ||
<%= f.label :name %><br /> | ||
<%= f.text_field :name %> | ||
</p> | ||
<p> | ||
<%= f.label :domain %><br /> | ||
<%= f.collection_select :domain_id, Domain.all, :id, :name %> | ||
</p> | ||
<p> | ||
<%= f.label :number %><br /> | ||
<%= f.text_field :name %> | ||
</p> | ||
<p> | ||
<%= f.label :mask %><br /> | ||
<%= f.text_field :name %> | ||
</p> | ||
<p> | ||
<%= f.label :ranges %><br /> | ||
<%= f.text_field :name, :title => ""A list of comma separated single IPs or start-end couples."" %> | ||
</p> | ||
<p> | ||
<%= f.label :priority %><br /> | ||
<%= f.text_field :name %> | ||
</p> | ||
<p> | ||
<%= f.label :vlanid %><br /> | ||
<%= f.text_field :name %> | ||
</p> | ||
<p> | ||
<p><%= f.submit "Submit" %></p> | ||
|
||
<% unless @subnet.new_record? -%> | ||
Used by <%= @subnet.hosts.count %> hosts | ||
<% end -%> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<% title "Edit Subnet" %> | ||
|
||
<%= render :partial => 'form' %> | ||
|
||
<p><%= link_to "View All Subnets", subnets_path %></p> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<% title "Subnets" %> | ||
|
||
<table class="list"> | ||
<tr> | ||
<th>Name</th> | ||
<th>Domain</th> | ||
<th>Number</th> | ||
<th>Mask</th> | ||
<th>Ranges</th> | ||
<th>Priority</th> | ||
<th>VLAN id</th> | ||
<th></th> | ||
</tr> | ||
<% for subnet in @subnets %> | ||
<tr class="<%= cycle("even", "odd") -%>"> | ||
<td><%=link_to h(subnet.name), edit_subnet_path(subnet)%></td> | ||
<td><%=subnet.domain%></td> | ||
<td><%=subnet.number%></td> | ||
<td><%=subnet.mask%></td> | ||
<td><%=subnet.ranges%></td> | ||
<td><%=subnet.priority%></td> | ||
<td><%=subnet.vlanid%></td> | ||
<td align="right"> | ||
<%= link_to "Destroy", subnet, :confirm => "Delete #{subnet.name}?", :method => :delete %> | ||
</td> | ||
</tr> | ||
<% end %> | ||
</table> | ||
<%= page_entries_info @subnets %> | ||
<%= will_paginate @subnets %> | ||
|
||
<p><%= link_to "New Subnet", new_subnet_path %></p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<% title "New Subnet" %> | ||
|
||
<%= render :partial => 'form' %> | ||
|
||
<p><%= link_to "Back to List", subnets_path %></p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,11 @@ | ||
require 'netdb_manager/host_ext' | ||
#require "netdb_manager/routing" | ||
|
||
%w{ models controllers helpers}.each do |dir| | ||
path = File.join(File.dirname(__FILE__), 'app', dir) | ||
$LOAD_PATH << path | ||
ActiveSupport::Dependencies.load_paths << path | ||
ActiveSupport::Dependencies.load_once_paths.delete(path) | ||
end | ||
end | ||
|
||
ActionController::Base.prepend_view_path File.join(File.dirname(__FILE__), 'app', 'views') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module NetdbManager | ||
#:nodoc: | ||
module Routing | ||
#:nodoc: | ||
module MapperExtensions | ||
def NetdbManagers | ||
@set.add_route("/subnets", {:controller => "subnets", :action => "index"}) | ||
end | ||
end | ||
end | ||
end | ||
ActionController::Routing::RouteSet::Mapper.send :include, NetdbManager::Routing::MapperExtensions |