deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dko...@apache.org
Subject git commit: CIMI: map cimi networks and forwarding groups to Deltacloud subnets and networks
Date Mon, 03 Jun 2013 11:07:20 GMT
Updated Branches:
  refs/heads/master 85ccaa0cb -> 7ebb6808b


CIMI: map cimi networks and forwarding groups to Deltacloud
subnets and networks


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

Branch: refs/heads/master
Commit: 7ebb6808bec8a9b540639a12541bcb7f4440b6f4
Parents: 85ccaa0
Author: Dies Koper <diesk@fast.au.fujitsu.com>
Authored: Sun May 26 19:22:18 2013 +1000
Committer: Dies Koper <diesk@fast.au.fujitsu.com>
Committed: Mon Jun 3 21:00:19 2013 +1000

----------------------------------------------------------------------
 server/lib/cimi/collections/forwarding_groups.rb   |    4 +-
 server/lib/cimi/collections/networks.rb            |   48 +++---------
 server/lib/cimi/service/forwarding_group.rb        |   21 +++++-
 server/lib/cimi/service/network.rb                 |   54 +++++++++---
 server/lib/deltacloud/drivers/fgcp/fgcp_driver.rb  |    4 +-
 .../mock/data/cimi/forwarding_group/group1.json    |   13 ---
 .../drivers/mock/data/cimi/network/network1.json   |   15 ----
 .../drivers/mock/data/cimi/network/network2.json   |   15 ----
 .../drivers/mock/data/subnets/subnet1.yml          |    1 +
 .../drivers/mock/data/subnets/subnet2.yml          |    1 +
 .../drivers/mock/data/subnets/subnet3.yml          |    1 +
 .../drivers/mock/data/subnets/subnet4.yml          |    1 +
 .../drivers/mock/mock_driver_cimi_methods.rb       |   64 ---------------
 server/lib/deltacloud/models/subnet.rb             |    1 +
 .../cimi/collections/cloud_entry_point_test.rb     |    4 +-
 15 files changed, 80 insertions(+), 167 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltacloud/blob/7ebb6808/server/lib/cimi/collections/forwarding_groups.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/collections/forwarding_groups.rb b/server/lib/cimi/collections/forwarding_groups.rb
index fe2ec3d..4f58150 100644
--- a/server/lib/cimi/collections/forwarding_groups.rb
+++ b/server/lib/cimi/collections/forwarding_groups.rb
@@ -19,8 +19,8 @@ module CIMI::Collections
 
     collection :forwarding_groups do
 
-      generate_index_operation :with_capability => :forwarding_groups
-      generate_show_operation :with_capability => :forwarding_groups
+      generate_index_operation :with_capability => :networks
+      generate_show_operation :with_capability => :network
 
     end
 

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/7ebb6808/server/lib/cimi/collections/networks.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/collections/networks.rb b/server/lib/cimi/collections/networks.rb
index 3590466..a204d59 100644
--- a/server/lib/cimi/collections/networks.rb
+++ b/server/lib/cimi/collections/networks.rb
@@ -21,60 +21,32 @@ module CIMI::Collections
     collection :networks do
       description 'A Network represents an abstraction of a layer 2 broadcast domain'
 
-      generate_show_operation :with_capability => :networks
-      generate_index_operation :with_capability => :networks
-      generate_delete_operation :with_capability => :destroy_network
-      generate_create_operation :with_capability => :create_network
+      generate_show_operation :with_capability => :subnet
+      generate_index_operation :with_capability => :subnets
+      generate_delete_operation :with_capability => :destroy_subnet
+      generate_create_operation :with_capability => :create_subnet
 
 
-      action :start, :with_capability => :start_network do
+      action :start, :with_capability => :start_subnet do
         description "Start specific network."
         param :id, :string, :required
         control do
           network = Network.find(params[:id], self)
-          report_error(404) unless network
-          if current_content_type == :json
-            action = Action.from_json(request.body.read)
-          else
-            action = Action.from_xml(request.body.read)
-          end
-          network.perform(action, self) do |operation|
+          action = Action.parse(self)
+          network.perform(action) do |operation|
             no_content_with_status(202) if operation.success?
             # Handle errors using operation.failure?
           end
         end
       end
 
-      action :stop, :with_capability => :stop_network do
+      action :stop, :with_capability => :stop_subnet do
         description "Stop specific network."
         param :id, :string, :required
         control do
           network = Network.find(params[:id], self)
