Also, supporting nav to get you there.
Signed-off-by: Jason Guiditta <jason.guiditta(a)gmail.com>
---
src/app/controllers/instance_controller.rb | 40 +++++++++++++++++++++
src/app/controllers/portal_pool_controller.rb | 4 ++-
src/app/controllers/provider_controller.rb | 9 ++++-
src/app/helpers/instance_helper.rb | 2 +
src/app/models/instance.rb | 2 +-
src/app/views/instance/create.html.erb | 2 +
src/app/views/instance/delete.html.erb | 2 +
src/app/views/instance/index.html.erb | 2 +
src/app/views/instance/new.html.erb | 29 +++++++++++++++
src/app/views/instance/show.html.erb | 8 ++++
src/app/views/portal_pool/show.html.erb | 2 +-
src/app/views/provider/show.html.erb | 6 +++-
src/db/migrate/20090804142049_create_instances.rb | 2 +-
src/test/functional/instance_controller_test.rb | 8 ++++
14 files changed, 111 insertions(+), 7 deletions(-)
create mode 100644 src/app/controllers/instance_controller.rb
create mode 100644 src/app/helpers/instance_helper.rb
create mode 100644 src/app/views/instance/create.html.erb
create mode 100644 src/app/views/instance/delete.html.erb
create mode 100644 src/app/views/instance/index.html.erb
create mode 100644 src/app/views/instance/new.html.erb
create mode 100644 src/app/views/instance/show.html.erb
create mode 100644 src/test/functional/instance_controller_test.rb
diff --git a/src/app/controllers/instance_controller.rb b/src/app/controllers/instance_controller.rb
new file mode 100644
index 0000000..b9e9db4
--- /dev/null
+++ b/src/app/controllers/instance_controller.rb
@@ -0,0 +1,40 @@
+class InstanceController < ApplicationController
+ def index
+ end
+
+ def show
+ @instances = Instance.find(:all, :conditions => {:portal_pool_id => params[:id]})
+ end
+
+ def new
+ @flavors = Flavor.find(:all, :conditions => {:provider_id => params[:provider]})
+ @images = Image.find(:all, :conditions => {:provider_id => params[:provider]})
+ @realms = Realm.find(:all, :conditions => {:provider_id => params[:provider]})
+ @instance = Instance.new({:portal_pool_id => params[:id]})
+ @provider_id = params[:provider]
+ end
+
+ def create
+ @instance = Instance.new(params[:instance])
+ #FIXME: This should probably be in a transaction
+ if @instance.save
+
+ @task = InstanceTask.new({:user => @instance.portal_pool.cloud_account.username,
+ :task_target => @instance,
+ :action => InstanceTask::ACTION_CREATE})
+ if @task.save!
+ flash[:notice] = "Instance added."
+ redirect_to :action => 'show', :id => @instance.portal_pool_id, :provider => params[:provider_id]
+ else
+ render :action => 'new', :id => [:instance][:portal_pool_id]
+ end
+ else
+ puts "Instance did not save: " + @instance.inspect
+ render :action => 'new', :id => @instance.portal_pool_id, :provider => params[:provider_id]
+ end
+ end
+
+ def delete
+ end
+
+end
diff --git a/src/app/controllers/portal_pool_controller.rb b/src/app/controllers/portal_pool_controller.rb
index 16d043c..49c2d90 100644
--- a/src/app/controllers/portal_pool_controller.rb
+++ b/src/app/controllers/portal_pool_controller.rb
@@ -5,7 +5,9 @@ class PortalPoolController < ApplicationController
def show
@instances = Instance.find(:all, :conditions => {:portal_pool_id => params[:id]})
- @pool = params[:id]
+ #FIXME: clean this up, many error cases here
+ @pool = PortalPool.find(params[:id])
+ @provider = @pool.cloud_account.provider
end
def new
diff --git a/src/app/controllers/provider_controller.rb b/src/app/controllers/provider_controller.rb
index 90d5a2d..9b5e841 100644
--- a/src/app/controllers/provider_controller.rb
+++ b/src/app/controllers/provider_controller.rb
@@ -11,11 +11,16 @@ class ProviderController < ApplicationController
@provider = Provider.new(params[:provider])
if request.post? && @provider.save && @provider.populate_flavors
flash[:notice] = "Provider added."
- redirect_to :action => "index", :id => @provider
+ redirect_to :action => "show", :id => @provider
end
end
- def delete
+ def destroy
+ if request.post?
+ p =Provider.find(params[:provider][:id])
+ p.destroy
+ end
+ redirect_to :action => "index"
end
end
diff --git a/src/app/helpers/instance_helper.rb b/src/app/helpers/instance_helper.rb
new file mode 100644
index 0000000..212ddac
--- /dev/null
+++ b/src/app/helpers/instance_helper.rb
@@ -0,0 +1,2 @@
+module InstanceHelper
+end
diff --git a/src/app/models/instance.rb b/src/app/models/instance.rb
index 0440319..4435b09 100644
--- a/src/app/models/instance.rb
+++ b/src/app/models/instance.rb
@@ -6,7 +6,7 @@ class Instance < ActiveRecord::Base
validates_presence_of :portal_pool_id
- validates_presence_of :external_key
+ #validates_presence_of :external_key
# TODO: can we do uniqueness validation on indirect association
# -- portal_pool.account.provider
#validates_uniqueness_of :external_key, :scope => :provider_id
diff --git a/src/app/views/instance/create.html.erb b/src/app/views/instance/create.html.erb
new file mode 100644
index 0000000..4f6287a
--- /dev/null
+++ b/src/app/views/instance/create.html.erb
@@ -0,0 +1,2 @@
+<h1>Instance#create</h1>
+<p>Find me in app/views/instance/create.html.erb</p>
diff --git a/src/app/views/instance/delete.html.erb b/src/app/views/instance/delete.html.erb
new file mode 100644
index 0000000..2afa7f3
--- /dev/null
+++ b/src/app/views/instance/delete.html.erb
@@ -0,0 +1,2 @@
+<h1>Instance#delete</h1>
+<p>Find me in app/views/instance/delete.html.erb</p>
diff --git a/src/app/views/instance/index.html.erb b/src/app/views/instance/index.html.erb
new file mode 100644
index 0000000..a632f6c
--- /dev/null
+++ b/src/app/views/instance/index.html.erb
@@ -0,0 +1,2 @@
+<h1>Instance#index</h1>
+<p>Find me in app/views/instance/index.html.erb</p>
diff --git a/src/app/views/instance/new.html.erb b/src/app/views/instance/new.html.erb
new file mode 100644
index 0000000..8772ec0
--- /dev/null
+++ b/src/app/views/instance/new.html.erb
@@ -0,0 +1,29 @@
+<div class="dcloud_form">
+ <%= error_messages_for 'instance' %>
+
+ <h2>Add a New Instance</h2><br />
+ <% form_tag :action => 'create' do-%>
+ <ul>
+ <li><label>Name<span>Name for this new Instance</span></label><%= text_field :instance, :name, :class => "txtfield" %></li>
+ <% if @flavors.size > 0 %>
+ <li><label>Flavor<span>Pick your flavor</span></label>
+ <%= select("instance", "flavor_id", @flavors.collect {|p| [ p.name, p.id ] }, { :include_blank => true }) %>
+ </li>
+ <% end %>
+ <% if @images.size > 0 %>
+ <li><label>Image<span>Choose a bundled image to use</span></label>
+ <%= select("instance", "image_id", @images.collect {|i| [ i.name, i.id ] }, { :include_blank => true }) %>
+ </li>
+ <% end %>
+ <% if @realms.size > 0 %>
+ <li><label>Realm<span>Choose a realm</span></label>
+ <%= select("instance", "realm_id", @realms.collect {|r| [ r.name, r.id ] }, { :include_blank => true }) %>
+ </li>
+ <% end %>
+ </ul>
+ <input id="instance_provider_id" type="hidden" value="<%=@provider_id%>" name="provider_id"/>
+ <%#= hidden_field :provider, :provider_id %>
+ <%= hidden_field :instance, :portal_pool_id %>
+ <%= submit_tag "Save", :class => "submit" %>
+ <% end %>
+</div>
\ No newline at end of file
diff --git a/src/app/views/instance/show.html.erb b/src/app/views/instance/show.html.erb
new file mode 100644
index 0000000..f660595
--- /dev/null
+++ b/src/app/views/instance/show.html.erb
@@ -0,0 +1,8 @@
+<% if @instances.size == 0 %>
+<h1>There are no pools to display</h1>
+<% else %>
+ <%(a)instances.each {|instance| %>
+ <%= instance.name %><br/>
+ <% } %>
+<% end %>
+<%= link_to "Add a new instance", :controller => "instance", :action => "new", :id => @pool, :provider => @provider%>
diff --git a/src/app/views/portal_pool/show.html.erb b/src/app/views/portal_pool/show.html.erb
index cd19999..f660595 100644
--- a/src/app/views/portal_pool/show.html.erb
+++ b/src/app/views/portal_pool/show.html.erb
@@ -5,4 +5,4 @@
<%= instance.name %><br/>
<% } %>
<% end %>
-<%= link_to "Add a pool", :controller => "instance", :action => "new", :pool => @pool%>
+<%= link_to "Add a new instance", :controller => "instance", :action => "new", :id => @pool, :provider => @provider%>
diff --git a/src/app/views/provider/show.html.erb b/src/app/views/provider/show.html.erb
index 8bc0334..07e0d4d 100644
--- a/src/app/views/provider/show.html.erb
+++ b/src/app/views/provider/show.html.erb
@@ -5,4 +5,8 @@
<%= pool.name %><br/>
<% } %>
<% end %>
-<%= link_to "Add a pool", :controller => "portal_pool", :action => "new", :provider => @provider%>
\ No newline at end of file
+<%= link_to "Add a pool", :controller => "portal_pool", :action => "new", :provider => @provider%>
+<% form_tag :action => 'destroy' do %>
+ <%=hidden_field :provider, :id %>
+ <%= submit_tag "Delete Provider", :class => "submit_link" %>
+<% end %>
\ No newline at end of file
diff --git a/src/db/migrate/20090804142049_create_instances.rb b/src/db/migrate/20090804142049_create_instances.rb
index 82f574e..e0ed3e2 100644
--- a/src/db/migrate/20090804142049_create_instances.rb
+++ b/src/db/migrate/20090804142049_create_instances.rb
@@ -1,7 +1,7 @@
class CreateInstances < ActiveRecord::Migration
def self.up
create_table :instances do |t|
- t.string :external_key, :null => false
+ t.string :external_key
t.string :name, :null => false, :limit => 1024
t.integer :flavor_id, :null => false
t.integer :image_id, :null => false
diff --git a/src/test/functional/instance_controller_test.rb b/src/test/functional/instance_controller_test.rb
new file mode 100644
index 0000000..f44cfcf
--- /dev/null
+++ b/src/test/functional/instance_controller_test.rb
@@ -0,0 +1,8 @@
+require 'test_helper'
+
+class InstanceControllerTest < ActionController::TestCase
+ # Replace this with your real tests.
+ test "the truth" do
+ assert true
+ end
+end
--
1.6.2.5