[Et-mgmt-commits-list] [SCM] virt-factory branch, master now at b61399cdadf4adc828d08452cc1d567d3e7650a7
Scott Seago
sseago at redhat.com
Mon Apr 16 17:58:13 UTC 2007
Hello,
This is an automated email from the git hooks/update script, it was
generated because a ref change was pushed to the repository.
Updating branch, master,
via b61399cdadf4adc828d08452cc1d567d3e7650a7 (commit)
from b44c72c43bf0ab9a0fc0de1d5400d4e3e3ecf814 (commit)
- Log -----------------------------------------------------------------
commit b61399cdadf4adc828d08452cc1d567d3e7650a7
Author: Scott Seago <sseago at redhat.com>
Date: Mon Apr 16 13:57:59 2007 -0400
refactored to remove deprecation warnings in the WUI
-----------------------------------------------------------------------
Diffstat:
.../app/controllers/abstract_object_controller.rb | 37 +++++++++-------
wui/src/app/controllers/application.rb | 10 ++--
wui/src/app/controllers/deployment_controller.rb | 28 ++++++------
wui/src/app/controllers/login_controller.rb | 16 ++++----
wui/src/app/controllers/machine_controller.rb | 2 +-
wui/src/app/controllers/profile_controller.rb | 2 +-
wui/src/app/controllers/regtoken_controller.rb | 2 +-
wui/src/app/controllers/task_controller.rb | 2 +-
wui/src/app/models/deployment.rb | 2 +-
wui/src/app/models/managed_object.rb | 45 ++++++++++----------
.../app/views/layouts/virt-factory-layout.rhtml | 16 ++++----
11 files changed, 83 insertions(+), 79 deletions(-)
diff --git a/wui/src/app/controllers/abstract_object_controller.rb b/wui/src/app/controllers/abstract_object_controller.rb
index 54a24c0..f804fe0 100755
--- a/wui/src/app/controllers/abstract_object_controller.rb
+++ b/wui/src/app/controllers/abstract_object_controller.rb
@@ -26,7 +26,7 @@ class AbstractObjectController < ApplicationController
def list
begin
- @items = ManagedObject.retrieve_all(object_class, @session)
+ @items = ManagedObject.retrieve_all(object_class, get_login)
rescue XMLRPCClientException => ex
@items = []
set_flash_on_exception(ex)
@@ -40,10 +40,13 @@ class AbstractObjectController < ApplicationController
#+++
def logout
- @session[:login] = nil
+ session[:login] = nil
redirect_to :controller => "login", :action => "index"
end
+ def get_login
+ session[:login]
+ end
# this page retrieves parameters needed to edit or add the given record.
# whether an edit or add is performed in the backend
# depends on whether there was an id field attached to the submission. adds do not
@@ -53,20 +56,20 @@ class AbstractObjectController < ApplicationController
def edit
- if @params[:id].nil?
- @item = object_class.new(@session)
+ if params[:id].nil?
+ @item = object_class.new(get_login)
@operation = "add"
else
begin
@operation = "edit"
- @item = ManagedObject.retrieve(object_class, at session, @params[:id])
+ @item = ManagedObject.retrieve(object_class,get_login, params[:id])
rescue XMLRPCClientException => ex
- @item = object_class.new(@session)
+ @item = object_class.new(get_login)
set_flash_on_exception(ex)
end
end
- if @params[:item_from_flash] == "1"
- @item.update_from_hash(@flash[:err_item_hash], @session)
+ if params[:item_from_flash] == "1"
+ @item.update_from_hash(flash[:err_item_hash], get_login)
end
end
@@ -74,7 +77,7 @@ class AbstractObjectController < ApplicationController
# should link to the edit controller for each item.
def view
- @item = ManagedObject.retrieve(object_class,session, @params[:id])
+ @item = ManagedObject.retrieve(object_class,get_login, params[:id])
end
# edit submit processes all new addition calls and all edit calls. you can tell whether
@@ -85,15 +88,15 @@ class AbstractObjectController < ApplicationController
def edit_submit
begin
- obj = ManagedObject.from_hash(object_class, at params["form"], @session)
+ obj = ManagedObject.from_hash(object_class,params["form"], get_login)
operation = obj.id.nil? ? "add" : "edit"
obj.save()
- @flash[:notice] = "#{object_class::METHOD_PREFIX} #{obj.objname} #{operation} succeeded."
+ flash[:notice] = "#{object_class::METHOD_PREFIX} #{obj.objname} #{operation} succeeded."
redirect_to :action => 'list'
return
rescue XMLRPCClientException => ex
set_flash_on_exception(ex)
- @flash[:err_item_hash] = @params["form"]
+ flash[:err_item_hash] = params["form"]
end
# what page we redirect depends on whether this was an add or an edit
if operation == "add"
@@ -107,8 +110,8 @@ class AbstractObjectController < ApplicationController
def delete
begin
- ManagedObject.delete(object_class, @params[:id], @session)
- @flash[:notice] = "Deleted #{object_class::METHOD_PREFIX} #{@params[:id]}"
+ ManagedObject.delete(object_class, params[:id], get_login)
+ flash[:notice] = "Deleted #{object_class::METHOD_PREFIX} #{params[:id]}"
rescue XMLRPCClientException => ex
set_flash_on_exception(ex)
end
@@ -124,11 +127,11 @@ class AbstractObjectController < ApplicationController
# how to explain themselves in friendly user-speak and we can ask them to do that.
def set_flash_on_exception(ex)
- # populate @flash with a human readable error string suitable by
+ # populate flash with a human readable error string suitable by
# display in the WUI
- @flash[:errmsg] = ex.get_human_readable()
+ flash[:errmsg] = ex.get_human_readable()
- @flash[:invalid_fields] = ex.invalid_fields
+ flash[:invalid_fields] = ex.invalid_fields
end
end
diff --git a/wui/src/app/controllers/application.rb b/wui/src/app/controllers/application.rb
index c846b9e..776c06b 100755
--- a/wui/src/app/controllers/application.rb
+++ b/wui/src/app/controllers/application.rb
@@ -113,26 +113,26 @@ class ApplicationController < ActionController::Base
layout "virt-factory-layout"
def login_required
- unless @session[:login]
+ unless session[:login]
redirect_to :controller => "login", :action => "input"
return false
end
begin
- (rc, data) = @@server.call("token_check", @session[:login])
+ (rc, data) = @@server.call("token_check", session[:login])
rescue RuntimeError
# internal server error (500) likely here if connection to web svc was
# severed by a restart of the web service during development.
- @flash[:notice] = "Internal Server Error"
+ flash[:notice] = "Internal Server Error"
redirect_to :controller => "login", :action => "input"
return false
end
unless rc == ERR_SUCCESS
# token has timed out, so redirect here and get a new one
# rather than having to do a lot of duplicate error handling in other places
- @flash[:notice] = "Session timeout (#{ERRORS[rc]})."
+ flash[:notice] = "Session timeout (#{ERRORS[rc]})."
stacktrace = data["stacktrace"]
- @flash[:errmsg] = stacktrace if stacktrace
+ flash[:errmsg] = stacktrace if stacktrace
redirect_to :controller => "login", :action => "input"
return false
end
diff --git a/wui/src/app/controllers/deployment_controller.rb b/wui/src/app/controllers/deployment_controller.rb
index aa8d64b..28b78ae 100755
--- a/wui/src/app/controllers/deployment_controller.rb
+++ b/wui/src/app/controllers/deployment_controller.rb
@@ -12,8 +12,8 @@ class DeploymentController < AbstractObjectController
# talk to the node daemon of the host to see what the guest's
# current state is, and update it.
- if !@params.nil? and !params[:id].nil?
- obj = ManagedObject.retrieve(Deployment, @session, @params[:id])
+ if !params[:id].nil?
+ obj = ManagedObject.retrieve(Deployment, get_login, params[:id])
obj.refresh()
end
@@ -21,7 +21,7 @@ class DeploymentController < AbstractObjectController
super
# get a list of address to ip mappings
- @machines = ManagedObject.retrieve_all(Machine, @session).collect do |machine|
+ @machines = ManagedObject.retrieve_all(Machine, get_login).collect do |machine|
[machine.hostname, machine.id] unless machine.id < 0 or machine.hostname.nil?
end
@machines.reject! { |foo| foo.nil? }
@@ -34,7 +34,7 @@ class DeploymentController < AbstractObjectController
# are virtual only.
@profiles = []
- ManagedObject.retrieve_all(Profile, @session).each do |profile|
+ ManagedObject.retrieve_all(Profile, get_login).each do |profile|
@profiles << [profile.name, profile.id] unless profile.id < 0 or profile.valid_targets == PROFILE_IS_BAREMETAL
end
@profiles.reject! { |foo| foo.nil? }
@@ -42,33 +42,33 @@ class DeploymentController < AbstractObjectController
end
def pause
- obj = ManagedObject.retrieve(Deployment, @session, @params[:id])
+ obj = ManagedObject.retrieve(Deployment, get_login, params[:id])
obj.pause()
- redirect_to :action=> "edit", :id => @params[:id]
+ redirect_to :action=> "edit", :id => params[:id]
end
def unpause
- obj = ManagedObject.retrieve(Deployment, @session, @params[:id])
+ obj = ManagedObject.retrieve(Deployment, get_login, params[:id])
obj.unpause()
- redirect_to :action=> "edit", :id => @params[:id]
+ redirect_to :action=> "edit", :id => params[:id]
end
def start
- obj = ManagedObject.retrieve(Deployment, @session, @params[:id])
+ obj = ManagedObject.retrieve(Deployment, get_login, params[:id])
obj.start()
- redirect_to :action=> "edit", :id => @params[:id]
+ redirect_to :action=> "edit", :id => params[:id]
end
def shutdown
- obj = ManagedObject.retrieve(Deployment, @session, @params[:id])
+ obj = ManagedObject.retrieve(Deployment, get_login, params[:id])
obj.shutdown()
- redirect_to :action=> "edit", :id => @params[:id]
+ redirect_to :action=> "edit", :id => params[:id]
end
def destroy
- obj = ManagedObject.retrieve(Deployment, @session, @params[:id])
+ obj = ManagedObject.retrieve(Deployment, get_login, params[:id])
obj.destroy()
- redirect_to :action=> "edit", :id => @params[:id]
+ redirect_to :action=> "edit", :id => params[:id]
end
end
diff --git a/wui/src/app/controllers/login_controller.rb b/wui/src/app/controllers/login_controller.rb
index 93d8fda..6a70120 100755
--- a/wui/src/app/controllers/login_controller.rb
+++ b/wui/src/app/controllers/login_controller.rb
@@ -1,6 +1,6 @@
require "util/codes"
-# the login controller is what the app users get when there is no valid token in the @session variable.
+# the login controller is what the app users get when there is no valid token in the session variable.
# it should be the only controller in the application derived from ApplicationControllerUnlocked, all
# others, being Locked, require a token. Should this be changed to derive from a Locked controller, you'll
# get an infinite reload to this page.
@@ -18,30 +18,30 @@ class LoginController < ApplicationControllerUnlocked
def submit
- f_username = @params["form"]["username"]
- f_password = @params["form"]["password"]
+ f_username = params["form"]["username"]
+ f_password = params["form"]["password"]
# check on authentication via XMLRPC.
# FIXME: this really needs to be https in the future.
begin
(rc, results) = @@server.call("user_login",f_username,f_password)
rescue Errno::ECONNREFUSED
- @flash[:notice] = "Could not connect to virt-factory server."
+ flash[:notice] = "Could not connect to virt-factory server."
redirect_to :action => "input"
return
end
if rc != 0
# FIXME: look up error codes in string table
- @flash[:notice] = "Login failed (#{ERRORS[rc]})."
+ flash[:notice] = "Login failed (#{ERRORS[rc]})."
# ask the user to input the fields again
- # (the right error messages will show up on redirect because of @flash)
+ # (the right error messages will show up on redirect because of flash)
redirect_to :action => "input"
return
else
# login was successful, so store the session token, which is needed for all
- # future RPC calls, in @session.
- @session[:login] = results["data"]
+ # future RPC calls, in session.
+ session[:login] = results["data"]
# go to the user/list page on default login.
# FIXME: this isn't a super-compelling page to go to, we eventually would want
# something more "dashboard" like, or at least "Welcome to virt-factory" like.
diff --git a/wui/src/app/controllers/machine_controller.rb b/wui/src/app/controllers/machine_controller.rb
index e2ca80c..d3f2207 100755
--- a/wui/src/app/controllers/machine_controller.rb
+++ b/wui/src/app/controllers/machine_controller.rb
@@ -13,7 +13,7 @@ class MachineController < AbstractObjectController
# TODO: ideally, out of the box, we'd ship and install an profile that would be suitable for a stock
# container.
- ManagedObject.retrieve_all(Profile, @session, true).each do |profile|
+ ManagedObject.retrieve_all(Profile, get_login, true).each do |profile|
if !profile.nil?
@profiles << [profile.name, profile.id] unless profile.valid_targets == PROFILE_IS_VIRT
end
diff --git a/wui/src/app/controllers/profile_controller.rb b/wui/src/app/controllers/profile_controller.rb
index e3bdadf..e29e00e 100755
--- a/wui/src/app/controllers/profile_controller.rb
+++ b/wui/src/app/controllers/profile_controller.rb
@@ -11,7 +11,7 @@ class ProfileController < AbstractObjectController
# fight that when we come to it.
#+++
super
- @distributions = ManagedObject.retrieve_all(Distribution, @session).collect do |dist|
+ @distributions = ManagedObject.retrieve_all(Distribution, get_login).collect do |dist|
[dist.name, dist.id]
end
# the list needs to start off with no selection in the GUI.
diff --git a/wui/src/app/controllers/regtoken_controller.rb b/wui/src/app/controllers/regtoken_controller.rb
index 27f5f48..51e6336 100755
--- a/wui/src/app/controllers/regtoken_controller.rb
+++ b/wui/src/app/controllers/regtoken_controller.rb
@@ -11,7 +11,7 @@ class RegtokenController < AbstractObjectController
super
@profiles = []
- ManagedObject.retrieve_all(Profile, @session).each do |profile|
+ ManagedObject.retrieve_all(Profile, get_login).each do |profile|
@profiles << [profile.name, profile.id]
end
@profiles.insert(0,EMPTY_ENTRY)
diff --git a/wui/src/app/controllers/task_controller.rb b/wui/src/app/controllers/task_controller.rb
index c994d14..e3fce9d 100755
--- a/wui/src/app/controllers/task_controller.rb
+++ b/wui/src/app/controllers/task_controller.rb
@@ -29,7 +29,7 @@ class TaskController < AbstractObjectController
# NOTE: this is mainly for development purposes, we probably won't allow this directly once released
# may be good to have the list though.
super
- @users = ManagedObject.retrieve_all(User, @session).collect do |entry|
+ @users = ManagedObject.retrieve_all(User, get_login).collect do |entry|
[ entry.username, entry.id ]
end
# FIXME: for consistancy this should be in codes-lookup.rb
diff --git a/wui/src/app/models/deployment.rb b/wui/src/app/models/deployment.rb
index 803dc34..f6aa48a 100755
--- a/wui/src/app/models/deployment.rb
+++ b/wui/src/app/models/deployment.rb
@@ -34,7 +34,7 @@ class Deployment < ManagedObject
end
def __virt_call(id, op)
- ManagedObject.call_server(op, @session, { "id" => id }, id.to_s)
+ ManagedObject.call_server(op, session[:login], { "id" => id }, id.to_s)
end
def pause
diff --git a/wui/src/app/models/managed_object.rb b/wui/src/app/models/managed_object.rb
index 75d5563..bb2203c 100755
--- a/wui/src/app/models/managed_object.rb
+++ b/wui/src/app/models/managed_object.rb
@@ -8,12 +8,13 @@ class ManagedObject
class Boolean
end
- # I think this means every object is constructed with a reference to the session state. (Correct?)
- def initialize(session)
- @session = session
+ # each object is created with a reference to the login token for
+ # connecting to the xmlrpc server.
+ def initialize(login)
+ @login = login
end
- attr_reader :session
+ attr_reader :login
# basically each subclass will have a call to set_attrs in it's constructor. Each attr in the list
# contains a name of a field and a type value for that field. Each field will be made an accessor,
@@ -51,7 +52,7 @@ class ManagedObject
if !instance_variable_get(attr_symbol)
id = instance_variable_get(id_symbol)
if (id >= 0)
- object = ManagedObject.retrieve(metadata[:type], self.session, id)
+ object = ManagedObject.retrieve(metadata[:type], self.login, id)
instance_variable_set(attr_symbol, object)
end
end
@@ -73,14 +74,14 @@ class ManagedObject
def save
operation = (@id.nil? || @id < 0) ? "add" : "edit"
ManagedObject.call_server("#{self.class::METHOD_PREFIX}_#{operation}",
- @session, self.to_hash, objname)
+ self.login, self.to_hash, objname)
end
# deleting an object, only the id is a required argument.
- def self.delete(object_class,id,session)
+ def self.delete(object_class,id,login)
self.call_server("#{object_class::METHOD_PREFIX}_delete",
- session, { "id" => id }, id.to_s)
+ login, { "id" => id }, id.to_s)
end
# this is a call usable in the controller to get all of the objects that the backend knows about
@@ -89,10 +90,10 @@ class ManagedObject
# with really long system lists (i.e. a couple thousand). Ok to add in later release.
#+++
- def self.retrieve_all(object_class, session, retrieve_nulls = false)
- print "calling retrieve all for: #{object_class::METHOD_PREFIX}_list\n"
- results = self.call_server("#{object_class::METHOD_PREFIX}_list", session, {})
- results = results.collect {|hash| ManagedObject.from_hash(object_class, hash, session) if !hash.nil? and (retrieve_nulls or hash["id"] >= 0) }
+ def self.retrieve_all(object_class, login, retrieve_nulls = false)
+ #print "calling retrieve all for: #{object_class::METHOD_PREFIX}_list\n"
+ results = self.call_server("#{object_class::METHOD_PREFIX}_list", login, {})
+ results = results.collect {|hash| ManagedObject.from_hash(object_class, hash, login) if !hash.nil? and (retrieve_nulls or hash["id"] >= 0) }
results.reject! { |foo| foo.nil? }
return results
end
@@ -100,25 +101,25 @@ class ManagedObject
# retrieves a single object (not a list) that corresponds to a certain id. Should return
# null if it isn't there, but it might raise an exception. Need to check on this.
- def self.retrieve(object_class, session, id)
+ def self.retrieve(object_class, login, id)
results = self.call_server("#{object_class::METHOD_PREFIX}_get",
- session, {"id" => id }, id.to_s)
- ManagedObject.from_hash(object_class,results, session)
+ login, {"id" => id }, id.to_s)
+ ManagedObject.from_hash(object_class,results, login)
end
#updates an existing instance with attributes form a passed-in hash
- def update_from_hash(hash, session)
- ManagedObject.from_hash(self.class, hash, session, self)
+ def update_from_hash(hash, login)
+ ManagedObject.from_hash(self.class, hash, login, self)
end
# from_hash vivifies an object (or an object tree) using it's hash representation, recursively doing the right
# thing as neccessary.
- def self.from_hash(object_class, hash, session, object_instance = nil)
+ def self.from_hash(object_class, hash, login, object_instance = nil)
# create the instance, we'll fill it's data as we go along
- object_instance = object_class.new(session) if object_instance.nil?
+ object_instance = object_class.new(login) if object_instance.nil?
# initially create nil values for everything, even if not in passed-in arguments.
object_class::ATTR_LIST.each do |sym,meta|
@@ -151,7 +152,7 @@ class ManagedObject
elsif atype.methods.include?("from_hash")
# ManagedObjects result in recursive calls...
raise RuntimeError.new("No child arguments?") if not value.is_a?(Hash)
- new_item = self.from_hash(atype, value, session)
+ new_item = self.from_hash(atype, value, login)
else
# we have no idea what to do with this...
raise RuntimeError.new("Model class #{object_class.to_s} load error for #{key} of type #{atype.to_s} and value type #{value.class()}")
@@ -196,12 +197,12 @@ class ManagedObject
# this is a wrapper around the XMLRPC calls the various methods make.
- def self.call_server(method_name, session, args, errmsg = "")
+ def self.call_server(method_name, login, args, errmsg = "")
# the return signature for a backend API method is usually (rc, hash) where hash contains
# one or more of the following fields. See explanation in XMLRPCClientException class.
- (rc, rawdata) = @@server.call(method_name, session[:login], args)
+ (rc, rawdata) = @@server.call(method_name, login, args)
unless rc == ERR_SUCCESS
# convert error codes to Ruby exceptions. We don't use XMLRPC faults because it's harder
diff --git a/wui/src/app/views/layouts/virt-factory-layout.rhtml b/wui/src/app/views/layouts/virt-factory-layout.rhtml
index a3fd035..8dee3b1 100755
--- a/wui/src/app/views/layouts/virt-factory-layout.rhtml
+++ b/wui/src/app/views/layouts/virt-factory-layout.rhtml
@@ -34,10 +34,10 @@
<!-- if any fields are invalid, turn them red -->
<!-- fixme: should also mention reasons later -->
- <% if @flash[:invalid_fields] %>
+ <% if flash[:invalid_fields] %>
<SCRIPT LANGUAGE="Javascript">
- <% @flash[:invalid_fields].each do |field, reason| %>
+ <% flash[:invalid_fields].each do |field, reason| %>
document.getElementById("form_<%= field.to_s() %>").style.backgroundColor='red';
<% end %>
@@ -45,20 +45,20 @@
<% end %>
<!-- secondary informational section, if applicable -->
- <% if @flash[:notice] or @flash[:errmsg] %>
+ <% if flash[:notice] or flash[:errmsg] %>
<div class = "alertbox">
- <% if @flash[:notice] %>
- <%= @flash[:notice] %>
+ <% if flash[:notice] %>
+ <%= flash[:notice] %>
<% end %>
- <% if @flash[:notice] and @flash[:errmsg] %>
+ <% if flash[:notice] and flash[:errmsg] %>
<br/>
<% end %>
- <% if @flash[:errmsg] %>
- <%= @flash[:errmsg] %>
+ <% if flash[:errmsg] %>
+ <%= flash[:errmsg] %>
<% end %>
</div>
hooks/update
---
Git Source Code Management System
hooks/update refs/heads/master \
b44c72c43bf0ab9a0fc0de1d5400d4e3e3ecf814 \
b61399cdadf4adc828d08452cc1d567d3e7650a7
More information about the Et-mgmt-commits-list
mailing list