Revision 5f6b2196
Added by Paul Kelly about 14 years ago
- ID 5f6b2196e7bb3283bc2a294cdeba8b59f088812c
app/controllers/application_controller.rb | ||
---|---|---|
render :partial => 'common/fact_selected', :layout => false
|
||
end
|
||
|
||
def import_environments
|
||
ec, pc = Environment.count, Puppetclass.count
|
||
Environment.importClasses
|
||
|
||
flash[:foreman_notice] = "Environments old:#{ec} current:#{Environment.count}<br>PuppetClasses old:#{pc} current:#{Puppetclass.count}"
|
||
redirect_to :back
|
||
end
|
||
|
||
protected
|
||
|
||
def require_ssl
|
app/controllers/environments_controller.rb | ||
---|---|---|
class EnvironmentsController < ApplicationController
|
||
active_scaffold :environment do |config|
|
||
config.columns = %w{name}
|
||
config.nested.add_link("Hosts", [:hosts])
|
||
config.nested.add_link("Classes", [:puppetclasses])
|
||
def index
|
||
@search = Environment.search(params[:search])
|
||
@environments = @search.paginate :page => params[:page]
|
||
end
|
||
|
||
def show
|
||
@environment = Environment.find(params[:id])
|
||
end
|
||
|
||
def new
|
||
@environment = Environment.new
|
||
end
|
||
|
||
def create
|
||
@environment = Environment.new(params[:environment])
|
||
if @environment.save
|
||
flash[:foreman_notice] = "Successfully created environment."
|
||
redirect_to environments_path
|
||
else
|
||
render :action => 'new'
|
||
end
|
||
end
|
||
|
||
def edit
|
||
@environment = Environment.find(params[:id])
|
||
end
|
||
|
||
config.action_links.add 'import_classes_and_environments', :label => 'Import environments and classes', :inline => false,
|
||
:page => :true , :type => :table
|
||
def update
|
||
@environment = Environment.find(params[:id])
|
||
if @environment.update_attributes(params[:environment])
|
||
flash[:foreman_notice] = "Successfully updated environment."
|
||
redirect_to environments_path
|
||
else
|
||
render :action => 'edit'
|
||
end
|
||
end
|
||
|
||
def destroy
|
||
@environment = Environment.find(params[:id])
|
||
if @environment.destroy
|
||
flash[:foreman_notice] = "Successfully destroyed '#{@environment.name}''"
|
||
else
|
||
flash[:foreman_error] = @environment.errors.full_messages.join("<br>")
|
||
end
|
||
redirect_to environments_url
|
||
end
|
||
|
||
end
|
app/controllers/puppetclasses_controller.rb | ||
---|---|---|
redirect_to puppetclasses_url
|
||
end
|
||
|
||
def import
|
||
ec, pc = Environment.count, Puppetclass.count
|
||
Environment.importClasses
|
||
flash[:foreman_notice] = "Environments old:#{ec}\tcurrent:#{Environment.count}<br>PuppetClasses old:#{pc}\tcurrent:#{Puppetclass.count}"
|
||
redirect_to :back
|
||
end
|
||
|
||
# AJAX methods
|
||
|
||
# adds a puppetclass to an existing host or hostgroup
|
app/models/environment.rb | ||
---|---|---|
has_many :hosts
|
||
validates_presence_of :name
|
||
validates_uniqueness_of :name
|
||
validates_format_of :name, :with => /^\S+$/, :message => "Name cannot contain spaces"
|
||
validates_format_of :name, :with => /^\S+$/, :message => "cannot contain spaces"
|
||
default_scope :order => 'name'
|
||
|
||
def to_label
|
||
... | ... | |
name
|
||
end
|
||
|
||
def self.per_page
|
||
10
|
||
end
|
||
|
||
# returns an hash of all puppet environments and their relative paths
|
||
def self.puppetEnvs
|
||
env = Hash.new
|
app/models/model.rb | ||
---|---|---|
def to_label
|
||
name
|
||
end
|
||
|
||
alias_method :to_s, :to_label
|
||
end
|
app/views/environments/_form.html.erb | ||
---|---|---|
<% form_for @environment do |f| %>
|
||
<%= f.error_messages %>
|
||
<table>
|
||
<tr>
|
||
<td> Name<br> <%= f.text_field :name %> </td>
|
||
</tr>
|
||
</table>
|
||
<%= f.submit "Submit" %></p>
|
||
<% end %>
|
app/views/environments/edit.html.erb | ||
---|---|---|
<% title "Edit Environment" %>
|
||
|
||
<%= render :partial => 'form' %>
|
||
|
||
<p>
|
||
<%= link_to "View All", environments_path %>
|
||
</p>
|
app/views/environments/index.html.erb | ||
---|---|---|
<% title "Environments" %>
|
||
|
||
<table class="list">
|
||
<tr>
|
||
<th>Name</th><th></th>
|
||
</tr>
|
||
|
||
<% for environment in @environments %>
|
||
<tr class="<%= cycle("even", "odd") -%>">
|
||
<td>
|
||
<%= link_to h(environment.name), edit_environment_path(environment) %>
|
||
</td>
|
||
<td style="float:right;">
|
||
<%= link_to "Hosts", hosts_path + "?search[environment_id_equals]=#{environment.id}"%>
|
||
<%= link_to "classes", puppetclasses_path + "?search[environments_id_equals]=#{environment.id}"%>
|
||
<%= link_to "Destroy", environment, :confirm => "Delete environment '#{environment.name}'?", :method => :delete %>
|
||
</td>
|
||
</tr>
|
||
<% end %>
|
||
</table>
|
||
|
||
<%= page_entries_info @environments %>
|
||
<%= will_paginate @environmentsS %>
|
||
|
||
<p><%= link_to "New Environment", new_environment_path %>
|
||
<%= link_to "Import all classes and environments", import_environments_environments_path %>
|
||
</p>
|
app/views/environments/new.html.erb | ||
---|---|---|
<% title "New Environment" %>
|
||
|
||
<%= render :partial => 'form' %>
|
||
|
||
<p><%= link_to "Back to List", environments_path %></p>
|
app/views/puppetclasses/index.html.erb | ||
---|---|---|
<%= page_entries_info @puppetclasses %>
|
||
<%= will_paginate @puppetclasses %>
|
||
<p><%= link_to "New Puppetclass", new_puppetclass_path %> |
|
||
<%= link_to "Import new puppet classes and environments", import_classes_path %>
|
||
<%= link_to "Import new puppet classes and environments", import_environments_puppetclasses_path %>
|
||
</p>
|
config/routes.rb | ||
---|---|---|
map.resources :medias
|
||
map.resources :models
|
||
map.resources :architectures
|
||
map.resources :puppetclasses, :member => { :assign => :post }
|
||
map.import_classes '/puppetclass/import', :controller => 'puppetclasses', :action => 'import'
|
||
map.resources :puppetclasses, :member => { :assign => :post }, :collection => {:import_environments => :get}
|
||
map.resources :hostgroups
|
||
map.resources :common_parameters
|
||
map.resources :environments, :active_scaffold => true
|
||
map.resources :environments, :collection => {:import_environments => :get}
|
||
map.resources :subnets, :active_scaffold => true
|
||
map.resources :fact_values, :active_scaffold => true
|
||
map.resources :ptables
|
test/fixtures/environments.yml | ||
---|---|---|
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
|
||
|
||
one:
|
||
production:
|
||
name: production
|
||
#
|
||
# two:
|
||
# column: value
|
||
|
||
global_puppetmaster:
|
||
name: global_puppetmaster
|
test/functional/environments_controller_test.rb | ||
---|---|---|
require 'test_helper'
|
||
|
||
class EnvironmentsControllerTest < ActionController::TestCase
|
||
test "ActiveScaffold should look for Environment model" do
|
||
assert_not_nil EnvironmentsController.active_scaffold_config
|
||
assert EnvironmentsController.active_scaffold_config.model == Environment
|
||
end
|
||
|
||
test "should get index" do
|
||
get :index, {}, set_session_user
|
||
assert_response :success
|
||
assert_not_nil assigns(:records)
|
||
assert_not_nil assigns(:environments)
|
||
end
|
||
|
||
test "should get new" do
|
||
... | ... | |
|
||
test "should create new environment" do
|
||
assert_difference 'Environment.count' do
|
||
post :create, { :commit => "Create", :record => {:name => "some_environment"} }, set_session_user
|
||
post :create, { :commit => "Create", :environment => {:name => "some_environment"} }, set_session_user
|
||
end
|
||
|
||
assert_redirected_to environments_path
|
||
... | ... | |
environment = Environment.new :name => "some_environment"
|
||
assert environment.save!
|
||
|
||
put :update, { :commit => "Update", :id => environment.id, :record => {:name => "other_environment"} }, set_session_user
|
||
put :update, { :commit => "Update", :id => environment.id, :environment => {:name => "other_environment"} }, set_session_user
|
||
environment = Environment.find_by_id(environment.id)
|
||
assert environment.name == "other_environment"
|
||
|
test/unit/host_test.rb | ||
---|---|---|
:architecture => Architecture.first, :environment => Environment.first, :disk => "aaa"
|
||
|
||
# dummy external node info
|
||
nodeinfo = {"environment" => "production", "parameters"=>{"puppetmaster"=>"puppet", "MYVAR"=>"value"}, "classes"=>["base","apache"]}
|
||
nodeinfo = {"environment" => "global_puppetmaster", "parameters"=>{"puppetmaster"=>"puppet", "MYVAR"=>"value"}, "classes"=>["base","apache"]}
|
||
|
||
host.importNode nodeinfo
|
||
|
Also available in: Unified diff
Fixes #204 - Remove AS from environments page
Merged import facility in Environment and Puppetclass controllers