From: Michal Fojtik <mfoj...@redhat.com>
Signed-off-by: Michal fojtik <mfoj...@redhat.com> --- server/lib/deltacloud/hardware_profile.rb | 8 ++ .../lib/deltacloud/helpers/application_helper.rb | 6 +- server/server.rb | 5 +- server/views/instances/new.xml.haml | 99 ++++++++++++++++++++ 4 files changed, 114 insertions(+), 4 deletions(-) create mode 100644 server/views/instances/new.xml.haml diff --git a/server/lib/deltacloud/hardware_profile.rb b/server/lib/deltacloud/hardware_profile.rb index e304d7c..0c2bac9 100644 --- a/server/lib/deltacloud/hardware_profile.rb +++ b/server/lib/deltacloud/hardware_profile.rb @@ -68,6 +68,14 @@ module Deltacloud kind == :fixed end + def range? + kind == :range + end + + def enum? + kind == :enum + end + def to_param return nil if kind == :fixed if kind == :range diff --git a/server/lib/deltacloud/helpers/application_helper.rb b/server/lib/deltacloud/helpers/application_helper.rb index 46fa0eb..9c4aa21 100644 --- a/server/lib/deltacloud/helpers/application_helper.rb +++ b/server/lib/deltacloud/helpers/application_helper.rb @@ -49,13 +49,17 @@ module ApplicationHelper end def driver_has_feature?(feature_name, collection_name = :instances) - not driver.features(collection_name).select{ |f| f.name.eql?(feature_name) }.empty? + driver_feature(collection_name, feature_name) end def driver_has_auth_features? driver_has_feature?(:authentication_password) || driver_has_feature?(:authentication_key) end + def driver_feature(collection_name, feature_name) + driver.features(collection_name).select{ |f| f.name.eql?(feature_name) }.first + end + def driver_auth_feature_name return 'key' if driver_has_feature?(:authentication_key) return 'password' if driver_has_feature?(:authentication_password) diff --git a/server/server.rb b/server/server.rb index 42ff24a..d06539c 100644 --- a/server/server.rb +++ b/server/server.rb @@ -411,9 +411,8 @@ END @keys = driver.keys(credentials) if driver_has_feature?(:authentication_key) @firewalls = driver.firewalls(credentials) if driver_has_feature?(:firewalls) respond_to do |format| - format.html do - haml :'instances/new' - end + format.xml { haml :'instances/new' } + format.html { haml :'instances/new' } end end end diff --git a/server/views/instances/new.xml.haml b/server/views/instances/new.xml.haml new file mode 100644 index 0000000..498dec2 --- /dev/null +++ b/server/views/instances/new.xml.haml @@ -0,0 +1,99 @@ +%xforms{ :'xmlns:xf' => "http://www.w3.org/2002/xforms", :'xmlns:xsd' => "http://www.w3.org/2001/XMLSchema", :'xmlns:xsi' => "http://www.w3.org/2001/XMLSchema-instance"} + %model + %submission{ :id =>"new_instance", :method => "GET", :action => create_instance_url } + %instance + %instance + %image_id{ :'xsi:type' => 'xsd:token' }=@image ? @image.id : nil + - if driver_has_feature?(:user_name) and driver_feature(:instances, :user_name).constraints[:max_length] + %xsd:element{ :name => :name } + %xsd:simpleType + %xsd:restriction{ :base => "xs:string" } + %xsd:maxLength{ :value => driver_feature(:instances, :user_name).constraints[:max_length] } + - if driver_has_feature?(:user_name) + %name{ :'xsi:type' => 'xsd:token' } + - if driver_has_feature?(:user_data) + %user_data{ :'xsi:type' => 'xsd:base64Binary' } + - if driver_has_feature?(:instance_count) + %instance_count{ :'xsi:type' => 'xsd:decimal' } + - if driver_has_feature?(:authentication_key) + %keyname{ :'xsi:type' => 'xsd:token' } + - if driver_has_feature?(:register_to_load_balancer) + %load_balancer_id{ :'xsi:type' => 'xsd:token' } + - if driver_has_feature?(:firewalls) + - @firewalls.each_index do |i| + ='<firewalls'+i+' xsi:type="xsd:boolean" />' + - unless @realms.empty? + %realm_id{ :'xsi:type' => 'xsd:token'}=@realms.first.id + - unless @hardware_profiles.empty? + - @hardware_profiles.each do |profile| + %hwp_id{ :'xsi:type' => 'xsd:token', :type => profile.name } + - profile.properties.reject { |prop| prop.fixed? }.each do |prop| + - if prop.name == :architecture + %hwp_architecture{ :'xsi:type' => 'xsd:token'}=prop.value + - else + ='<hwp_'+prop.name.to_s+' xsi:type="xsd:decimal"/>' + - profile.properties.select { |prop| prop.fixed? }.each do |prop| + - if prop.name == :architecture + %hwp_architecture{ :'xsi:type' => 'xsd:token'}=prop.value + - else + ='<hwp_'+prop.name.to_s+' xsi:type="xsd:decimal">'+prop.value.to_s+'</hwp_'+prop.name.to_s+'>' + %bind{ :nodeset => "instance/image_id", :required => 'true()'} + - if driver_has_feature?(:user_name) and driver_feature(:instances, :user_name).constraints[:max_length] + %bind{ :nodeset => "user_name:to", :constraints => ". > ../user_name:from" } + %input{ :model => :instance, :ref => "image_id" } + %label Image ID + - if driver_has_feature?(:user_name) + %input{ :model => :instance, :ref => "name" } + %label Instance name + - if driver_has_feature?(:user_data) + %input{ :model => :instance, :ref => "user_data"} + %label User data + - if driver_has_feature?(:instance_count) + %input{ :model => :instance, :ref => "instance_count"} + %label Number of instances to launch + - unless @realms.empty? + %select1{ :model => :instance, :ref => :realm_id} + %label Place instance into realm + - @realms.each do |realm| + %item + %name=realm.name + %value=realm.id + - if driver_has_feature?(:authentication_key) + %select1{ :model => :instance, :ref => :authentication_key} + %label Instance authentication key + - @keys.each do |key| + %item + %name=key.id + %value=key.id + - if driver_has_feature?(:register_to_load_balancer) + %select1{ :model => :instance, :ref => :load_balancer_id} + %label Register instance to loadbalancers + - @load_balancers.each do |load_balancer| + %item + %name=load_balancer.id + %value=load_balancer.id + - if driver_has_feature?(:firewalls) + - @firewalls.each_index do |i| + %input{ :model => :instance, :ref => "firewalls#{i}"} + %label="Assign to firewall #{i}" + - unless @hardware_profiles.empty? + %select1{ :model => :instance, :ref => "hwp_id" } + %label Hardware Profile + - @hardware_profiles.each do |profile| + %item{ :type => profile.name} + %value=profile.name + - profile.properties.select { |prop| prop.fixed? }.each do |prop| + %select1{ :model => :instance, :ref => "hwp_id[@type=#{profile.name}]/hwp_#{prop.name}"} + %label="#{prop.name.to_s.capitalize}" + %item + %value=prop.value + - profile.properties.reject { |prop| prop.fixed? }.each do |prop| + - if prop.range? + %range{ :ref => "hwp_id[@type=#{profile.name}]/hwp_#{prop.name}", :model => :instance, :start => prop.first, :end => prop.last, :step => 1} + %label="#{prop.name.to_s.capitalize}" + -if prop.enum? + %select{ :ref => "hwp_id[@type=#{profile.name}]/hwp_#{prop.name}", :model => :instance} + %label="#{prop.name.to_s.capitalize}" + - prop.values.each do |v| + %item + %value=v -- 1.7.4.1