deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "marios@redhat.com" <mandr...@redhat.com>
Subject Re: [PATCH 3/3] CIMI: separates the CIMI mocking methods to a new file for cleanness
Date Fri, 16 Mar 2012 13:44:39 GMT
On 16/03/12 14:55, Michal Fojtik wrote:
> ACK.
> 

thanks for keeping it all tidy :) I implemented the nits in 1/3 and pushed.

> Btw. does this stuff got some test:unit coverage as well? :-)

sure ... watch this space (_real_soon_now_) - i want to finish all the
networking stuff (at least for mock driver) first -still vsp and then
all the create/delete ops

> 
>  -- michal
> 
> Michal Fojtik
> http://deltacloud.org
> mfojtik@redhat.com
> 
> On Mar 15, 2012, at 4:59 PM, marios@redhat.com wrote:
> 
>> From: marios <marios@redhat.com>
>>
>>
>> Signed-off-by: marios <marios@redhat.com>
>> ---
>> server/lib/deltacloud/drivers/mock/mock_driver.rb  |   74 +--------------
>> .../drivers/mock/mock_driver_cimi_methods.rb       |  101 ++++++++++++++++++++
>> 2 files changed, 102 insertions(+), 73 deletions(-)
>> create mode 100644 server/lib/deltacloud/drivers/mock/mock_driver_cimi_methods.rb
>>
>> diff --git a/server/lib/deltacloud/drivers/mock/mock_driver.rb b/server/lib/deltacloud/drivers/mock/mock_driver.rb
>> index 83dae09..67b4990 100644
>> --- a/server/lib/deltacloud/drivers/mock/mock_driver.rb
>> +++ b/server/lib/deltacloud/drivers/mock/mock_driver.rb
>> @@ -20,6 +20,7 @@ require 'base64'
>> require 'etc'
>> require 'deltacloud/base_driver'
>> require 'deltacloud/drivers/mock/mock_client'
>> +require 'deltacloud/drivers/mock/mock_driver_cimi_methods'
>>
>> module Deltacloud::Drivers::Mock
>>
>> @@ -453,50 +454,6 @@ module Deltacloud::Drivers::Mock
>>       return false
>>     end
>>
>> -    def networks(credentials, opts={})
>> -      check_credentials(credentials)
>> -      if opts[:id].nil?
>> -        networks = @client.load_all_cimi(:network).map{|net| CIMI::Model::Network.from_json(net)}
>> -        networks.map{|net|convert_cimi_mock_urls(:network, net ,opts[:env])}.flatten
>> -      else
>> -        network = CIMI::Model::Network.from_json(@client.load_cimi(:network, opts[:id]))
>> -        convert_cimi_mock_urls(:network, network, opts[:env])
>> -      end
>> -    end
>> -
>> -    def network_configurations(credentials, opts={})
>> -      check_credentials(credentials)
>> -      if opts[:id].nil?
>> -        network_configs = @client.load_all_cimi(:network_configuration).map{|net_config|
CIMI::Model::NetworkConfiguration.from_json(net_config)}
>> -        network_configs.map{|net_config|convert_cimi_mock_urls(:network_configuration,
net_config, opts[:env])}.flatten
>> -      else
>> -        network_config = CIMI::Model::NetworkConfiguration.from_json(@client.load_cimi(:network_configuration,
opts[:id]))
>> -        convert_cimi_mock_urls(:network_configuration, network_config, opts[:env])
>> -      end
>> -    end
>> -
>> -    def network_templates(credentials, opts={})
>> -      check_credentials(credentials)
>> -      if opts[:id].nil?
>> -        network_templates = @client.load_all_cimi(:network_template).map{|net_templ|
CIMI::Model::NetworkTemplate.from_json(net_templ)}
>> -        network_templates.map{|net_templ|convert_cimi_mock_urls(:network_template,
net_templ, opts[:env])}.flatten
>> -      else
>> -        network_template = CIMI::Model::NetworkTemplate.from_json(@client.load_cimi(:network_template,
opts[:id]))
>> -        convert_cimi_mock_urls(:network_template, network_template, opts[:env])
>> -      end
>> -    end
>> -
>> -    def routing_groups(credentials, opts={})
>> -      check_credentials(credentials)
>> -      if opts[:id].nil?
>> -        routing_groups = @client.load_all_cimi(:routing_group).map{|rg| CIMI::Model::RoutingGroup.from_json(rg)}
>> -        routing_groups.map{|rg|convert_cimi_mock_urls(:routing_group, rg, opts[:env])}.flatten
>> -      else
>> -        routing_group = CIMI::Model::RoutingGroup.from_json(@client.load_cimi(:routing_group,
opts[:id]))
>> -        convert_cimi_mock_urls(:routing_group, routing_group, opts[:env])
>> -      end
>> -    end
>> -
>>     private
>>
>>     def check_credentials(credentials)
>> @@ -533,35 +490,6 @@ module Deltacloud::Drivers::Mock
>>       StorageVolume.new(volume)
>>     end
>>
>> -    def convert_cimi_mock_urls(model_name, cimi_object, context)
>> -      cimi_object.attribute_values.each do |k,v|
>> -        if ( v.is_a?(Struct) || ( v.is_a?(Array) && v.first.is_a?(Struct)))
>> -          case v
>> -            when Array
>> -              v.each do |item|
>> -                convert_struct_urls(item, k.to_s.singularize.to_sym, context)
>> -              end
>> -            else
>> -              convert_struct_urls(v, k, context)
>> -            end
>> -        end
>> -      end
>> -      object_url = context.send(:"#{model_name}_url", cimi_object.name)
>> -      cimi_object.id=object_url
>> -      cimi_object.operations.each{|op| op.href=object_url  }
>> -      cimi_object
>> -    end
>> -
>> -    def convert_struct_urls(struct, cimi_name, context)
>> -      return unless (struct.respond_to?(:href) && (not struct.href.nil?)
&& (not cimi_name == :operation ))
>> -      obj_name = struct.href.split("/").last
>> -      if cimi_name.to_s.end_with?("config")
>> -        struct.href = context.send(:"#{cimi_name}uration_url", obj_name)
>> -      else
>> -        struct.href = context.send(:"#{cimi_name}_url", obj_name)
>> -      end
>> -    end
>> -
>>     exceptions do
>>
>>       on /AuthFailure/ do
>> diff --git a/server/lib/deltacloud/drivers/mock/mock_driver_cimi_methods.rb b/server/lib/deltacloud/drivers/mock/mock_driver_cimi_methods.rb
>> new file mode 100644
>> index 0000000..1e7b3c2
>> --- /dev/null
>> +++ b/server/lib/deltacloud/drivers/mock/mock_driver_cimi_methods.rb
>> @@ -0,0 +1,101 @@
>> +#
>> +# 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.
>> +#
>> +#Definition of CIMI methods for the mock driver - seperation from deltacloud
>> +#API mock driver methods
>> +
>> +module Deltacloud::Drivers::Mock
>> +
>> +  class MockDriver < Deltacloud::BaseDriver
>> +
>> +    def networks(credentials, opts={})
>> +      check_credentials(credentials)
>> +      if opts[:id].nil?
>> +        networks = @client.load_all_cimi(:network).map{|net| CIMI::Model::Network.from_json(net)}
>> +        networks.map{|net|convert_cimi_mock_urls(:network, net ,opts[:env])}.flatten
>> +      else
>> +        network = CIMI::Model::Network.from_json(@client.load_cimi(:network, opts[:id]))
>> +        convert_cimi_mock_urls(:network, network, opts[:env])
>> +      end
>> +    end
>> +
>> +    def network_configurations(credentials, opts={})
>> +      check_credentials(credentials)
>> +      if opts[:id].nil?
>> +        network_configs = @client.load_all_cimi(:network_configuration).map{|net_config|
CIMI::Model::NetworkConfiguration.from_json(net_config)}
>> +        network_configs.map{|net_config|convert_cimi_mock_urls(:network_configuration,
net_config, opts[:env])}.flatten
>> +      else
>> +        network_config = CIMI::Model::NetworkConfiguration.from_json(@client.load_cimi(:network_configuration,
opts[:id]))
>> +        convert_cimi_mock_urls(:network_configuration, network_config, opts[:env])
>> +      end
>> +    end
>> +
>> +    def network_templates(credentials, opts={})
>> +      check_credentials(credentials)
>> +      if opts[:id].nil?
>> +        network_templates = @client.load_all_cimi(:network_template).map{|net_templ|
CIMI::Model::NetworkTemplate.from_json(net_templ)}
>> +        network_templates.map{|net_templ|convert_cimi_mock_urls(:network_template,
net_templ, opts[:env])}.flatten
>> +      else
>> +        network_template = CIMI::Model::NetworkTemplate.from_json(@client.load_cimi(:network_template,
opts[:id]))
>> +        convert_cimi_mock_urls(:network_template, network_template, opts[:env])
>> +      end
>> +    end
>> +
>> +    def routing_groups(credentials, opts={})
>> +      check_credentials(credentials)
>> +      if opts[:id].nil?
>> +        routing_groups = @client.load_all_cimi(:routing_group).map{|rg| CIMI::Model::RoutingGroup.from_json(rg)}
>> +        routing_groups.map{|rg|convert_cimi_mock_urls(:routing_group, rg, opts[:env])}.flatten
>> +      else
>> +        routing_group = CIMI::Model::RoutingGroup.from_json(@client.load_cimi(:routing_group,
opts[:id]))
>> +        convert_cimi_mock_urls(:routing_group, routing_group, opts[:env])
>> +      end
>> +    end
>> +
>> +    private
>> +
>> +    def convert_cimi_mock_urls(model_name, cimi_object, context)
>> +      cimi_object.attribute_values.each do |k,v|
>> +        if ( v.is_a?(Struct) || ( v.is_a?(Array) && v.first.is_a?(Struct)))
>> +          case v
>> +            when Array
>> +              v.each do |item|
>> +                convert_struct_urls(item, k.to_s.singularize.to_sym, context)
>> +              end
>> +            else
>> +              convert_struct_urls(v, k, context)
>> +            end
>> +        end
>> +      end
>> +      object_url = context.send(:"#{model_name}_url", cimi_object.name)
>> +      cimi_object.id=object_url
>> +      cimi_object.operations.each{|op| op.href=object_url  }
>> +      cimi_object
>> +    end
>> +
>> +    def convert_struct_urls(struct, cimi_name, context)
>> +      return unless (struct.respond_to?(:href) && (not struct.href.nil?)
&& (not cimi_name == :operation ))
>> +      obj_name = struct.href.split("/").last
>> +      if cimi_name.to_s.end_with?("config")
>> +        struct.href = context.send(:"#{cimi_name}uration_url", obj_name)
>> +      else
>> +        struct.href = context.send(:"#{cimi_name}_url", obj_name)
>> +      end
>> +    end
>> +
>> +  end
>> +
>> +end
>> -- 
>> 1.7.6.5
>>
> 


Mime
View raw message