deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From <di...@fast.au.fujitsu.com>
Subject [PATCH] added Template subcollections to SystemTemplate
Date Thu, 28 Mar 2013 00:11:58 GMT
From: Dies Koper <diesk@fast.au.fujitsu.com>

---
 server/lib/cimi/collections/systems.rb             |  58 +++++++++--
 server/lib/cimi/models.rb                          |  12 ++-
 server/lib/cimi/models/machine_template.rb         |   6 +-
 server/lib/cimi/models/network_template.rb         |   4 +-
 server/lib/cimi/models/system.rb                   |  24 ++---
 server/lib/cimi/models/system_template.rb          |  20 ++--
 server/lib/cimi/models/volume_template.rb          |   4 +-
 server/lib/cimi/service.rb                         |   2 +
 server/lib/deltacloud/drivers/fgcp/fgcp_client.rb  |   4 +
 .../drivers/fgcp/fgcp_driver_cimi_methods.rb       | 116 +++++++++++++++++----
 .../mock/data/cimi/system_template/template1.json  |  31 +++++-
 .../drivers/mock/mock_driver_cimi_methods.rb       |  64 ++++++++++++
 .../cimi/collections/system_templates_test.rb      |  47 +++++++++
 13 files changed, 329 insertions(+), 63 deletions(-)

diff --git a/server/lib/cimi/collections/systems.rb b/server/lib/cimi/collections/systems.rb
index 5c3903e..d9a1e75 100644
--- a/server/lib/cimi/collections/systems.rb
+++ b/server/lib/cimi/collections/systems.rb
@@ -107,10 +107,37 @@ module CIMI::Collections
         end
       end
 
+      #use rabbit subcollections for machines index/show:
+      collection :machines, :with_id => :machine_id do
+
+        operation :index, :with_capability => :system_machines do
+          description "Retrieve the System's SystemMachineCollection"
+          control do
+            volumes = SystemMachine.collection_for_system(params[:id], self)
+            respond_to do |format|
+              format.json {volumes.to_json}
+              format.xml  {volumes.to_xml}
+            end
+          end
+        end
+
+        operation :show, :with_capability => :system_machines do
+          description "Retrieve a System's specific SystemMachine"
+          control do
+            volume = SystemMachine.find(params[:id], self, params[:machine_id])
+            respond_to do |format|
+              format.json {volume.to_json}
+              format.xml  {volume.to_xml}
+            end
+          end
+        end
+
+      end
+
       #use rabbit subcollections for volumes index/show:
       collection :volumes, :with_id => :vol_id do
 
-        operation :index, :with_capability => :storage_volumes do
+        operation :index, :with_capability => :system_volumes do
           description "Retrieve the System's SystemVolumeCollection"
           control do
             volumes = SystemVolume.collection_for_system(params[:id], self)
@@ -121,7 +148,7 @@ module CIMI::Collections
           end
         end
 
-        operation :show, :with_capability => :storage_volumes do
+        operation :show, :with_capability => :system_volumes do
           description "Retrieve a System's specific SystemVolume"
           control do
             volume = SystemVolume.find(params[:id], self, params[:vol_id])
@@ -131,16 +158,29 @@ module CIMI::Collections
             end
           end
         end
+      end
 
-        operation :destroy, :with_capability => :detach_storage_volume do
-          description "Remove/detach a volume from the System's SystemVolumeCollection"
+      #use rabbit subcollections for networks index/show:
+      collection :networks, :with_id => :network_id do
+
+        operation :index, :with_capability => :system_networks do
+          description "Retrieve the System's SystemNetworkCollection"
           control do
-            system_volume = SystemVolume.find(params[:id], self, params[:vol_id])
-            location = system_volume.initial_location
-            system_volumes = System.detach_volume(params[:vol_id], location, self)
+            volumes = SystemNetwork.collection_for_system(params[:id], self)
             respond_to do |format|
