You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@deltacloud.apache.org by mf...@redhat.com on 2011/12/09 13:52:15 UTC

[PATCH core 2/2] Core: Added support for dynamic provider list in /api/drivers/:id

From: Michal Fojtik <mf...@redhat.com>

Signed-off-by: Michal fojtik <mf...@redhat.com>
---
 server/lib/deltacloud/base_driver/base_driver.rb   |    1 +
 .../lib/deltacloud/drivers/rhevm/rhevm_client.rb   |    4 +-
 server/lib/deltacloud/models.rb                    |    1 +
 server/lib/deltacloud/models/provider.rb           |   27 ++++++++++++++++++++
 server/lib/deltacloud/server.rb                    |    1 +
 server/views/drivers/show.xml.haml                 |   13 ++++++---
 6 files changed, 41 insertions(+), 6 deletions(-)
 create mode 100644 server/lib/deltacloud/models/provider.rb

diff --git a/server/lib/deltacloud/base_driver/base_driver.rb b/server/lib/deltacloud/base_driver/base_driver.rb
index 68003ed..5620a30 100644
--- a/server/lib/deltacloud/base_driver/base_driver.rb
+++ b/server/lib/deltacloud/base_driver/base_driver.rb
@@ -159,6 +159,7 @@ module Deltacloud
     # def delete_firewall(credentials, opts)
     # def create_firewall_rule(credentials, opts)
     # def delete_firewall_rule(credentials, opts)
+    # def providers(credentials)
     def realm(credentials, opts)
       realms = realms(credentials, opts).first if has_capability?(:realms)
     end
diff --git a/server/lib/deltacloud/drivers/rhevm/rhevm_client.rb b/server/lib/deltacloud/drivers/rhevm/rhevm_client.rb
index 47a7ef5..e0efc0e 100644
--- a/server/lib/deltacloud/drivers/rhevm/rhevm_client.rb
+++ b/server/lib/deltacloud/drivers/rhevm/rhevm_client.rb
@@ -58,8 +58,8 @@ module RHEVM
       }
       headers.merge!(auth_header)
       if opts[:id]
-        return [] unless current_datacenter.cluster_ids.include?((vm/'cluster').first[:id])
         vm = Client::parse_response(RHEVM::client(@api_entrypoint)["/vms/%s" % opts[:id]].get(headers)).root
+        return [] unless current_datacenter.cluster_ids.include?((vm/'cluster').first[:id])
         [ RHEVM::VM::new(self, vm)]
       else
         Client::parse_response(RHEVM::client(@api_entrypoint)["/vms"].get(headers)).xpath('/vms/vm').collect do |vm|
@@ -73,7 +73,7 @@ module RHEVM
       headers.merge!(auth_header)
       headers.merge!({:accept => 'application/xml'})
       vm = vms(:id => id)
-      raise RHEVMBackendException::new("Requested VM not found in datacenter #{self.current_datacenter.id}") if vm.empty
+      raise RHEVMBackendException::new("Requested VM not found in datacenter #{self.current_datacenter.id}") if vm.empty?
       if action==:delete
         RHEVM::client(@api_entrypoint)["/vms/%s" % id].delete(headers)
       else
diff --git a/server/lib/deltacloud/models.rb b/server/lib/deltacloud/models.rb
index e8cd035..a794192 100644
--- a/server/lib/deltacloud/models.rb
+++ b/server/lib/deltacloud/models.rb
@@ -29,3 +29,4 @@ require 'deltacloud/models/blob'
 require 'deltacloud/models/load_balancer'
 require 'deltacloud/models/firewall'
 require 'deltacloud/models/firewall_rule'
+require 'deltacloud/models/provider'
diff --git a/server/lib/deltacloud/models/provider.rb b/server/lib/deltacloud/models/provider.rb
new file mode 100644
index 0000000..1fc2c7d
--- /dev/null
+++ b/server/lib/deltacloud/models/provider.rb
@@ -0,0 +1,27 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.  The
+# ASF licenses this file to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance with the
+# License.  You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+# Model to store the hardware profile applied to an instance together with
+# any instance-specific overrides
+
+class Provider < BaseModel
+  attr_accessor :url
+  attr_accessor :name
+
+  def initialize(opts={})
+    super(opts)
+  end
+
+end
diff --git a/server/lib/deltacloud/server.rb b/server/lib/deltacloud/server.rb
index f636d14..88250a6 100644
--- a/server/lib/deltacloud/server.rb
+++ b/server/lib/deltacloud/server.rb
@@ -148,6 +148,7 @@ EOS
     param :id,      :string
     control do
       @name = params[:id].to_sym
+      @providers = driver.providers(credentials) if driver.respond_to? :providers
       @driver = settings.drivers[@name]
       return [404, "Driver #{@name} not found"] unless @driver
       respond_to do |format|
diff --git a/server/views/drivers/show.xml.haml b/server/views/drivers/show.xml.haml
index ea5f508..3734c4d 100644
--- a/server/views/drivers/show.xml.haml
+++ b/server/views/drivers/show.xml.haml
@@ -1,7 +1,12 @@
 %driver{ :href => driver_url(@name), :id => @name }
   %name<
     = @driver[:name]
-  - driver_provider(@driver).each do |prov, details|
-    %provider{ :id => prov }
-      - details.each do |kind, url|
-        %entrypoint{ :kind => kind }<=cdata(url)
+  - if @providers.nil?
+    - driver_provider(@driver).each do |prov, details|
+      %provider{ :id => prov }
+        - details.each do |kind, url|
+          %entrypoint{ :kind => kind }<=cdata(url)
+  - else
+    - @providers.each do |p|
+      %provider{ :id => p.id }
+        %entrypoint{ :kind => p.name }<=p.url
-- 
1.7.4.4