From: Jan Provaznik <[email protected]>
---
.../controllers/resources/instances_controller.rb | 71 +++++++++++++++++++-
src/app/views/resources/instances/_list.haml | 4 +-
src/app/views/resources/instances/new.haml | 25 +++++++
.../views/resources/instances/select_template.haml | 18 +++++
src/config/routes.rb | 2 +-
5 files changed, 116 insertions(+), 4 deletions(-)
create mode 100644 src/app/views/resources/instances/new.haml
create mode 100644 src/app/views/resources/instances/select_template.haml
diff --git a/src/app/controllers/resources/instances_controller.rb
b/src/app/controllers/resources/instances_controller.rb
index bb08c69..bf95731 100644
--- a/src/app/controllers/resources/instances_controller.rb
+++ b/src/app/controllers/resources/instances_controller.rb
@@ -2,6 +2,76 @@ class Resources::InstancesController < ApplicationController
before_filter :require_user
def new
+ @instance = Instance.new(params[:instance])
+ #require_privilege(Privilege::INSTANCE_MODIFY, @instance.pool) if
@instance.pool
+
+ unless @instance.template
+ redirect_to select_template_resources_instances_path
+ return
+ end
+
+ @pools = Pool.list_for_user(@current_user, Privilege::INSTANCE_MODIFY)
+ @realms = Realm.find(:all, :conditions => { :provider_id => nil })
+ @hardware_profiles = HardwareProfile.all(
+ :include => :architecture,
+ :conditions => {
+ :provider_id => nil,
+ 'hardware_profile_properties.value' => @instance.template.architecture
+ }
+ )
+ end
+
+ def select_template
+ # FIXME: we need to list only templates for particular user,
+ # => TODO: add TEMPLATE_* permissions
+ @templates = Template.paginate(
+ :page => params[:page] || 1,
+ :include => {:images => :replicated_images},
+ :conditions => "replicated_images.uploaded = 't'"
+ )
+ end
+
+ def create
+ if params[:cancel]
+ redirect_to select_template_resources_instances_path
+ return
+ end
+
+ @instance = Instance.new(params[:instance])
+ @instance.state = Instance::STATE_NEW
+ @instance.owner = current_user
+
+ require_privilege(Privilege::INSTANCE_MODIFY,
+ Pool.find(@instance.pool_id))
+ #FIXME: This should probably be in a transaction
+ if @instance.save
+ @task = InstanceTask.new({:user => current_user,
+ :task_target => @instance,
+ :action => InstanceTask::ACTION_CREATE})
+ if @task.save
+ condormatic_instance_create(@task)
+ if Quota.can_start_instance?(@instance, nil)
+ flash[:notice] = "Instance added."
+ else
+ flash[:warning] = "Quota Exceeded: Instance will not start until
you have free quota"
+ end
+ else
+ @pool = @instance.pool
+ render :new
+ end
+ redirect_to resources_instances_path
+ else
+ @pools = Pool.list_for_user(@current_user, Privilege::INSTANCE_MODIFY)
+ @realms = Realm.find(:all, :conditions => { :provider_id => nil })
+ @hardware_profiles = HardwareProfile.all(
+ :include => :architecture,
+ :conditions => {
+ :provider_id => nil,
+ 'hardware_profile_properties.value' =>
@instance.template.architecture
+ }
+ )
+ render :new
+ end
end
def edit
@@ -21,7 +91,6 @@ class Resources::InstancesController < ApplicationController
{:name => 'PUBLIC ADDRESS', :sort_attr => 'public_addresses'},
{:name => 'PROVIDER', :sortable => false},
{:name => 'CREATED BY', :sort_attr => 'users.last_name'},
- {:name => '', :sortable => false},
]
pools = Pool.list_for_user(@current_user, Privilege::INSTANCE_MODIFY)
diff --git a/src/app/views/resources/instances/_list.haml
b/src/app/views/resources/instances/_list.haml
index b49b99d..79c55ba 100644
--- a/src/app/views/resources/instances/_list.haml
+++ b/src/app/views/resources/instances/_list.haml
@@ -1,7 +1,7 @@
- form_tag do
= restful_submit_tag 'Start', 'start', start_resources_instances_path, 'GET'
= restful_submit_tag 'Stop', 'start', stop_resources_instances_path, 'GET'
- = restful_submit_tag 'Create', 'new', new_resources_instance_path, 'GET'
+ = restful_submit_tag 'Create', 'new',
select_template_resources_instances_path, 'GET'
%p
Select:
@@ -16,8 +16,8 @@
- selected = params[:select] == 'all'
%input{:checked => selected, :name => 'ids', :type => 'checkbox',
:value => inst.id, :id => "inst_ids_#{inst.id}" }
= link_to inst.name, resources_instance_path(inst)
+ %td= inst.state
%td= inst.template.name
%td= inst.public_addresses
%td= inst.cloud_account ? inst.cloud_account.provider.name : ''
%td= owner_name(inst)
- %td= link_to 'edit', edit_resources_instance_path(inst)
diff --git a/src/app/views/resources/instances/new.haml
b/src/app/views/resources/instances/new.haml
new file mode 100644
index 0000000..9d1d331
--- /dev/null
+++ b/src/app/views/resources/instances/new.haml
@@ -0,0 +1,25 @@
+%h2 Launch instance
+- form_for @instance, :url => resources_instances_path do
+ = hidden_field :instance, :template_id
+ %ul
+ %li
+ = label :instance, :name
+ = text_field :instance, :name
+ %li
+ = label :instance, :template
+ = text_field_tag :template_name, @instance.template ?
@instance.template.name : '', :disabled => true
+ %li
+ = label :instance, :pool
+ - if @instance.pool
+ = text_field_tag :pool_name, @instance.pool.name, :disabled => true
+ - else
+ = select :instance, :pool_id, @pools.map {|p| [ p.name, p.id ]}, {
:include_blank => true }
+ %li
+ = label :instance, :hardware_profile
+ = select :instance, :hardware_profile_id, @hardware_profiles.map {|p| [
p.name, p.id ]}, { :include_blank => false }
+ %li
+ = label :instance, :realm
+ = select :instance, :realm_id, @realms.map {|r| [ r.name, r.id ]}, {
:include_blank => true }
+
+ = submit_tag 'Cancel', :name => 'cancel'
+ = submit_tag 'Launch', :name => 'launch'
diff --git a/src/app/views/resources/instances/select_template.haml
b/src/app/views/resources/instances/select_template.haml
new file mode 100644
index 0000000..ab0cfc4
--- /dev/null
+++ b/src/app/views/resources/instances/select_template.haml
@@ -0,0 +1,18 @@
+%h3 Show Templates
+%hr
+%ul
+ - @templates.each do |tpl|
+ %li
+ - form_tag new_resources_instance_path do
+ = hidden_field :instance, :template_id, :value => tpl.id
+ = image_tag "platform_#{tpl.platform}.png", :size => "32x32", :alt =>
tpl.platform
+ %h3= tpl.name
+ %p= tpl.summary
+ %p
+ %label Group:
+ System
+ %label Version:
+ 2.5
+ = submit_tag 'Launch', :name => 'launch'
+= will_paginate(@templates)
+= page_entries_info(@templates)
diff --git a/src/config/routes.rb b/src/config/routes.rb
index 699ee25..cb1536a 100644
--- a/src/config/routes.rb
+++ b/src/config/routes.rb
@@ -34,7 +34,7 @@ ActionController::Routing::Routes.draw do |map|
map.namespace 'resources' do |r|
r.resources :pools, :deployments
- r.resources :instances, :collection => {:start => :get, :stop => :get}
+ r.resources :instances, :collection => {:start => :get, :stop => :get,
:select_template => :get}
end
map.namespace 'image_factory' do |r|
--
1.7.2.3
_______________________________________________
deltacloud-devel mailing list
[email protected]
https://fedorahosted.org/mailman/listinfo/deltacloud-devel