deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dko...@apache.org
Subject git commit: FGCP: add mapping for GET system and system_templates
Date Sat, 23 Feb 2013 05:28:27 GMT
Updated Branches:
  refs/heads/master 0c3bc007e -> 022dd0b2c


FGCP: add mapping for GET system and system_templates


Project: http://git-wip-us.apache.org/repos/asf/deltacloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltacloud/commit/022dd0b2
Tree: http://git-wip-us.apache.org/repos/asf/deltacloud/tree/022dd0b2
Diff: http://git-wip-us.apache.org/repos/asf/deltacloud/diff/022dd0b2

Branch: refs/heads/master
Commit: 022dd0b2c227e82c97ee3e6ac9942591a18a883a
Parents: 0c3bc00
Author: Dies Koper <diesk@fast.au.fujitsu.com>
Authored: Fri Feb 22 17:35:41 2013 +1100
Committer: Dies Koper <diesk@fast.au.fujitsu.com>
Committed: Sat Feb 23 16:27:01 2013 +1100

----------------------------------------------------------------------
 server/lib/cimi/models/system.rb                   |    7 +-
 server/lib/cimi/models/system_template.rb          |    7 +-
 server/lib/deltacloud/drivers/fgcp/fgcp_driver.rb  |    1 +
 .../drivers/fgcp/fgcp_driver_cimi_methods.rb       |   74 +++++++++++++++
 .../drivers/mock/mock_driver_cimi_methods.rb       |   14 +--
 5 files changed, 87 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltacloud/blob/022dd0b2/server/lib/cimi/models/system.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/models/system.rb b/server/lib/cimi/models/system.rb
index c2b94db..e238259 100644
--- a/server/lib/cimi/models/system.rb
+++ b/server/lib/cimi/models/system.rb
@@ -39,13 +39,12 @@ class CIMI::Model::System < CIMI::Model::Base
   end
 
   def self.find(id, context)
-    systems = []
     if id == :all
       systems = context.driver.systems(context.credentials, {:env=>context})
     else
-      system = context.driver.systems(context.credentials, {:env=>context, :id=>id})
-      raise CIMI::Model::NotFound unless system
-      system
+      systems = context.driver.systems(context.credentials, {:env=>context, :id=>id})
+      raise CIMI::Model::NotFound unless systems.first
+      systems.first
     end
   end
 

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/022dd0b2/server/lib/cimi/models/system_template.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/models/system_template.rb b/server/lib/cimi/models/system_template.rb
index f252e28..09cd9b0 100644
--- a/server/lib/cimi/models/system_template.rb
+++ b/server/lib/cimi/models/system_template.rb
@@ -45,13 +45,12 @@ class CIMI::Model::SystemTemplate < CIMI::Model::Base
 
   class << self
     def find(id, context)
-      templates = []
       if id == :all
         templates = context.driver.system_templates(context.credentials, {:env=>context})
       else
-        template = context.driver.system_templates(context.credentials, {:env=>context,
:id=>id})
-        raise CIMI::Model::NotFound unless template
-        template
+        templates = context.driver.system_templates(context.credentials, {:env=>context,
:id=>id})
+        raise CIMI::Model::NotFound unless templates.first
+        templates.first
       end
     end
 

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/022dd0b2/server/lib/deltacloud/drivers/fgcp/fgcp_driver.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/drivers/fgcp/fgcp_driver.rb b/server/lib/deltacloud/drivers/fgcp/fgcp_driver.rb
index 8d29a8e..436cb50 100644
--- a/server/lib/deltacloud/drivers/fgcp/fgcp_driver.rb
+++ b/server/lib/deltacloud/drivers/fgcp/fgcp_driver.rb
@@ -17,6 +17,7 @@
 
 require_relative 'fgcp_client'
 require_relative '../../runner'
