[Libcloud-list] [PATCH server] Add 'selected' to main nav.
by jason.guiditta
This works for 95% of pages we have now, but is only a
temporary solution.
Signed-off-by: Jason Guiditta <jason.guiditta(a)gmail.com>
---
src/app/views/layouts/_main_nav.html.erb | 27 +++++++++++++++++++++++++++
src/app/views/layouts/dcloud.rhtml | 18 +-----------------
2 files changed, 28 insertions(+), 17 deletions(-)
create mode 100644 src/app/views/layouts/_main_nav.html.erb
diff --git a/src/app/views/layouts/_main_nav.html.erb b/src/app/views/layouts/_main_nav.html.erb
new file mode 100644
index 0000000..894318e
--- /dev/null
+++ b/src/app/views/layouts/_main_nav.html.erb
@@ -0,0 +1,27 @@
+<ul id="providers">
+ <% curId = params[:id].to_i %>
+ <% @providers.each { |provider| %>
+ <%#Note that this is a temporary way to selected proper list item for demo, and is not expected to stay this way%>
+ <% if controller.controller_name == "provider" && provider.id == curId
+ selected_provider = "selected"
+ else
+ selected_provider = ""
+ end %>
+ <li><%= link_to provider.name,
+ {:controller => "provider", :action => "show", :id => provider},
+ :class => "providername #{selected_provider}"%>
+ <% provider.portal_pools.each { |pool| %>
+ <ul id="portal_pool-<%=provider.id%>">
+ <% if controller.controller_name == "portal_pool" && pool.id == curId
+ selected_pool = "selected"
+ else selected_pool = ""
+ end %>
+ <li><%= link_to pool.name,
+ {:controller => "portal_pool", :action => "show", :id => pool},
+ :class => "poolname #{selected_pool}" %></li>
+ </ul>
+ <% } %>
+ </li>
+ <% } %>
+</ul>
+<%=link_to "Add a provider", {:controller => "provider", :action => "new"}, :class => "actionlink" %>
\ No newline at end of file
diff --git a/src/app/views/layouts/dcloud.rhtml b/src/app/views/layouts/dcloud.rhtml
index dde8018..74ee09c 100644
--- a/src/app/views/layouts/dcloud.rhtml
+++ b/src/app/views/layouts/dcloud.rhtml
@@ -68,23 +68,7 @@
</div>
<div id="side">
- <%#= render :partial => '/layouts/tree' %>
- <ul id="providers">
- <% @providers.each { |provider| %>
- <li><%= link_to provider.name,
- {:controller => "provider", :action => "show", :id => provider},
- :class => "providername"%>
- <% provider.portal_pools.each { |pool| %>
- <ul id="portal_pool-<%=provider.id%>">
- <li><%= link_to pool.name,
- {:controller => "portal_pool", :action => "show", :id => pool},
- :class => "poolname" %></li>
- </ul>
- <% } %>
- </li>
- <% } %>
- </ul>
- <%=link_to "Add a provider", {:controller => "provider", :action => "new"}, :class => "actionlink" %>
+ <%= render :partial => '/layouts/main_nav' %>
</div>
<div id="tabs-and-content-container">
--
1.6.2.5
14 years, 10 months
[Libcloud-list] [PATCH server] Tweaks to tables.
by jason.guiditta
Make provider page have a table, and try to make new instance
form fail less horribly. Now at least it brings you back to a
(blank) for for the correct pool so you can start over, but not
showing any errors. Surely I am overlooking something silly, but
at least there wont be a stack trace if you mess up on that form now.
Signed-off-by: Jason Guiditta <jason.guiditta(a)gmail.com>
---
src/app/controllers/instance_controller.rb | 31 +++++++++++++++++++---------
src/app/views/layouts/dcloud.rhtml | 8 +++++-
src/app/views/portal_pool/show.html.erb | 8 ++++++-
src/app/views/provider/show.html.erb | 17 +++++++++++++-
4 files changed, 49 insertions(+), 15 deletions(-)
diff --git a/src/app/controllers/instance_controller.rb b/src/app/controllers/instance_controller.rb
index 42b1cb8..c6cbc7f 100644
--- a/src/app/controllers/instance_controller.rb
+++ b/src/app/controllers/instance_controller.rb
@@ -2,6 +2,10 @@ class InstanceController < ApplicationController
def index
end
+ # Right now this is essentially a duplicate of PortalPoolController#show,
+ # but really it should be a single instance should we decide to have a page
+ # for that. Redirect on create was all that brought you here anyway, so
+ # should be unused for the moment.
def show
@instances = Instance.find(:all, :conditions => {:portal_pool_id => params[:id]})
@pool = PortalPool.find(params[:id])
@@ -9,11 +13,7 @@ class InstanceController < ApplicationController
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]
+ _new(params[:provider],params[:id])
end
def create
@@ -25,15 +25,16 @@ class InstanceController < ApplicationController
@task = InstanceTask.new({:user => @instance.portal_pool.cloud_account.username,
:task_target => @instance,
:action => InstanceTask::ACTION_CREATE})
- if @task.save!
+ if @task.save
flash[:notice] = "Instance added."
- redirect_to :action => 'show', :id => @instance.portal_pool_id, :provider => params[:provider_id]
+ redirect_to :controller => "portal_pool", :action => 'show', :id => @instance.portal_pool_id
else
- render :action => 'new', :id => [:instance][:portal_pool_id]
+ _new(params[:provider_id],params[:instance][:portal_pool_id])
+ render :action => 'new'
end
else
- puts "Instance did not save: " + @instance.inspect
- render :action => 'new', :id => @instance.portal_pool_id, :provider => params[:provider_id]
+ _new(params[:provider_id],params[:instance][:portal_pool_id])
+ render :action => 'new'
end
end
@@ -57,4 +58,14 @@ class InstanceController < ApplicationController
def delete
end
+ private
+
+ def _new(provider, pool)
+ @flavors = Flavor.find(:all, :conditions => {:provider_id => provider})
+ @images = Image.find(:all, :conditions => {:provider_id => provider})
+ @realms = Realm.find(:all, :conditions => {:provider_id => provider})
+ @instance = Instance.new({:portal_pool_id => pool})
+ @provider_id = provider
+ end
+
end
diff --git a/src/app/views/layouts/dcloud.rhtml b/src/app/views/layouts/dcloud.rhtml
index 4c2f103..dde8018 100644
--- a/src/app/views/layouts/dcloud.rhtml
+++ b/src/app/views/layouts/dcloud.rhtml
@@ -71,10 +71,14 @@
<%#= render :partial => '/layouts/tree' %>
<ul id="providers">
<% @providers.each { |provider| %>
- <li><%= link_to provider.name, {:controller => "provider", :action => "show", :id => provider}, :class => "providername"%>
+ <li><%= link_to provider.name,
+ {:controller => "provider", :action => "show", :id => provider},
+ :class => "providername"%>
<% provider.portal_pools.each { |pool| %>
<ul id="portal_pool-<%=provider.id%>">
- <li><%= link_to pool.name, {:controller => "portal_pool", :action => "show", :id => pool}, :class => "poolname" %></li>
+ <li><%= link_to pool.name,
+ {:controller => "portal_pool", :action => "show", :id => pool},
+ :class => "poolname" %></li>
</ul>
<% } %>
</li>
diff --git a/src/app/views/portal_pool/show.html.erb b/src/app/views/portal_pool/show.html.erb
index 2a550d8..88d8e3f 100644
--- a/src/app/views/portal_pool/show.html.erb
+++ b/src/app/views/portal_pool/show.html.erb
@@ -6,6 +6,9 @@
<tr>
<th scope="col">Actions</th>
<th scope="col">Name</th>
+ <th scope="col">State</th>
+ <th scope="col">Flavor</th>
+ <th scope="col">Image</th>
</tr>
</thead>
<tbody>
@@ -20,7 +23,10 @@
<br/>
<% } %>
</td>
- <td><div><%= instance.name %></div></td>
+ <td><%= instance.name %></td>
+ <td><%= instance.state %></td>
+ <td><%= instance.flavor.name %></td>
+ <td><%= instance.image.name %></td>
</tr>
<% } %>
</tbody>
diff --git a/src/app/views/provider/show.html.erb b/src/app/views/provider/show.html.erb
index 07e0d4d..bfeacdb 100644
--- a/src/app/views/provider/show.html.erb
+++ b/src/app/views/provider/show.html.erb
@@ -1,9 +1,22 @@
<% if @provider.portal_pools.size == 0 %>
<h1>There are no pools to display</h1>
<% else %>
+ <table>
+ <thead>
+ <tr>
+ <th scope="col">Name</th>
+ <th scope="col">Instances</th>
+ </tr>
+ </thead>
+ <tbody>
<%(a)provider.portal_pools.each {|pool| %>
- <%= pool.name %><br/>
- <% } %>
+ <tr>
+ <td><%= pool.name %></td>
+ <td><%= pool.instances.count %></td>
+ </tr>
+ <% } %>
+ </tbody>
+ </table>
<% end %>
<%= link_to "Add a pool", :controller => "portal_pool", :action => "new", :provider => @provider%>
<% form_tag :action => 'destroy' do %>
--
1.6.2.5
14 years, 10 months
[Libcloud-list] [PATCH server] action links for instances now work -- submitting tasks for taskomatic.
by Scott Seago
I've tested create, start, reboot, and stop with the mock driver. Destroy currently fails.
rhevm and ec2 testing to come later.
Signed-off-by: Scott Seago <sseago(a)redhat.com>
---
src/app/controllers/instance_controller.rb | 17 ++++++++++++++++
src/app/models/instance.rb | 29 ++++++++++++++++++++++++++++
src/app/models/instance_task.rb | 23 ++++++++++++---------
src/app/models/portal_pool.rb | 4 ++-
src/app/views/instance/show.html.erb | 12 +++++++++-
src/app/views/portal_pool/show.html.erb | 10 ++++++++-
src/task-omatic/taskomatic_instance.rb | 10 +++++---
7 files changed, 87 insertions(+), 18 deletions(-)
diff --git a/src/app/controllers/instance_controller.rb b/src/app/controllers/instance_controller.rb
index 32d5e3f..42b1cb8 100644
--- a/src/app/controllers/instance_controller.rb
+++ b/src/app/controllers/instance_controller.rb
@@ -37,6 +37,23 @@ class InstanceController < ApplicationController
end
end
+ def instance_action
+ action = params[:instance_action]
+ action_args = params[:action_data]
+ @instance = Instance.find(params[:id])
+ unless @instance.valid_action?(action)
+ raise ActionError.new("#{action} is an invalid action.")
+ end
+ #permissons check here
+ @task = @instance.queue_action(get_login_user, action, action_args)
+ unless @task
+ raise ActionError.new("#{action} cannot be performed on this instance.")
+ end
+ alert = "#{(a)instance.name}: #{action} was successfully queued."
+ flash[:notice] = alert
+ redirect_to :action => 'show', :id => @instance.portal_pool_id
+ end
+
def delete
end
diff --git a/src/app/models/instance.rb b/src/app/models/instance.rb
index 6234b91..4ce0459 100644
--- a/src/app/models/instance.rb
+++ b/src/app/models/instance.rb
@@ -29,4 +29,33 @@ class Instance < ActiveRecord::Base
:in => [STATE_NEW, STATE_PENDING, STATE_RUNNING,
STATE_SHUTTING_DOWN, STATE_STOPPED]
+ def get_action_list(user=nil)
+ # return empty list rather than nil
+ # FIXME: not handling pending state now -- only current state
+ return_val = InstanceTask.valid_actions_for_instance_state(state,
+ self,
+ user) || []
+ # filter actions based on quota
+ # FIXME: not doing quota filtering now
+ return_val
+ end
+
+ # Provide method to check if requested action exists, so caller can decide
+ # if they want to throw an error of some sort before continuing
+ # (ie in service api)
+ def valid_action?(action)
+ return get_action_list.include?(action) ? true : false
+ end
+
+ def queue_action(user, action, data = nil)
+ return false unless get_action_list.include?(action)
+ task = InstanceTask.new({ :user => user,
+ :task_target => self,
+ :action => action,
+ :args => data})
+ task.save!
+ return task
+ end
+
+
end
diff --git a/src/app/models/instance_task.rb b/src/app/models/instance_task.rb
index 9f32217..cd55d91 100644
--- a/src/app/models/instance_task.rb
+++ b/src/app/models/instance_task.rb
@@ -42,17 +42,20 @@ class InstanceTask < Task
# automatic transitions from transient states.
def self.valid_actions_for_instance_state(state, instance, user=nil)
actions = []
- transitions = c.instance_state(state).transitions
- transitions.each do |transition|
- # FIXME if we allow actions based on the expected state after
- # automatic transitions, we need to call this method again with
- # the state from transition.to passed in.
- unless transition.action.nil?
- add_action = true
- if (instance and user)
- # FIXME: check permissions here if we filter actions by permission
+ c_state = instance.portal_pool.cloud_account.connect.instance_state(state)
+ if c_state
+ transitions = c_state.transitions
+ transitions.each do |transition|
+ # FIXME if we allow actions based on the expected state after
+ # automatic transitions, we need to call this method again with
+ # the state from transition.to passed in.
+ unless transition.action.nil?
+ add_action = true
+ if (instance and user)
+ # FIXME: check permissions here if we filter actions by permission
+ end
+ actions << transition.action if add_action
end
- actions << transition.action if add_action
end
end
actions
diff --git a/src/app/models/portal_pool.rb b/src/app/models/portal_pool.rb
index 675a5ce..206d88e 100644
--- a/src/app/models/portal_pool.rb
+++ b/src/app/models/portal_pool.rb
@@ -34,7 +34,9 @@ class PortalPool < ActiveRecord::Base
unless Image.find_by_external_key_and_provider_id(image.id,
cloud_account.provider.id)
ar_image = Image.new(:external_key => image.id,
- :name => image.description ? image.description : image.id,
+ :name => image.name ? image.name :
+ (image.description ? image.description :
+ image.id),
:architecture => image.architecture,
:provider_id => cloud_account.provider.id)
ar_image.save!
diff --git a/src/app/views/instance/show.html.erb b/src/app/views/instance/show.html.erb
index 1327ef5..2a550d8 100644
--- a/src/app/views/instance/show.html.erb
+++ b/src/app/views/instance/show.html.erb
@@ -11,11 +11,19 @@
<tbody>
<%(a)instances.each {|instance| %>
<tr>
- <td></td>
+ <td>
+ <%instance.get_action_list.each {|action|%>
+ <%= link_to action, :controller => "instance",
+ :action => "instance_action",
+ :id => instance,
+ :instance_action => action %>
+ <br/>
+ <% } %>
+ </td>
<td><div><%= instance.name %></div></td>
</tr>
<% } %>
</tbody>
</table>
<% end %>
-<%= link_to "Add a new instance", :controller => "instance", :action => "new", :id => @pool, :provider => @provider%>
\ No newline at end of file
+<%= 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 8dd06f5..2a550d8 100644
--- a/src/app/views/portal_pool/show.html.erb
+++ b/src/app/views/portal_pool/show.html.erb
@@ -11,7 +11,15 @@
<tbody>
<%(a)instances.each {|instance| %>
<tr>
- <td></td>
+ <td>
+ <%instance.get_action_list.each {|action|%>
+ <%= link_to action, :controller => "instance",
+ :action => "instance_action",
+ :id => instance,
+ :instance_action => action %>
+ <br/>
+ <% } %>
+ </td>
<td><div><%= instance.name %></div></td>
</tr>
<% } %>
diff --git a/src/task-omatic/taskomatic_instance.rb b/src/task-omatic/taskomatic_instance.rb
index 05186e3..0dfe903 100644
--- a/src/task-omatic/taskomatic_instance.rb
+++ b/src/task-omatic/taskomatic_instance.rb
@@ -21,13 +21,15 @@ require 'taskomatic_task'
def dcloud_to_instance_state(state_str)
case state_str
when 'PENDING'
- return InstanceTask::STATE_PENDING
+ return Instance::STATE_PENDING
when 'RUNNING'
- return InstanceTask::STATE_RUNNING
+ return Instance::STATE_RUNNING
when 'STOPPED'
- return InstanceTask::STATE_STOPPED
+ return Instance::STATE_STOPPED
+ when 'SHUTTING_DOWN'
+ return Instance::STATE_SHUTTING_DOWN
else
- return InstanceTask::STATE_PENDING
+ return Instance::STATE_PENDING
end
end
--
1.6.2.5
14 years, 10 months
[Libcloud-list] [PATCH server] Attempt to implement reboot and destroy tasks.
by Ian Main
The amount of cut/paste coding going on is high here but I'll fix
it later.
---
src/task-omatic/taskomatic_instance.rb | 38 +++++++++++++++++++++++++++++++-
1 files changed, 37 insertions(+), 1 deletions(-)
diff --git a/src/task-omatic/taskomatic_instance.rb b/src/task-omatic/taskomatic_instance.rb
index 171112c..05186e3 100644
--- a/src/task-omatic/taskomatic_instance.rb
+++ b/src/task-omatic/taskomatic_instance.rb
@@ -110,7 +110,7 @@ class TaskomaticInstanceStop < TaskomaticTask
end
def run
- @logger.info("TaskomaticInstanceStart running.")
+ @logger.info("TaskomaticInstanceStop running.")
client = @task.instance.portal_pool.cloud_account.connect
dcloud_instance = client.instance((a)task.instance.external_key)
@@ -140,6 +140,24 @@ class TaskomaticInstanceReboot < TaskomaticTask
end
def run
+ @logger.info("TaskomaticInstanceReboot running.")
+
+ client = @task.instance.portal_pool.cloud_account.connect
+ dcloud_instance = client.instance((a)task.instance.external_key)
+ dcloud_instance.reboot!
+
+ @task.instance.state = dcloud_to_instance_state(dcloud_instance.state)
+ @task.instance.save!
+
+ while dcloud_instance.state == 'PENDING' or dcloud_instance.state == "SHUTTING_DOWN"
+ sleep(5)
+ dcloud_instance = client.instance((a)task.instance.external_key)
+ end
+
+ @task.instance.state = dcloud_to_instance_state(dcloud_instance.state)
+ @task.instance.save!
+
+ @logger.info("Reboot completed.")
end
end
@@ -152,5 +170,23 @@ class TaskomaticInstanceDestroy < TaskomaticTask
end
def run
+ @logger.info("TaskomaticInstanceDestroy running.")
+
+ client = @task.instance.portal_pool.cloud_account.connect
+ dcloud_instance = client.instance((a)task.instance.external_key)
+ dcloud_instance.destroy!
+
+ @task.instance.state = dcloud_to_instance_state(dcloud_instance.state)
+ @task.instance.save!
+
+ while dcloud_instance.state == 'PENDING' or dcloud_instance.state == "SHUTTING_DOWN"
+ sleep(5)
+ dcloud_instance = client.instance((a)task.instance.external_key)
+ end
+
+ @task.instance.state = dcloud_to_instance_state(dcloud_instance.state)
+ @task.instance.save!
+
+ @logger.info("Destroy completed.")
end
end
--
1.6.2.5
14 years, 10 months
[Libcloud-list] [PATCH server] Attempt to impelemnt stop.
by Ian Main
---
src/task-omatic/taskomatic_instance.rb | 18 ++++++++++++++++++
1 files changed, 18 insertions(+), 0 deletions(-)
diff --git a/src/task-omatic/taskomatic_instance.rb b/src/task-omatic/taskomatic_instance.rb
index bb9fdb8..171112c 100644
--- a/src/task-omatic/taskomatic_instance.rb
+++ b/src/task-omatic/taskomatic_instance.rb
@@ -110,6 +110,24 @@ class TaskomaticInstanceStop < TaskomaticTask
end
def run
+ @logger.info("TaskomaticInstanceStart running.")
+
+ client = @task.instance.portal_pool.cloud_account.connect
+ dcloud_instance = client.instance((a)task.instance.external_key)
+ dcloud_instance.stop!
+
+ @task.instance.state = dcloud_to_instance_state(dcloud_instance.state)
+ @task.instance.save!
+
+ while dcloud_instance.state == 'PENDING' or dcloud_instance.state == "SHUTTING_DOWN"
+ sleep(5)
+ dcloud_instance = client.instance((a)task.instance.external_key)
+ end
+
+ @task.instance.state = dcloud_to_instance_state(dcloud_instance.state)
+ @task.instance.save!
+
+ @logger.info("Instance started.")
end
end
--
1.6.2.5
14 years, 10 months
[Libcloud-list] [PATCH server] Attempt to write the start task. Also swap reget/sleep in polling.
by Ian Main
---
src/task-omatic/taskomatic_instance.rb | 24 ++++++++++++++++++++----
1 files changed, 20 insertions(+), 4 deletions(-)
diff --git a/src/task-omatic/taskomatic_instance.rb b/src/task-omatic/taskomatic_instance.rb
index dcb9e6b..bb9fdb8 100644
--- a/src/task-omatic/taskomatic_instance.rb
+++ b/src/task-omatic/taskomatic_instance.rb
@@ -40,6 +40,8 @@ class TaskomaticInstanceCreate < TaskomaticTask
end
def run
+ @logger.info("TaskomaticInstanceCreate running.")
+
client = @task.instance.portal_pool.cloud_account.connect
puts "client is #{client.type}"
@logger.info "Creating instance with name #{(a)task.instance.image.external_key}, flavor #{(a)task.instance.flavor.name}, realm #{(a)task.instance.realm.name}"
@@ -52,8 +54,8 @@ class TaskomaticInstanceCreate < TaskomaticTask
@task.instance.save!
while dcloud_instance.state == 'PENDING'
- dcloud_instance = client.instance((a)task.instance.external_key)
sleep(5)
+ dcloud_instance = client.instance((a)task.instance.external_key)
end
@task.instance.state = dcloud_to_instance_state(dcloud_instance.state)
@@ -78,10 +80,24 @@ class TaskomaticInstanceStart < TaskomaticTask
end
def run
+ @logger.info("TaskomaticInstanceStart running.")
+
client = @task.instance.portal_pool.cloud_account.connect
- instance = client.instance((a)task.instance.image.name)
- #instance.stop
- @logger.info("New instance created.")
+ dcloud_instance = client.instance((a)task.instance.external_key)
+ dcloud_instance.start!
+
+ @task.instance.state = dcloud_to_instance_state(dcloud_instance.state)
+ @task.instance.save!
+
+ while dcloud_instance.state == 'PENDING'
+ sleep(5)
+ dcloud_instance = client.instance((a)task.instance.external_key)
+ end
+
+ @task.instance.state = dcloud_to_instance_state(dcloud_instance.state)
+ @task.instance.save!
+
+ @logger.info("Instance started.")
end
end
--
1.6.2.5
14 years, 10 months
[Libcloud-list] [PATCH server] Add state conversion function from dcloud API to model instance.
by Ian Main
---
src/task-omatic/taskomatic_instance.rb | 23 ++++++++++++++++++-----
1 files changed, 18 insertions(+), 5 deletions(-)
diff --git a/src/task-omatic/taskomatic_instance.rb b/src/task-omatic/taskomatic_instance.rb
index 6899997..dcb9e6b 100644
--- a/src/task-omatic/taskomatic_instance.rb
+++ b/src/task-omatic/taskomatic_instance.rb
@@ -18,6 +18,19 @@
require 'taskomatic_task'
+def dcloud_to_instance_state(state_str)
+ case state_str
+ when 'PENDING'
+ return InstanceTask::STATE_PENDING
+ when 'RUNNING'
+ return InstanceTask::STATE_RUNNING
+ when 'STOPPED'
+ return InstanceTask::STATE_STOPPED
+ else
+ return InstanceTask::STATE_PENDING
+ end
+end
+
# Create a new instance on a cloud.
class TaskomaticInstanceCreate < TaskomaticTask
@@ -30,12 +43,12 @@ class TaskomaticInstanceCreate < TaskomaticTask
client = @task.instance.portal_pool.cloud_account.connect
puts "client is #{client.type}"
@logger.info "Creating instance with name #{(a)task.instance.image.external_key}, flavor #{(a)task.instance.flavor.name}, realm #{(a)task.instance.realm.name}"
- dcloud_instance = client.create_instance((a)task.instance.image.external_key,
- :flavor => @task.instance.flavor.name,
- :realm => @task.instance.realm.name)
+ dcloud_instance = client.create_instance((a)task.instance.image.external_key)
+ #:flavor => @task.instance.image.external_key,
+ #:realm => @task.instance.image.external_key)
@logger.info "Instance created with key #{dcloud_instance.id} and state #{dcloud_instance.state}"
@task.instance.external_key = dcloud_instance.id
- @task.instance.state = dcloud_instance.state
+ @task.instance.state = dcloud_to_instance_state(dcloud_instance.state)
@task.instance.save!
while dcloud_instance.state == 'PENDING'
@@ -43,7 +56,7 @@ class TaskomaticInstanceCreate < TaskomaticTask
sleep(5)
end
- @task.instance.state = dcloud_instance.state
+ @task.instance.state = dcloud_to_instance_state(dcloud_instance.state)
@task.instance.save!
# Instance::STATE_NEW
--
1.6.2.5
14 years, 10 months
[Libcloud-list] [PATCH server 07/10] Work in progress getting create task to work.
by Ian Main
---
src/task-omatic/taskomatic.rb | 18 +++++++++---------
src/task-omatic/taskomatic_instance.rb | 24 +++++++++++++++++++++++-
2 files changed, 32 insertions(+), 10 deletions(-)
diff --git a/src/task-omatic/taskomatic.rb b/src/task-omatic/taskomatic.rb
index 29e0358..3357815 100755
--- a/src/task-omatic/taskomatic.rb
+++ b/src/task-omatic/taskomatic.rb
@@ -53,7 +53,7 @@ class TaskOmatic
def initialize()
super()
- @sleeptime = 2
+ @sleeptime = 20
@nth_host = 0
do_daemon = true
@@ -132,15 +132,15 @@ class TaskOmatic
state = Task::STATE_FINISHED
begin
case task.action
- when InstanceTask::CREATE
+ when InstanceTask::ACTION_CREATE
tasko_task = TaskomaticInstanceCreate.new(@logger, task)
- when InstanceTask::START
+ when InstanceTask::ACTION_START
tasko_task = TaskomaticInstanceStart.new(@logger, task)
- when InstanceTask::STOP
+ when InstanceTask::ACTION_STOP
tasko_task = TaskomaticInstanceStop.new(@logger, task)
- when InstanceTask::REBOOT
+ when InstanceTask::ACTION_REBOOT
tasko_task = TaskomaticInstanceReboot.new(@logger, task)
- when InstanceTask::DESTROY
+ when InstanceTask::ACTION_DESTROY
tasko_task = TaskomaticInstanceDestroy.new(@logger, task)
else
@logger.error "unknown task " + task.action
@@ -159,10 +159,10 @@ class TaskOmatic
task.message = ex.message
end
- task.state = state
- task.time_ended = Time.now
+ #task.state = state
+ #task.time_ended = Time.now
begin
- task.save!
+ #task.save!
rescue Exception => ex
@logger.error "Error saving task state for task #{task.id}: #{ex.class}: #{ex.message}"
@logger.error ex.backtrace
diff --git a/src/task-omatic/taskomatic_instance.rb b/src/task-omatic/taskomatic_instance.rb
index c9d16ab..60eeadf 100644
--- a/src/task-omatic/taskomatic_instance.rb
+++ b/src/task-omatic/taskomatic_instance.rb
@@ -28,7 +28,29 @@ class TaskomaticInstanceCreate < TaskomaticTask
def run
client = @task.instance.portal_pool.cloud_account.connect
- instance = client.create_instance((a)task.instance.image.name)
+ dcloud_instance = client.create_instance((a)task.instance.image.name)
+ dcloud_instance.methods.sort.each do |method|
+ puts "method is #{method}"
+ end
+ #(a)logger.info "Instance created with state #{dcloud_instance[:state]}"
+ @task.instance.external_key = dcloud_instance.id
+ @task.instance.state = dcloud_instance[:state]
+ @task.instance.save!
+
+ while instance[:state] == 'PENDING'
+ instance = client.instance((a)task.instance.external_key)
+ sleep(5)
+ end
+
+ @task.instance.state = instance.state
+ @task.instance.save!
+
+ # Instance::STATE_NEW
+ # Instance::STATE_PENDING
+ # Instance::STATE_RUNNING
+ # Instance::STATE_SHUTTING_DOWN
+ # Instance::STATE_STOPPED
+
@logger.info("New instance created.")
end
end
--
1.6.2.5
14 years, 10 months
[Libcloud-list] [PATCH server] add some initial tables, fix broken css file.
by jason.guiditta
Signed-off-by: Jason Guiditta <jason.guiditta(a)gmail.com>
---
src/app/controllers/instance_controller.rb | 2 ++
src/app/views/instance/show.html.erb | 21 +++++++++++++++++----
src/app/views/portal_pool/show.html.erb | 19 ++++++++++++++++---
src/public/stylesheets/dcloud.css | 2 +-
4 files changed, 36 insertions(+), 8 deletions(-)
diff --git a/src/app/controllers/instance_controller.rb b/src/app/controllers/instance_controller.rb
index 1ab1a5e..32d5e3f 100644
--- a/src/app/controllers/instance_controller.rb
+++ b/src/app/controllers/instance_controller.rb
@@ -4,6 +4,8 @@ class InstanceController < ApplicationController
def show
@instances = Instance.find(:all, :conditions => {:portal_pool_id => params[:id]})
+ @pool = PortalPool.find(params[:id])
+ @provider = @pool.cloud_account.provider
end
def new
diff --git a/src/app/views/instance/show.html.erb b/src/app/views/instance/show.html.erb
index f660595..1327ef5 100644
--- a/src/app/views/instance/show.html.erb
+++ b/src/app/views/instance/show.html.erb
@@ -1,8 +1,21 @@
<% if @instances.size == 0 %>
<h1>There are no pools to display</h1>
<% else %>
- <%(a)instances.each {|instance| %>
- <%= instance.name %><br/>
- <% } %>
+ <table>
+ <thead>
+ <tr>
+ <th scope="col">Actions</th>
+ <th scope="col">Name</th>
+ </tr>
+ </thead>
+ <tbody>
+ <%(a)instances.each {|instance| %>
+ <tr>
+ <td></td>
+ <td><div><%= instance.name %></div></td>
+ </tr>
+ <% } %>
+ </tbody>
+ </table>
<% end %>
-<%= link_to "Add a new instance", :controller => "instance", :action => "new", :id => @pool, :provider => @provider%>
+<%= link_to "Add a new instance", :controller => "instance", :action => "new", :id => @pool, :provider => @provider%>
\ No newline at end of file
diff --git a/src/app/views/portal_pool/show.html.erb b/src/app/views/portal_pool/show.html.erb
index f660595..8dd06f5 100644
--- a/src/app/views/portal_pool/show.html.erb
+++ b/src/app/views/portal_pool/show.html.erb
@@ -1,8 +1,21 @@
<% if @instances.size == 0 %>
<h1>There are no pools to display</h1>
<% else %>
- <%(a)instances.each {|instance| %>
- <%= instance.name %><br/>
- <% } %>
+ <table>
+ <thead>
+ <tr>
+ <th scope="col">Actions</th>
+ <th scope="col">Name</th>
+ </tr>
+ </thead>
+ <tbody>
+ <%(a)instances.each {|instance| %>
+ <tr>
+ <td></td>
+ <td><div><%= instance.name %></div></td>
+ </tr>
+ <% } %>
+ </tbody>
+ </table>
<% end %>
<%= link_to "Add a new instance", :controller => "instance", :action => "new", :id => @pool, :provider => @provider%>
diff --git a/src/public/stylesheets/dcloud.css b/src/public/stylesheets/dcloud.css
index 0267815..143feec 100644
--- a/src/public/stylesheets/dcloud.css
+++ b/src/public/stylesheets/dcloud.css
@@ -138,7 +138,7 @@ input, select {
text-align:left;
font-size: 14px;
line-height: 18px;
-
+}
#content_area table th {
background: none;
--
1.6.2.5
14 years, 10 months
[Libcloud-list] [PATCH server] Create Instance form.
by jason.guiditta
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
14 years, 10 months