You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltacloud.apache.org by mf...@apache.org on 2011/11/16 13:49:16 UTC
svn commit: r1202674 - in /incubator/deltacloud/trunk/server:
lib/cimi/model/machine_image.rb spec/cimi/data/machine_image.json
spec/cimi/data/machine_image.xml spec/cimi/model/machine_image_spec.rb
Author: mfojtik
Date: Wed Nov 16 12:49:16 2011
New Revision: 1202674
URL: http://svn.apache.org/viewvc?rev=1202674&view=rev
Log:
CIMI: Added MachineImage model
Added:
incubator/deltacloud/trunk/server/lib/cimi/model/machine_image.rb (with props)
incubator/deltacloud/trunk/server/spec/cimi/data/machine_image.json
incubator/deltacloud/trunk/server/spec/cimi/data/machine_image.xml (with props)
incubator/deltacloud/trunk/server/spec/cimi/model/machine_image_spec.rb (with props)
Added: incubator/deltacloud/trunk/server/lib/cimi/model/machine_image.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/lib/cimi/model/machine_image.rb?rev=1202674&view=auto
==============================================================================
--- incubator/deltacloud/trunk/server/lib/cimi/model/machine_image.rb (added)
+++ incubator/deltacloud/trunk/server/lib/cimi/model/machine_image.rb Wed Nov 16 12:49:16 2011
@@ -0,0 +1,23 @@
+# 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::MachineImage < CIMI::Model::Base
+
+ scalar :image_location
+
+ array :operations do
+ scalar :rel, :href
+ end
+end
Propchange: incubator/deltacloud/trunk/server/lib/cimi/model/machine_image.rb
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/deltacloud/trunk/server/spec/cimi/data/machine_image.json
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/spec/cimi/data/machine_image.json?rev=1202674&view=auto
==============================================================================
--- incubator/deltacloud/trunk/server/spec/cimi/data/machine_image.json (added)
+++ incubator/deltacloud/trunk/server/spec/cimi/data/machine_image.json Wed Nov 16 12:49:16 2011
@@ -0,0 +1,13 @@
+{
+ "uri": "http://cimi.example.org/machine_images/1",
+ "name": "My First image",
+ "description": "A image for testing",
+ "created": "2011-11-14",
+ "imageLocation": { "href": "nfs://cimi.example.com/images/1.img"}
+ "properties": [ {"name": "status", "value": "build"}, { "name": "locked", "value": "true" } ]
+ "operations": [
+ { "rel": "edit",
+ "href": "http://cimi.example.org/machine_images/1/edit" },
+ { "rel": "delete",
+ "href": "http://cimi.example.org/machine_images/1/delete" }]
+}
Added: incubator/deltacloud/trunk/server/spec/cimi/data/machine_image.xml
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/spec/cimi/data/machine_image.xml?rev=1202674&view=auto
==============================================================================
--- incubator/deltacloud/trunk/server/spec/cimi/data/machine_image.xml (added)
+++ incubator/deltacloud/trunk/server/spec/cimi/data/machine_image.xml Wed Nov 16 12:49:16 2011
@@ -0,0 +1,11 @@
+<MachineImage xmlns="http://www.dmtf.org/cimi">
+ <uri>http://cimi.example.org/machine_image/1</uri>
+ <name>img1</name>
+ <description>Machine Image One</description>
+ <created>2011-11-14</created>
+ <property name="status">BUILD</property>
+ <property name="locked">true</property>
+ <imageLocation href="nfs://cimi.example.com/images/1.img"/>
+ <operation rel="edit" href="http://cimi.example.org/machine_image/1/edit"/>
+ <operation rel="delete" href="http://cimi.example.org/machine_image/1/delete"/>
+</MachineImage>
Propchange: incubator/deltacloud/trunk/server/spec/cimi/data/machine_image.xml
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/deltacloud/trunk/server/spec/cimi/model/machine_image_spec.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/spec/cimi/model/machine_image_spec.rb?rev=1202674&view=auto
==============================================================================
--- incubator/deltacloud/trunk/server/spec/cimi/model/machine_image_spec.rb (added)
+++ incubator/deltacloud/trunk/server/spec/cimi/model/machine_image_spec.rb Wed Nov 16 12:49:16 2011
@@ -0,0 +1,66 @@
+# 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 "MachineImage model" do
+
+ before(:all) do
+ @xml = IO::read(File::join(DATA_DIR, "machine_image.xml"))
+ @json = IO::read(File::join(DATA_DIR, "machine_template.json"))
+ end
+
+ it "can be constructed from XML" do
+ img = CIMI::Model::MachineImage.from_xml(@xml)
+ img.should_not be_nil
+ img.created.should == "2011-11-14"
+ img.name.should == "img1"
+ img.description.should == "Machine Image One"
+ img.uri.should == "http://cimi.example.org/machine_image/1"
+ img.image_location.size == 1
+ img.image_location[0]['href'].should == 'nfs://cimi.example.com/images/1.img'
+ img.operations.any? { |operation| operation.rel == 'edit' }.should be_true
+ img.operations.any? { |operation| operation.rel == 'delete' }.should be_true
+ img.operations.each { |operation| operation.href.should =~ /^http:\/\/.*\/(#{operation.rel})$/ }
+ img.should serialize_to @xml, :fmt => :xml
+ end
+
+ it "should parse properties correctly in XML" do
+ img = CIMI::Model::MachineImage.from_xml(@xml)
+ img.property.any? { |p| p.name == 'status' }.should be_true
+ img.property.any? { |p| p.name == 'locked' }.should be_true
+ img.property.size.should == 2
+ end
+
+ it "should convert strings in keys to symbols when contructed from XML" do
+ imgl = CIMI::Model::MachineImage.from_xml(@xml)
+ imgl.should_not be_nil
+ imgl.attribute_values.keys.each { |key| key.should be_a(Symbol) }
+ end
+
+ it "can be constructed from JSON" do
+ templ = CIMI::Model::MachineTemplate.from_json(@json)
+ templ.should_not be_nil
+ templ.created.should == "2011-11-01"
+ templ.should serialize_to @json, :fmt => :json
+ end
+
+ it "should parse properties correctly in JSON" do
+ img = CIMI::Model::MachineImage.from_json(@json)
+ # TODO: Fix this
+ # img.property.any? { |p| p.name == 'status' }.should be_true
+ # img.property.any? { |p| p.name == 'locked' }.should be_true
+ # img.property.size.should == 2
+ end
+end
Propchange: incubator/deltacloud/trunk/server/spec/cimi/model/machine_image_spec.rb
------------------------------------------------------------------------------
svn:eol-style = native