-          report_error(404) unless network
-          if current_content_type == :json
-            action = Action.from_json(request.body.read)
-          else
-            action = Action.from_xml(request.body.read)
-          end
-          network.perform(action, self) do |operation|
-            no_content_with_status(202) if operation.success?
-            # Handle errors using operation.failure?
-          end
-        end
-      end
-
-      action :suspend, :with_capability => :suspend_network do
-        description "Suspend specific network."
-        param :id, :string, :required
-        control do
-          network = Network.find(params[:id], self)
-          report_error(404) unless network
-          if current_content_type == :json
-            action = Action.from_json(request.body.read)
-          else
-            action = Action.from_xml(request.body.read)
-          end
-          network.perform(action, self) do |operation|
+          action = Action.parse(self)
+          network.perform(action) do |operation|
             no_content_with_status(202) if operation.success?
             # Handle errors using operation.failure?
           end

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/7ebb6808/server/lib/cimi/service/forwarding_group.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/service/forwarding_group.rb b/server/lib/cimi/service/forwarding_group.rb
index ef12350..ba383c8 100644
--- a/server/lib/cimi/service/forwarding_group.rb
+++ b/server/lib/cimi/service/forwarding_group.rb
@@ -17,10 +17,27 @@ class CIMI::Service::ForwardingGroup < CIMI::Service::Base
 
   def self.find(id, context)
     if id==:all
-      context.driver.forwarding_groups(context.credentials, {:env=>context})
+      networks = context.driver.networks(context.credentials)
+      networks.map { |network| from_network(network, context) }.compact
     else
-      context.driver.forwarding_groups(context.credentials, {:env=>context, :id=>id})
+      network = context.driver.network(context.credentials, :id=>id)
+      raise CIMI::Model::NotFound unless network and network.subnets.size > 1
+      from_network(network, context)
     end
   end
 
+  def self.delete!(id, context)
+    context.driver.destroy_network(context.credentials, id)
+  end
+
+  def self.from_network(network, context)
+    network_spec = {
+      :id               => context.forwarding_group_url(network.id),
+      :name             => network.name,
+      :description      => network.description || "No description set for Forwarding Group
#{network.name}",
+      :networks         => network.subnets.collect {|s| {:href=>context.network_url(s)}
}
+    }
+    self.new(context, :values => network_spec) if network.subnets.size > 1
+  end
+
 end

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/7ebb6808/server/lib/cimi/service/network.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/service/network.rb b/server/lib/cimi/service/network.rb
index a58aa1e..786af93 100644
--- a/server/lib/cimi/service/network.rb
+++ b/server/lib/cimi/service/network.rb
@@ -16,36 +16,62 @@
 class CIMI::Service::Network < CIMI::Service::Base
 
   def self.find(id, context)
-    networks=[]
     if id==:all
-      networks = context.driver.networks(context.credentials, {:env=>context})
+      subnets = context.driver.subnets(context.credentials)
+      subnets.map { |subnet| from_subnet(subnet, context) }.compact
     else
-      networks = context.driver.networks(context.credentials, {:id=>id, :env=>context})
+      subnet = context.driver.subnet(context.credentials, :id=>id)
+      raise CIMI::Model::NotFound unless subnet
+      from_subnet(subnet, context)
     end
-    if context.expand? :networkPorts
-      networks.each do |network|
-        network.network_ports = CIMI::Service::NetworkPort.collection_for_network(network.id,
context)
-      end
-    end
-    networks
   end
 
-
   def self.delete!(id, context)
-    context.driver.delete_network(context.credentials, id)
+    context.driver.destroy_subnet(context.credentials, id)
   end
 
-  def perform(action, context, &block)
+  def perform(action, &block)
     begin
-      if context.driver.send(:"#{action.name}_network", context.credentials, self.name)
+      op = action.operation
+      if context.driver.send(:"#{op}_network", context.credentials, id)
         block.callback :success
       else
-        raise "Operation #{action.name} failed to execute on the Network #{self.name} "
+        raise "Operation #{action.name} failed to execute on the Network #{id} "
       end
     rescue => e
       block.callback :failure, e.message
     end
   end
 
