deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mar...@apache.org
Subject [3/5] git commit: CIMI: Fixes/Updates Address entities
Date Wed, 26 Sep 2012 09:04:52 GMT
CIMI: Fixes/Updates Address entities


Project: http://git-wip-us.apache.org/repos/asf/deltacloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltacloud/commit/0fa95022
Tree: http://git-wip-us.apache.org/repos/asf/deltacloud/tree/0fa95022
Diff: http://git-wip-us.apache.org/repos/asf/deltacloud/diff/0fa95022

Branch: refs/heads/master
Commit: 0fa9502247d76785175076a0dc24284a24903dcf
Parents: fe35656
Author: marios <marios@redhat.com>
Authored: Tue Sep 25 15:55:12 2012 +0300
Committer: marios <marios@redhat.com>
Committed: Tue Sep 25 15:55:12 2012 +0300

----------------------------------------------------------------------
 server/lib/cimi/collections/address_templates.rb   |    2 +-
 server/lib/cimi/collections/addresses.rb           |    2 +-
 server/lib/cimi/models/address.rb                  |   34 +++++++++++++--
 server/lib/cimi/models/address_template.rb         |    2 -
 .../data/cimi/address_template/addr_template1.json |    3 +-
 .../data/cimi/address_template/addr_template2.json |    3 +-
 6 files changed, 34 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltacloud/blob/0fa95022/server/lib/cimi/collections/address_templates.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/collections/address_templates.rb b/server/lib/cimi/collections/address_templates.rb
index 42cd82d..6501f03 100644
--- a/server/lib/cimi/collections/address_templates.rb
+++ b/server/lib/cimi/collections/address_templates.rb
@@ -32,7 +32,7 @@ module CIMI::Collections
         end
       end
 
-      operation :show, :with_capability => :address_template do
+      operation :show, :with_capability => :address_templates do
         description 'Show a specific AddressTemplate'
         control do
           address_template = CIMI::Model::AddressTemplate.find(params[:id], self)

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/0fa95022/server/lib/cimi/collections/addresses.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/collections/addresses.rb b/server/lib/cimi/collections/addresses.rb
index c3d3239..ea9af07 100644
--- a/server/lib/cimi/collections/addresses.rb
+++ b/server/lib/cimi/collections/addresses.rb
@@ -26,7 +26,7 @@ module CIMI::Collections
         description 'List all Addresses in the AddressCollection'
         param :CIMISelect, :string, :optional
         control do
-          addresses = Address.find(self).filter_by(params[:CIMISelect])
+          addresses = Address.list(self).filter_by(params[:CIMISelect])
           respond_to do |format|
             format.xml {addresses.to_xml}
             format.json {addresses.to_json}

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/0fa95022/server/lib/cimi/models/address.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/models/address.rb b/server/lib/cimi/models/address.rb
index 1704933..042df1b 100644
--- a/server/lib/cimi/models/address.rb
+++ b/server/lib/cimi/models/address.rb
@@ -27,8 +27,6 @@ class CIMI::Model::Address < CIMI::Model::Base
 
   text :dns
 
-  text :mac_address
-
   text :protocol
 
   text :mask
@@ -43,9 +41,11 @@ class CIMI::Model::Address < CIMI::Model::Base
 
   def self.find(id, context)
     if id==:all
-      context.driver.addresses(context.credentials, {:env=>context})
+      addresses = context.driver.addresses(context.credentials)
+      addresses.map{|addr| from_address(addr, context)}
     else
-      context.driver.addresses(context.credentials, {:id=>id, :env=>context})
+      address = context.driver.address(context.credentials, {:id=>id})
+      from_address(address, context)
     end
   end
 
@@ -71,4 +71,30 @@ class CIMI::Model::Address < CIMI::Model::Base
     context.driver.delete_address(context.credentials, id)
   end
 
+  private
+
+  def self.from_address(address, context)
+    self.new(
+      :name => address.id,
+      :id => context.address_url(address.id),
+      :description => "Address #{address.id}",
+      :ip => address.id,
+      :allocation => "dynamic", #or "static"
+      :default_gateway => "unkown", #wtf
+      :dns => "unknown", #wtf
+      :protocol => protocol_from_address(address.id),
+      :mask => "unknown",
+      :resource => (address.instance_id) ? {:href=> context.machine_url(address.instance_id)}
: nil,
+      :network => nil #unknown
+      #optional:
+      #:hostname =>
+      #:
+    )
+  end
+
+  def self.protocol_from_address(address)
+    addr = IPAddr.new(address)
+    addr.ipv4? ? "ipv4" : "ipv6"
+  end
+
 end

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/0fa95022/server/lib/cimi/models/address_template.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/models/address_template.rb b/server/lib/cimi/models/address_template.rb
index 9d7c36b..5ca6850 100644
--- a/server/lib/cimi/models/address_template.rb
+++ b/server/lib/cimi/models/address_template.rb
@@ -27,8 +27,6 @@ class CIMI::Model::AddressTemplate < CIMI::Model::Base
 
   text :dns
 
-  text :mac_address
-
   text :protocol
 
   text :mask

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/0fa95022/server/lib/deltacloud/drivers/mock/data/cimi/address_template/addr_template1.json
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/drivers/mock/data/cimi/address_template/addr_template1.json
b/server/lib/deltacloud/drivers/mock/data/cimi/address_template/addr_template1.json
index fd5140b..9853838 100644
--- a/server/lib/deltacloud/drivers/mock/data/cimi/address_template/addr_template1.json
+++ b/server/lib/deltacloud/drivers/mock/data/cimi/address_template/addr_template1.json
@@ -4,10 +4,9 @@
   "created": "Tue Apr 03 10:34:45 EET 2012",
   "ip": "192.168.10.1",
   "hostname": "marios.local",
-  "allocation": "static",
+  "allocation": "dynamic",
   "defaultGateway": "192.168.0.1",
   "dns": "192.168.0.10",
-  "macAddress": "",
   "protocol": "IPv4",
   "mask": "255.255.0.0",
   "network": {"href": "http://cimi.example.org/networks/network1"},

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/0fa95022/server/lib/deltacloud/drivers/mock/data/cimi/address_template/addr_template2.json
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/drivers/mock/data/cimi/address_template/addr_template2.json
b/server/lib/deltacloud/drivers/mock/data/cimi/address_template/addr_template2.json
index f4bdb56..c1ca418 100644
--- a/server/lib/deltacloud/drivers/mock/data/cimi/address_template/addr_template2.json
+++ b/server/lib/deltacloud/drivers/mock/data/cimi/address_template/addr_template2.json
@@ -4,10 +4,9 @@
   "created": "Wed Apr 04 13:27:15 EET 2012",
   "ip": "192.168.10.1",
   "hostname": "foo.bar",
-  "allocation": "static",
+  "allocation": "dynamic",
   "defaultGateway": "192.168.0.1",
   "dns": "192.168.0.10",
-  "macAddress": "",
   "protocol": "IPv4",
   "mask": "255.255.0.0",
   "network": {"href": "http://cimi.example.org/networks/network1"},


Mime
View raw message