deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michal Fojtik <mfoj...@redhat.com>
Subject Re: [PATCH 2/3] CIMI: adds network_templates and routing_groups to deltacloud mock driver and mocking data (json)
Date Fri, 16 Mar 2012 12:54:09 GMT
On Mar 15, 2012, at 4:59 PM, marios@redhat.com wrote:

ACK.

> From: marios <marios@redhat.com>
> 
> 
> Signed-off-by: marios <marios@redhat.com>
> ---
> .../drivers/mock/data/cimi/network/network1.json   |    2 +-
> .../drivers/mock/data/cimi/network/network2.json   |    2 +-
> .../network_configuration/network_config1.json     |    2 +-
> .../network_configuration/network_config2.json     |    2 +-
> .../mock/data/cimi/network_template/template1.json |   10 ++++
> .../mock/data/cimi/network_template/template2.json |   10 ++++
> .../mock/data/cimi/routing_group/group1.json       |   13 +++++
> server/lib/deltacloud/drivers/mock/mock_driver.rb  |   50 ++++++++++++++++++-
> 8 files changed, 84 insertions(+), 7 deletions(-)
> create mode 100644 server/lib/deltacloud/drivers/mock/data/cimi/network_template/template1.json
> create mode 100644 server/lib/deltacloud/drivers/mock/data/cimi/network_template/template2.json
> create mode 100644 server/lib/deltacloud/drivers/mock/data/cimi/routing_group/group1.json
> 
> diff --git a/server/lib/deltacloud/drivers/mock/data/cimi/network/network1.json b/server/lib/deltacloud/drivers/mock/data/cimi/network/network1.json
> index 165ef8a..28cf767 100644
> --- a/server/lib/deltacloud/drivers/mock/data/cimi/network/network1.json
> +++ b/server/lib/deltacloud/drivers/mock/data/cimi/network/network1.json
> @@ -1,4 +1,4 @@
> -{ "uri": "http://cimi.example.org/networks/network1",
> +{ "id": "http://cimi.example.org/networks/network1",
>   "name": "network1",
>   "description": "the first network",
>   "created": "Thu Jan 12 15:25:41 EET 2012",
> diff --git a/server/lib/deltacloud/drivers/mock/data/cimi/network/network2.json b/server/lib/deltacloud/drivers/mock/data/cimi/network/network2.json
> index 3bd264e..370db99 100644
> --- a/server/lib/deltacloud/drivers/mock/data/cimi/network/network2.json
> +++ b/server/lib/deltacloud/drivers/mock/data/cimi/network/network2.json
> @@ -1,4 +1,4 @@
> -{ "uri": "http://cimi.example.org/networks/network2",
> +{ "id": "http://cimi.example.org/networks/network2",
>   "name": "network2",
>   "description": "another network",
>   "created": "Fri Jan 13 17:30:34 EET 2012",
> diff --git a/server/lib/deltacloud/drivers/mock/data/cimi/network_configuration/network_config1.json
b/server/lib/deltacloud/drivers/mock/data/cimi/network_configuration/network_config1.json
> index f767de9..8fad5d3 100644
> --- a/server/lib/deltacloud/drivers/mock/data/cimi/network_configuration/network_config1.json
> +++ b/server/lib/deltacloud/drivers/mock/data/cimi/network_configuration/network_config1.json
> @@ -1,4 +1,4 @@
> -{ "uri": "http://cimi.example.org/network_configurations/network_config1",
> +{ "id": "http://cimi.example.org/network_configurations/network_config1",
>   "name": "network_config1",
>   "description": "a network configuration",
>   "created": "Fri Mar 9 11:57:39 EET 2012",
> diff --git a/server/lib/deltacloud/drivers/mock/data/cimi/network_configuration/network_config2.json
b/server/lib/deltacloud/drivers/mock/data/cimi/network_configuration/network_config2.json
> index b22d837..e489bf5 100644
> --- a/server/lib/deltacloud/drivers/mock/data/cimi/network_configuration/network_config2.json
> +++ b/server/lib/deltacloud/drivers/mock/data/cimi/network_configuration/network_config2.json
> @@ -1,4 +1,4 @@
> -{ "uri": "http://cimi.example.org/network_configurations/network_config2",
> +{ "id": "http://cimi.example.org/network_configurations/network_config2",
>   "name": "network_config2",
>   "description": "a network configuration",
>   "created": "Fri Mar 9 12:01:53 EET 2012",
> diff --git a/server/lib/deltacloud/drivers/mock/data/cimi/network_template/template1.json
b/server/lib/deltacloud/drivers/mock/data/cimi/network_template/template1.json
> new file mode 100644
> index 0000000..682d39b
> --- /dev/null
> +++ b/server/lib/deltacloud/drivers/mock/data/cimi/network_template/template1.json
> @@ -0,0 +1,10 @@
> +{ "id": "http://cimi.example.org/network_templates/template1",
> +  "name": "template1",
> +  "description": "A mock network template",
> +  "created": "Thu Mar 15 12:15:15 EET 2012",
> +  "networkConfig": {"href": "http://cimi.example.org/network_configurations/network_config1"},
> +  "routingGroup": {"href": "http://cimi.example.org/routing_groups/group1"},
> +  "operations": [
> +    { "rel": "edit", "href": "http://cimi.example.org/network_templates/template1" },
> +    { "rel": "delete", "href": "http://cimi.example.org/network_templates/template1"
}]
> +}
> diff --git a/server/lib/deltacloud/drivers/mock/data/cimi/network_template/template2.json
b/server/lib/deltacloud/drivers/mock/data/cimi/network_template/template2.json
> new file mode 100644
> index 0000000..b7222cc
> --- /dev/null
> +++ b/server/lib/deltacloud/drivers/mock/data/cimi/network_template/template2.json
> @@ -0,0 +1,10 @@
> +{ "id": "http://cimi.example.org/network_templates/template2",
> +  "name": "template2",
> +  "description": "Another mock network template",
> +  "created": "Thu Mar 15 13:51:12 EET 2012",
> +  "networkConfig": {"href": "http://cimi.example.org/network_configurations/network_config2"},
> +  "routingGroup": {"href": "http://cimi.example.org/routing_groups/group1"},
> +  "operations": [
> +    { "rel": "edit", "href": "http://cimi.example.org/network_templates/template2" },
> +    { "rel": "delete", "href": "http://cimi.example.org/network_templates/template2"
}]
> +}
> diff --git a/server/lib/deltacloud/drivers/mock/data/cimi/routing_group/group1.json b/server/lib/deltacloud/drivers/mock/data/cimi/routing_group/group1.json
> new file mode 100644
> index 0000000..e10e0bd
> --- /dev/null
> +++ b/server/lib/deltacloud/drivers/mock/data/cimi/routing_group/group1.json
> @@ -0,0 +1,13 @@
> +{ "id": "http://cimi.example.org/routing_groups/group1",
> +  "name": "group1",
> +  "description": "a mock routing group",
> +  "created": "Thu Jan 12 16:02:56 EET 2012",
> +  "networks": [
> +    { "href": "http://cimi.example.org/networks/network1"},
> +    { "href": "http://cimi.example.org/networks/network2"}
> +  ],
> +  "operations": [
> +    { "rel": "edit", "href": "http://cimi.example.org/routing_groups/group1" },
> +    { "rel": "delete", "href": "http://cimi.example.org/routing_groups/group1" }
> +  ]
> +}
> diff --git a/server/lib/deltacloud/drivers/mock/mock_driver.rb b/server/lib/deltacloud/drivers/mock/mock_driver.rb
> index 1725538..83dae09 100644
> --- a/server/lib/deltacloud/drivers/mock/mock_driver.rb
> +++ b/server/lib/deltacloud/drivers/mock/mock_driver.rb
> @@ -475,6 +475,28 @@ module Deltacloud::Drivers::Mock
>       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)
> @@ -512,12 +534,34 @@ module Deltacloud::Drivers::Mock
>     end
> 
>     def convert_cimi_mock_urls(model_name, cimi_object, context)
> -      uri=context.send(:"#{model_name}_url", cimi_object.name)
> -      cimi_object.id=uri
> -      cimi_object.operations.each{|op| op.href=uri}
> +      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
> -- 
> 1.7.6.5
> 


Mime
View raw message