-              format.json{ system_volumes.to_json}
-              format.xml{ system_volumes.to_xml}
+              format.json {volumes.to_json}
+              format.xml  {volumes.to_xml}
+            end
+          end
+        end
+
+        operation :show, :with_capability => :system_networks do
+          description "Retrieve a System's specific SystemNetwork"
+          control do
+            volume = SystemNetwork.find(params[:id], self, params[:network_id])
+            respond_to do |format|
+              format.json {volume.to_json}
+              format.xml  {volume.to_xml}
             end
           end
         end
diff --git a/server/lib/cimi/models.rb b/server/lib/cimi/models.rb
index 8eeb96c..c8f138c 100644
--- a/server/lib/cimi/models.rb
+++ b/server/lib/cimi/models.rb
@@ -79,7 +79,15 @@ require_relative './models/address_template_create'
 require_relative './models/address_create'
 require_relative './models/forwarding_group'
 require_relative './models/forwarding_group_template'
-require_relative './models/system_template'
-require_relative './models/system'
 require_relative './models/network_template'
 require_relative './models/network_create'
+require_relative './models/system_template'
+require_relative './models/system_network_port'
+require_relative './models/system_network'
+require_relative './models/system_address'
+require_relative './models/system_forwarding_group'
+require_relative './models/system_machine'
+require_relative './models/system_volume'
+require_relative './models/system_credential'
+require_relative './models/system_system'
+require_relative './models/system'
diff --git a/server/lib/cimi/models/machine_template.rb b/server/lib/cimi/models/machine_template.rb
index 68e865b..c167555 100644
--- a/server/lib/cimi/models/machine_template.rb
+++ b/server/lib/cimi/models/machine_template.rb
@@ -28,10 +28,12 @@ class CIMI::Model::MachineTemplate < CIMI::Model::Base
     scalar :href, :initial_location
   end
 
-  array :volume_templates do
-    scalar :href, :initial_location
+  class CIMI::Model::VolumeTemplateWithLocation < CIMI::Model::VolumeTemplate
+    text :initial_location
   end
 
+  array :volume_templates, :ref => CIMI::Model::VolumeTemplateWithLocation
+
   array :network_interfaces do
     href :vsp
     text :hostname, :mac_address, :state, :protocol, :allocation
diff --git a/server/lib/cimi/models/network_template.rb b/server/lib/cimi/models/network_template.rb
index 4f69f52..4515351 100644
--- a/server/lib/cimi/models/network_template.rb
+++ b/server/lib/cimi/models/network_template.rb
@@ -17,8 +17,8 @@ class CIMI::Model::NetworkTemplate < CIMI::Model::Base
 
   acts_as_root_entity
 
-  ref :network_config, :required => true
-  ref :forwarding_group, :required => true
+  ref :network_config, :class => CIMI::Model::NetworkConfiguration
+  ref :forwarding_group, :class => CIMI::Model::ForwardingGroup
 
   array :operations do
     scalar :rel, :href
diff --git a/server/lib/cimi/models/system.rb b/server/lib/cimi/models/system.rb
index 118f9f5..dbab95b 100644
--- a/server/lib/cimi/models/system.rb
+++ b/server/lib/cimi/models/system.rb
@@ -17,18 +17,18 @@ class CIMI::Model::System < CIMI::Model::Base
 
   acts_as_root_entity
 