+require_relative 'fgcp_driver_cimi_methods'
 require 'openssl'
 require 'xmlsimple'
 

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/022dd0b2/server/lib/deltacloud/drivers/fgcp/fgcp_driver_cimi_methods.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/drivers/fgcp/fgcp_driver_cimi_methods.rb b/server/lib/deltacloud/drivers/fgcp/fgcp_driver_cimi_methods.rb
new file mode 100644
index 0000000..b4d31f6
--- /dev/null
+++ b/server/lib/deltacloud/drivers/fgcp/fgcp_driver_cimi_methods.rb
@@ -0,0 +1,74 @@
+#
+# 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.
+#
+#Definition of CIMI methods for the Fgcp driver - separation from deltacloud
+#API Fgcp driver methods
+
+module Deltacloud::Drivers::Fgcp
+
+  class FgcpDriver < Deltacloud::BaseDriver
+
+    #cimi features
+    feature :machines, :default_initial_state do
+      { :values => ["STOPPED"] }
+    end
+
+    def systems(credentials, opts={})
+      safely do
+        client = new_client(credentials)
+
+        if opts and opts[:id]
+          vsys_ids = [opts[:id]]
+        else
+          xml = client.list_vsys['vsyss']
+          return [] if xml.nil?
+          vsys_ids = xml[0]['vsys'].collect { |vsys| vsys['vsysId'][0] }
+        end
+
+        vsys_ids.collect do |vsys_id|
+          vsys = client.get_vsys_configuration(vsys_id)['vsys'][0]
+          vsys_description_el = vsys['description']
+          CIMI::Model::System.new(
+            :id          => vsys['vsysId'][0],
+            :name        => vsys['vsysName'][0],
+#            :machines    => "http://cimi.example.org/systems/#{vsys['vsysId'][0]}/machines?realm_id=#{vsys['vsysId'][0]}",
+#            :volumes     => "http://cimi.example.org/systems/#{vsys['vsysId'][0]}/volumes?realm_id=#{vsys['vsysId'][0]}",
+#            :networks    => "http://cimi.example.org/systems/#{vsys['vsysId'][0]}/networks?realm_id=#{vsys['vsysId'][0]}",
+#            :addresses   => "http://cimi.example.org/systems/#{vsys['vsysId'][0]}/addresses?realm_id=#{vsys['vsysId'][0]}",
+            :description => vsys_description_el ? vsys_description_el[0] : nil
+          )
+        end
+      end
+    end
+
+    def system_templates(credentials, opts={})
+      safely do
+        client = new_client(credentials)
+        templates = client.list_vsys_descriptor['vsysdescriptors'][0]['vsysdescriptor'].collect
do |desc|
+          CIMI::Model::SystemTemplate.new(
+            :id           => desc['vsysdescriptorId'][0],
+            :name         => desc['vsysdescriptorName'][0],
+            :description  => desc['description'][0]
+          )
+        end
+        templates = templates.select { |t| opts[:id] == t[:id] } if opts[:id]
+        templates
+      end
+    end
+
+  end
+
+end

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/022dd0b2/server/lib/deltacloud/drivers/mock/mock_driver_cimi_methods.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/drivers/mock/mock_driver_cimi_methods.rb b/server/lib/deltacloud/drivers/mock/mock_driver_cimi_methods.rb
index 1180243..b1c57c8 100644
--- a/server/lib/deltacloud/drivers/mock/mock_driver_cimi_methods.rb
+++ b/server/lib/deltacloud/drivers/mock/mock_driver_cimi_methods.rb
@@ -25,30 +25,28 @@ module Deltacloud::Drivers::Mock
       check_credentials(credentials)
       if opts[:id].nil?
         systems = @client.load_all_cimi(:system).map{|sys| CIMI::Model::System.from_json(sys)}
-        systems.map{|sys|convert_cimi_mock_urls(:system, sys ,opts[:env])}.flatten
       else
         begin
-          system = CIMI::Model::System.from_json(@client.load_cimi(:system, opts[:id]))
-          convert_cimi_mock_urls(:system, system, opts[:env])
+          systems = [CIMI::Model::System.from_json(@client.load_cimi(:system, opts[:id]))]
         rescue Errno::ENOENT
-          nil
+          return []
         end
       end
+      systems.map{|sys|convert_cimi_mock_urls(:system, sys ,opts[:env])}.flatten
     end
 
     def system_templates(credentials, opts={})
       check_credentials(credentials)
       if opts[:id].nil?
         system_templates = @client.load_all_cimi(:system_template).map{|sys_templ| CIMI::Model::SystemTemplate.from_json(sys_templ)}
-        system_templates.map{|sys_templ|convert_cimi_mock_urls(:system_template, sys_templ,
opts[:env])}.flatten
       else
         begin
-          system_template = CIMI::Model::SystemTemplate.from_json(@client.load_cimi(:system_template,
opts[:id]))
-          convert_cimi_mock_urls(:system_template, system_template, opts[:env])
+          system_templates = [CIMI::Model::SystemTemplate.from_json(@client.load_cimi(:system_template,
opts[:id]))]
         rescue Errno::ENOENT
-          nil
+          return []
         end
       end
+      system_templates.map{|sys_templ|convert_cimi_mock_urls(:system_template, sys_templ,
opts[:env])}.flatten
     end
 
     def networks(credentials, opts={})


Mime
View raw message