+  def self.from_subnet(subnet, context)
+    network_spec = {
+      :id               => context.network_url(subnet.id),
+      :name             => subnet.name,
+      :description      => subnet.description || "No description set for Network #{subnet.name}",
+      :state            => convert_subnet_state(subnet.state),
+      :network_type     => subnet.type,
+#      :mtu              => subnet.mtu,
+#      :class_of_service => subnet.classOfService,
+#TODO: only networks with multiple subnets can be mapped to forwarding groups
+#      :forwarding_group => context.forwarding_group_url(subnet.network),
+      :network_ports    => { :href=>context.network_url(subnet.id)+"/network_ports"}
+    }
+    network_spec[:operations] = [{ :href => context.send(:destroy_network_url, subnet.id),
:rel => "delete" }]
+    if context.driver.respond_to? :start_subnet and network_spec[:state] == 'STOPPED'
+      network_spec[:operations] << { :href => context.send(:start_network_url, subnet.id),
:rel => "http://schemas.dmtf.org/cimi/1/action/start" }
+    end
+    if context.driver.respond_to? :stop_subnet and network_spec[:state] == 'STARTED'
+      network_spec[:operations] << { :href => context.send(:stop_network_url, subnet.id),
:rel => "http://schemas.dmtf.org/cimi/1/action/stop" }
+    end
+    self.new(context, :values => network_spec)
+  end
+
+  def self.convert_subnet_state(state)
+    case state
+      when "UP" then "STARTED"
+      when "DOWN" then "STOPPED"
+      else state
+    end
+  end
 
 end

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/7ebb6808/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 c3067b5..4a8a80b 100644
--- a/server/lib/deltacloud/drivers/fgcp/fgcp_driver.rb
+++ b/server/lib/deltacloud/drivers/fgcp/fgcp_driver.rb
@@ -278,7 +278,7 @@ class FgcpDriver < Deltacloud::BaseDriver
           :name           => 'Network for ' + vsys['vsysName'][0],
           :address_blocks => address_blocks,
           :subnets        => vnets,
-          :state          => 'STARTED' # base on FW status? (DEPLOYING, RUNNING, etc.)
+          :state          => 'UP' # base on FW status? (DEPLOYING, RUNNING, etc.)
         )
       end
     end
@@ -321,7 +321,7 @@ class FgcpDriver < Deltacloud::BaseDriver
             :network       => vsys_id + '-N',
             :address_block => address_block,
             :type          => 'PRIVATE',
-            :state         => 'STARTED' # base on vsys status? (DEPLOYING, NORMAL, etc.)
+            :state         => 'UP' # base on vsys status? (DEPLOYING, NORMAL, etc.)
           )
         end
       end

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/7ebb6808/server/lib/deltacloud/drivers/mock/data/cimi/forwarding_group/group1.json
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/drivers/mock/data/cimi/forwarding_group/group1.json b/server/lib/deltacloud/drivers/mock/data/cimi/forwarding_group/group1.json
deleted file mode 100644
index 04f9266..0000000
--- a/server/lib/deltacloud/drivers/mock/data/cimi/forwarding_group/group1.json
+++ /dev/null
@@ -1,13 +0,0 @@
-{ "id": "http://cimi.example.org/forwarding_groups/group1",
-  "name": "group1",
-  "description": "a mock routing group",
-  "created": "Thu Jan 12 16:02:56 EET 2012",
-  "networks": [
-    { "href": "http://cimi.example.org/networks/network1"},
-    { "href": "http://cimi.example.org/networks/network2"}
-  ],
-  "operations": [
-    { "rel": "edit", "href": "http://cimi.example.org/forwarding_groups/group1" },
-    { "rel": "delete", "href": "http://cimi.example.org/forwarding_groups/group1" }
-  ]
-}

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/7ebb6808/server/lib/deltacloud/drivers/mock/data/cimi/network/network1.json
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/drivers/mock/data/cimi/network/network1.json b/server/lib/deltacloud/drivers/mock/data/cimi/network/network1.json
deleted file mode 100644
index f8cc34d..0000000
--- a/server/lib/deltacloud/drivers/mock/data/cimi/network/network1.json
+++ /dev/null
@@ -1,15 +0,0 @@
-{ "id": "http://cimi.example.org/networks/network1",
-  "name": "network1",
-  "description": "the first network",
-  "created": "Thu Jan 12 15:25:41 EET 2012",
-  "state": "STARTED",
-  "networkType": "PUBLIC",
-  "classOfService": "GOLD",
-  "mtu": 1500,
-  "networkPorts": { "href": "http://cimi.example.org/networks/network1/network_ports"},
-  "forwardingGroup": { "href": "http://cimi.example.org/forwarding_groups/group1" },
-  "operations": [
-    { "rel": "edit", "href": "http://cimi.example.org/networks/network1" },
-    { "rel": "delete", "href": "http://cimi.example.org/networks/network1" }
-  ]
-}

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/7ebb6808/server/lib/deltacloud/drivers/mock/data/cimi/network/network2.json
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/drivers/mock/data/cimi/network/network2.json b/server/lib/deltacloud/drivers/mock/data/cimi/network/network2.json
deleted file mode 100644
index 85adff1..0000000
--- a/server/lib/deltacloud/drivers/mock/data/cimi/network/network2.json
+++ /dev/null
@@ -1,15 +0,0 @@
-{ "id": "http://cimi.example.org/networks/network2",
-  "name": "network2",
-  "description": "another network",
-  "created": "Fri Jan 13 17:30:34 EET 2012",
-  "state": "STARTED",
-  "networkType": "PUBLIC",
-  "classOfService": "SILVER",
-  "mtu": 1500,
-  "networkPorts": { "href": "http://cimi.example.org/networks/network2/network_ports"},
-  "forwardingGroup": { "href": "http://cimi.example.org/forwarding_groups/group1" },
-  "operations": [
-    { "rel": "edit", "href": "http://cimi.example.org/networks/network2" },
-    { "rel": "delete", "href": "http://cimi.example.org/networks/network2" }
-  ]
-}

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/7ebb6808/server/lib/deltacloud/drivers/mock/data/subnets/subnet1.yml
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/drivers/mock/data/subnets/subnet1.yml b/server/lib/deltacloud/drivers/mock/data/subnets/subnet1.yml
index 11d5db9..322df7f 100644
--- a/server/lib/deltacloud/drivers/mock/data/subnets/subnet1.yml
+++ b/server/lib/deltacloud/drivers/mock/data/subnets/subnet1.yml
@@ -3,4 +3,5 @@
 :name: subnet1
 :network: net1
 :address_block: 192.168.1.0/24