-  text :state
-
-  # FIXME: Any reason for these comments?
-
-  #  collection :systems, :class => CIMI::Model::SystemSystem
-  #  collection :machines, :class => CIMI::Model::SystemMachine
-  #  collection :credentials, :class => CIMI::Model::SystemCredential
-  #  collection :volumes, :class => CIMI::Model::SystemVolume
-  #  collection :networks, :class => CIMI::Model::SystemNetwork
-  #  collection :network_ports, :class => CIMI::Model::SystemNetworkPort
-  #  collection :addresses, :class => CIMI::Model::SystemAddress
-  #  collection :forwarding_groups, :class => CIMI::Model::SystemForwardingGroup
+  text :state, :required => true
+
+  collection :systems, :class => CIMI::Model::SystemSystem
+  collection :machines, :class => CIMI::Model::SystemMachine
+  collection :credentials, :class => CIMI::Model::SystemCredential
+  collection :volumes, :class => CIMI::Model::SystemVolume
+  collection :networks, :class => CIMI::Model::SystemNetwork
+  collection :network_ports, :class => CIMI::Model::SystemNetworkPort
+  collection :addresses, :class => CIMI::Model::SystemAddress
+  collection :forwarding_groups, :class => CIMI::Model::SystemForwardingGroup
+
+  #TODO: implement the attributes commented out
 
   #  array :meters do
   #    scalar :href
diff --git a/server/lib/cimi/models/system_template.rb b/server/lib/cimi/models/system_template.rb
index 82e418b..c60f759 100644
--- a/server/lib/cimi/models/system_template.rb
+++ b/server/lib/cimi/models/system_template.rb
@@ -20,19 +20,17 @@ class CIMI::Model::SystemTemplate < CIMI::Model::Base
   array :component_descriptors do
     text :name, :description
     hash_map :properties
-    text :type
-
-    # FIXME: Any reasons for these comments?
+    text :type, :required => true
 
     #component_template, comprises:
-    #    struct :machine_template, :class => CIMI::Model::MachineTemplate
-    #    struct :system_template, :class => CIMI::Model::SystemTemplate
-    #    struct :credential_template, :class => CIMI::Model::CredentialTemplate
-    #    struct :volume_template, :class => CIMI::Model::VolumeTemplate
-    #    struct :network_template, :class => CIMI::Model::NetworkTemplate
-    #    struct :network_port_template, :class => CIMI::Model::NetworkPortTemplate
-    #    struct :forwarding_group_template, :class => CIMI::Model::ForwardingGroupTemplate
-    #    struct :address_template, :class => CIMI::Model::AddressTemplate
+    ref :machine_template, :class => CIMI::Model::MachineTemplate
+    ref :system_template, :class => CIMI::Model::SystemTemplate
+    ref :credential_template, :class => CIMI::Model::CredentialTemplate
+    ref :volume_template, :class => CIMI::Model::VolumeTemplate
+    ref :network_template, :class => CIMI::Model::NetworkTemplate
+    ref :network_port_template, :class => CIMI::Model::NetworkPortTemplate
+    ref :forwarding_group_template, :class => CIMI::Model::ForwardingGroupTemplate
+    ref :address_template, :class => CIMI::Model::AddressTemplate
     text :quantity
   end
 
diff --git a/server/lib/cimi/models/volume_template.rb b/server/lib/cimi/models/volume_template.rb
index bda4657..43e9c86 100644
--- a/server/lib/cimi/models/volume_template.rb
+++ b/server/lib/cimi/models/volume_template.rb
@@ -17,8 +17,8 @@ class CIMI::Model::VolumeTemplate < CIMI::Model::Base
 
   acts_as_root_entity
 
-  ref :volume_config, :required => true
-  ref :volume_image, :required => true
+  ref :volume_config, :required => true, :class => CIMI::Model::VolumeConfiguration
+  ref :volume_image
 
   array :meter_templates do
   end
diff --git a/server/lib/cimi/service.rb b/server/lib/cimi/service.rb
index 8176532..9dbd85c 100644
--- a/server/lib/cimi/service.rb
+++ b/server/lib/cimi/service.rb
@@ -45,6 +45,8 @@ require_relative './service/network_create'
 require_relative './service/network'
 require_relative './service/forwarding_group'
 require_relative './service/volume_template_create'
+require_relative './service/system_machine'
+require_relative './service/system_volume'
 require_relative './service/system'
 require_relative './service/address_template_create'
 require_relative './service/volume'
