deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From <di...@fast.au.fujitsu.com>
Subject [PATCH] FGCP: add mapping for GET system and system_templates
Date Fri, 22 Feb 2013 12:45:25 GMT
From: Dies Koper <diesk@fast.au.fujitsu.com>

---
 server/lib/deltacloud/drivers/fgcp/fgcp_driver.rb  |   1 +
 .../drivers/fgcp/fgcp_driver_cimi_methods.rb       | 137 +++++++++++++++++++++
 2 files changed, 138 insertions(+)
 create mode 100644 server/lib/deltacloud/drivers/fgcp/fgcp_driver_cimi_methods.rb

diff --git a/server/lib/deltacloud/drivers/fgcp/fgcp_driver.rb b/server/lib/deltacloud/drivers/fgcp/fgcp_driver.rb
index 71b53bd..4d71c11 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'
 
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..db26a05
--- /dev/null
+++ b/server/lib/deltacloud/drivers/fgcp/fgcp_driver_cimi_methods.rb
@@ -0,0 +1,137 @@
+#
+# 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={})
+      systems = []
+
+      safely do
+        client = new_client(credentials)
+
+        if opts and opts[:id]
+          vsys_config = client.get_vsys_configuration(opts[:id])
+          return CIMI::Model::System.new(
+            :id          => opts[:id],
+            :name        => vsys_config['vsys'][0]['vsysName'][0],
+#            :machines    => "http://cimi.example.org/machines?realm_id=#{}",
+#            :volumes     => "http://cimi.example.org/volumes?realm_id=#{}",
+#            :addresses   => "http://cimi.example.org/addresses?realm_id=#{}",
+            :description => vsys_config['vsys'][0]['description'][0]
+          )
+        elsif xml = client.list_vsys['vsyss']
+
+          return [] if xml.nil?
+          xml[0]['vsys'].each do |vsys|
+
+            vsys_config = client.get_vsys_configuration(vsys['vsysId'][0])
+            vsys_description_el = vsys_config['vsys'][0]['description']
+            systems << CIMI::Model::System.new(
+              :id          => vsys['vsysId'][0],
+              :name        => vsys_config['vsys'][0]['vsysName'][0],
+#              :machines    => "http://cimi.example.org/machines?realm_id=#{vsys['vsysId'][0]}",
+#              :volumes     => "http://cimi.example.org/volumes?realm_id=#{vsys['vsysId'][0]}",
+#              :networks    => "http://cimi.example.org/networks?realm_id=#{vsys['vsysId'][0]}",
+#              :addresses   => "http://cimi.example.org/addresses?realm_id=#{vsys['vsysId'][0]}",
+              :description => vsys_description_el ? vsys_description_el[0] : nil
+            )
+          end
+        end
+      end
+      systems
+    end
+
+    def system_templates(credentials, opts={})
+      templates = []
+      safely do
+        client = new_client(credentials)
+        client.list_vsys_descriptor['vsysdescriptors'][0]['vsysdescriptor'].each do |desc|
+          templates << CIMI::Model::SystemTemplate.new(
+              :id           => desc['vsysdescriptorId'][0],
+              :name         => desc['vsysdescriptorName'][0],
+              :description  => desc['description'][0]
+          )
+          return templates.last if opts and opts[:id] == desc['vsysdescriptorId'][0]
+        end
+      end
+      templates
+    end
+
+    def networks(credentials, opts={})
+      #list vsys
+      #list vsys config
+      # add network per network segment.
+      # add public network.
+      networks = []
+
+      safely do
+        client = new_client(credentials)
+
+        if opts and opts[:id]
+          #list vsys config
+          # add network segment.
+          # or public network?
+
+          vsys_id = client.extract_vsys_id(opts[:id])
+          vsys_config = client.get_vsys_configuration(vsys_id)
+          vsys_config['vsys'][0]['vnets'][0]['vnet'].find do |vnet|
+
+            networks << CIMI::Model::Network.new(
+              :id           => opts[:id],
+              :name         => opts[:id],
+              :state        => 'STARTED',
+              :network_type => 'PRIVATE'
+            ) if vnet['networkId'][0] == opts[:id]
+          end
+        elsif xml = client.list_vsys['vsyss']
+
+          return [] if xml.nil?
+          xml[0]['vsys'].each do |vsys|
+
+            # use get_vsys_configuration (instead of get_vserver_configuration) to retrieve
all vservers in one call
+            vsys_config = client.get_vsys_configuration(vsys['vsysId'][0])
+            vsys_config['vsys'][0]['vservers'][0]['vserver'].each do |vserver|
+
+              # skip firewalls - they probably don't belong here and their new type ('firewall'
instead of 
+              # 'economy') causes errors when trying to map to available profiles)
+              unless determine_server_type(vserver) == 'FW'
+                # to keep the response time of this method acceptable, retrieve state
+                # only if required because state is filtered on
+                state_data = opts[:state] ? instance_state_data(vserver, client) : nil
+                # filter on state
+                if opts[:state].nil? or opts[:state] == state_data[:state]
+                  instances << convert_to_instance(client, vserver, state_data)
+                end
+              end
+            end
+          end
+        end
+      end
+    end
+
+  end
+
+end
-- 
1.8.0.msysgit.0



Mime
View raw message