+:type: PRIVATE
 :state: UP

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/7ebb6808/server/lib/deltacloud/drivers/mock/data/subnets/subnet2.yml
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/drivers/mock/data/subnets/subnet2.yml b/server/lib/deltacloud/drivers/mock/data/subnets/subnet2.yml
index d2ef7c2..5cfbed8 100644
--- a/server/lib/deltacloud/drivers/mock/data/subnets/subnet2.yml
+++ b/server/lib/deltacloud/drivers/mock/data/subnets/subnet2.yml
@@ -3,4 +3,5 @@
 :name: subnet2
 :network: net1
 :address_block: 192.168.2.0/24
+:type: PRIVATE
 :state: UP

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/7ebb6808/server/lib/deltacloud/drivers/mock/data/subnets/subnet3.yml
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/drivers/mock/data/subnets/subnet3.yml b/server/lib/deltacloud/drivers/mock/data/subnets/subnet3.yml
index 7109179..5a63959 100644
--- a/server/lib/deltacloud/drivers/mock/data/subnets/subnet3.yml
+++ b/server/lib/deltacloud/drivers/mock/data/subnets/subnet3.yml
@@ -3,4 +3,5 @@
 :name: subnet3
 :network: net2
 :address_block: 10.1.0.0/16
+:type: PRIVATE
 :state: UP

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/7ebb6808/server/lib/deltacloud/drivers/mock/data/subnets/subnet4.yml
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/drivers/mock/data/subnets/subnet4.yml b/server/lib/deltacloud/drivers/mock/data/subnets/subnet4.yml
index 937baaf..629bc99 100644
--- a/server/lib/deltacloud/drivers/mock/data/subnets/subnet4.yml
+++ b/server/lib/deltacloud/drivers/mock/data/subnets/subnet4.yml
@@ -3,4 +3,5 @@
 :name: subnet4
 :network: net2
 :address_block: 10.2.0.0/16
+:type: PRIVATE
 :state: UP

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/7ebb6808/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 f533758..aa7a330 100644
--- a/server/lib/deltacloud/drivers/mock/mock_driver_cimi_methods.rb
+++ b/server/lib/deltacloud/drivers/mock/mock_driver_cimi_methods.rb
@@ -223,59 +223,6 @@ module Deltacloud::Drivers::Mock
       system_templates.map{|sys_templ| convert_urls(sys_templ, opts[:env])}.flatten
     end
 