diff --git a/server/lib/deltacloud/drivers/fgcp/fgcp_client.rb b/server/lib/deltacloud/drivers/fgcp/fgcp_client.rb
index fed3b70..9597c13 100644
--- a/server/lib/deltacloud/drivers/fgcp/fgcp_client.rb
+++ b/server/lib/deltacloud/drivers/fgcp/fgcp_client.rb
@@ -94,6 +94,10 @@ class FgcpClient
     request('ListVSYSDescriptor')
   end
 
+  def get_vsys_descriptor_configuration(vsys_descriptor_id)
+    request('GetVSYSDescriptorConfiguration', {'vsysDescriptorId' => vsys_descriptor_id})
+  end
+
   def list_vservers(vsys_id)
     request('ListVServer', {'vsysId' => vsys_id})
   end
diff --git a/server/lib/deltacloud/drivers/fgcp/fgcp_driver_cimi_methods.rb b/server/lib/deltacloud/drivers/fgcp/fgcp_driver_cimi_methods.rb
index b4d31f6..b1a4a5b 100644
--- a/server/lib/deltacloud/drivers/fgcp/fgcp_driver_cimi_methods.rb
+++ b/server/lib/deltacloud/drivers/fgcp/fgcp_driver_cimi_methods.rb
@@ -29,39 +29,117 @@ module Deltacloud::Drivers::Fgcp
     def systems(credentials, opts={})
       safely do
         client = new_client(credentials)
+        xml = client.list_vsys['vsyss']
+        return [] if xml.nil?
+        context = opts[:env]
 
-        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]
+        systems = xml[0]['vsys'].collect do |vsys|
+          vsys_id = vsys['vsysId'][0]
           vsys_description_el = vsys['description']
           CIMI::Model::System.new(
-            :id          => vsys['vsysId'][0],
+            :id          => vsys_id,
             :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
+            :description => vsys_description_el ? vsys_description_el[0] : nil,
+            :machines    => { :href => context.system_url("#{vsys_id}/machines") },
+            :volumes     => { :href => context.system_url("#{vsys_id}/volumes") },
+            :networks    => { :href => context.system_url("#{vsys_id}/networks") },
+            :addresses   => { :href => context.system_url("#{vsys_id}/addresses") }
           )
         end
+        systems = systems.select { |s| opts[:id] == s[:id] } if opts[:id]
+        # now add system state
+        systems.each do |system|
+          xml = client.list_vservers(system[:id])['vservers']
+          if xml.nil?
+            system[:state] = 'MIXED'
+          else
+            xml[0]['vserver'].each do |vserver|
+              state = @@INSTANCE_STATE_MAP[client.get_vserver_status(vserver['vserverId'][0])['vserverStatus'][0]]
+              state = 'STARTED' if state == 'RUNNING'
+              system[:state] ||= state
+              if system[:state] != state
+                system[:state] = 'MIXED'
+                break
+              end
+            end
+          end
+        end
+        systems
+      end
+    end
+
+    def system_machines(credentials, opts={})
+      safely do
+        client = new_client(credentials)
+        #if :expand not specified, list of hrefs only, else convert from :instances?
+        xml = client.list_vservers(opts[:system_id])['vservers']
+        return [] if xml.nil?
+        context = opts[:env]
+
+        machines = xml[0]['vserver'].collect do |vserver|
+          vserver_id = vserver['vserverId'][0]
+          CIMI::Model::SystemMachine.new(
+            :id      => context.machine_url(vserver_id),
+            :name    => vserver['vserverName'][0],
+            :machine => { :href => context.machine_url(vserver_id)}
+          ) unless opts[:id] and opts[:id] != vserver_id
+        end
+        machines.compact
+        machines.each { |m| puts m.inspect}
       end
     end
 
     def system_templates(credentials, opts={})
       safely do
         client = new_client(credentials)
