You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltacloud.apache.org by lu...@apache.org on 2013/02/25 22:08:27 UTC

[6/6] git commit: CIMI Webapp creating MachineTemplate

Updated Branches:
  refs/heads/master 9130760a0 -> a09a7cf79


CIMI Webapp creating MachineTemplate


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

Branch: refs/heads/master
Commit: 71de4dc6ff1be572d65db30e08b655d19e2cc487
Parents: 598bdbc
Author: NjeriChelimo <ma...@gmail.com>
Authored: Mon Feb 25 12:29:40 2013 +0300
Committer: David Lutterkort <lu...@redhat.com>
Committed: Mon Feb 25 13:05:58 2013 -0800

----------------------------------------------------------------------
 clients/cimi/lib/entities/machine_template.rb   |   23 +++++++++++++
 clients/cimi/views/machine_templates/index.haml |   32 ++++++++++++++++++
 clients/cimi/views/machine_templates/show.haml  |   12 ++----
 3 files changed, 59 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltacloud/blob/71de4dc6/clients/cimi/lib/entities/machine_template.rb
----------------------------------------------------------------------
diff --git a/clients/cimi/lib/entities/machine_template.rb b/clients/cimi/lib/entities/machine_template.rb
index ccc80a3..9986639 100644
--- a/clients/cimi/lib/entities/machine_template.rb
+++ b/clients/cimi/lib/entities/machine_template.rb
@@ -22,9 +22,32 @@ class CIMI::Frontend::MachineTemplate < CIMI::Frontend::Entity
   end
 
   get '/cimi/machine_templates' do
+    machine_image_xml = get_entity_collection('machine_images', credentials)
+    @machine_images = CIMI::Model::MachineImageCollection.from_xml(machine_image_xml)
+    machine_conf_xml = get_entity_collection('machine_configurations', credentials)
+    @machine_configurations = CIMI::Model::MachineConfigurationCollection.from_xml(machine_conf_xml)
     machine_template_xml = get_entity_collection('machine_templates', credentials)
     @machine_templates = CIMI::Model::MachineTemplateCollection.from_xml(machine_template_xml)
     haml :'machine_templates/index'
   end
 
+  post '/cimi/machine_templates' do
+    machine_template_xml = Nokogiri::XML::Builder.new do |xml|
+      xml.MachineTemplate(:xmlns => CIMI::Frontend::CMWG_NAMESPACE) {
+        xml.name params[:machine_template][:name]
+        xml.description params[:machine_template][:description]
+        xml.machineConfig( :href => params[:machine_template][:machine_config] )
+        xml.machineImage( :href => params[:machine_template][:machine_image] )
+      }
+    end.to_xml
+    begin
+      result = create_entity('machine_templates', machine_template_xml, credentials)
+      machine_template = CIMI::Model::MachineTemplateCollection.from_xml(result)
+      flash[:success] = "Machine Template was successfully created."
+      redirect "/cimi/machine_templates/#{machine_template.name}", 302
+    rescue => e
+      flash[:error] = "Machine Template cannot be created: #{e.message}"
+    end
+  end
+
 end

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/71de4dc6/clients/cimi/views/machine_templates/index.haml
----------------------------------------------------------------------
diff --git a/clients/cimi/views/machine_templates/index.haml b/clients/cimi/views/machine_templates/index.haml
index 165dcf4..75af386 100644
--- a/clients/cimi/views/machine_templates/index.haml
+++ b/clients/cimi/views/machine_templates/index.haml
@@ -8,6 +8,38 @@
     %li.active
       MachineTemplateCollection
 
+- content_for :actions do
+
+  %p
+    %a{ :href => '#machineTemplateModal', :class => 'btn btn-primary', :'data-toggle' => :modal} New Machine Template
+
+  %div{ :id => :machineTemplateModal, :class => 'modal hide fade' }
+    .modal-header
+      %h3 Create new Machine Template
+    .modal-body
+      %form{ :action => "/cimi/machine_templates", :method => :post }
+        %fieldset
+          .control-group
+            %label.control-label{ :for => 'machine_template[name]' } Machine Template Name
+            .controls
+              %input{ :type => :text, :name => 'machine_template[name]' }
+            %label.control-label{ :for => 'machine_template[machine_image]' } Machine Image
+            .controls
+              %select{ :name => 'machine_template[machine_image]' }
+                - @machine_images.machine_images.each do |image|
+                  %option{ :value => image.id }=href_to_id(image.id)
+            %label.control-label{ :for => 'machine_template[machine_config]' } Machine Configuration
+            .controls
+              %select{ :name => 'machine_template[machine_config]' }
+                - @machine_configurations.machine_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 MachineTemplate...', :onclick => "postModalForm(this, 'machineTemplateModal')"} Continue
+      %a{ :href => '#', :class => 'btn', :'data-dismiss' => 'modal'} Cancel
+  %p{:style => 'text-align:right;'}
+    %a{ :href => "#{@machine_templates.id}?format=xml", :class => 'label warning' } XML
+    %a{ :href => "#{@machine_templates.id}?format=json", :class => 'label warning' } JSON
+
 %blockquote
   %p
     A Machine Template Collection entity represents the collection of

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/71de4dc6/clients/cimi/views/machine_templates/show.haml
----------------------------------------------------------------------
diff --git a/clients/cimi/views/machine_templates/show.haml b/clients/cimi/views/machine_templates/show.haml
index bc7d587..c3b5013 100644
--- a/clients/cimi/views/machine_templates/show.haml
+++ b/clients/cimi/views/machine_templates/show.haml
@@ -6,19 +6,15 @@
       %a{ :href => "/cimi/cloudEntryPoint"} CloudEntryPoint
       %span.divider="/"
     %li
-      %a{ :href => "/cimi/machine_templates"} MachineConfigurationCollection
+      %a{ :href => "/cimi/machine_templates"} MachineTemplateCollection
       %span.divider="/"
     %li.active
       = @machine_template.name
 
-%blockquote
-  %p
-    The Machine Configuration entity represents the set of configuration values
-    that define the (virtual) hardware resources of a to-be-realized Machine
-    Instance. Machine Configurations are created by Providers and MAY, at the
-    Providers discretion, be created by Consumers.
-
 -details 'MachineTemplate details' do
   -row 'id',@machine_template.id
+  -row 'Name',@machine_template.name
   -row 'Description',@machine_template.description
   -row 'Created',@machine_template.created
+  -row 'Machine Image', url("/cimi/machine_images/#{href_to_id @machine_template.machine_image.href}")
+  -row 'Machine Configuration', url("/cimi/machine_configurations/#{href_to_id @machine_template.machine_config.href}")