From: Michal Fojtik <mfoj...@redhat.com> 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.
Signed-off-by: Michal fojtik <mfoj...@redhat.com> --- 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(-) diff --git a/server/lib/cimi/models/machine.rb b/server/lib/cimi/models/machine.rb index 0e180ce..04fdba4 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 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 => [ 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" } } 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" -- 1.8.1