+        context = opts[:env]
         templates = client.list_vsys_descriptor['vsysdescriptors'][0]['vsysdescriptor'].collect
do |desc|
+          conf = client.get_vsys_descriptor_configuration(desc['vsysdescriptorId'][0])['vsysdescriptor'][0]
+          components = conf['vservers'][0]['vserver'].collect do |vserver|
+            next if vserver['vserverType'][0] == 'firewall'
+            volume_templates = vserver['vdisks'][0]['vdisk'].collect do |vdisk|
+              CIMI::Model::VolumeTemplateWithLocation.new(
+#                :volume_config => {:capacity => "#{vdisk['size'][0].to_i * 1024 *
1024}"}
+                :volume_config => CIMI::Model::VolumeConfiguration.new(:capacity =>
vdisk['size'][0].to_i * 1024 * 1024)
+              )
+            end if vserver['vdisks']
+            {
+              :name             => desc['vsysdescriptorName'][0],
+              :description      => '',
+              :type             => "http://schemas.dmtf.org/cimi/1/Machine",
+              :machine_template => CIMI::Model::MachineTemplate.new(
+                :name             => vserver['vserverName'][0],
+                :description      => '',
+                :machine_config   => CIMI::Service::MachineConfiguration.find(vserver['vserverType'][0],
context),
+                :machine_image    => { :href => context.machine_image_url(vserver['diskimageId'][0])
},
+                :volume_templates => volume_templates
+              )
+            }
+          end
+          # add network templates
+          if conf['vsysdescriptorId'][0] =~ /(1|2|3)-tier Skeleton/
+            tiers = ['DMZ', 'Secure1', 'Secure2']
+            components += 1.upto($1.to_i).collect do |n|
+              {
+                :name             => tiers[n],
+                :description      => "Network tier #{n}",
+                :type             => "http://schemas.dmtf.org/cimi/1/Network",
+                :network_template => CIMI::Model::NetworkTemplate.new(
+                  :name             => 'Private network',
+                  :description      => '',
+                  :network_config   => CIMI::Model::NetworkConfiguration.new(
+                    :network_type     => 'PRIVATE',
+                    :class_of_service => 'BRONZE'
+                  )
+                )
+              }
+            end
+          end
           CIMI::Model::SystemTemplate.new(
-            :id           => desc['vsysdescriptorId'][0],
-            :name         => desc['vsysdescriptorName'][0],
-            :description  => desc['description'][0]
+            :id                    => desc['vsysdescriptorId'][0],
+            :name                  => desc['vsysdescriptorName'][0],
+            :description           => desc['description'][0],
+            :component_descriptors => components.compact
           )
         end
         templates = templates.select { |t| opts[:id] == t[:id] } if opts[:id]
