[PATCH configure 1/2] replace http_method param and uri property in web request module w/ specific http method parameters that take uris
by Mo Morsi
---
.../aeolus_recipe/lib/puppet/provider/web/curl.rb | 118 +++++++++++---------
recipes/aeolus_recipe/lib/puppet/type/web.rb | 18 ++--
recipes/aeolus_recipe/manifests/conductor.pp | 6 +-
3 files changed, 77 insertions(+), 65 deletions(-)
diff --git a/recipes/aeolus_recipe/lib/puppet/provider/web/curl.rb b/recipes/aeolus_recipe/lib/puppet/provider/web/curl.rb
index b5f4468..5f86e87 100644
--- a/recipes/aeolus_recipe/lib/puppet/provider/web/curl.rb
+++ b/recipes/aeolus_recipe/lib/puppet/provider/web/curl.rb
@@ -50,65 +50,79 @@ def verify_result(result, verify = {})
end
end
+# Helper to process/parse web parameters
+def process_params(request_method, params, uri)
+ begin
+ # Set request method and generate a unique session key
+ session = "/tmp/#{UUID.new.generate}"
+
+ # Invoke a login request if necessary
+ if params[:login]
+ login_params = params[:login].reject { |k,v| ['http_method', 'uri'].include?(k) }
+ web_request(params[:login]['http_method'], params[:login]['uri'],
+ login_params, :cookie => session, :follow => params[:follow]).close
+ end
+
+ # Check to see if we should actually run the request
+ skip_request = !params[:unless].nil?
+ if params[:unless]
+ result = web_request(params[:unless]['http_method'], params[:unless]['uri'],
+ params[:unless]['parameters'],
+ :cookie => session, :follow => params[:follow])
+ begin
+ verify_result(result,
+ :returns => params[:unless]['returns'],
+ :body => params[:unless]['verify'])
+ rescue Puppet::Error => e
+ skip_request = false
+ end
+ result.close
+ end
+ return if skip_request
+
+ # Actually run the request and verify the result
+ uri = params[:name] if uri.nil?
+ result = web_request(request_method, uri, params[:parameters],
+ :cookie => session, :follow => params[:follow])
+ verify_result(result,
+ :returns => params[:returns],
+ :body => params[:verify])
+ result.close
+
+ # Invoke a logout request if necessary
+ if params[:logout]
+ logout_params = params[:login].reject { |k,v| ['http_method', 'uri'].include?(k) }
+ web_request(params[:logout]['http_method'], params[:logout]['uri'],
+ logout_params, :cookie => session, :follow => params[:follow]).close
+ end
+
+ rescue Exception => e
+ raise Puppet::Error, "An exception was raised when invoking web request: #{e}"
+
+ ensure
+ FileUtils.rm_f(session) if params[:logout]
+ end
+end
+
# Puppet provider definition
Puppet::Type.type(:web).provide :curl do
desc "Use curl to access web resources"
- def http_method
- @request_method
+ def get
+ @uri
end
- def http_method=(request_method)
- begin
- # Set request method and generate a unique session key
- @request_method = request_method
- session = "/tmp/#{UUID.new.generate}"
-
- # Invoke a login request if necessary
- if @resource[:login]
- login_params = @resource[:login].reject { |k,v| ['http_method', 'uri'].include?(k) }
- web_request(@resource[:login]['http_method'], @resource[:login]['uri'],
- login_params, :cookie => session, :follow => @resource[:follow]).close
- end
-
- # Check to see if we should actually run the request
- skip_request = !@resource[:unless].nil?
- if @resource[:unless]
- result = web_request(@resource[:unless]['http_method'], @resource[:unless]['uri'],
- @resource[:unless]['parameters'],
- :cookie => session, :follow => @resource[:follow])
- begin
- verify_result(result,
- :returns => @resource[:unless]['returns'],
- :body => @resource[:unless]['verify'])
- rescue Puppet::Error => e
- skip_request = false
- end
- result.close
- end
- return if skip_request
-
- # Actually run the request and verify the result
- uri = !@resource[:uri].nil? ? @resource[:uri] : @resource[:name]
- result = web_request(request_method, uri, @resource[:parameters],
- :cookie => session, :follow => @resource[:follow])
- verify_result(result,
- :returns => @resource[:returns],
- :body => @resource[:verify])
- result.close
-
- # Invoke a logout request if necessary
- if @resource[:logout]
- logout_params = @resource[:login].reject { |k,v| ['http_method', 'uri'].include?(k) }
- web_request(@resource[:logout]['http_method'], @resource[:logout]['uri'],
- logout_params, :cookie => session, :follow => @resource[:follow]).close
- end
+ def post
+ @uri
+ end
- rescue Exception => e
- raise Puppet::Error, "An exception was raised when invoking web request: #{e}"
+ def get=(uri)
+ @uri = uri
+ process_params('get', @resource, uri)
+ end
- ensure
- FileUtils.rm_f(session) if @resource[:logout]
- end
+ def post=(uri)
+ @uri = uri
+ process_params('post', @resource, uri)
end
end
diff --git a/recipes/aeolus_recipe/lib/puppet/type/web.rb b/recipes/aeolus_recipe/lib/puppet/type/web.rb
index a9bf765..5701ac2 100644
--- a/recipes/aeolus_recipe/lib/puppet/type/web.rb
+++ b/recipes/aeolus_recipe/lib/puppet/type/web.rb
@@ -3,19 +3,19 @@ Puppet::Type.newtype(:web) do
newparam :name
- newparam(:uri) do
- desc "URI to the web resource"
+ newproperty(:get) do
+ desc "Issue get request to the specified uri"
+ # TODO valid value to be a uri
end
- newproperty(:http_method) do
- desc "HTTP method through which to issue the web request"
- validate do |value|
- unless ['post', 'get', 'put', 'delete'].include?(value)
- raise ArgumentError, "#{value} is not a valid HTTP request method"
- end
- end
+ newproperty(:post) do
+ desc "Issue get request to the specified uri"
+ # TODO valid value to be a uri
end
+ #newproperty(:delete)
+ #newproperty(:put)
+
newparam(:parameters) do
desc "Hash of parameters to include in the web request"
end
diff --git a/recipes/aeolus_recipe/manifests/conductor.pp b/recipes/aeolus_recipe/manifests/conductor.pp
index 7312e3a..31c5145 100644
--- a/recipes/aeolus_recipe/manifests/conductor.pp
+++ b/recipes/aeolus_recipe/manifests/conductor.pp
@@ -231,8 +231,7 @@ define aeolus::site_admin($email="", $password="", $first_name="", $last_name=""
# Create a new provider via the conductor
define aeolus::conductor::provider($type="",$url=""){
web{ "provider-$name":
- uri => "https://localhost/conductor/admin/providers",
- http_method => 'post',
+ post => "https://localhost/conductor/admin/providers",
parameters => { 'provider[name]' => $name, 'provider[url]' => $url,
'provider[provider_type_codename]' => $type },
returns => '200',
@@ -247,8 +246,7 @@ define aeolus::conductor::provider($type="",$url=""){
define aeolus::conductor::hwp($memory='', $cpu='', $storage='', $architecture=''){
web{ "hwp-$name":
- uri => "https://localhost/conductor/admin/hardware_profiles",
- http_method => 'post',
+ post => "https://localhost/conductor/admin/hardware_profiles",
parameters => {'hardware_profile[name]' => $name,
'hardware_profile[memory_attributes][value]' => $memory,
'hardware_profile[cpu_attributes][value]' => $cpu,
--
1.7.2.3
12 years, 11 months
[PATCH conductor] JSON responds for instances/deployments/pools
by Jan Provazník
From: Jan Provaznik <jprovazn(a)redhat.com>
https://www.aeolusproject.org/redmine/issues/1448
---
src/app/controllers/deployments_controller.rb | 84 +++++++---
src/app/controllers/instances_controller.rb | 175 +++++++++++++--------
src/app/controllers/pools_controller.rb | 63 +++++---
src/features/deployment.feature | 27 +++
src/features/instance.feature | 25 +++-
src/features/pool.feature | 27 +++-
src/features/step_definitions/deployment_steps.rb | 43 +++++
src/features/step_definitions/instance_steps.rb | 41 +++++-
src/features/step_definitions/pool_steps.rb | 39 +++++-
9 files changed, 409 insertions(+), 115 deletions(-)
diff --git a/src/app/controllers/deployments_controller.rb b/src/app/controllers/deployments_controller.rb
index 9159daa..bdf40de 100644
--- a/src/app/controllers/deployments_controller.rb
+++ b/src/app/controllers/deployments_controller.rb
@@ -4,6 +4,10 @@ class DeploymentsController < ApplicationController
before_filter :load_deployment, :only => [:edit, :update]
def index
+ respond_to do |format|
+ format.html
+ format.json { render :json => @deployments }
+ end
end
def launch_new
@@ -11,16 +15,25 @@ class DeploymentsController < ApplicationController
Deployable.all.each do |deployable|
@launchable_deployables << deployable if deployable.launchable?
end
+ respond_to do |format|
+ format.html
+ format.json { render :json => @launchable_deployables }
+ end
end
def new
require_privilege(Privilege::CREATE, Deployment)
@deployment = Deployment.new(:deployable_id => params[:deployable_id])
- if @deployment.deployable.assemblies.empty?
- flash[:warning] = "Deployable must have at least one assembly"
- redirect_to deployments_path
- else
- init_new_deployment_attrs
+ respond_to do |format|
+ if @deployment.deployable.assemblies.empty?
+ flash[:warning] = "Deployable must have at least one assembly"
+ format.html { redirect_to deployments_path }
+ format.json { render :json => {:error => flash[:warning]}, :status => :unprocessable_entity }
+ else
+ init_new_deployment_attrs
+ format.html
+ format.json { render :json => @deployment }
+ end
end
end
@@ -28,20 +41,24 @@ class DeploymentsController < ApplicationController
require_privilege(Privilege::CREATE, Deployment)
@deployment = Deployment.new(params[:deployment])
@deployment.owner = current_user
- if @deployment.save
- flash[:notice] = "Deployment launched"
- errors = @deployment.launch(params[:hw_profiles] || {}, current_user)
- unless errors.empty?
- flash[:error] = {
- :summary => "Failed to launch following assemblies:",
- :failures => errors
- }
+ respond_to do |format|
+ if @deployment.save
+ flash[:notice] = "Deployment launched"
+ errors = @deployment.launch(params[:hw_profiles] || {}, current_user)
+ unless errors.empty?
+ flash[:error] = {
+ :summary => "Failed to launch following assemblies:",
+ :failures => errors
+ }
+ end
+ format.html { redirect_to deployment_path(@deployment) }
+ format.json { render :json => @deployment, :status => :created }
+ else
+ flash.now[:warning] = "Deployment launch failed"
+ init_new_deployment_attrs
+ format.html { render :action => 'new' }
+ format.json { render :json => @deployment.errors, :status => :unprocessable_entity }
end
- redirect_to deployment_path(@deployment)
- else
- flash.now[:warning] = "Deployment launch failed"
- init_new_deployment_attrs
- render :new
end
end
@@ -59,23 +76,32 @@ class DeploymentsController < ApplicationController
render :partial => @details_tab and return
end
format.html { render :action => 'show'}
+ format.json { render :json => @deployment }
end
end
def edit
require_privilege(Privilege::MODIFY, @deployment)
+ respond_to do |format|
+ format.html
+ format.json { render :json => @deployment }
+ end
end
# TODO - This should eventually support updating multiple objects
def update
attrs = {}
params[:deployment].each_pair{|k,v| attrs[k] = v if Deployment::USER_MUTABLE_ATTRS.include?(k)}
- if check_privilege(Privilege::MODIFY, @deployment) and @deployment.update_attributes(attrs)
- flash[:success] = t('deployments.updated', :count => 1, :list => @deployment.name)
- redirect_to @deployment
- else
- flash[:error] = t('deployments.not_updated', :count => 1, :list => @deployment.name)
- render :action => :edit
+ respond_to do |format|
+ if check_privilege(Privilege::MODIFY, @deployment) and @deployment.update_attributes(attrs)
+ flash[:success] = t('deployments.updated', :count => 1, :list => @deployment.name)
+ format.html { redirect_to @deployment }
+ format.json { render :json => @deployment }
+ else
+ flash[:error] = t('deployments.not_updated', :count => 1, :list => @deployment.name)
+ format.html { render :action => :edit }
+ format.json { render :json => @deployment.errors, :status => :unprocessable_entity }
+ end
end
end
@@ -92,7 +118,10 @@ class DeploymentsController < ApplicationController
end
flash[:success] = t('deployments.deleted', :list => destroyed, :count => destroyed.size) if destroyed.present?
flash[:error] = t('deployments.not_deleted', :list => failed, :count => failed.size) if failed.present?
- redirect_to deployments_url
+ respond_to do |format|
+ format.html { redirect_to deployments_url }
+ format.json { render :json => {:success => destroyed, :errors => failed} }
+ end
end
def multi_stop
@@ -121,7 +150,10 @@ class DeploymentsController < ApplicationController
end
flash[:notice] = notices unless notices.blank?
flash[:error] = errors unless errors.blank?
- redirect_to deployments_path
+ respond_to do |format|
+ format.html { redirect_to deployments_path }
+ format.json { render :json => {:success => notices, :errors => errors} }
+ end
end
private
diff --git a/src/app/controllers/instances_controller.rb b/src/app/controllers/instances_controller.rb
index f44e3af..f04db3c 100644
--- a/src/app/controllers/instances_controller.rb
+++ b/src/app/controllers/instances_controller.rb
@@ -8,13 +8,14 @@ class InstancesController < ApplicationController
@search_term = params[:q]
if @search_term.blank?
load_instances
- return
+ else
+ @instances = Instance.search { keywords(params[:q]) }.results
end
- search = Instance.search do
- keywords(params[:q])
+ respond_to do |format|
+ format.html
+ format.json { render :json => @instances }
end
- @instances = search.results
end
def new
@@ -27,6 +28,10 @@ class InstancesController < ApplicationController
end
init_new_instance_attrs
+ respond_to do |format|
+ format.html
+ format.json { render :json => @instance }
+ end
end
def select_template
@@ -37,6 +42,10 @@ class InstancesController < ApplicationController
:include => {:images => :provider_images},
:conditions => "provider_images.status = '#{ProviderImage::STATE_COMPLETED}'"
)
+ respond_to do |format|
+ format.html
+ format.json { render :json => @templates }
+ end
end
def create
@@ -49,30 +58,34 @@ class InstancesController < ApplicationController
@instance.state = Instance::STATE_NEW
@instance.owner = current_user
- begin
- require_privilege(Privilege::CREATE, Instance,
- Pool.find((a)instance.pool_id))
- free_quota = Quota.can_start_instance?(@instance, nil)
- raise "Pool is not enabled" unless @instance.pool and @instance.pool.enabled
- @instance.transaction do
- @instance.save!
- # set owner permissions:
- @task = InstanceTask.create!({:user => current_user,
- :task_target => @instance,
- :action => InstanceTask::ACTION_CREATE})
- condormatic_instance_create(@task)
- end
- rescue
- init_new_instance_attrs
- flash[:warning] = "Failed to launch instance: #{$!}"
- render :new
- else
- if free_quota
- flash[:notice] = "Instance added."
+ respond_to do |format|
+ begin
+ require_privilege(Privilege::CREATE, Instance,
+ Pool.find((a)instance.pool_id))
+ free_quota = Quota.can_start_instance?(@instance, nil)
+ raise "Pool is not enabled" unless @instance.pool and @instance.pool.enabled
+ @instance.transaction do
+ @instance.save!
+ # set owner permissions:
+ @task = InstanceTask.create!({:user => current_user,
+ :task_target => @instance,
+ :action => InstanceTask::ACTION_CREATE})
+ condormatic_instance_create(@task)
+ end
+ rescue
+ init_new_instance_attrs
+ flash[:warning] = "Failed to launch instance: #{$!}"
+ format.html { render :new }
+ format.json { render :json => @instance, :status => :unprocessable_entity}
else
- flash[:warning] = "Quota Exceeded: Instance will not start until you have free quota"
+ if free_quota
+ flash[:notice] = "Instance added."
+ else
+ flash[:warning] = "Quota Exceeded: Instance will not start until you have free quota"
+ end
+ format.html { redirect_to instances_path }
+ format.json { render :json => @instance, :status => :created }
end
- redirect_to instances_path
end
end
@@ -89,6 +102,7 @@ class InstancesController < ApplicationController
render :partial => @details_tab and return
end
format.html { render :action => 'show'}
+ format.json { render :json => @instance }
end
end
@@ -102,12 +116,16 @@ class InstancesController < ApplicationController
# since it won't do what they expect). As we build this out, this logic will become more complex.
attrs = {}
params[:instance].each_pair{|k,v| attrs[k] = v if Instance::USER_MUTABLE_ATTRS.include?(k)}
- if check_privilege(Privilege::MODIFY, @instance) and @instance.update_attributes(attrs)
- flash[:success] = t('instances.updated', :count => 1, :list => @instance.name)
- redirect_to @instance
- else
- flash[:error] = t('instances.not_updated', :count =>1, :list => @instance.name)
- render :action => :edit
+ respond_to do |format|
+ if check_privilege(Privilege::MODIFY, @instance) and @instance.update_attributes(attrs)
+ flash[:success] = t('instances.updated', :count => 1, :list => @instance.name)
+ format.html { redirect_to @instance }
+ format.json { render :json => @instance }
+ else
+ flash[:error] = t('instances.not_updated', :count =>1, :list => @instance.name)
+ format.html { render :action => :edit }
+ format.json { render :json => @instance.errors, :status => :unprocessable_entity }
+ end
end
end
@@ -124,18 +142,27 @@ class InstancesController < ApplicationController
end
flash[:success] = t('instances.deleted', :list => destroyed.to_sentence, :count => destroyed.size) if destroyed.present?
flash[:error] = t('instances.not_deleted', :list => failed.to_sentence, :count => failed.size) if failed.present?
- render :action => :show
+ respond_to do |format|
+ format.html { render :action => :show }
+ format.json { render :json => {:success => destroyed, :errors => failed} }
+ end
end
def key
- unless @instance.instance_key.nil?
- send_data @instance.instance_key.pem,
- :filename => "#{(a)instance.instance_key.name}.pem",
- :type => "text/plain"
- return
+ respond_to do |format|
+ if @instance.instance_key.nil?
+ flash[:warning] = "SSH Key not found for this Instance."
+ format.html { redirect_to instance_path(@instance) }
+ format.json { render :json => flash[:warning], :status => :not_found }
+ else
+ format.html { send_data @instance.instance_key.pem,
+ :filename => "#{(a)instance.instance_key.name}.pem",
+ :type => "text/plain" }
+ format.json { render :json => {:key => @instance.instance_key.pem,
+ :filename => "#{(a)instance.instance_key.name}.pem",
+ :type => "text/plain" } }
+ end
end
- flash[:warning] = "SSH Key not found for this Instance."
- redirect_to instance_path(@instance)
end
def multi_stop
@@ -162,7 +189,10 @@ class InstancesController < ApplicationController
end
flash[:notice] = notices unless notices.blank?
flash[:error] = errors unless errors.blank?
- redirect_to instances_path
+ respond_to do |format|
+ format.html { redirect_to instances_path }
+ format.json { render :json => {:success => notices, :errors => errors} }
+ end
end
def remove_failed
@@ -181,36 +211,53 @@ class InstancesController < ApplicationController
end
flash[:notice] = notices unless notices.blank?
flash[:error] = errors unless errors.blank?
- redirect_to instances_path
+ respond_to do |format|
+ format.html { redirect_to instances_path }
+ format.json { render :json => {:success => notices, :errors => errors}, :status => :unprocessable_entity }
+ end
end
def can_create
- begin
- provider_account = ProviderAccount.find(params[:provider_account_id])
- @instance = Instance.find(params[:instance_id])
- @action_request = "can_create"
- @value = Quota.can_create_instance?(@instance, provider_account)
- render :partial => 'can_perform_state_change.xml'
- rescue ActiveRecord::RecordNotFound
- head :not_found
- rescue Exception
- head :internal_server_error
+ respond_to do |format|
+ begin
+ provider_account = ProviderAccount.find(params[:provider_account_id])
+ @instance = Instance.find(params[:instance_id])
+ @action_request = "can_create"
+ @value = Quota.can_create_instance?(@instance, provider_account)
+ format.html { render :partial => 'can_perform_state_change.xml' }
+ format.json { render :json => {:action_request => @action_request, :instance_id => @instance.id, :value => @value} }
+ rescue ActiveRecord::RecordNotFound
+ format.html { head :not_found }
+ format.json { render :json => {:error => 'Record not found'}, :status => :not_found }
+ rescue Exception
+ format.html { head :internal_server_error }
+ format.json { render :json => {:error => $!}, :status => :internal_server_error }
+ end
end
end
def can_start
- begin
- provider_account = ProviderAccount.find(params[:provider_account_id])
- @instance = Instance.find(params[:instance_id])
- @action_request = "can_start"
- @value = Quota.can_start_instance?(@instance, provider_account)
- render :partial => 'can_perform_state_change.xml'
- rescue ActiveRecord::RecordNotFound => e
- puts e.inspect
- head :not_found
- rescue Exception => e
- puts e.inspect
- head :internal_server_error
+ respond_to do |format|
+ begin
+ provider_account = ProviderAccount.find(params[:provider_account_id])
+ @instance = Instance.find(params[:instance_id])
+ @action_request = "can_start"
+ @value = Quota.can_start_instance?(@instance, provider_account)
+ format.html { render :partial => 'can_perform_state_change.xml' }
+ format.json { render :json => {:action_request => @action_request, :instance_id => @instance.id, :value => @value} }
+ rescue ActiveRecord::RecordNotFound => e
+ format.html do
+ puts e.inspect
+ head :not_found
+ end
+ format.json { render :json => {:error => 'Record not found'}, :status => :not_found }
+ rescue Exception => e
+ format.html do
+ puts e.inspect
+ head :internal_server_error
+ end
+ format.json { render :json => {:error => $!}, :status => :internal_server_error }
+ end
end
end
diff --git a/src/app/controllers/pools_controller.rb b/src/app/controllers/pools_controller.rb
index 0ccbf78..ea09745 100644
--- a/src/app/controllers/pools_controller.rb
+++ b/src/app/controllers/pools_controller.rb
@@ -7,13 +7,13 @@ class PoolsController < ApplicationController
@search_term = params[:q]
if @search_term.blank?
load_pools
- return
+ else
+ @pools = Pool.search() { keywords(params[:q]) }.results
end
-
- search = Pool.search() do
- keywords(params[:q])
+ respond_to do |format|
+ format.html
+ format.json { render :json => @pools }
end
- @pools = search.results
end
def show
@@ -31,6 +31,7 @@ class PoolsController < ApplicationController
render :partial => @details_tab and return
end
format.html { render :action => 'show'}
+ format.json { render :json => @pool }
end
end
@@ -38,6 +39,10 @@ class PoolsController < ApplicationController
require_privilege(Privilege::CREATE, Pool)
@pool = Pool.new
@quota = Quota.new
+ respond_to do |format|
+ format.html
+ format.json { render :json => @pool }
+ end
end
def create
@@ -49,13 +54,17 @@ class PoolsController < ApplicationController
limit = params[:quota][:maximum_running_instances] if params[:quota]
@pool.quota.set_maximum_running_instances(limit)
- if @pool.save
- @pool.assign_owner_roles(current_user)
- flash[:notice] = "Pool added."
- redirect_to :action => 'show', :id => @pool.id
- else
- flash.now[:warning] = "Pool creation failed."
- render :new and return
+ respond_to do |format|
+ if @pool.save
+ @pool.assign_owner_roles(current_user)
+ flash[:notice] = "Pool added."
+ format.html { redirect_to :action => 'show', :id => @pool.id }
+ format.json { render :json => @pool, :status => :created }
+ else
+ flash.now[:warning] = "Pool creation failed."
+ format.html { render :new }
+ format.json { render :json => @pool.errors, :status => :unprocessable_entity }
+ end
end
end
@@ -63,6 +72,10 @@ class PoolsController < ApplicationController
@pool = Pool.find(params[:id])
require_privilege(Privilege::MODIFY, @pool)
@quota = @pool.quota
+ respond_to do |format|
+ format.html
+ format.json { render :json => @pool }
+ end
end
def update
@@ -72,12 +85,16 @@ class PoolsController < ApplicationController
limit = params[:quota][:maximum_running_instances] if params[:quota]
@pool.quota.set_maximum_running_instances(limit)
- if @pool.update_attributes(params[:pool])
- flash[:notice] = "Pool updated."
- redirect_to :action => 'show', :id => @pool.id
- else
- flash[:error] = "Pool wasn't updated!"
- render :action => :edit
+ respond_to do |format|
+ if @pool.update_attributes(params[:pool])
+ flash[:notice] = "Pool updated."
+ format.html { redirect_to :action => 'show', :id => @pool.id }
+ format.json { render :json => @pool }
+ else
+ flash[:error] = "Pool wasn't updated!"
+ format.html { render :action => :edit }
+ format.json { render :json => @pool.errors, :status => :unprocessable_entity }
+ end
end
end
@@ -97,7 +114,10 @@ class PoolsController < ApplicationController
end
flash[:success] = t('pools.index.pool_deleted', :list => destroyed.to_sentence, :count => destroyed.size) if destroyed.present?
flash[:error] = t('pools.index.pool_not_deleted', :list => failed.to_sentence, :count => failed.size) if failed.present?
- redirect_to instances_url
+ respond_to do |format|
+ format.html { redirect_to pools_url }
+ format.json { render :json => {:success => destroyed, :errors => failed} }
+ end
end
def multi_destroy
@@ -127,7 +147,10 @@ class PoolsController < ApplicationController
unless error_messages.empty?
flash[:error] = error_messages.join('<br />')
end
- redirect_to pools_url
+ respond_to do |format|
+ format.html { redirect_to pools_url }
+ format.json { render :json => {:success => destroyed, :errors => failed} }
+ end
end
protected
diff --git a/src/features/deployment.feature b/src/features/deployment.feature
index b98505d..3907c5e 100644
--- a/src/features/deployment.feature
+++ b/src/features/deployment.feature
@@ -49,3 +49,30 @@ Feature: Manage Deployments
And I press "Save"
Then I should be on Jenkins's deployment page
And I should see "Jenkins"
+
+ Scenario: View all deployments in JSON format
+ Given There is a mock pulp repository
+ And there are 2 deployments
+ And I accept JSON
+ When I go to the deployments page
+ Then I should see 2 deployments in JSON format
+
+ Scenario: View a deployment in JSON format
+ Given There is a mock pulp repository
+ And a deployment "mockdeployment" exists
+ And I accept JSON
+ When I am viewing the deployment "mockdeployment"
+ Then I should see deployment "mockdeployment" in JSON format
+
+ Scenario: Create a deployment and get JSON response
+ Given There is a mock pulp repository
+ And I accept JSON
+ When I create a deployment
+ Then I should get back a deployment in JSON format
+
+ Scenario: Stop a deployment
+ Given a deployment "mockdeployment" exists
+ And There is a mock pulp repository
+ And I accept JSON
+ When I stop "mockdeployment" deployment
+ Then I should get back JSON object with success and errors
diff --git a/src/features/instance.feature b/src/features/instance.feature
index 8ba3251..9b05a2b 100644
--- a/src/features/instance.feature
+++ b/src/features/instance.feature
@@ -153,4 +153,27 @@ Feature: Mange Instances
And I fill in "name" with "Tomcat"
And I press "Save"
Then I should be on Tomcat's instance page
- And I should see "Tomcat"
\ No newline at end of file
+ And I should see "Tomcat"
+
+ Scenario: View all instances in JSON format
+ Given there are 2 instances
+ And I accept JSON
+ When I go to the instances page
+ Then I should see 2 instances in JSON format
+
+ Scenario: View an instance in JSON format
+ Given a mock running instance exists
+ And I accept JSON
+ When I am viewing the mock instance
+ Then I should see mock instance in JSON format
+
+ Scenario: Create an instance and get JSON response
+ Given I accept JSON
+ When I create mock instance
+ Then I should get back instance in JSON format
+
+ Scenario: Stop an instance
+ Given there is a "mock1" running instance
+ And I accept JSON
+ When I stop "mock1" instance
+ Then I should get back JSON object with success and errors
diff --git a/src/features/pool.feature b/src/features/pool.feature
index 534e69c..55aab9f 100644
--- a/src/features/pool.feature
+++ b/src/features/pool.feature
@@ -48,8 +48,8 @@ Feature: Manage Pools
Given I am on the pools page
And a pool "Amazon Startrek Pool" exists
And a pool "Redhat Voyager Pool" exists
- And I am on the pools page
- And there are 3 pools
+ When I go to the pools page
+ Then there should be 3 pools
When I check "Redhat Voyager Pool" pool
And I check "Amazon Startrek Pool" pool
And I press "Destroy"
@@ -100,3 +100,26 @@ Feature: Manage Pools
And I press "Destroy"
Then I should see "The default pool cannot be deleted"
And I should see "pool_default"
+
+ Scenario: View all pools in JSON format
+ Given there are 2 pools
+ And I accept JSON
+ When I go to the pools page
+ Then I should see 2 pools in JSON format
+
+ Scenario: View a pool in JSON format
+ Given a pool "mockpool" exists
+ And I accept JSON
+ When I am viewing the pool "mockpool"
+ Then I should see pool "mockpool" in JSON format
+
+ Scenario: Create a pool and get JSON response
+ Given I accept JSON
+ When I create a pool
+ Then I should get back a pool in JSON format
+
+ Scenario: Delete a pool
+ Given a pool "mockpool" exists
+ And I accept JSON
+ When I delete "mockpool" pool
+ Then I should get back JSON object with success and errors
diff --git a/src/features/step_definitions/deployment_steps.rb b/src/features/step_definitions/deployment_steps.rb
index 343e7c8..465cbbb 100644
--- a/src/features/step_definitions/deployment_steps.rb
+++ b/src/features/step_definitions/deployment_steps.rb
@@ -8,3 +8,46 @@ When /^I check "([^"]*)" deployment/ do |name|
deployment = Deployment.find_by_name(name)
check("deployment_checkbox_#{deployment.id}")
end
+
+Given /^there are (\d+) deployments$/ do |arg1|
+ Deployment.all.each {|i| i.destroy}
+ arg1.to_i.times do |i|
+ Factory :deployment, :name => "deployment#{i}"
+ end
+end
+
+Then /^I should see (\d+) deployments in JSON format$/ do |arg1|
+ data = ActiveSupport::JSON.decode(response.body)
+ data.length.should == arg1.to_i
+end
+
+Given /^a deployment "([^"]*)" exists$/ do |arg1|
+ Factory(:deployment, :name => arg1) unless Deployment.find_by_name(arg1)
+end
+
+When /^I am viewing the deployment "([^"]*)"$/ do |arg1|
+ visit deployment_url(Deployment.find_by_name(arg1))
+end
+
+Then /^I should see deployment "([^"]*)" in JSON format$/ do |arg1|
+ depl = Deployment.find_by_name(arg1)
+ data = ActiveSupport::JSON.decode(response.body)
+ data['deployment']['name'].should == depl.name
+end
+
+When /^I create a deployment$/ do
+ deployment = Factory.build :deployment
+ deployment.pool.save!
+ deployment.deployable.save!
+ visit(deployments_url, :post, 'deployment[name]' => deployment.name,
+ 'deployment[pool_id]' => deployment.pool.id, 'deployment[deployable_id]' => deployment.deployable.id)
+end
+
+Then /^I should get back a deployment in JSON format$/ do
+ data = ActiveSupport::JSON.decode(response.body)
+ data['deployment'].should_not be_nil
+end
+
+When /^I stop "([^"]*)" deployment$/ do |arg1|
+ visit(multi_stop_deployments_url, :post, 'deployments_selected[]' => Deployment.find_by_name(arg1).id)
+end
diff --git a/src/features/step_definitions/instance_steps.rb b/src/features/step_definitions/instance_steps.rb
index c4ceb0c..b3c9eed 100644
--- a/src/features/step_definitions/instance_steps.rb
+++ b/src/features/step_definitions/instance_steps.rb
@@ -22,6 +22,10 @@ When /^I am viewing the pending instance detail$/ do
visit instance_url(pending_instance)
end
+When /^I am viewing the mock instance$/ do
+ visit instance_url(mock_instance)
+end
+
When /^I manually go to the key action for this instance$/ do
visit key_instance_url(pending_instance)
end
@@ -95,7 +99,42 @@ end
Given /^there are (\d+) instances$/ do |count|
+ Instance.all.each {|i| i.destroy}
count.to_i.times do |i|
- Factory :mock_running_instance, :name => "inst#{i}"
+ Factory :mock_pending_instance, :name => "inst#{i}"
end
end
+
+Given /^I accept JSON$/ do
+ header 'Accept', 'application/json'
+end
+
+Then /^I should see (\d+) instances in JSON format$/ do |count|
+ ActiveSupport::JSON.decode(response.body).length.should == count.to_i
+end
+
+When /^I create mock instance$/ do
+ inst = Factory.build :mock_running_instance
+ visit instances_url, :post, 'instance[name]' => inst.name, 'instance[template_id]' => inst.template_id
+end
+
+Then /^I should see mock instance in JSON format$/ do
+ data = ActiveSupport::JSON.decode(response.body)
+ data['instance']['name'].should == mock_instance.name
+end
+
+Then /^I should get back instance in JSON format$/ do
+ data = ActiveSupport::JSON.decode(response.body)
+ data['instance'].should_not be_nil
+end
+
+When /^I stop "([^"]*)" instance$/ do |arg1|
+ inst = Instance.find_by_name(arg1)
+ visit multi_stop_instances_url, :post, 'instance_selected[]' => inst.id
+end
+
+Then /^I should get back JSON object with success and errors$/ do
+ data = ActiveSupport::JSON.decode(response.body)
+ data['success'].should_not be_nil
+ data['errors'].should_not be_nil
+end
diff --git a/src/features/step_definitions/pool_steps.rb b/src/features/step_definitions/pool_steps.rb
index f2a813a..11db612 100644
--- a/src/features/step_definitions/pool_steps.rb
+++ b/src/features/step_definitions/pool_steps.rb
@@ -8,7 +8,7 @@ Given /^I have Pool Creator permissions on a pool named "([^\"]*)"$/ do |name|
Factory(:pool_creator_permission, :user => @user, :permission_object => @pool)
end
-Given /^there are (\d+) pools$/ do |number|
+Then /^there should be (\d+) pools$/ do |number|
Pool.count.should == number.to_i
end
@@ -61,3 +61,40 @@ Given /^I renamed default_pool to pool_default$/ do
p.name = "pool_default"
p.save
end
+
+Then /^I should see (\d+) pools in JSON format$/ do |arg1|
+ data = ActiveSupport::JSON.decode(response.body)
+ data.length.should == arg1.to_i
+end
+
+When /^I am viewing the pool "([^"]*)"$/ do |arg1|
+ visit pool_url(Pool.find_by_name(arg1))
+end
+
+Then /^I should see pool "([^"]*)" in JSON format$/ do |arg1|
+ pool = Pool.find_by_name(arg1)
+ data = ActiveSupport::JSON.decode(response.body)
+ data['pool']['name'].should == pool.name
+end
+
+When /^I create a pool$/ do
+ pool = Factory.build :pool
+ pool.pool_family.save!
+ visit pools_url, :post, 'pool[name]' => pool.name, 'pool[pool_family_id]' => pool.pool_family.id
+end
+
+Then /^I should get back a pool in JSON format$/ do
+ data = ActiveSupport::JSON.decode(response.body)
+ data['pool'].should_not be_nil
+end
+
+When /^I delete "([^"]*)" pool$/ do |arg1|
+ visit(multi_destroy_pools_url, :post, 'pools_selected[]' => Pool.find_by_name(arg1).id)
+end
+
+Given /^there are (\d+) pools$/ do |arg1|
+ Pool.all.each {|i| i.destroy}
+ arg1.to_i.times do |i|
+ Factory :pool, :name => "pool#{i}"
+ end
+end
--
1.7.4
12 years, 11 months
RPM config for connector
by Jason Guiditta
[PATCH conductor] Issue #1433: Update rpm spec to put config file in
Aside from verifying that updated rpm has new version and installs properly,
this can be verified by running a full aeolus setup on two machines. Since
puppet does not yet configure this for you, you will need to manually edit
the appropriate yml files and open ports in your firewall as needed. I made
the following changes to test this:
== Machine 1 (runs imagefactory and connector) ==
* set the warehouse url in /etc/imagefactory.conf to Machine 2
* set the url in /etc/aeolus_connector.yml to Machine 2
* open port 2003 in /etc/sysconfig/iptables with:
-A INPUT -m state --state NEW -m tcp -p tcp --dport 2003 -j ACCEPT
* restart iptables, aeolus-connector, and imagefactory services
== Machine 2 (runs iwhd and conductor) ==
* set the urls in /usr/share/aeolus-conductor/config/image_factory_console.yml to Machine 1
* set the url in /usr/share/aeolus-conductor/config/image_warehouse.yml to Machine 1
* open port 9090 in /etc/sysconfig/iptables with:
-A INPUT -m state --state NEW -m tcp -p tcp --dport 9090 -j ACCEPT
* restart iptables
* restart aeolus services
* note that I had to actually restart machine 2 for some of these settings to pick up, unsure
if this behavior will be consistent for others
You should now be set up to run aeolus on multiple machines.
-j
12 years, 11 months
ViewState on the controller side (rev. 1)
by Tomas Sedovic
This adds some filters and helper methods for an easy declaration and use of
view states.
2 main things still missing:
* while we have the viewstate model prepared, this code is not accessing the
database yet
* dynamic routing (and therefore the viewstate API in general)
However, the support for the JS-impaired users is there and while not clean
or fast, it should work everywhere.
To declare a controller action as stateful, put something like this into the
controler definition:
viewstate :index do |default|
default.merge!({
:pretty_view => true,
:order_field => 'name',
:order_dir => 'asc',
:page => 1
})
end
and it should all work. That is done by the `handle_viewstate` before_filter,
which the `viewstate` class method sets up automatically.
Note that the filter merges new params to the current viewstate and does
redirects.
Should that be a problem, one can `skip_filter` and use the provided viewstate
methods directly for a desired behaviour.
To test this patch, I recommend using Incoginto or somesuch mode in your browser.
You can add this code to views/layouts/application.haml to see how the session
viewstate changes:
#viewstate
viewstate:
- if @viewstate
= @viewstate.id
= @viewstate.state.inspect
12 years, 11 months
Breadcrumb trail for site navigation rev.1
by Jirka Tomasek
This patch implements Redmine tasks #1351 and #1352 Breadcrumbs are
defined to work for Pools, Instances and Deployments. ViewState
functionality is integrated, although it depends on its final
implementation.
12 years, 11 months
Breadcrumb trail for site navigation
by Jirka Tomasek
This patch implements Redmine tasks #1351 and #1352
Its not finished yet, just sending for reference. I need to implement
viewstate integration and marking related viewstate for deletion when
breadcrumb is shifted.
12 years, 11 months
My dev setup
by Mark McLoughlin
Hey,
Before hacking on Aeolus, I wanted to have a dev setup where:
- I build and run all the main Aeolus-specific bits from git, to make
it easy to debug and modify anything I need. I figure I want
conductor, deltacloud, iwhd and image factory
- I want to do as much as non-root as possible to avoid needing to
change system configuration or screwing up a RPM/puppet install
of Aeolus
- I want to have all the various daemons running in the foreground to
make it easy to keep an eye on logs, kill them if needed or debug
them
- I want to avoid as much "magic" going on as possible - even if
means making some work for myself, I'd prefer to get a feel for all
the pieces of the system rather than having something done
automatically that I don't know about
My notes below. I'd have put them here:
http://www.aeolusproject.org/page/Development_Setup
but perhaps this is too sadistic a setup to be generally recommended?
Thoughts?
Cheers,
Mark.
First up, we need to enable the aeolus RPM repository which we'll pull
various dependencies from:
$> sudo wget -O /etc/yum.repos.d/fedora-aeolus.repo http://repos.fedorapeople.org/repos/aeolus/packages/fedora-aeolus.repo
Next, create an aeolus directory:
$> mkdir aeolus
Set up image factory:
$> cd aeolus
$> git clone git://github.com/jacobian/python-cloudservers.git
$> git clone git://github.com/clalancette/oz.git
$> git clone git://github.com/aeolusproject/image_factory
$> yum install -y python-qmf python-zope-interface python-libguestfs
$> service qpidd start
$> cd image_factory
$> PYTHONPATH=../oz/:../python-cloudservers/ ./imgfac.py --debug --foreground --qmf
IWHD:
$> cd aeolus
$> git clone git://git.fedorahosted.org/iwhd.git
$> yum install -y jansson-devel libmicrohttpd-devel hail-devel gc-devel gperf mongodb-devel
$> cd iwhd
$> ./boostrap
$> ./configure --prefix=/usr --localstatedir=/var --sysconfdir=/etc
$> make check
$> ./iwhd -a
Deltacloud:
$> cd aeolus
$> git clone git://git.apache.org/deltacloud.git
$> yum install -y rubygem-net-ssh rubygem-haml
$> cd deltacloud/server
$> ./bin/deltacloudd -i mock -p 3002
$> ./bin/deltacloudd -i ec2 -p 3003 --provider us-east-1
$> ./bin/deltacloudd -i ec2 -p 3004 --provider us-west-1
Conductor:
$> cd aeolus
$> git clone git://git.fedorahosted.org/git/aeolus/conductor.git -b next
$> cd conductor
$> yum install -y rubygem-delayed_job ruby-sqlite3 rubygem-net-scp
$> yum install -y rubygem-sunspot_rails
$> cp config/database.sqlite config/database.yml
$> rake sunspot:solr:start
$> rake dc:setup
$> rake sunspot:reindex
$> ./script/server -P /conductor server
Condor:
$> cd aeolus/conductor
$> yum install -u classads-devel rest-devel
$> ./autogen.sh --prefix=/usr --sysconfdir=/etc --localstatedir=/var
$> make install # as root
$> cp ~markmc/projects/aeolus/configure/recipes/aeolus_recipe/files/condor_config.local /var/lib/condor/condor_config.local
$> service condor start
Check for any stale jobs and remove them:
$> condor_q
$> condor_rm -all
dbomatic:
$> cd aeolus/conductor/src/dbomatic
$> ./dbomatic -f . -r . -l - -n
condor_refreshd:
$> cd aeolus/conductor/src/condor_refreshd
$> ./condor_refreshd -f . -l - -n
warehouse_sync:
$> cd aeolus/conductor/src/warehouse_sync
$> ./warehouse_sync-server -f . -l - -n
delayed_job:
$> cd aeolus/conductor/src
$> ./script/delayed_job run
Set up providers and a hardware profile:
$> /usr/bin/curl -c /tmp/aeolus-admin.cookie -f -i --location --post301 --post302 -d user_session[login]=admin -d user_session[password]=password -d commit=submit -X POST http://localhost:3000/user_session
$> /usr/bin/curl -b /tmp/aeolus-admin.cookie -f -i --silent --location --post301 --post302 -H 'Accept: application/xml' -d provider[name]=mock -d provider[url]=http://localhost:3002/api -d provider[provider_type_codename]=mock -X POST http://localhost:3000/admin/providers
$> /usr/bin/curl -b /tmp/aeolus-admin.cookie -f -i --silent --location --post301 --post302 -H 'Accept: application/xml' -d provider[name]=ec2-us-east-1 -d provider[url]=http://localhost:3003/api -d provider[provider_type_codename]=ec2 -X POST http://localhost:3000/admin/providers
$> /usr/bin/curl -b /tmp/aeolus-admin.cookie -f -i --silent --location --post301 --post302 -H 'Accept: application/xml' -d provider[name]=ec2-us-west-1 -d provider[url]=http://localhost:3004/api -d provider[provider_type_codename]=ec2 -X POST http://localhost:3000/admin/providers
$> /usr/bin/curl -b /tmp/aeolus-admin.cookie -f -i --silent --location --post301 --post302 -H 'Accept: application/xml' -d hardware_profile[name]=hwp1 -d hardware_profile[memory_attributes][value]=1 -d hardware_profile[cpu_attributes][value]=1 -d hardware_profile[storage_attributes][value]=1 -d hardware_profile[architecture_attributes][value]=x86_64 -d hardware_profile[memory_attributes][name]=memory -d hardware_profile[memory_attributes][unit]=MB -d hardware_profile[cpu_attributes][name]=cpu -d hardware_profile[cpu_attributes][unit]=count -d hardware_profile[storage_attributes][name]=storage -d hardware_profile[storage_attributes][unit]=GB -d hardware_profile[architecture_attributes][name]=architecture -d hardware_profile[architecture_attributes][unit]=label -d commit=Save -X POST http://localhost:3000/admin/hardware_profiles
$> /usr/bin/curl -c /tmp/aeolus-admin.cookie -f -i --location http://localhost:3000/logout
Now you should be able to login through http://localhost:3000 with
username 'admin' and password 'password'.
Do some basic testing by:
1) Adding a provider account for each of the three providers
2) Importing an image from http://fedoraproject.org/wiki/Cloud_SIG/EC2_Images
3) Starting an EC2 instance the image
12 years, 11 months
ViewState on the controller side
by Tomas Sedovic
More a stab at the general direction rather than a final code. It needs to be
put into proper places and I'm sure I've missed stuff out.
But hopefully you guys can look at it if it make sense and yell at me if it
doesn't.
Thomas
12 years, 11 months