You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltacloud.apache.org by ma...@apache.org on 2013/02/06 16:16:49 UTC
git commit: CIMI - implement initial_states capability in mock driver
- DTACLOUD-447
Updated Branches:
refs/heads/master 717ce9e60 -> 4275a2a52
CIMI - implement initial_states capability in mock driver - DTACLOUD-447
https://issues.apache.org/jira/browse/DTACLOUD-447
Project: http://git-wip-us.apache.org/repos/asf/deltacloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltacloud/commit/4275a2a5
Tree: http://git-wip-us.apache.org/repos/asf/deltacloud/tree/4275a2a5
Diff: http://git-wip-us.apache.org/repos/asf/deltacloud/diff/4275a2a5
Branch: refs/heads/master
Commit: 4275a2a529c2728dc691569a9af0192f8d88c1e0
Parents: 717ce9e
Author: marios <ma...@redhat.com>
Authored: Tue Feb 5 11:30:56 2013 +0200
Committer: marios <ma...@redhat.com>
Committed: Wed Feb 6 17:16:30 2013 +0200
----------------------------------------------------------------------
server/lib/cimi/models/machine.rb | 11 ++++++++---
server/lib/deltacloud/drivers/mock/mock_driver.rb | 6 +++---
2 files changed, 11 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/4275a2a5/server/lib/cimi/models/machine.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/models/machine.rb b/server/lib/cimi/models/machine.rb
index 67e3eef..6e075e8 100644
--- a/server/lib/cimi/models/machine.rb
+++ b/server/lib/cimi/models/machine.rb
@@ -52,6 +52,7 @@ class CIMI::Model::Machine < CIMI::Model::Base
def self.create_from_json(body, context)
json = JSON.parse(body)
+ additional_params={}
machine_template = json['machineTemplate']
if !machine_template['href'].nil?
template = current_db.machine_templates.first(:id => machine_template['href'].split('/').last)
@@ -65,8 +66,9 @@ class CIMI::Model::Machine < CIMI::Model::Base
additional_params[:keyname] = machine_template['credential']["href"].split('/').last
end
end
-
- additional_params = {}
+ if machine_template.has_key? "initialState"
+ additional_params[:initial_state] = machine_template["initialState"].strip
+ end
additional_params[:name] = json['name'] if json['name']
instance = context.driver.create_instance(context.credentials, image_id, {
:hwp_id => hardware_profile_id
@@ -80,6 +82,7 @@ class CIMI::Model::Machine < CIMI::Model::Base
def self.create_from_xml(body, context)
xml = XmlSimple.xml_in(body)
+ additional_params = {}
if xml['machineTemplate'][0]['href']
template = current_db.machine_templates_dataset.first(:id => xml['machineTemplate'][0]['href'].split('/').last)
hardware_profile_id = template.machine_config.split('/').last
@@ -92,7 +95,9 @@ class CIMI::Model::Machine < CIMI::Model::Base
additional_params[:keyname] = machine_template['credential'][0]["href"].split('/').last
end
end
- additional_params = {}
+ if xml["machineTemplate"][0].has_key? "initialState"
+ additional_params[:initial_state] = xml["machineTemplate"][0]["initialState"].first.strip
+ end
additional_params[:name] = xml['name'][0] if xml['name']
instance = context.driver.create_instance(context.credentials, image_id, {
:hwp_id => hardware_profile_id
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/4275a2a5/server/lib/deltacloud/drivers/mock/mock_driver.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/drivers/mock/mock_driver.rb b/server/lib/deltacloud/drivers/mock/mock_driver.rb
index b12ca57..cb18e92 100644
--- a/server/lib/deltacloud/drivers/mock/mock_driver.rb
+++ b/server/lib/deltacloud/drivers/mock/mock_driver.rb
@@ -205,11 +205,11 @@ module Deltacloud::Drivers::Mock
hwp ||= find_hardware_profile(credentials, 'm1-small', image_id)
name = opts[:name] || "i-#{Time.now.to_i}"
-
+ initial_state = opts[:initial_state] || "RUNNING"
instance = {
:id => next_id,
:name=>name,
- :state=>'RUNNING',
+ :state=> (initial_state == "STARTED" ? "RUNNING" : initial_state),
:keyname => opts[:keyname],
:image_id=>image_id,
:owner_id=>credentials.user,
@@ -218,7 +218,7 @@ module Deltacloud::Drivers::Mock
:instance_profile => InstanceProfile.new(hwp.name, opts),
:realm_id=>realm_id,
:create_image=>true,
- :actions=>instance_actions_for( 'RUNNING' ),
+ :actions=>instance_actions_for((initial_state == "STARTED" ? "RUNNING" : initial_state)),
:user_data => opts[:user_data] ? Base64::decode64(opts[:user_data]) : nil
}
@client.store(:instances, instance)