deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@apache.org
Subject [2/5] git commit: CIMI: Add support for 'realm' in MachineTemplate
Date Tue, 19 Feb 2013 09:11:23 GMT
CIMI: Add support for 'realm' in MachineTemplate

Clients can now specify the 'realm' attribute when
creating the new MachineTemplate entity. If they then use
this MachineTemplate to create a new Machine, the Machine
will be placed into that realm.


Project: http://git-wip-us.apache.org/repos/asf/deltacloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltacloud/commit/165922f7
Tree: http://git-wip-us.apache.org/repos/asf/deltacloud/tree/165922f7
Diff: http://git-wip-us.apache.org/repos/asf/deltacloud/diff/165922f7

Branch: refs/heads/master
Commit: 165922f798787af6cc23287763c67218d5991e99
Parents: 3c23c18
Author: Michal Fojtik <mfojtik@redhat.com>
Authored: Thu Feb 7 15:34:06 2013 +0100
Committer: Michal fojtik <mfojtik@redhat.com>
Committed: Tue Feb 19 10:10:57 2013 +0100

----------------------------------------------------------------------
 server/lib/cimi/models/machine.rb          |    4 +++-
 server/lib/cimi/models/machine_template.rb |    6 ++++++
 server/support/cimi/machine_from_temp.json |    2 +-
 server/support/cimi/machine_template.json  |    1 +
 4 files changed, 11 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltacloud/blob/165922f7/server/lib/cimi/models/machine.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/models/machine.rb b/server/lib/cimi/models/machine.rb
index 4a1c42e..1b8e28a 100644
--- a/server/lib/cimi/models/machine.rb
+++ b/server/lib/cimi/models/machine.rb
@@ -55,10 +55,11 @@ class CIMI::Model::Machine < CIMI::Model::Base
     additional_params={}
     machine_template = json['machineTemplate']
     if !machine_template['href'].nil?
-      template = current_db.machine_templates.first(:id => machine_template['href'].split('/').last)
+      template = current_db.machine_templates_dataset.first(:id => machine_template['href'].split('/').last)
       raise 'Could not find the MachineTemplate' if template.nil?
       hardware_profile_id = template.machine_config.split('/').last
       image_id = template.machine_image.split('/').last
+      json['realm'] = template.realm
     else
       hardware_profile_id = machine_template['machineConfig']["href"].split('/').last
       image_id = machine_template['machineImage']["href"].split('/').last
@@ -92,6 +93,7 @@ class CIMI::Model::Machine < CIMI::Model::Base
       template = current_db.machine_templates_dataset.first(:id => xml['machineTemplate'][0]['href'].split('/').last)
       hardware_profile_id = template.machine_config.split('/').last
       image_id = template.machine_image.split('/').last
+      xml['realm'] = [ template.realm ]
     else
       machine_template = xml['machineTemplate'][0]
       hardware_profile_id = machine_template['machineConfig'].first["href"].split('/').last

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/165922f7/server/lib/cimi/models/machine_template.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/models/machine_template.rb b/server/lib/cimi/models/machine_template.rb
index 5ba9b3e..685fef5 100644
--- a/server/lib/cimi/models/machine_template.rb
+++ b/server/lib/cimi/models/machine_template.rb
@@ -21,6 +21,9 @@ class CIMI::Model::MachineTemplate < CIMI::Model::Base
   href :machine_image
   href :credential
 
+  resource_attr :realm, :required => false,
+    :constraints => lambda { |c| c.driver.realms(c.credentials).map { |r| r.id }}
+
   array :volumes do
     scalar :href
     scalar :protocol
@@ -59,6 +62,7 @@ class CIMI::Model::MachineTemplate < CIMI::Model::Base
         :description => json['description'],
         :machine_config => json['machineConfig']['href'],
         :machine_image => json['machineImage']['href'],
+        :realm => json['realm'],
         :ent_properties => json['properties'] ? json['properties'].to_json : {}
       )
       from_db(new_template, context)
@@ -71,6 +75,7 @@ class CIMI::Model::MachineTemplate < CIMI::Model::Base
         :description => xml['description'].first,
         :machine_config => xml['machineConfig'].first['href'],
         :machine_image => xml['machineImage'].first['href'],
+        :realm => xml['realm'].first,
         :ent_properties => xml['property'] ? JSON::dump(xml['property'].inject({}) { |r,
p| r[p['key']]=p['content']; r }) : {}
       )
       from_db(new_template, context)
@@ -89,6 +94,7 @@ class CIMI::Model::MachineTemplate < CIMI::Model::Base
         :description => model.description,
         :machine_config => { :href => model.machine_config },
         :machine_image => { :href => model.machine_image },
+        :realm => model.realm,
         :property => (model.ent_properties ? JSON::parse(model.ent_properties) :  nil),
         :created => Time.parse(model.created_at.to_s).xmlschema,
         :operations => [

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/165922f7/server/support/cimi/machine_from_temp.json
----------------------------------------------------------------------
diff --git a/server/support/cimi/machine_from_temp.json b/server/support/cimi/machine_from_temp.json
index c7d7ab8..b4cd0d7 100644
--- a/server/support/cimi/machine_from_temp.json
+++ b/server/support/cimi/machine_from_temp.json
@@ -6,5 +6,5 @@
     "foo": "bar",
     "life": "is life"
   },
-  "machineTemplate": { "href": "http://localhost:3001/cimi/machine_templates/8" }
+  "machineTemplate": { "href": "http://localhost:3001/cimi/machine_templates/1" }
 }

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/165922f7/server/support/cimi/machine_template.json
----------------------------------------------------------------------
diff --git a/server/support/cimi/machine_template.json b/server/support/cimi/machine_template.json
index 3f219dc..edc1294 100644
--- a/server/support/cimi/machine_template.json
+++ b/server/support/cimi/machine_template.json
@@ -4,6 +4,7 @@
   "description": "My very loved machine template",
   "machineConfig": { "href": "http://localhost:3001/cimi/machine_configurations/m1-xlarge"
},
   "machineImage": { "href": "http://localhost:3001/cimi/machine_images/img3" },
+  "realm": "us",
   "properties": {
     "foo": "bar",
     "life": "is life"


Mime
View raw message