deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@redhat.com
Subject [PATCH core 4/5] CIMI: Added MachineConfiguration model
Date Mon, 14 Nov 2011 15:09:30 GMT
From: Michal Fojtik <mfojtik@redhat.com>


Signed-off-by: Michal fojtik <mfojtik@redhat.com>
---
 server/lib/cimi/model/machine_configuration.rb     |   28 +++++++
 server/spec/cimi/data/machine_configuration.json   |   17 ++++
 server/spec/cimi/data/machine_configuration.xml    |   14 ++++
 .../spec/cimi/model/machine_configuration_spec.rb  |   78 ++++++++++++++++++++
 4 files changed, 137 insertions(+), 0 deletions(-)
 create mode 100644 server/lib/cimi/model/machine_configuration.rb
 create mode 100644 server/spec/cimi/data/machine_configuration.json
 create mode 100644 server/spec/cimi/data/machine_configuration.xml
 create mode 100644 server/spec/cimi/model/machine_configuration_spec.rb

diff --git a/server/lib/cimi/model/machine_configuration.rb b/server/lib/cimi/model/machine_configuration.rb
new file mode 100644
index 0000000..221236c
--- /dev/null
+++ b/server/lib/cimi/model/machine_configuration.rb
@@ -0,0 +1,28 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.  The
+# ASF licenses this file to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance with the
+# License.  You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+class CIMI::Model::MachineConfiguration < CIMI::Model::Base
+
+  scalar :memory
+  text :cpu
+
+  array :disk do
+    scalar :capacity
+  end
+
+  array :operations do
+    scalar :rel, :href
+  end
+end
diff --git a/server/spec/cimi/data/machine_configuration.json b/server/spec/cimi/data/machine_configuration.json
new file mode 100644
index 0000000..8864340
--- /dev/null
+++ b/server/spec/cimi/data/machine_configuration.json
@@ -0,0 +1,17 @@
+{
+  "uri": "http://cimi.example.org/machine_configurations/1",
+  "name": "MachineConfiguration1",
+  "description": "Example MachineConfiguration One",
+  "created": "2011-11-14",
+  "cpu": "2",
+  "memory" : { "quantity": "1", "units": "gigabyte" },
+  "disks" : [
+    { "capacity": { "quantity": "1", "units": "terabyte", "format": "ext4", "attachmentPoint":
"/" } }
+  ],
+  "properties": [ { "name": "architectore", "value" : "i386" } ],
+  "operations": [
+    { "rel": "edit",
+      "href": "http://cimi.example.org/machine_images/1/edit" },
+    { "rel": "delete",
+      "href": "http://cimi.example.org/machine_images/1/delete" }]
+}
diff --git a/server/spec/cimi/data/machine_configuration.xml b/server/spec/cimi/data/machine_configuration.xml
new file mode 100644
index 0000000..788a185
--- /dev/null
+++ b/server/spec/cimi/data/machine_configuration.xml
@@ -0,0 +1,14 @@
+<MachineConfiguration xmlns="http://www.dmtf.org/cimi">
+  <uri>http://cimi.example.org/machine_configurations/1</uri>
+  <name>MachineConfiguration1</name>
+  <description>Example MachineConfiguration One</description>
+  <created>2011-11-14</created>
+  <property name="architecture">i386</property>
+  <cpu>2</cpu>
+  <memory quantity="1" units="gigabyte"/>
+  <disk>
+    <capacity quantity="1" units="terabyte" format="ext4" attachmentPoint="/"/>
+  </disk>
+  <operation rel="edit" href="http://cimi.example.org/machine_configurations/1/edit"/>
+  <operation rel="delete" href="http://cimi.example.org/machine_configurations/1/delete"/>
+</MachineConfiguration>
diff --git a/server/spec/cimi/model/machine_configuration_spec.rb b/server/spec/cimi/model/machine_configuration_spec.rb
new file mode 100644
index 0000000..f17c69b
--- /dev/null
+++ b/server/spec/cimi/model/machine_configuration_spec.rb
@@ -0,0 +1,78 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.  The
+# ASF licenses this file to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance with the
+# License.  You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+# License for the specific language governing permissions and limitations
+# under the License.
+#
+describe "MachineConfiguration model" do
+
+  before(:all) do
+    @xml = IO::read(File::join(DATA_DIR, "machine_configuration.xml"))
+    @json = IO::read(File::join(DATA_DIR, "machine_configuration.json"))
+  end
+
+  it "can be constructed from XML" do
+    conf = CIMI::Model::MachineConfiguration.from_xml(@xml)
+    conf.should_not be_nil
+    conf.name.should == 'MachineConfiguration1'
+    conf.uri == 'http://cimi.example.org/machine_configurations/1'
+    conf.description == 'Example MachineConfiguration One'
+    conf.created.should == "2011-11-14"
+    conf.cpu.should == "2"
+    conf.memory.size.should == 1
+    conf.memory[0]['quantity'].should == '1'
+    conf.memory[0]['units'].should == 'gigabyte'
+    conf.disk.size.should == 1
+    conf.disk[0].respond_to?(:capacity).should be_true
+    conf.disk[0].capacity.size.should == 1
+    conf.disk[0].capacity[0]['format'] == 'ext4'
+    conf.disk[0].capacity[0]['quantity'] == '1'
+    conf.disk[0].capacity[0]['attachmentPoint'] == '/'
+    conf.disk[0].capacity[0]['units'] == 'terabyte'
+    conf.operations.size.should == 2
+    conf.operations.any? { |operation| operation.rel == 'edit' }.should be_true
+    conf.operations.any? { |operation| operation.rel == 'delete' }.should be_true
+    conf.operations.each { |operation| operation.href.should =~ /^http:\/\/.*\/(#{operation.rel})$/
}
+    conf.should serialize_to @xml, :fmt => :xml
+  end
+
+  it "should convert strings in keys to symbols when contructed from XML" do
+    conf = CIMI::Model::MachineConfiguration.from_xml(@xml)
+    conf.should_not be_nil
+    conf.attribute_values.keys.each { |key| key.should be_a(Symbol) }
+  end
+
+  it "can be constructed from JSON" do
+    conf = CIMI::Model::MachineConfiguration.from_json(@json)
+    conf.should_not be_nil
+    conf.name.should == 'MachineConfiguration1'
+    conf.uri == 'http://cimi.example.org/machine_configurations/1'
+    conf.description == 'Example MachineConfiguration One'
+    conf.created.should == "2011-11-14"
+    conf.cpu.should == "2"
+    conf.memory.size.should == 1
+    conf.memory[0]['quantity'].should == '1'
+    conf.memory[0]['units'].should == 'gigabyte'
+    conf.disk.size.should == 1
+    conf.disk[0].respond_to?(:capacity).should be_true
+    conf.disk[0].capacity.size.should == 1
+    conf.disk[0].capacity[0]['format'] == 'ext4'
+    conf.disk[0].capacity[0]['quantity'] == '1'
+    conf.disk[0].capacity[0]['attachmentPoint'] == '/'
+    conf.disk[0].capacity[0]['units'] == 'terabyte'
+    conf.operations.size.should == 2
+    conf.operations.any? { |operation| operation.rel == 'edit' }.should be_true
+    conf.operations.any? { |operation| operation.rel == 'delete' }.should be_true
+    conf.operations.each { |operation| operation.href.should =~ /^http:\/\/.*\/(#{operation.rel})$/
}
+    conf.should serialize_to @json, :fmt => :json
+  end
+end
-- 
1.7.4.4


Mime
View raw message