deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mar...@redhat.com
Subject [PATCH 2/3] Network API Routes and Views
Date Mon, 05 Nov 2012 14:42:18 GMT
From: marios <marios@redhat.com>


Signed-off-by: marios <marios@redhat.com>
---
 server/lib/deltacloud/collections/networks.rb | 62 +++++++++++++++++++++++++++
 server/lib/deltacloud/collections/ports.rb    | 57 ++++++++++++++++++++++++
 server/lib/deltacloud/collections/subnets.rb  | 58 +++++++++++++++++++++++++
 server/views/networks/index.html.haml         | 10 +++++
 server/views/networks/index.xml.haml          |  4 ++
 server/views/networks/new.html.haml           | 10 +++++
 server/views/networks/show.html.haml          | 24 +++++++++++
 server/views/networks/show.xml.haml           | 16 +++++++
 8 files changed, 241 insertions(+)
 create mode 100644 server/lib/deltacloud/collections/networks.rb
 create mode 100644 server/lib/deltacloud/collections/ports.rb
 create mode 100644 server/lib/deltacloud/collections/subnets.rb
 create mode 100644 server/views/networks/index.html.haml
 create mode 100644 server/views/networks/index.xml.haml
 create mode 100644 server/views/networks/new.html.haml
 create mode 100644 server/views/networks/show.html.haml
 create mode 100644 server/views/networks/show.xml.haml
 create mode 100644 server/views/ports/index.html.haml
 create mode 100644 server/views/ports/index.xml.haml
 create mode 100644 server/views/ports/show.html.haml
 create mode 100644 server/views/ports/show.xml.haml
 create mode 100644 server/views/subnets/index.html.haml
 create mode 100644 server/views/subnets/index.xml.haml
 create mode 100644 server/views/subnets/show.html.haml
 create mode 100644 server/views/subnets/show.xml.haml