-    def networks(credentials, opts={})
-      check_credentials(credentials)
-      if opts[:id].nil?
-        networks = @client.load_all_cimi(:network).map{|net| CIMI::Model::Network.from_json(net)}
-        networks.map{|net| convert_urls(net, opts[:env])}.flatten
-      else
-        network = CIMI::Model::Network.from_json(@client.load_cimi(:network, opts[:id]))
-        convert_urls(network, opts[:env])
-      end
-    end
-
-    def create_network(credentials, opts={})
-      check_credentials(credentials)
-      id = "#{opts[:env].send("networks_url")}/#{opts[:name]}"
-      net_hsh = { "id"=> id,
-                  "name" => opts[:name],
-                  "description" => opts[:description],
-                  "created" => Time.now,
-                  "state" => "STARTED",
-                  "networkType" => opts[:network_config].network_type,
-                  "mtu" =>  opts[:network_config].mtu,
-                  "classOfService" => opts[:network_config].class_of_service,
-
-
-                  "forwardingGroup"=> { "href" => opts[:forwarding_group].id },
-                  "operations" => [{"rel"=>"edit", "href"=> id},
-                                   {"rel"=>"delete", "href"=> id}]    }
-      network = CIMI::Model::Network.from_json(JSON.generate(net_hsh))
-
-      @client.store_cimi(:network, network)
-      network
-    end
-
-    def delete_network(credentials, id)
-      check_credentials(credentials)
-      @client.destroy_cimi(:network, id)
-    end
-
-    def start_network(credentials, id)
-      check_credentials(credentials)
-      update_object_state(id, "Network", "STARTED")
-    end
-
-    def stop_network(credentials, id)
-      check_credentials(credentials)
-      update_object_state(id, "Network", "STOPPED")
-    end
-
-    def suspend_network(credentials, id)
-      check_credentials(credentials)
-      update_object_state(id, "Network", "SUSPENDED")
-    end
-
     def network_configurations(credentials, opts={})
       check_credentials(credentials)
       if opts[:id].nil?
@@ -298,17 +245,6 @@ module Deltacloud::Drivers::Mock
       end
     end
 
-    def forwarding_groups(credentials, opts={})
-      check_credentials(credentials)
-      if opts[:id].nil?
-        forwarding_groups = @client.load_all_cimi(:forwarding_group).map{|fg| CIMI::Model::ForwardingGroup.from_json(fg)}
-        forwarding_groups.map{|fg| convert_urls(fg, opts[:env])}.flatten
-      else
-        forwarding_group = CIMI::Model::ForwardingGroup.from_json(@client.load_cimi(:forwarding_group,
opts[:id]))
-        convert_urls(forwarding_group, opts[:env])
-      end
-    end
-
     def forwarding_group_templates(credentials, opts={})
       check_credentials(credentials)
       if opts[:id].nil?

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/7ebb6808/server/lib/deltacloud/models/subnet.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/models/subnet.rb b/server/lib/deltacloud/models/subnet.rb
index 0a05804..a8dfd40 100644
--- a/server/lib/deltacloud/models/subnet.rb
+++ b/server/lib/deltacloud/models/subnet.rb
@@ -28,6 +28,7 @@ class Subnet < BaseModel
       :id => id,
       :name => name,
       :href => context.subnet_url(id),
+      :type => type,
       :state => state,
       :address_block => address_block,
       :network => {

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/7ebb6808/server/tests/cimi/collections/cloud_entry_point_test.rb
----------------------------------------------------------------------
diff --git a/server/tests/cimi/collections/cloud_entry_point_test.rb b/server/tests/cimi/collections/cloud_entry_point_test.rb
index 0790231..e132c4b 100644
--- a/server/tests/cimi/collections/cloud_entry_point_test.rb
+++ b/server/tests/cimi/collections/cloud_entry_point_test.rb
@@ -40,10 +40,10 @@ describe CIMI::Collections::CloudEntryPoint do
   it 'advertise only supported CIMI collections by driver' do
     header 'X-Deltacloud-Driver', 'ec2'
     get root_url + '/cloudEntryPoint'
-    (xml/'CloudEntryPoint/forwardingGroups').must_be_empty
+    (xml/'CloudEntryPoint/systems').must_be_empty
     header 'X-Deltacloud-Driver', 'mock'
     get root_url + '/cloudEntryPoint'
-    (xml/'CloudEntryPoint/forwardingGroups').wont_be_empty
+    (xml/'CloudEntryPoint/systems').wont_be_empty
   end
 
 end


Mime
View raw message