incubator-deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mar...@redhat.com
Subject [PATCH] Adds CIMI Volume model and spec data/test
Date Fri, 18 Nov 2011 09:25:25 GMT
From: marios <marios@redhat.com>


Signed-off-by: marios <marios@redhat.com>
---
 server/lib/cimi/model.rb              |    1 +
 server/lib/cimi/model/volume.rb       |   31 ++++++++++++++++++++++++++++
 server/spec/cimi/data/volume.json     |   16 ++++++++++++++
 server/spec/cimi/data/volume.xml      |   12 +++++++++++
 server/spec/cimi/model/volume_spec.rb |   36 +++++++++++++++++++++++++++++++++
 5 files changed, 96 insertions(+), 0 deletions(-)
 create mode 100644 server/lib/cimi/model/volume.rb
 create mode 100644 server/spec/cimi/data/volume.json
 create mode 100644 server/spec/cimi/data/volume.xml
 create mode 100644 server/spec/cimi/model/volume_spec.rb

diff --git a/server/lib/cimi/model.rb b/server/lib/cimi/model.rb
index 1e4a34a..c436074 100644
--- a/server/lib/cimi/model.rb
+++ b/server/lib/cimi/model.rb
@@ -25,3 +25,4 @@ require 'cimi/model/base'
 require 'cimi/model/machine_template'
 require 'cimi/model/machine_image'
 require 'cimi/model/machine_configuration'
+require 'cimi/model/volume'
diff --git a/server/lib/cimi/model/volume.rb b/server/lib/cimi/model/volume.rb
new file mode 100644
index 0000000..b83fcc3
--- /dev/null
+++ b/server/lib/cimi/model/volume.rb
@@ -0,0 +1,31 @@
+# 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::Volume < CIMI::Model::Base
+  struct :capacity do
+    scalar :quantity
+    scalar :units
+  end
+  text :bootable
+  text :supports_snapshots
+  array :snapshots do
+    scalar :ref
+  end
+  text :guest_interface
+  array :meters do
+    scalar :ref
+  end
+  scalar :eventlog
+end
diff --git a/server/spec/cimi/data/volume.json b/server/spec/cimi/data/volume.json
new file mode 100644
index 0000000..af22517
--- /dev/null
+++ b/server/spec/cimi/data/volume.json
@@ -0,0 +1,16 @@
+{
+  "uri": "http://cimi.example.org/volumes/1",
+  "name": "volume1",
+  "description": "Volume One",
+  "created": "2011-11-17",
+  "capacity": { "quantity": "10", "units": "gigabyte" },
+  "bootable": "false",
+  "supportsSnapshots": "false",
+  "guestInterface": "NFS",
+  "operations": [
+    { "rel": "edit",
+      "href": "http://cimi.example.org/volumes/1/edit" },
+    { "rel": "delete",
+      "href": "http://cimi.example.org/volumes/1/delete" }
+  ]
+}
diff --git a/server/spec/cimi/data/volume.xml b/server/spec/cimi/data/volume.xml
new file mode 100644
index 0000000..2e4699e
--- /dev/null
+++ b/server/spec/cimi/data/volume.xml
@@ -0,0 +1,12 @@
+<Volume xmlns="http://www.dmtf.org/cimi">
+  <uri>http://cimi.example.org/volumes/1</uri>
+  <name>volume1</name>
+  <description>Volume One</description>
+  <created>2011-11-17</created>
+  <capacity quantity="10" units="gigabyte"/>
+  <bootable>false</bootable>
+  <supportsSnapshots>false</supportsSnapshots>
+  <guestInterface>NFS</guestInterface>
+  <operation rel="edit" href="http://cimi.example.org/volumes/1/edit"/>
+  <operation rel="delete" href="http://cimi.example.org/volumes/1/delete"/>
+</Volume>
diff --git a/server/spec/cimi/model/volume_spec.rb b/server/spec/cimi/model/volume_spec.rb
new file mode 100644
index 0000000..829dc57
--- /dev/null
+++ b/server/spec/cimi/model/volume_spec.rb
@@ -0,0 +1,36 @@
+# 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 "Volume model" do
+
+  before(:all) do
+    @xml = IO::read(File::join(DATA_DIR, "volume.xml"))
+    @json = IO::read(File::join(DATA_DIR, "volume.json"))
+  end
+
+  it "can be constructed from XML" do
+    conf = CIMI::Model::Volume.from_xml(@xml)
+    conf.should_not be_nil
+    should_serialize_from_xml! conf, @xml, @json
+  end
+
+  it "can be constructed from JSON" do
+    conf = CIMI::Model::Volume.from_json(@json)
+    conf.should_not be_nil
+    should_serialize_from_json! conf, @xml, @json
+  end
+
+end
-- 
1.7.6.4


Mime
View raw message