From: marios <mar...@redhat.com>

Signed-off-by: marios <mar...@redhat.com>
---
 server/lib/deltacloud/collections/instances.rb |  5 ++
 server/lib/deltacloud/collections/networks.rb  | 63 +++++++++++++++++++++++++
 server/lib/deltacloud/collections/subnets.rb   | 65 ++++++++++++++++++++++++++
 3 files changed, 133 insertions(+)
 create mode 100644 server/lib/deltacloud/collections/networks.rb
 create mode 100644 server/lib/deltacloud/collections/subnets.rb

diff --git a/server/lib/deltacloud/collections/instances.rb 
b/server/lib/deltacloud/collections/instances.rb
index ee48f30..ecd6d00 100644
--- a/server/lib/deltacloud/collections/instances.rb
+++ b/server/lib/deltacloud/collections/instances.rb
@@ -29,6 +29,7 @@ module Deltacloud::Collections
       @realms ||= driver.realms(credentials)
       @firewalls = driver.firewalls(credentials) if driver.class.has_feature? 
:instances, :firewalls
       @keys = driver.keys(credentials) if driver.class.has_feature? 
:instances, :authentication_key
+      @networks = driver.networks(credentials) if driver.has_capability? 
:networks
     end
 
     get '/instances/:id/run' do
@@ -48,7 +49,11 @@ module Deltacloud::Collections
         param :realm_id,     :string, :optional
         param :hwp_id,       :string, :optional
         param :keyname,      :string, :optional
+        param :network_id,   :string, :optional
+        param :subnet_id,    :string, :optional
         control do
+          params.merge!({:network_id => 
params["network_id"].split("+").first}) unless params["network_id"].empty?
+          params.merge!({:subnet_id => params["network_id"].split("+").last}) 
unless params["network_id"].empty?
           @instance = driver.create_instance(credentials, params[:image_id], 
params)
           if @instance.kind_of? Array
             @elements = @instance
diff --git a/server/lib/deltacloud/collections/networks.rb 
b/server/lib/deltacloud/collections/networks.rb
new file mode 100644
index 0000000..34c7fad
--- /dev/null
+++ b/server/lib/deltacloud/collections/networks.rb
@@ -0,0 +1,63 @@
+# 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.
+
+module Deltacloud::Collections
+  class Networks < Base
+
+    include Deltacloud::Features
+
+    set :capability, lambda { |m| driver.respond_to? m }
+    check_features :for => lambda { |c, f| driver.class.has_feature?(c, f) }
+
+    get '/networks/new' do
+      respond_to do |format|
+        format.html { haml :"networks/new" }
+      end
+    end
+
+    collection :networks do
+
+      standard_show_operation
+      standard_index_operation
+
+      operation :create, :with_capability => :create_network do
+        param :address_block, :string, :optional
+        param :name,          :string, :optional
+        control do
+          @network = driver.create_network(credentials, { :address_block => 
params[:address_block]})
+          respond_to do |format|
+            format.xml  { haml :"networks/show" }
+            format.html { haml :"networks/show" }
+            format.json { xml_to_json("networks/show")}
+          end
+        end
+      end
+
+      operation :destroy, :with_capability => :destroy_network do
+        control do
+          driver.destroy_network(credentials, params[:id])
+          status 204
+          respond_to do |format|
+            format.xml
+            format.json
+            format.html { redirect(networks_url) }
+          end
+        end
+      end
+
+    end
+
+  end
+end
diff --git a/server/lib/deltacloud/collections/subnets.rb 
b/server/lib/deltacloud/collections/subnets.rb
new file mode 100644
index 0000000..9d5fd74
--- /dev/null
+++ b/server/lib/deltacloud/collections/subnets.rb
@@ -0,0 +1,65 @@
+
+# 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.
+
+module Deltacloud::Collections
+  class Subnets < Base
+
+    include Deltacloud::Features
+
+    set :capability, lambda { |m| driver.respond_to? m }
+    check_features :for => lambda { |c, f| driver.class.has_feature?(c, f) }
+
+    get '/subnets/new' do
+      respond_to do |format|
+        format.html { haml :"subnets/new" }
+      end
+    end
+
+
+    collection :subnets do
+
+      standard_show_operation
+      standard_index_operation
+
+      operation :create, :with_capability => :create_subnet do
+        param :network_id, :string, :required
+        param :address_block,  :string,  :required
+        control do
+          @subnet = driver.create_subnet(credentials, { :network_id => 
params[:network_id], :address_block => params[:address_block]})
+          respond_to do |format|
+            format.xml  { haml :"subnets/show"}
+            format.html { haml :"subnets/show" }
+            format.json { xml_to_json("subnets/show")}
+          end
+        end
+      end
+
+      operation :destroy, :with_capability => :destroy_subnet do
+        control do
+          driver.destroy_subnet(credentials, params[:id])
+          status 204
+          respond_to do |format|
+            format.xml
+            format.json
+            format.html { redirect(subnets_url) }
+          end
+        end
+      end
+
+    end
+
+  end
+end
-- 
1.8.1.4

Reply via email to