From: marios <[email protected]>
Signed-off-by: marios <[email protected]> --- server/lib/cimi/collections/address_templates.rb | 2 +- server/lib/cimi/models/address.rb | 34 +++++++++++++++++++--- server/lib/cimi/models/address_collection.rb | 11 ++++--- server/lib/cimi/models/address_template.rb | 2 -- .../lib/cimi/models/address_template_collection.rb | 11 ++++--- .../data/cimi/address_template/addr_template1.json | 3 +- .../data/cimi/address_template/addr_template2.json | 1 - 7 files changed, 46 insertions(+), 18 deletions(-) diff --git a/server/lib/cimi/collections/address_templates.rb b/server/lib/cimi/collections/address_templates.rb index 809fc82..ffe48c9 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) diff --git a/server/lib/cimi/models/address.rb b/server/lib/cimi/models/address.rb index f9e10a1..861a466 100644 --- a/server/lib/cimi/models/address.rb +++ b/server/lib/cimi/models/address.rb @@ -25,8 +25,6 @@ class CIMI::Model::Address < CIMI::Model::Base text :dns - text :mac_address - text :protocol text :mask @@ -41,9 +39,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 @@ -69,4 +69,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 diff --git a/server/lib/cimi/models/address_collection.rb b/server/lib/cimi/models/address_collection.rb index eef6c51..aa2597c 100644 --- a/server/lib/cimi/models/address_collection.rb +++ b/server/lib/cimi/models/address_collection.rb @@ -17,17 +17,20 @@ class CIMI::Model::AddressCollection < CIMI::Model::Base act_as_root_entity :address - array :addresses do - scalar :href - end + text :count + + self << CIMI::Model::Address + def self.default(context) + addresses = CIMI::Model::Address.all(context) self.new( :id => context.addresses_url, :name => 'default', :created => Time.now, :description => "#{context.driver.name.capitalize} AddressCollection", - :addresses => CIMI::Model::Address.all(context).map { |addr| { :href => addr.id } } + :count => addresses.count, + :addresses => addresses ) end diff --git a/server/lib/cimi/models/address_template.rb b/server/lib/cimi/models/address_template.rb index 9d2c409..56c9902 100644 --- a/server/lib/cimi/models/address_template.rb +++ b/server/lib/cimi/models/address_template.rb @@ -25,8 +25,6 @@ class CIMI::Model::AddressTemplate < CIMI::Model::Base text :dns - text :mac_address - text :protocol text :mask diff --git a/server/lib/cimi/models/address_template_collection.rb b/server/lib/cimi/models/address_template_collection.rb index 3bb95cd..c952c37 100644 --- a/server/lib/cimi/models/address_template_collection.rb +++ b/server/lib/cimi/models/address_template_collection.rb @@ -17,17 +17,20 @@ class CIMI::Model::AddressTemplateCollection < CIMI::Model::Base act_as_root_entity :address_template - array :address_templates do - scalar :href - end + text :count + + self << CIMI::Model::AddressTemplate + def self.default(context) + address_templates = CIMI::Model::AddressTemplate.all(context) self.new( :id => context.address_templates_url, :name => 'default', :created => Time.now, :description => "#{context.driver.name.capitalize} AddressTemplateCollection", - :address_templates => CIMI::Model::AddressTemplate.all(context).map { |addr| { :href => addr.id } } + :count => address_templates.size, + :address_templates => address_templates ) end 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"}, 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..de6866f 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 @@ -7,7 +7,6 @@ "allocation": "static", "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"}, -- 1.7.11.4
