deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@redhat.com
Subject [PATCH core 4/7] CIMI: Add database support to Address entity
Date Wed, 02 Jan 2013 12:23:54 GMT
From: Michal Fojtik <mfojtik@redhat.com>


Signed-off-by: Michal fojtik <mfojtik@redhat.com>
---
 server/lib/cimi/models/address.rb | 15 ++++++++++-----
 server/support/cimi/address.json  | 10 ++++++++++
 server/support/cimi/address.xml   |  9 +++++++++
 3 files changed, 29 insertions(+), 5 deletions(-)
 create mode 100644 server/support/cimi/address.json
 create mode 100644 server/support/cimi/address.xml

diff --git a/server/lib/cimi/models/address.rb b/server/lib/cimi/models/address.rb
index 042df1b..29318aa 100644
--- a/server/lib/cimi/models/address.rb
+++ b/server/lib/cimi/models/address.rb
@@ -51,7 +51,7 @@ class CIMI::Model::Address < CIMI::Model::Base
 
   def self.create(request_body, context, type)
     input = (type == :xml)? XmlSimple.xml_in(request_body, {"ForceArray"=>false, "NormaliseSpace"=>2})
: JSON.parse(request_body)
-    if input["addressTemplate"]["href"] #by reference
+    if input['AddressTemplate'] and input["addressTemplate"]["href"] #by reference
       address_template = CIMI::Model::AddressTemplate.find(context.href_id(input["addressTemplate"]["href"],
:address_templates), context)
     else
       case type
@@ -64,27 +64,32 @@ class CIMI::Model::Address < CIMI::Model::Base
     end
     params = {:name=>input["name"], :description=>input["description"], :address_template=>address_template,
:env=>context }
     raise CIMI::Model::BadRequest.new("Bad request - missing required parameters. Client
sent: #{request_body} which produced #{params.inspect}")  if params.has_value?(nil)
-    context.driver.create_address(context.credentials, params)
+    address = context.driver.create_address(context.credentials, params)
+    store_attributes_for(address, input)
+    from_address(address, context)
   end
 
   def self.delete!(id, context)
     context.driver.delete_address(context.credentials, id)
+    delete_attributes_for(::Address.new(:id => id))
   end
 
   private
 
   def self.from_address(address, context)
+    stored_attributes = load_attributes_for(address)
     self.new(
-      :name => address.id,
+      :name => stored_attributes[:name] || address.id,
       :id => context.address_url(address.id),
-      :description => "Address #{address.id}",
+      :description => stored_attributes[:description] || "Address #{address.id}",
       :ip => address.id,
       :allocation => "dynamic", #or "static"
-      :default_gateway => "unkown", #wtf
+      :default_gateway => "unknown", #wtf
       :dns => "unknown", #wtf
       :protocol => protocol_from_address(address.id),
       :mask => "unknown",
       :resource => (address.instance_id) ? {:href=> context.machine_url(address.instance_id)}
: nil,
+      :property => stored_attributes[:property],
       :network => nil #unknown
       #optional:
       #:hostname =>
diff --git a/server/support/cimi/address.json b/server/support/cimi/address.json
new file mode 100644
index 0000000..e3df598
--- /dev/null
+++ b/server/support/cimi/address.json
@@ -0,0 +1,10 @@
+{
+  "resourceURI": "http://schemas.dmtf.org/cimi/1/AddressCreate",
+  "name": "myDemoAddress",
+  "description": "My very favorite address",
+  "addressTemplate": { "ip" : "127.0.0.1" },
+  "properties": {
+    "foo": "bar",
+    "life": "is life"
+  }
+}
diff --git a/server/support/cimi/address.xml b/server/support/cimi/address.xml
new file mode 100644
index 0000000..a687d02
--- /dev/null
+++ b/server/support/cimi/address.xml
@@ -0,0 +1,9 @@
+<AddressCreate>
+  <name>myAddress</name>
+  <addressTemplate>
+    <ip>127.0.0.1</ip>
+  </addressTemplate>
+  <description>Description of my new address</description>
+  <property key="address_test">value_address</property>
+  <property key="foo">bar</property>
+</AddressCreate>
-- 
1.8.0.2


Mime
View raw message