diff --git a/server/lib/deltacloud/collections/networks.rb b/server/lib/deltacloud/collections/networks.rb
new file mode 100644
index 0000000..f0a6c70
--- /dev/null
+++ b/server/lib/deltacloud/collections/networks.rb
@@ -0,0 +1,62 @@
+# 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
+        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, { :id => 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/ports.rb b/server/lib/deltacloud/collections/ports.rb
new file mode 100644
index 0000000..2947246
--- /dev/null
+++ b/server/lib/deltacloud/collections/ports.rb
@@ -0,0 +1,57 @@
+
+# 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 Ports < Base
+
+    include Deltacloud::Features
+
+    set :capability, lambda { |m| driver.respond_to? m }
+    check_features :for => lambda { |c, f| driver.class.has_feature?(c, f) }
+
+    collection :ports do
+
+      standard_show_operation
+      standard_index_operation
+
+      operation :create, :with_capability => :create_port do
+        param :network,  :string,  :required
+        control do
+          @port = driver.create_port(credentials, { :network => params[:network] })
+          respond_to do |format|
+            format.xml  { haml :"ports/show"}
+            format.html { haml :"ports/show" }
+            format.json { xml_to_json("ports/show")}
+          end
+        end
+      end
+
+      operation :destroy, :with_capability => :destroy_port do
+        control do
+          driver.destroy_port(credentials, { :id => params[:id]})
+          status 204
+          respond_to do |format|
+            format.xml
+            format.json
+            format.html { redirect(ports_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..7d70ae4
--- /dev/null
+++ b/server/lib/deltacloud/collections/subnets.rb
@@ -0,0 +1,58 @@
+
+# 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) }
+
+    collection :subnets do
+
+      standard_show_operation
+      standard_index_operation
+
+      operation :create, :with_capability => :create_subnet do
+        param :address_block,  :string,  :optional
+        param :ports, :string, :optional
+        control do
+          @subnet = driver.create_subnet(credentials, { :ports => params[:ports], :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, { :id => params[:id]})
+          status 204
+          respond_to do |format|
+            format.xml
+            format.json
+            format.html { redirect(subnets_url) }
+          end
+        end
+      end
+
+    end
+
+  end
+end
diff --git a/server/views/networks/index.html.haml b/server/views/networks/index.html.haml
new file mode 100644
index 0000000..aa0050b
--- /dev/null
+++ b/server/views/networks/index.html.haml
@@ -0,0 +1,10 @@
+=header "Networks" do
+  %a{ :href => url_for('networks/new'), :'data-icon' => :plus, :'data-role' => :button,
:class => 'ui-btn-right'} Create new network
+
+%div{ :'data-role' => :content, :'data-theme' => 'c'}
+  %ul{ :'data-role' => :listview , :'data-inset' => :true, :'data-divider-theme' =>
'a'}
+    - @elements.each do |net|
+      %li
+        %a{ :href => network_url(net.id), :'data-ajax' => 'false'}
+          %img{ :class => 'ui-link-thumb', :src => '/images/cloud.png'}
+          %h3=net.id
diff --git a/server/views/networks/index.xml.haml b/server/views/networks/index.xml.haml
new file mode 100644
index 0000000..f2eaac6
--- /dev/null
+++ b/server/views/networks/index.xml.haml
@@ -0,0 +1,4 @@
+!!!XML
+%networks
+  - @elements.each do |c|
+    = haml :'networks/show', :locals => { :@network => c, :partial => true }
diff --git a/server/views/networks/new.html.haml b/server/views/networks/new.html.haml
new file mode 100644
index 0000000..0087259
--- /dev/null
+++ b/server/views/networks/new.html.haml
@@ -0,0 +1,10 @@
+=header "Create new network"
+
+%div{ :'data-role' => :content, :'data-theme' => 'c', :class => 'middle-dialog'}
+  %form{ :action => networks_url, :method => :post}
+    %div{ 'data-role' => :fieldcontain }
+      %p
+        %label{ :for => :address_block} CIDR Address block (optional):
+      %p
+        %input{ :type => :text, :id => :address_block, :name => :address_block,
:value => '' }
+    %button{ :type => :submit} Create network
diff --git a/server/views/networks/show.html.haml b/server/views/networks/show.html.haml
new file mode 100644
index 0000000..db69784
--- /dev/null
+++ b/server/views/networks/show.html.haml
@@ -0,0 +1,24 @@
+=header "Network"
+=subheader @network.id
+
+%div{ :'data-role' => :content, :'data-theme' => 'c'}
+  %ul{ :'data-role' => :listview , :'data-inset' => :true, :'data-divider-theme' =>
'd'}
+    %li{ :'data-role' => 'list-divider'} Identifier
+    %li
+      %p{ :'data-role' => 'fieldcontain'}=@network.id
+    %li{ :'data-role' => 'list-divider'} Name
+    %li
+      %p{ :'data-role' => 'fieldcontain'}=@network.name
+    %li{ :'data-role' => 'list-divider'} State
+    %li
+      %p{ :'data-role' => 'fieldcontain'}=@network.state
+    %li{ :'data-role' => 'list-divider'} Address Block
+    %li
+      %p{ :'data-role' => 'fieldcontain'}=(@network.address_block ? @network.address_block
: nil)
+    %li{ :'data-role' => 'list-divider'} Subnets
+    %li
+      %p{ :'data-role' => 'fieldcontain'}= (@network.subnets ? @network.subnets.join(",")
: nil)
+    %li{ :'data-role' => 'list-divider'} Actions
+    %li
+      %div{ :'data-role' => 'controlgroup', :'data-type' => "horizontal" }
+        =link_to_action "Destroy", destroy_network_url(@network.id), :delete
diff --git a/server/views/networks/show.xml.haml b/server/views/networks/show.xml.haml
new file mode 100644
index 0000000..4b4e07a
--- /dev/null
+++ b/server/views/networks/show.xml.haml
@@ -0,0 +1,16 @@
+- unless defined?(partial)
+  !!! XML
+%network{ :href => network_url(@network.id), :id => @network.id }
+  %name=@network.name
+  %state<
+    =@network.state
+  %address_block=@network.address_block
+  %subnets
+    - (@network.subnets || []).each do |subnet|
+      %subnet{:href => subnet_url(subnet), :id=>subnet}
+  %ports
+    - (@network.ports || []).each do |port|
+      %port{:href => port_url(port), :id=>port}
+  %actions
+    - if driver.respond_to?(:destroy_network)
+      %link{ :rel => "destroy", :method => "delete", :href => destroy_network_url(@network.id)}
diff --git a/server/views/ports/index.html.haml b/server/views/ports/index.html.haml
new file mode 100644
index 0000000..e69de29
diff --git a/server/views/ports/index.xml.haml b/server/views/ports/index.xml.haml
new file mode 100644
index 0000000..e69de29
diff --git a/server/views/ports/show.html.haml b/server/views/ports/show.html.haml
new file mode 100644
index 0000000..e69de29
diff --git a/server/views/ports/show.xml.haml b/server/views/ports/show.xml.haml
new file mode 100644
index 0000000..e69de29
diff --git a/server/views/subnets/index.html.haml b/server/views/subnets/index.html.haml
new file mode 100644
index 0000000..e69de29
diff --git a/server/views/subnets/index.xml.haml b/server/views/subnets/index.xml.haml
new file mode 100644
index 0000000..e69de29
diff --git a/server/views/subnets/show.html.haml b/server/views/subnets/show.html.haml
new file mode 100644
index 0000000..e69de29
diff --git a/server/views/subnets/show.xml.haml b/server/views/subnets/show.xml.haml
new file mode 100644
index 0000000..e69de29
-- 
1.7.11.7


Mime
View raw message