You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@deltacloud.apache.org by ma...@redhat.com on 2012/03/15 16:59:56 UTC
[PATCH 1/3] CIMI: Adds NetworkTemplates and RoutingGroup (+collections) to CIMI frontend server
From: marios <ma...@redhat.com>
Signed-off-by: marios <ma...@redhat.com>
---
server/lib/cimi/model.rb | 3 +
server/lib/cimi/model/network_template.rb | 10 +++
.../lib/cimi/model/network_template_collection.rb | 35 +++++++++++
server/lib/cimi/model/routing_group.rb | 36 ++++++++++++
server/lib/cimi/model/routing_group_collection.rb | 34 +++++++++++
server/lib/cimi/server.rb | 61 ++++++++++++++++++++
6 files changed, 179 insertions(+), 0 deletions(-)
create mode 100644 server/lib/cimi/model/network_template_collection.rb
create mode 100644 server/lib/cimi/model/routing_group.rb
create mode 100644 server/lib/cimi/model/routing_group_collection.rb
diff --git a/server/lib/cimi/model.rb b/server/lib/cimi/model.rb
index 1ecf848..6b3359b 100644
--- a/server/lib/cimi/model.rb
+++ b/server/lib/cimi/model.rb
@@ -50,3 +50,6 @@ require 'cimi/model/network_collection'
require 'cimi/model/network_configuration'
require 'cimi/model/network_configuration_collection'
require 'cimi/model/network_template'
+require 'cimi/model/network_template_collection'
+require 'cimi/model/routing_group.rb'
+require 'cimi/model/routing_group_collection.rb'
diff --git a/server/lib/cimi/model/network_template.rb b/server/lib/cimi/model/network_template.rb
index 7b6b125..ce3b990 100644
--- a/server/lib/cimi/model/network_template.rb
+++ b/server/lib/cimi/model/network_template.rb
@@ -23,4 +23,14 @@ class CIMI::Model::NetworkTemplate < CIMI::Model::Base
scalar :rel, :href
end
+ def self.find(id, context)
+ network_templates = []
+ if id==:all
+ network_templates = context.driver.network_templates(context.credentials, {:env=>context})
+ else
+ network_templates = context.driver.network_templates(context.credentials, {:env=>context, :id=>id})
+ end
+ network_templates
+ end
+
end
diff --git a/server/lib/cimi/model/network_template_collection.rb b/server/lib/cimi/model/network_template_collection.rb
new file mode 100644
index 0000000..4235b19
--- /dev/null
+++ b/server/lib/cimi/model/network_template_collection.rb
@@ -0,0 +1,35 @@
+# 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.
+
+
+class CIMI::Model::NetworkTemplateCollection < CIMI::Model::Base
+
+ act_as_root_entity :network_template
+
+ array :network_templates do
+ scalar :href
+ end
+
+ def self.default(context)
+ self.new(
+ :id => context.network_templates_url,
+ :name => 'default',
+ :created => Time.now,
+ :description => "#{context.driver.name.capitalize} NetworkTemplateCollection",
+ :network_templates => NetworkTemplate.all(context).map {|t| {:href=> t.id}}
+ )
+ end
+
+end
diff --git a/server/lib/cimi/model/routing_group.rb b/server/lib/cimi/model/routing_group.rb
new file mode 100644
index 0000000..2399974
--- /dev/null
+++ b/server/lib/cimi/model/routing_group.rb
@@ -0,0 +1,36 @@
+# 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.
+
+class CIMI::Model::RoutingGroup < CIMI::Model::Base
+
+ array :networks do
+ scalar :href
+ end
+
+ array :operations do
+ scalar :rel, :href
+ end
+
+ def self.find(id, context)
+ routing_groups = []
+ if id==:all
+ routing_groups = context.driver.routing_groups(context.credentials, {:env=>context})
+ else
+ routing_groups = context.driver.routing_groups(context.credentials, {:env=>context, :id=>id})
+ end
+ routing_groups
+ end
+
+end
diff --git a/server/lib/cimi/model/routing_group_collection.rb b/server/lib/cimi/model/routing_group_collection.rb
new file mode 100644
index 0000000..945e0ca
--- /dev/null
+++ b/server/lib/cimi/model/routing_group_collection.rb
@@ -0,0 +1,34 @@
+# 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.
+
+class CIMI::Model::RoutingGroupCollection < CIMI::Model::Base
+
+ act_as_root_entity :routing_group
+
+ array :routing_groups do
+ scalar :href
+ end
+
+ def self.default(context)
+ self.new(
+ :id => context.routing_groups_url,
+ :name => 'default',
+ :created => Time.now,
+ :description => "#{context.driver.name.capitalize} RoutingGroupCollection",
+ :routing_groups => RoutingGroup.all(context).map {|rg| {:href=> rg.id}}
+ )
+ end
+
+end
diff --git a/server/lib/cimi/server.rb b/server/lib/cimi/server.rb
index 6cd845e..06ad758 100644
--- a/server/lib/cimi/server.rb
+++ b/server/lib/cimi/server.rb
@@ -574,3 +574,64 @@ global_collection :network_configurations do
end
end
end
+
+global_collection :network_templates do
+
+ description 'Network Template is a set of configuration values for realizing a Network. An instance of Network Template may be used to create multiple Networks'
+
+ operation :index do
+ description 'List all Network Templates in the NetworkTemplateCollection'
+ param :CIMISelect, :string, :optional
+ control do
+ network_templates = NetworkTemplateCollection.default(self).filter_by(params[:CIMISelect])
+ respond_to do |format|
+ format.xml {network_templates.to_xml}
+ format.json {network_templates.to_json}
+ end
+ end
+ end
+
+ operation :show do
+ description 'Show a specific Network Template'
+ param :id, :string, :required
+ control do
+ network_template = NetworkTemplate.find(params[:id], self)
+ respond_to do |format|
+ format.xml {network_template.to_xml}
+ format.json {network_template.to_json}
+ end
+ end
+ end
+
+end
+
+
+global_collection :routing_groups do
+
+ description 'Routing Groups represent a collection of Networks that route to each other. Providers shall not allow two Networks to be routable to each other unless they are explicitly connected by being part of a common RoutingGroup.'
+
+ operation :index do
+ description 'List all RoutingGroups in the RoutingGroupsCollection'
+ param :CIMISelect, :string, :optional
+ control do
+ routing_groups = RoutingGroupCollection.default(self).filter_by(params[:CIMISelect])
+ respond_to do |format|
+ format.xml {routing_groups.to_xml}
+ format.json {routing_groups.to_json}
+ end
+ end
+ end
+
+ operation :show do
+ description 'Show a specific RoutingGroup'
+ param :id, :string, :required
+ control do
+ routing_group = RoutingGroup.find(params[:id], self)
+ respond_to do |format|
+ format.xml {routing_group.to_xml}
+ format.json {routing_group.to_json}
+ end
+ end
+ end
+
+end
--
1.7.6.5
Re: [PATCH 1/3] CIMI: Adds NetworkTemplates and RoutingGroup (+collections) to CIMI frontend server
Posted by Michal Fojtik <mf...@redhat.com>.
Hi,
ACK. Few comments bellow.
Michal Fojtik
http://deltacloud.org
mfojtik@redhat.com
On Mar 15, 2012, at 4:59 PM, marios@redhat.com wrote:
> From: marios <ma...@redhat.com>
>
>
> Signed-off-by: marios <ma...@redhat.com>
> ---
> server/lib/cimi/model.rb | 3 +
> server/lib/cimi/model/network_template.rb | 10 +++
> .../lib/cimi/model/network_template_collection.rb | 35 +++++++++++
> server/lib/cimi/model/routing_group.rb | 36 ++++++++++++
> server/lib/cimi/model/routing_group_collection.rb | 34 +++++++++++
> server/lib/cimi/server.rb | 61 ++++++++++++++++++++
> 6 files changed, 179 insertions(+), 0 deletions(-)
> create mode 100644 server/lib/cimi/model/network_template_collection.rb
> create mode 100644 server/lib/cimi/model/routing_group.rb
> create mode 100644 server/lib/cimi/model/routing_group_collection.rb
>
> diff --git a/server/lib/cimi/model.rb b/server/lib/cimi/model.rb
> index 1ecf848..6b3359b 100644
> --- a/server/lib/cimi/model.rb
> +++ b/server/lib/cimi/model.rb
> @@ -50,3 +50,6 @@ require 'cimi/model/network_collection'
> require 'cimi/model/network_configuration'
> require 'cimi/model/network_configuration_collection'
> require 'cimi/model/network_template'
> +require 'cimi/model/network_template_collection'
> +require 'cimi/model/routing_group.rb'
> +require 'cimi/model/routing_group_collection.rb'
It's necessary to require those files with '.rb' extension?
> diff --git a/server/lib/cimi/model/network_template.rb b/server/lib/cimi/model/network_template.rb
> index 7b6b125..ce3b990 100644
> --- a/server/lib/cimi/model/network_template.rb
> +++ b/server/lib/cimi/model/network_template.rb
> @@ -23,4 +23,14 @@ class CIMI::Model::NetworkTemplate < CIMI::Model::Base
> scalar :rel, :href
> end
>
> + def self.find(id, context)
> + network_templates = []
> + if id==:all
> + network_templates = context.driver.network_templates(context.credentials, {:env=>context})
> + else
> + network_templates = context.driver.network_templates(context.credentials, {:env=>context, :id=>id})
> + end
> + network_templates
> + end
> +
> end
> diff --git a/server/lib/cimi/model/network_template_collection.rb b/server/lib/cimi/model/network_template_collection.rb
> new file mode 100644
> index 0000000..4235b19
> --- /dev/null
> +++ b/server/lib/cimi/model/network_template_collection.rb
> @@ -0,0 +1,35 @@
> +# 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.
> +
> +
> +class CIMI::Model::NetworkTemplateCollection < CIMI::Model::Base
> +
> + act_as_root_entity :network_template
> +
> + array :network_templates do
> + scalar :href
> + end
> +
> + def self.default(context)
> + self.new(
> + :id => context.network_templates_url,
> + :name => 'default',
> + :created => Time.now,
> + :description => "#{context.driver.name.capitalize} NetworkTemplateCollection",
> + :network_templates => NetworkTemplate.all(context).map {|t| {:href=> t.id}}
I think the ':network_templates => NetworkTemplate.all_uri(context)' helper will work
as well.
> + )
> + end
> +
> +end
> diff --git a/server/lib/cimi/model/routing_group.rb b/server/lib/cimi/model/routing_group.rb
> new file mode 100644
> index 0000000..2399974
> --- /dev/null
> +++ b/server/lib/cimi/model/routing_group.rb
> @@ -0,0 +1,36 @@
> +# 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.
> +
> +class CIMI::Model::RoutingGroup < CIMI::Model::Base
> +
> + array :networks do
> + scalar :href
> + end
> +
> + array :operations do
> + scalar :rel, :href
> + end
> +
> + def self.find(id, context)
> + routing_groups = []
> + if id==:all
> + routing_groups = context.driver.routing_groups(context.credentials, {:env=>context})
> + else
> + routing_groups = context.driver.routing_groups(context.credentials, {:env=>context, :id=>id})
> + end
> + routing_groups
> + end
In fact you don't need to store anything:
def self.find(id, context)
if id == :all
context.driver.routing_groups(context.credentials, :env=>context)
else
context.driver.routing_groups(context.credentials, :env=>context, :id=>id)
end
end
> +
> +end
> diff --git a/server/lib/cimi/model/routing_group_collection.rb b/server/lib/cimi/model/routing_group_collection.rb
> new file mode 100644
> index 0000000..945e0ca
> --- /dev/null
> +++ b/server/lib/cimi/model/routing_group_collection.rb
> @@ -0,0 +1,34 @@
> +# 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.
> +
> +class CIMI::Model::RoutingGroupCollection < CIMI::Model::Base
> +
> + act_as_root_entity :routing_group
> +
> + array :routing_groups do
> + scalar :href
> + end
> +
> + def self.default(context)
> + self.new(
> + :id => context.routing_groups_url,
> + :name => 'default',
> + :created => Time.now,
> + :description => "#{context.driver.name.capitalize} RoutingGroupCollection",
> + :routing_groups => RoutingGroup.all(context).map {|rg| {:href=> rg.id}}
The same suggestion like above (.all_uri helper will do this as well).
> + )
> + end
> +
> +end
> diff --git a/server/lib/cimi/server.rb b/server/lib/cimi/server.rb
> index 6cd845e..06ad758 100644
> --- a/server/lib/cimi/server.rb
> +++ b/server/lib/cimi/server.rb
> @@ -574,3 +574,64 @@ global_collection :network_configurations do
> end
> end
> end
> +
> +global_collection :network_templates do
> +
> + description 'Network Template is a set of configuration values for realizing a Network. An instance of Network Template may be used to create multiple Networks'
> +
> + operation :index do
> + description 'List all Network Templates in the NetworkTemplateCollection'
> + param :CIMISelect, :string, :optional
> + control do
> + network_templates = NetworkTemplateCollection.default(self).filter_by(params[:CIMISelect])
> + respond_to do |format|
> + format.xml {network_templates.to_xml}
> + format.json {network_templates.to_json}
> + end
> + end
> + end
> +
> + operation :show do
> + description 'Show a specific Network Template'
> + param :id, :string, :required
> + control do
> + network_template = NetworkTemplate.find(params[:id], self)
> + respond_to do |format|
> + format.xml {network_template.to_xml}
> + format.json {network_template.to_json}
> + end
> + end
> + end
> +
> +end
> +
> +
> +global_collection :routing_groups do
> +
> + description 'Routing Groups represent a collection of Networks that route to each other. Providers shall not allow two Networks to be routable to each other unless they are explicitly connected by being part of a common RoutingGroup.'
> +
> + operation :index do
> + description 'List all RoutingGroups in the RoutingGroupsCollection'
> + param :CIMISelect, :string, :optional
> + control do
> + routing_groups = RoutingGroupCollection.default(self).filter_by(params[:CIMISelect])
> + respond_to do |format|
> + format.xml {routing_groups.to_xml}
> + format.json {routing_groups.to_json}
> + end
> + end
> + end
> +
> + operation :show do
> + description 'Show a specific RoutingGroup'
> + param :id, :string, :required
> + control do
> + routing_group = RoutingGroup.find(params[:id], self)
> + respond_to do |format|
> + format.xml {routing_group.to_xml}
> + format.json {routing_group.to_json}
> + end
> + end
> + end
> +
> +end
> --
> 1.7.6.5
>