From: marios marios@redhat.com
--- server/deltacloud.rb | 1 + server/lib/deltacloud/base_driver/base_driver.rb | 17 ++++ server/lib/deltacloud/base_driver/features.rb | 6 ++ server/server.rb | 86 ++++++++++++++++++++-- server/views/api/show.html.haml | 2 + 5 files changed, 104 insertions(+), 8 deletions(-)
diff --git a/server/deltacloud.rb b/server/deltacloud.rb index 1c19a5d..dd23ef0 100644 --- a/server/deltacloud.rb +++ b/server/deltacloud.rb @@ -12,3 +12,4 @@ require 'deltacloud/models/instance' require 'deltacloud/models/instance_profile' require 'deltacloud/models/storage_snapshot' require 'deltacloud/models/storage_volume' +require 'deltacloud/models/access_rule' diff --git a/server/lib/deltacloud/base_driver/base_driver.rb b/server/lib/deltacloud/base_driver/base_driver.rb index a2b3bbe..daa58c1 100644 --- a/server/lib/deltacloud/base_driver/base_driver.rb +++ b/server/lib/deltacloud/base_driver/base_driver.rb @@ -154,6 +154,23 @@ module Deltacloud def reboot_instance(credentials, id) end
+ + def access_rules(credentials, opts) + [] + end + + def access_rule(credentials, opts) + rules = access_rules(credentials, opts) + return rules.first unless rules.empty? + nil + end + + def create_access_rule(credentials, opts) + end + def delete_access_rule(credentials, opts) + end + + def storage_volume(credentials, opts) volumes = storage_volumes(credentials, opts) return volumes.first unless volumes.empty? diff --git a/server/lib/deltacloud/base_driver/features.rb b/server/lib/deltacloud/base_driver/features.rb index 8ad354a..9fac444 100644 --- a/server/lib/deltacloud/base_driver/features.rb +++ b/server/lib/deltacloud/base_driver/features.rb @@ -155,5 +155,11 @@ module Deltacloud description "Size instances according to changes to a hardware profile" # The parameters are filled in from the hardware profiles end + + declare_feature :access_rules, :show do + operation :index do + + end + end end end diff --git a/server/server.rb b/server/server.rb index b5bdfac..4844746 100644 --- a/server/server.rb +++ b/server/server.rb @@ -65,6 +65,8 @@ def show(model) end
+ + # # Error handlers # @@ -108,7 +110,58 @@ get '/api/?' do end end
+get '/api/access_rules/:id/destroy' do + method = "delete_access_rule" + not_found unless driver.respond_to?(method) + opts = {} + opts[:id] = params[:id] + driver.send(method, credentials, opts) + redirect access_rules_url +end + +get '/api/access_rules/new' do + respond_to do |format| + format.html { haml :"access_rules/new" } + end +end + + +def delete_access_rule(service_id) + driver.send(delete_access_rule, credentials, {:id => params[:id]}) +end + # Rabbit DSL +collection :access_rules do + + description "Allow user to expose a public IP address/port and map these onto an internal IP address/port. eg expose ssh access [port 22, tcp]." + operation :index do + description 'Show all available network services' + control { filter_all(:access_rules) } + end + + operation :show do + description 'Show a access rule identified by its id' + param :id, :string, :required + control { show(:access_rule) } + end + + operation :create do + description 'Create a new access rule' + param :protocol, :string, :required + param :port, :string, :required + param :instance_group, :string, :required + control do + driver.create_access_rule(credentials, params ) + filter_all(:access_rules) + end + end + + operation :destroy, :method => :post do + description 'destroy given access rule' + param :id, :string, :required + control { delete_access_rule(:id) } + end +end
collection :realms do description "Within a cloud provider a realm represents a boundary containing resources. The exact definition of a realm is left to the cloud provider. In some cases, a realm may represent different datacenters, different continents, or different pools of resources within a single datacenter. A cloud provider may insist that resources must all exist within a single realm in order to cooperate. For instance, storage volumes may only be allowed to be mounted to instances within the same realm." @@ -186,6 +239,22 @@ collection :instance_states do end end
+# Special instance get operations that we only allow for HTML +get "/api/instances/:id/:action" do + meth = :"#{params[:action]}_instance" + not_found unless driver.respond_to?(meth) + respond_to do |format| + format.html do + driver.send(meth, credentials, params[:id]) + if ( (params[:action] == 'destroy') or (params[:action] == 'stop') ) + redirect instances_url + else + redirect instance_url(params[:id]) + end + end + end +end + get "/api/instances/new" do @instance = Instance.new( { :id=>params[:id], :image_id=>params[:image_id] } ) @image = driver.image( credentials, :id => params[:image_id] ) @@ -197,14 +266,15 @@ get "/api/instances/new" do end
def instance_action(name) - @instance = driver.send(:"#{name}_instance", credentials, params["id"]) - - return redirect(instances_url) if name.eql?(:destroy) or @instance.class!=Instance - - respond_to do |format| - format.html { haml :"instances/show" } - format.xml { haml :"instances/show" } - format.json {convert_to_json(:instance, @instance) } + @instance = driver.send(:"#{name}_instance", credentials, params[:id]) + if name==:destroy or name==:stop + redirect instances_url + else + respond_to do |format| + format.html { haml :"instances/show" } + format.xml { haml :"instances/show" } + format.json {convert_to_json(:instance, @instance) } + end end end
diff --git a/server/views/api/show.html.haml b/server/views/api/show.html.haml index 455e919..19d2af7 100644 --- a/server/views/api/show.html.haml +++ b/server/views/api/show.html.haml @@ -4,6 +4,8 @@ %ul - collections.keys.sort_by { |k| k.to_s }.each do |key| %li + - if key == :access_rules + - next if driver.features(key).empty? = link_to key.to_s.gsub('_', ' ').titlecase, url_for("/api/#{key}") %dl - collections[key].operations.each_key do |op|