deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@apache.org
Subject svn commit: r1211506 - in /deltacloud/trunk: clients/cimi/lib/cimi_frontend_helper.rb clients/cimi/views/machines/show.haml server/lib/cimi/model/machine.rb
Date Wed, 07 Dec 2011 16:19:38 GMT
Author: mfojtik
Date: Wed Dec  7 16:19:38 2011
New Revision: 1211506

URL: http://svn.apache.org/viewvc?rev=1211506&view=rev
Log:
CIMI: Added properties to Machine (machine_admin, machine_image references). Added some helpers
to handle UI for properties

Modified:
    deltacloud/trunk/clients/cimi/lib/cimi_frontend_helper.rb
    deltacloud/trunk/clients/cimi/views/machines/show.haml
    deltacloud/trunk/server/lib/cimi/model/machine.rb

Modified: deltacloud/trunk/clients/cimi/lib/cimi_frontend_helper.rb
URL: http://svn.apache.org/viewvc/deltacloud/trunk/clients/cimi/lib/cimi_frontend_helper.rb?rev=1211506&r1=1211505&r2=1211506&view=diff
==============================================================================
--- deltacloud/trunk/clients/cimi/lib/cimi_frontend_helper.rb (original)
+++ deltacloud/trunk/clients/cimi/lib/cimi_frontend_helper.rb Wed Dec  7 16:19:38 2011
@@ -17,6 +17,8 @@ module CIMI
   module Frontend
     module Helper
 
+      require 'uri'
+
       def href_to_id(href) 
         href.split('/').last
       end
@@ -63,6 +65,27 @@ module CIMI
         end
       end
 
+      def relativize_url(absolute_url)
+        URI.parse(absolute_url).path
+      end
+
+      def convert_urls(value)
+        value.gsub( %r{http(s?)://[^\s<]+} ) { |url| "<a href='#{relativize_url(url)}'>#{href_to_id(url)}</a>"
}
+      end
+
+      def not_implemented(collection_name)
+        return unless ['machine_templates', 'volume_templates'].include?(collection_name)
+        capture_haml do
+          haml_tag :span, :class => [ :label, :warning ] do
+            haml_concat 'pending'
+          end
+        end
+      end
+
+      def struct_to_name(struct_name)
+        struct_name.class.name.split('_').last
+      end
+
     end
   end
 end

Modified: deltacloud/trunk/clients/cimi/views/machines/show.haml
URL: http://svn.apache.org/viewvc/deltacloud/trunk/clients/cimi/views/machines/show.haml?rev=1211506&r1=1211505&r2=1211506&view=diff
==============================================================================
--- deltacloud/trunk/clients/cimi/views/machines/show.haml (original)
+++ deltacloud/trunk/clients/cimi/views/machines/show.haml Wed Dec  7 16:19:38 2011
@@ -51,7 +51,7 @@
     - if @machine.memory.quantity.nil?
       %span.label Not specified
     - else
-      =[@memory.quantity, @memory.units].join("&nbsp;")
+      =[@machine.memory.quantity, @machine.memory.units].join("&nbsp;")
   %dt Meters
   %dd
     - if @machine.meters.empty?
@@ -60,6 +60,19 @@
       - @machine.meters.each do |meters|
         %dd=meters.ref
 
+%h3 Properties
+
+%table.bordered-table
+  %thead
+    %tr
+      %th Name
+      %th Value
+  %tbody
+    - @machine.property.each do |property|
+      %tr
+        %td=property.name
+        %td=convert_urls property.value
+
 %h3 Network Interfaces
 
 %table.bordered-table
@@ -75,6 +88,11 @@
         %td
           %span.label.success=interface.state
         %td=interface.protocol
+    - if @machine.network_interfaces.empty?
+      %tr
+        %td{ :colspan => 3 }
+          %strong
+            There are no network interfaces defined for this Machine.
 
 %h3 Volumes
 
@@ -91,6 +109,12 @@
           %a{:href => "/cimi/volumes/#{href_to_id(volume.href)}" }=href_to_id(volume.href)
         %td=volume.attachment_point
         %td=volume.protocol
+    - if @machine.volumes.empty?
+      %tr
+        %td{ :colspan => 3 }
+          %strong
+            There are no Volume entities defined for this Machine.
+
 
 %h3 Disks
 
@@ -106,3 +130,8 @@
         %td=[boolean_span_for(disk.capacity.quantity), disk.capacity.units].join("&nbsp;")
         %td=boolean_span_for disk.format
         %td=boolean_span_for disk.attachment_point
+    - if @machine.disks.empty?
+      %tr
+        %td{ :colspan => 3 }
+          %strong
+            There are no disks defined for this Machine.

Modified: deltacloud/trunk/server/lib/cimi/model/machine.rb
URL: http://svn.apache.org/viewvc/deltacloud/trunk/server/lib/cimi/model/machine.rb?rev=1211506&r1=1211505&r2=1211506&view=diff
==============================================================================
--- deltacloud/trunk/server/lib/cimi/model/machine.rb (original)
+++ deltacloud/trunk/server/lib/cimi/model/machine.rb Wed Dec  7 16:19:38 2011
@@ -78,9 +78,16 @@ class CIMI::Model::Machine < CIMI::Model
 
   def self.create_from_xml(body, context)
     xml = XmlSimple.xml_in(body)
-    hardware_profile_id = xml['MachineTemplate'][0]['MachineConfig'][0]["href"].split('/').last
-    image_id = xml['MachineTemplate'][0]['MachineImage'][0]["href"].split('/').last
-    instance = context.driver.create_instance(context.credentials, image_id, { :hwp_id =>
hardware_profile_id })
+    machine_template = xml['MachineTemplate'][0]
+    hardware_profile_id = machine_template['MachineConfig'][0]["href"].split('/').last
+    image_id = machine_template['MachineImage'][0]["href"].split('/').last
+    additional_params = {}
+    if machine_template.has_key? 'MachineAdmin'
+      additional_params[:keyname] = machine_template['MachineAdmin'][0]["href"].split('/').last
+    end
+    instance = context.driver.create_instance(context.credentials, image_id, { 
+      :hwp_id => hardware_profile_id
+    }.merge(additional_params))
     from_instance(instance, context)
   end
 
@@ -106,14 +113,15 @@ class CIMI::Model::Machine < CIMI::Model
     self.new(
       :name => instance.id,
       :description => instance.name,
-      :created => Time.now,
+      :created => instance.launch_time,
       :uri => context.machine_url(instance.id),
       :state => convert_instance_state(instance.state),
       :cpu => convert_instance_cpu(instance.instance_profile, context),
       :memory => convert_instance_memory(instance.instance_profile, context),
       :disks => convert_instance_storage(instance.instance_profile, context),
       :network_interfaces => convert_instance_addresses(instance),
-      :operations => convert_instance_actions(instance, context)
+      :operations => convert_instance_actions(instance, context),
+      :property => convert_instance_properties(instance, context)
     )
   end
 
@@ -124,6 +132,15 @@ class CIMI::Model::Machine < CIMI::Model
     ('RUNNING' == state) ? 'STARTED' : state
   end
 
+  def self.convert_instance_properties(instance, context)
+    properties = []
+    properties << { :name => :machine_image, :value => context.machine_image_url(instance.image_id)
}
+    if instance.respond_to? :keyname
+      properties << { :name => :machine_admin, :value => context.machine_admin_url(instance.keyname)
}
+    end
+    properties
+  end
+
   def self.convert_instance_cpu(profile, context)
     cpu_override = profile.overrides.find { |p, v| p == :cpu }
     if cpu_override.nil?



Mime
View raw message