From: NjeriChelimo <[email protected]>
---
clients/cimi/lib/entities/volume_image.rb | 21 +++++++++++++++++++++
clients/cimi/views/volume_images/index.haml | 26 ++++++++++++++++++++++++++
2 files changed, 47 insertions(+)
diff --git a/clients/cimi/lib/entities/volume_image.rb
b/clients/cimi/lib/entities/volume_image.rb
index f3cc56b..df96ddc 100644
--- a/clients/cimi/lib/entities/volume_image.rb
+++ b/clients/cimi/lib/entities/volume_image.rb
@@ -22,9 +22,30 @@ class CIMI::Frontend::VolumeImage < CIMI::Frontend::Entity
end
get '/cimi/volume_images' do
+ volumes_xml = get_entity_collection('volumes', credentials)
+ @volumes = CIMI::Model::VolumeCollection.from_xml(volumes_xml)
volume_images_xml = get_entity_collection('volume_images', credentials)
@volume_images =
CIMI::Model::VolumeImageCollection.from_xml(volume_images_xml)
haml :'volume_images/index'
end
+ post '/cimi/volume_images' do
+ volume_image_xml = Nokogiri::XML::Builder.new do |xml|
+ xml.VolumeImage(:xmlns => CIMI::Frontend::CMWG_NAMESPACE) {
+ xml.name params[:volume_image][:name]
+ xml.description params[:volume_image][:description]
+ xml.imageLocation( :href => params[:volume_image][:image_location] )
+ }
+ end.to_xml
+ begin
+ result = create_entity('volume_images', volume_image_xml, credentials)
+ volume_image = CIMI::Model::VolumeImageCollection.from_xml(result)
+ flash[:success] = "Volume Image was successfully created."
+ redirect "/cimi/volume_images/#{volume_image.name}", 302
+ rescue => e
+ flash[:error] = "Volume Image cannot be created: #{e.message}"
+ redirect :back
+ end
+ end
+
end
diff --git a/clients/cimi/views/volume_images/index.haml
b/clients/cimi/views/volume_images/index.haml
index ea32a1e..fa71008 100644
--- a/clients/cimi/views/volume_images/index.haml
+++ b/clients/cimi/views/volume_images/index.haml
@@ -9,6 +9,32 @@
VolumeImageCollection
- content_for :actions do
+
+ %p
+ %a{ :href => '#volumeImageModal', :class => 'btn btn-primary',
:'data-toggle' => :modal} New Volume Image
+
+ %div{ :id => :volumeImageModal, :class => 'modal hide fade' }
+ .modal-header
+ %h3 Create new Volume Image
+ %form{ :action => "/cimi/volume_images", :method => :post }
+ %fieldset
+ .control-group
+ %label.control-label{ :for => 'volume_image[name]' } Volume Image
Name
+ .controls
+ %input{ :type => :text, :name => 'volume_image[name]' }
+ %label.control-label{ :for => 'volume_image[description]' } Volume
Image Description
+ .controls
+ %input{ :type => :text, :name => 'volume_image[description]' }
+ %label.control-label{ :for => 'volume_image[image_location]' }
Image Location
+ .controls
+ %select{ :name => 'volume_image[image_location]' }
+ - @volumes.volumes.each do |volume|
+ %option{ :value => volume.id }=href_to_id(volume.id)
+ .modal-footer
+ %a{ :href => '#', :class => 'btn btn-primary', :'data-loading-text' =>
'Creating VolumeImage...', :onclick => "postModalForm(this,
'volumeImageModal')"} Continue
+ %a{ :href => '#', :class => 'btn', :'data-dismiss' => 'modal'} Cancel
+ %p{:style => 'text-align:right;'}
+
%p
%a{ :href => "#{@volume_images.id}?format=xml", :class => 'label warning'
} XML
%a{ :href => "#{@volume_images.id}?format=json", :class => 'label warning'
} JSON
--
1.7.9.5