diff --git a/server/lib/deltacloud/drivers/mock/data/cimi/system_template/template1.json b/server/lib/deltacloud/drivers/mock/data/cimi/system_template/template1.json
index 495fc24..913252b 100644
--- a/server/lib/deltacloud/drivers/mock/data/cimi/system_template/template1.json
+++ b/server/lib/deltacloud/drivers/mock/data/cimi/system_template/template1.json
@@ -4,20 +4,43 @@
   "created": "Fri Feb 08 12:15:15 EET 2013",
   "componentDescriptors": [
     { "name": "my machine",
-      "type": "http://schemas.dmtf.org/cimi/1/Machine",
       "description": "an inline mock machine template",
+      "type": "http://schemas.dmtf.org/cimi/1/Machine",
       "machineTemplate": {
         "name": "machine in mock system",
         "description": "machine in system",
         "machineConfig": { "href": "http://example.com/configs/m1-small" },
-        "machineImage": { "href": "http://example.com/images/img1" }
+        "machineImage": { "href": "http://example.com/images/img1" },
+        "volumeTemplates": [
+	  { "href": "http://example.com/volumes/sysvol1" }
+	]
       }
     },
+    { "name": "my second machine",
+      "description": "another inline mock machine template",
+      "type": "http://schemas.dmtf.org/cimi/1/Machine",
+      "machineTemplate": {
+        "name": "machine in mock system",
+        "description": "machine in system",
+        "machineConfig": { "href": "http://example.com/configs/m1-small" },
+        "machineImage": { "href": "http://example.com/images/img1" },
+        "volumeTemplates": [
+	  { "volumeConfig": {"capacity": 10485760} }
+	]
+      }
+    },
+    { "name": "my third machine",
+      "description": "a reference to a mock machine template",
+      "type": "http://schemas.dmtf.org/cimi/1/Machine",
+      "machineTemplate": { "href" : "http://example.com/machine_templates/template1" }
+    },
     { "name": "my network",
+      "description": "an inline network template",
       "type": "http://schemas.dmtf.org/cimi/1/Network",
-      "description": "a reference to an existing mock network template",
       "networkTemplate": {
-        "href": "http://cimi.example.org/network_templates/template1"
+        "name": "network in mock system",
+        "description": "network in system",
+        "networkConfig": { "networkType": "PRIVATE", "classOfService": "GOLD" }
       }
     }
   ],
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 b1c57c8..d2c1d78 100644
--- a/server/lib/deltacloud/drivers/mock/mock_driver_cimi_methods.rb
+++ b/server/lib/deltacloud/drivers/mock/mock_driver_cimi_methods.rb
@@ -35,6 +35,70 @@ module Deltacloud::Drivers::Mock
       systems.map{|sys|convert_cimi_mock_urls(:system, sys ,opts[:env])}.flatten
     end
 
+    def create_system(credentials, opts={})
+      check_credentials(credentials)
+      id = "#{opts[:env].send("systems_url")}/#{opts[:name]}"
+      sys_hsh = { "id"=> id,
+                  "name" => opts[:name],
+                  "description" => opts[:description],
+                  "created" => Time.now,
+                  "state" => "STOPPED",
+                  "systemTemplate"=> { "href" => opts[:system_template].id },
+                  "operations" => [{"rel"=>"edit", "href"=> id},
+                                   {"rel"=>"delete", "href"=> id}]    }
+      system = CIMI::Model::System.from_json(JSON.generate(sys_hsh))
+
+      @client.store_cimi(:system, system)
+      system
+    end
+
+    def delete_system(credentials, id)
+      check_credentials(credentials)
+      @client.destroy_cimi(:system, id)
+    end
+
+    def start_system(credentials, id)
+      check_credentials(credentials)
+      update_object_state(id, "System", "STARTED")
+    end
+
+    def stop_system(credentials, id)
+      check_credentials(credentials)
+      update_object_state(id, "System", "STOPPED")
+    end
+
+    def system_machines(credentials, opts={})
+      check_credentials(credentials)
+      if opts[:id].nil?
+        machines = @client.load_all_cimi(:system_machine).map{|mach| CIMI::Model::SystemMachine.from_json(mach)}
+      else
+        begin
+          machines = [CIMI::Model::SystemMachine.from_json(@client.load_cimi(:system_machine,
opts[:id]))]
+        rescue Errno::ENOENT
+          return []
+        end
+      end
+      #FIXME: with ":machines", delete url becomes 'http://localhost:3001/cimi/machines?id=sysmach1'
+      #with ":system_machine"/":system_machines", undefined method `system_machine_url' for
#<CIMI::Collections::Systems:0x44fe338> in mock_driver_cimi_methods.rb:261
+      machines.map{|mach|convert_cimi_mock_urls(:machines, mach, opts[:env])}.flatten
+   end
+
+    def system_volumes(credentials, opts={})
+      check_credentials(credentials)
+      if opts[:id].nil?
+        volumes = @client.load_all_cimi(:system_volume).map{|vol| CIMI::Model::SystemVolume.from_json(vol)}
+      else
+        begin
+          volumes = [CIMI::Model::SystemVolume.from_json(@client.load_cimi(:system_volume,
opts[:id]))]
+        rescue Errno::ENOENT
+          return []
+        end
+      end
+      #FIXME: with ":volumes", delete url becomes 'http://localhost:3001/cimi/volumes?id=sysvol1'
+      #with ":system_volume"/":system_volumes", undefined method `system_volume_url' for
#<CIMI::Collections::Systems:0x44fe338> in mock_driver_cimi_methods.rb:261
+      volumes.map{|vol|convert_cimi_mock_urls(:volumes, vol, opts[:env])}.flatten
+   end
+
     def system_templates(credentials, opts={})
       check_credentials(credentials)
       if opts[:id].nil?
