Signed-off-by: Scott Seago <sseago(a)redhat.com>
---
src/app/models/deployment.rb | 19 +++++++++---
src/app/models/instance.rb | 5 +++
src/app/util/assembly_xml.rb | 46 +++++++++++++++++++++++++++++++
src/app/util/condormatic.rb | 18 ++++++------
src/app/util/deployable_xml.rb | 51 +++++++++++++++++++++++++++++++++++
src/app/views/deployments/_new.haml | 25 ++++++++++++++---
6 files changed, 146 insertions(+), 18 deletions(-)
create mode 100644 src/app/util/assembly_xml.rb
create mode 100644 src/app/util/deployable_xml.rb
diff --git a/src/app/models/deployment.rb b/src/app/models/deployment.rb
index 52d09c7..36b6b22 100644
--- a/src/app/models/deployment.rb
+++ b/src/app/models/deployment.rb
@@ -36,6 +36,8 @@
# also available at
http://www.gnu.org/copyleft/gpl.html.
require 'sunspot_rails'
+require 'util/deployable_xml'
+
class Deployment < ActiveRecord::Base
include SearchFilter
include PermissionedObject
@@ -113,21 +115,24 @@ class Deployment < ActiveRecord::Base
def launch(hw_profiles, user)
errors = []
- raise "the deployable must have at least one assembly and each assembly must
have at least one template" unless legacy_deployable.launchable?
- legacy_deployable.legacy_assemblies.each do |assembly|
+ raise "the deployable must have at least one assembly and each assembly must
have at least one image" unless deployable_xml.launchable?
+ deployable_xml.assemblies.each do |assembly|
# TODO: for now we try to start all instances even if some of them fails
begin
Instance.transaction do
- hw_profile = hw_profiles[assembly.id.to_s]
+ hw_profile = HardwareProfile.frontend.find_by_name(assembly["hwp"])
+ raise "Hardware Profile #{assembly['hwp']} not found." unless
hw_profile
instance = Instance.create!(
:deployment => self,
:name => "#{name}/#{assembly.name}",
:frontend_realm => realm,
:pool => pool,
- :legacy_assembly => assembly,
+ :image_uuid => assembly.image_id,
+ :image_build_uuid => assembly.image_build,
+ :assembly_xml => assembly.to_s,
:state => Instance::STATE_NEW,
:owner => user,
- :hardware_profile => hw_profile ? HardwareProfile.find(hw_profile) : nil
+ :hardware_profile => hw_profile
)
task = InstanceTask.create!({:user => user,
:task_target => instance,
@@ -153,6 +158,10 @@ class Deployment < ActiveRecord::Base
deployments
end
+ def deployable_xml
+ @deployable_xml ||= DeployableXML.new(self[:deployable_xml].to_s)
+ end
+
def import_xml_from_url(url)
# Right now we allow this to raise exceptions on timeout / errors
resource = RestClient::Resource.new(url, :open_timeout => 10, :timeout => 45)
diff --git a/src/app/models/instance.rb b/src/app/models/instance.rb
index 1d36647..734e2c6 100644
--- a/src/app/models/instance.rb
+++ b/src/app/models/instance.rb
@@ -55,6 +55,7 @@
# Likewise, all the methods added will be available for all controllers.
require 'sunspot_rails'
+require 'util/assembly_xml'
class Instance < ActiveRecord::Base
include SearchFilter
include PermissionedObject
@@ -187,6 +188,10 @@ class Instance < ActiveRecord::Base
ImageBuild.find(image_build_uuid) if image_build_uuid
end
+ def assembly_xml
+ @assembly_xml ||= AssemblyXML.new(self[:assembly_xml].to_s)
+ end
+
# Provide method to check if requested action exists, so caller can decide
# if they want to throw an error of some sort before continuing
# (ie in service api)
diff --git a/src/app/util/assembly_xml.rb b/src/app/util/assembly_xml.rb
new file mode 100644
index 0000000..aa4657a
--- /dev/null
+++ b/src/app/util/assembly_xml.rb
@@ -0,0 +1,46 @@
+#
+# Copyright (C) 2011 Red Hat, Inc.
+# Written by Scott Seago <sseago(a)redhat.com>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+# MA 02110-1301, USA. A copy of the GNU General Public License is
+# also available at
http://www.gnu.org/copyleft/gpl.html.
+
+class AssemblyXML
+ def initialize(xmlstr = "")
+ @doc = Nokogiri::XML(xmlstr)
+ @root = @doc.root.at_xpath('/assembly') if @doc.root
+ @image = @root.at_xpath('image') if @root
+ end
+
+ def to_s
+ @root.to_s
+ end
+
+ def name
+ @root["name"] if @root
+ end
+
+ def hwp
+ @root["hwp"] if @root
+ end
+
+ def image_id
+ @image["id"] if @image
+ end
+
+ def image_build
+ @image["build"] if @image
+ end
+
diff --git a/src/app/util/condormatic.rb b/src/app/util/condormatic.rb
index 4278d06..d47accd 100644
--- a/src/app/util/condormatic.rb
+++ b/src/app/util/condormatic.rb
@@ -35,26 +35,26 @@ end
def match(instance)
possibles = []
- legacy_template_id = instance.legacy_template ? instance.legacy_template.id :
instance.legacy_assembly.legacy_templates.first.id
-
PoolFamily.all.each do |pool_family|
if instance.pool.pool_family.id != pool_family.id
next
end
+ if instance.image_build_uuid
+ image_build = instance.image_build
+ else
+ image_build = instance.image.latest_build
+ end
pool_family.provider_accounts.each do |account|
# match_provider_hardware_profile returns a single provider
# hardware_profile that can satisfy the input hardware_profile
hwp = HardwareProfile.match_provider_hardware_profile(account.provider,
instance.hardware_profile)
- provider_images = hwp.provider.legacy_provider_images.find(:all,
- :conditions =>
['provider_image_key IS NOT NULL'])
+ # FIXME: "provider images for account.provider whcih map to image_build
+ provider_images = ProviderImage.find_all_by_provider_and_build(account.provider,
+ image_build)
provider_images.each do |pi|
- if pi.legacy_image.legacy_template.id != legacy_template_id
- next
- end
-
if not instance.frontend_realm.nil?
instance.frontend_realm.realm_backend_targets.each do |brealm|
possibles << Possible.new(pool_family, account, hwp, pi,
@@ -134,7 +134,7 @@ def condormatic_instance_create(task)
"grid_resource = deltacloud #{found.account.provider.url}\n")
pipe_and_log(pipe, "DeltacloudUsername =
#{found.account.credentials_hash['username']}\n")
pipe_and_log(pipe, "DeltacloudPasswordFile = #{pwfilename}")
- pipe_and_log(pipe, "DeltacloudImageId =
#{found.provider_image.provider_image_key}\n")
+ pipe_and_log(pipe, "DeltacloudImageId =
#{found.provider_image.target_identifier}\n")
pipe_and_log(pipe,
"DeltacloudHardwareProfile = #{found.hwp.external_key}\n")
pipe_and_log(pipe,
diff --git a/src/app/util/deployable_xml.rb b/src/app/util/deployable_xml.rb
new file mode 100644
index 0000000..f034292
--- /dev/null
+++ b/src/app/util/deployable_xml.rb
@@ -0,0 +1,51 @@
+#
+# Copyright (C) 2011 Red Hat, Inc.
+# Written by Scott Seago <sseago(a)redhat.com>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+# MA 02110-1301, USA. A copy of the GNU General Public License is
+# also available at
http://www.gnu.org/copyleft/gpl.html.
+
+class DeployableXML
+
+ def initialize(xmlstr = "")
+ @doc = Nokogiri::XML(xmlstr)
+ @root = @doc.root.at_xpath('/deployable') if @doc.root
+ end
+
+ def name
+ @root["name"] if @root
+ end
+
+ def description
+ node = @root ? @root.at_xpath("description") : nil
+ node ? node.text : nil
+ end
+
+ def launchable?
+ assemblies = @root.xpath('/deployable/assemblies/assembly')
+ return false unless assemblies.size > 0
+ assemblies.each do |assembly|
+ return false unless assembly.xpath("image").size >0
+ end
+ return true
+ end
+
+ def assemblies
+ @assemblies ||=
+ @root.xpath('/deployable/assemblies/assembly').collect do |assembly_node|
+ Nokogiri::XML(assembly_node.to_s)
+ end
+ end
+end
diff --git a/src/app/views/deployments/_new.haml b/src/app/views/deployments/_new.haml
index f515d7f..a0903da 100644
--- a/src/app/views/deployments/_new.haml
+++ b/src/app/views/deployments/_new.haml
@@ -19,13 +19,30 @@
= link_to('view deployable definition', '#')
%h2
- Images
+ Deployable details
--# Cannot implement this with real data until we have deployments implemented...
-= filter_table(['Image'], []) do |image|
+%ul
+ %li
+ Name:
+ = @deployment.deployable_xml.name
+ %li
+ Description:
+ = @deployment.deployable_xml.description
+ %li
+ Launchable:
+ = @deployment.deployable_xml.launchable?
+
+%h2
+ Assemblies
+
+= filter_table(['Assembly Name', 'Hardware Profile', 'Image ID',
'Build ID'],
+ @deployment.deployable_xml.assemblies) do |assembly|
%tr
%td
- = image.name
+ = assembly["name"]
+ = assembly["hwp"]
+ = assembly["image"]["id"]
+ = assembly["image"]["build"]
- form_for @deployment do
= hidden_field :deployment, :name
--
1.7.4.4