From: NjeriChelimo <martha.c.ch...@gmail.com> --- clients/cimi/lib/entities/machine_template.rb | 23 ++++++++++++++ clients/cimi/views/machine_templates/index.haml | 38 ++++++++++++++++++++--- clients/cimi/views/machine_templates/show.haml | 12 +++---- server/lib/db/entity.rb | 2 +- 4 files changed, 62 insertions(+), 13 deletions(-)
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 diff --git a/clients/cimi/views/machine_templates/index.haml b/clients/cimi/views/machine_templates/index.haml index 3daff47..75af386 100644 --- a/clients/cimi/views/machine_templates/index.haml +++ b/clients/cimi/views/machine_templates/index.haml @@ -1,4 +1,4 @@ -- @title=@machine_templates.description +- @title=collection_name @machine_templates - content_for :breadcrumb do %ul.breadcrumb @@ -8,6 +8,37 @@ %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 @@ -19,9 +50,8 @@ %ul - @machine_templates.machine_templates.each do |temp| %li - %a{ :href => "/cimi/machine_templates/#{temp.href.split('/').last}"}=temp.href.split('/').last + %a{ :href => "/cimi/machine_templates/#{href_to_id(temp.id)}"}=href_to_id(temp.id) -details 'MachineTemplateCollection details' do -row 'id',@machine_templates.id - -row 'Description',@machine_templates.description - -row 'Created',@machine_templates.created + -row 'Count',@machine_templates.count 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}") diff --git a/server/lib/db/entity.rb b/server/lib/db/entity.rb index 45a7f30..a9c8f8b 100644 --- a/server/lib/db/entity.rb +++ b/server/lib/db/entity.rb @@ -15,7 +15,7 @@ module Deltacloud module Database - + require 'json/pure' class Entity < Sequel::Model attr_accessor :properties -- 1.7.9.5