diff --git a/server/tests/cimi/collections/system_templates_test.rb b/server/tests/cimi/collections/system_templates_test.rb
index 8c4f1a7..87488b4 100644
--- a/server/tests/cimi/collections/system_templates_test.rb
+++ b/server/tests/cimi/collections/system_templates_test.rb
@@ -38,4 +38,51 @@ describe CIMI::Collections::SystemTemplates do
     status.must_equal 404
   end
 
+  it 'should allow to retrieve system template\'s machine template\'s ref details' do
+    get root_url '/system_templates/template1'
+    (xml/'SystemTemplate/componentDescriptor').each do |c|
+      if (c/'name').inner_text == 'my third machine'
+        (c/'machineTemplate').wont_be_empty
+        (c/'machineTemplate').to_s.must_equal '<machineTemplate href="http://example.com/machine_templates/template1"/>'
+      end
+    end
+  end
+
+  it 'should allow to retrieve system template\'s machine template\'s inline details' do
+    get root_url '/system_templates/template1'
+    (xml/'SystemTemplate/componentDescriptor').each do |c|
+      if (c/'name').inner_text == 'my machine'
+        (c/'machineTemplate').wont_be_empty
+        (c/'machineTemplate/name').inner_text.must_equal 'machine in mock system'
+        (c/'machineTemplate/description').inner_text.must_equal 'machine in system'
+        (c/'machineTemplate/machineConfig').to_s.must_equal '<machineConfig href="http://example.com/configs/m1-small"/>'
+        (c/'machineTemplate/machineImage').to_s.must_equal '<machineImage href="http://example.com/images/img1"/>'
+        (c/'machineTemplate/volumeTemplate').to_s.must_equal '<volumeTemplate href="http://example.com/volumes/sysvol1"/>'
+      end
+    end
+  end
+
+  it 'should allow to retrieve system template\'s machine template\'s inline volume template'
do
+    get root_url '/system_templates/template1'
+    (xml/'SystemTemplate/componentDescriptor').each do |c|
+      if (c/'name').inner_text == 'my second machine'
+        (c/'machineTemplate').wont_be_empty
+        (c/'machineTemplate/description').inner_text.must_equal 'another inline mock machine
template'
+        (c/'machineTemplate/volumeTemplate').wont_be_empty
+        (c/'machineTemplate/volumeTemplate/volumeConfig').wont_be_empty
+        (c/'machineTemplate/volumeTemplate/volumeConfig/capacity').inner_text.must_equal
'10485760'
+      end
+    end
+  end
+
+  it 'should allow to retrieve system template\'s network' do
+    get root_url '/system_templates/template1'
+    (xml/'SystemTemplate/componentDescriptor').each do |c|
+      if (c/'name').inner_text == 'network in mock system'
+        (c/'networkTemplate').inner_text.must_equal 'my network'
+        (c/'networkTemplate/networkConfig/networkType').inner_text.must_equal 'GOLD'
+      end
+    end
+  end
+
 end
-- 
1.8.0.msysgit.0



Mime
View raw message