deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From martha.c.ch...@gmail.com
Subject [PATCH 3/4] CIMI Webapp creating a Network
Date Mon, 25 Feb 2013 09:29:42 GMT
From: NjeriChelimo <martha.c.chumo@gmail.com>

---
 clients/cimi/lib/entities/network.rb   |   25 +++++++++++++++++++++++++
 clients/cimi/views/networks/index.haml |   28 ++++++++++++++++++++++++++++
 2 files changed, 53 insertions(+)

diff --git a/clients/cimi/lib/entities/network.rb b/clients/cimi/lib/entities/network.rb
index 8ce9942..db1f011 100644
--- a/clients/cimi/lib/entities/network.rb
+++ b/clients/cimi/lib/entities/network.rb
@@ -22,9 +22,34 @@ class CIMI::Frontend::Network < CIMI::Frontend::Entity
   end
 
   get '/cimi/networks' do
+    forwarding_groups_xml = get_entity_collection('forwarding_groups', credentials)
+    @forwarding_groups = CIMI::Model::ForwardingGroupCollection.from_xml(forwarding_groups_xml)
+    network_config_xml = get_entity_collection('network_configurations', credentials)
+    @network_configurations = CIMI::Model::NetworkConfigurationCollection.from_xml(network_config_xml)
     networks_xml = get_entity_collection('networks', credentials)
     @networks = CIMI::Model::NetworkCollection.from_xml(networks_xml)
     haml :'networks/index'
   end
 
+  post '/cimi/networks' do
+    network_xml = Nokogiri::XML::Builder.new do |xml|
+      xml.Network(:xmlns => CIMI::Frontend::CMWG_NAMESPACE) {
+        xml.name params[:network][:name]
+        xml.description params[:network][:description]
+        xml.networkTemplate {
+          xml.networkConfig( :href => params[:network][:network_configuration] )
+          xml.forwardingGroup( :href => params[:network][:forwarding_group] )
+        }
+      }
+    end.to_xml
+    begin
+      result = create_entity('networks', network_xml, credentials)
+      network = CIMI::Model::NetworkCollection.from_xml(result)
+      flash[:success] = "Network was successfully created."
+      redirect "/cimi/networks/#{network.name}", 302
+    rescue => e
+      flash[:error] = "Network cannot be created: #{e.message}"
+    end
+  end
+
 end
diff --git a/clients/cimi/views/networks/index.haml b/clients/cimi/views/networks/index.haml
index 2ebd23f..405cd11 100644
--- a/clients/cimi/views/networks/index.haml
+++ b/clients/cimi/views/networks/index.haml
@@ -6,9 +6,37 @@
       %a{ :href => "/cimi/cloudEntryPoint"} CloudEntryPoint
       %span.divider="/"
     %li.active
+
       NetworkCollection
 
 - content_for :actions do
+
+  %p
+    %a{ :href => '#networkModal', :class => 'btn btn-primary', :'data-toggle' =>
:modal} New Network
+
+  %div{ :id => :networkModal, :class => 'modal hide fade' }
+    .modal-header
+      %h3 Create new Network entity
+    .modal-body
+      %form{ :action => "/cimi/networks", :method => :post }
+        %fieldset
+          .control-group
+            %label.control-label{ :for => 'network[name]' } Network Name
+            .controls
+              %input{ :type => :text, :name => 'network[name]' }
+            %label.control-label{ :for => 'network[forwarding_group]' } Forwarding Group
+            .controls
+              %select{ :name => 'network[forwarding_group]' }
+                - @forwarding_groups.forwarding_groups.each do |group|
+                  %option{ :value => group.id }=href_to_id(group.id)
+            %label.control-label{ :for => 'network[network_configuration]' } Network Configuration
+            .controls
+              %select{ :name => 'network[network_configuration]' }
+                - @network_configurations.network_configurations.each do |configuration|
+                  %option{ :value => configuration.id }=href_to_id(configuration.id)
+    .modal-footer
+      %a{ :href => '#', :class => 'btn btn-primary', :'data-loading-text' => 'Creating
Network...', :onclick => "postModalForm(this, 'networkModal')"} Continue
+      %a{ :href => '#', :class => 'btn', :'data-dismiss' => 'modal'} Cancel
   %p
     %a{ :href => "#{@networks.id}?format=xml", :class => 'label warning' } XML
     %a{ :href => "#{@networks.id}?format=json", :class => 'label warning' } JSON
-- 
1.7.9.5


Mime
View raw message