deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@apache.org
Subject [8/12] git commit: CIMI: Added more EntityCreate models for CIMI
Date Fri, 22 Feb 2013 10:32:24 GMT
CIMI: Added more EntityCreate models for CIMI

- AddressCreate
- AddressTemplateCreate
- CredentialCreate
- CredentialTemplateCreate
- MachineImageCreate
- NetworkCreate

As part of this patch, all 'create' operations were moved
to these EntityCreate models.


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

Branch: refs/heads/master
Commit: bb6aed4531459f3ec570e0f1dd43af7516bf011b
Parents: 32b99b7
Author: Michal Fojtik <mfojtik@redhat.com>
Authored: Mon Feb 11 16:45:37 2013 +0100
Committer: Michal fojtik <mfojtik@redhat.com>
Committed: Fri Feb 22 11:32:02 2013 +0100

----------------------------------------------------------------------
 server/lib/cimi/collections/address_templates.rb  |    7 +--
 server/lib/cimi/collections/addresses.rb          |    7 +--
 server/lib/cimi/collections/credentials.rb        |    7 +--
 server/lib/cimi/collections/machine_images.rb     |    3 +-
 server/lib/cimi/collections/machine_templates.rb  |    2 +-
 server/lib/cimi/collections/networks.rb           |    7 +--
 server/lib/cimi/models.rb                         |    6 ++-
 server/lib/cimi/models/address.rb                 |   35 +---------
 server/lib/cimi/models/address_create.rb          |   51 ++++++++++++++
 server/lib/cimi/models/address_template.rb        |   56 ++--------------
 server/lib/cimi/models/address_template_create.rb |   44 ++++++++++++
 server/lib/cimi/models/base.rb                    |   15 ++---
 server/lib/cimi/models/credential.rb              |    2 +-
 server/lib/cimi/models/credential_create.rb       |   46 +++++++++++++
 server/lib/cimi/models/credential_template.rb     |   24 +++++++
 server/lib/cimi/models/machine_image.rb           |   27 +-------
 server/lib/cimi/models/machine_image_create.rb    |   41 +++++++++++
 server/lib/cimi/models/network.rb                 |   38 -----------
 server/lib/cimi/models/network_create.rb          |   41 +++++++++++
 server/lib/cimi/models/network_template.rb        |    5 +-
 server/lib/cimi/models/schema.rb                  |    1 -
 server/support/cimi/address_template.xml          |    2 +-
 server/support/cimi/credential.json               |   10 +++
 server/support/cimi/machine_image.xml             |    1 -
 server/support/cimi/network.json                  |    9 +++
 25 files changed, 303 insertions(+), 184 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltacloud/blob/bb6aed45/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 d1bbe7d..72e167d 100644
--- a/server/lib/cimi/collections/address_templates.rb
+++ b/server/lib/cimi/collections/address_templates.rb
@@ -45,11 +45,8 @@ module CIMI::Collections
       operation :create do
         description "Create new AddressTemplate"
         control do
-          if current_content_type == :json
-            new_address_template = CIMI::Model::AddressTemplate.create_from_json(request.body.read,
self)
-          else
-            new_address_template = CIMI::Model::AddressTemplate.create_from_xml(request.body.read,
self)
-          end
+          addr_templ = CIMI::Model::AddressTemplateCreate.parse(request.body, request.content_type)
+          new_address_template = addr_templ.create(self)
           headers_for_create new_address_template
           respond_to do |format|
             format.json { new_address_template.to_json }

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/bb6aed45/server/lib/cimi/collections/addresses.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/collections/addresses.rb b/server/lib/cimi/collections/addresses.rb
index 4217da6..c34068d 100644
--- a/server/lib/cimi/collections/addresses.rb
+++ b/server/lib/cimi/collections/addresses.rb
@@ -47,11 +47,8 @@ module CIMI::Collections
       operation :create, :with_capability => :create_address do
         description "Create a new Address"
         control do
-          if current_content_type == :json
-            address = CIMI::Model::Address.create(request.body.read, self, :json)
-          else
-            address = CIMI::Model::Address.create(request.body.read, self, :xml)
-          end
+          addr = CIMI::Model::AddressCreate.parse(request.body, request.content_type)
+          address = addr.create(self)
           respond_to do |format|
             format.xml { address.to_xml }
             format.json { address.to_json }

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/bb6aed45/server/lib/cimi/collections/credentials.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/collections/credentials.rb b/server/lib/cimi/collections/credentials.rb
index fcaf458..8d90be6 100644
--- a/server/lib/cimi/collections/credentials.rb
+++ b/server/lib/cimi/collections/credentials.rb
@@ -46,11 +46,8 @@ module CIMI::Collections
       operation :create, :with_capability => :create_key do
         description "Show specific machine admin"
         control do
-          if current_content_type == :json
-            new_admin = Credential.create_from_json(request.body.read, self)
-          else
-            new_admin = Credential.create_from_xml(request.body.read, self)
-          end
+          c = CIMI::Model::CredentialCreate.parse(request.body, request.content_type)
+          new_admin = c.create(self)
           headers_for_create new_admin
           respond_to do |format|
             format.json { new_admin.to_json }

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/bb6aed45/server/lib/cimi/collections/machine_images.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/collections/machine_images.rb b/server/lib/cimi/collections/machine_images.rb
index 663c651..ee0033c 100644
--- a/server/lib/cimi/collections/machine_images.rb
+++ b/server/lib/cimi/collections/machine_images.rb
@@ -46,7 +46,8 @@ module CIMI::Collections
       operation :create, :with_capability => :create_image do
         description "Create a new machine image."
         control do
-          machine_image = CIMI::Model::MachineImage.create(request.body, self)
+          mi = CIMI::Model::MachineImageCreate.parse(request.body, request.content_type)
+          machine_image = mi.create(self)
           headers_for_create machine_image
           respond_to do |format|
             format.xml { machine_image.to_xml }

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/bb6aed45/server/lib/cimi/collections/machine_templates.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/collections/machine_templates.rb b/server/lib/cimi/collections/machine_templates.rb
index 8734319..6bdd1f2 100644
--- a/server/lib/cimi/collections/machine_templates.rb
+++ b/server/lib/cimi/collections/machine_templates.rb
@@ -45,7 +45,7 @@ module CIMI::Collections
       operation :create do
         description "Create new machine template"
         control do
-          mt = MachineTemplateCreate.parse(request.body, request.content_type)
+          mt = CIMI::Model::MachineTemplateCreate.parse(request.body, request.content_type)
           new_machine_template = mt.create(self)
           headers_for_create new_machine_template
           respond_to do |format|

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/bb6aed45/server/lib/cimi/collections/networks.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/collections/networks.rb b/server/lib/cimi/collections/networks.rb
index 16e4c9c..0f32827 100644
--- a/server/lib/cimi/collections/networks.rb
+++ b/server/lib/cimi/collections/networks.rb
@@ -46,11 +46,8 @@ module CIMI::Collections
       operation :create, :with_capability => :create_network do
         description "Create a new Network"
         control do
-          if current_content_type == :json
-            network = Network.create(request.body.read, self, :json)
-          else
-            network = Network.create(request.body.read, self, :xml)
-          end
+          n = CIMI::Model::NetworkCreate.parse(request.body, request.content_type)
+          network = n.create(self)
           respond_to do |format|
             format.xml { network.to_xml}
             format.json { network.to_json }

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/bb6aed45/server/lib/cimi/models.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/models.rb b/server/lib/cimi/models.rb
index dd93e8f..a86d6a9 100644
--- a/server/lib/cimi/models.rb
+++ b/server/lib/cimi/models.rb
@@ -61,6 +61,8 @@ require_relative './models/cloud_entry_point'
 CIMI::Model::ResourceMetadata.acts_as_root_entity
 
 require_relative './models/credential'
+require_relative './models/credential_template'
+require_relative './models/credential_create'
 require_relative './models/volume'
 require_relative './models/volume_template'
 require_relative './models/volume_configuration'
@@ -68,17 +70,19 @@ require_relative './models/volume_image'
 require_relative './models/machine'
 require_relative './models/machine_configuration'
 require_relative './models/machine_image'
+require_relative './models/machine_image_create'
 require_relative './models/machine_template'
 require_relative './models/machine_template_create'
 require_relative './models/machine_create'
 require_relative './models/network_port'
 require_relative './models/network'
-require_relative './models/network_template'
 require_relative './models/network_configuration'
 require_relative './models/network_port_template'
 require_relative './models/network_port_configuration'
 require_relative './models/address'
 require_relative './models/address_template'
+require_relative './models/address_template_create'
+require_relative './models/address_create'
 require_relative './models/forwarding_group'
 require_relative './models/forwarding_group_template'
 require_relative './models/system_template'

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/bb6aed45/server/lib/cimi/models/address.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/models/address.rb b/server/lib/cimi/models/address.rb
index 61d55dd..57e8be1 100644
--- a/server/lib/cimi/models/address.rb
+++ b/server/lib/cimi/models/address.rb
@@ -49,30 +49,6 @@ class CIMI::Model::Address < CIMI::Model::Base
     end
   end
 
-  def self.create(request_body, context, type)
-    input = (type == :xml)? XmlSimple.xml_in(request_body, {"ForceArray"=>false, "NormaliseSpace"=>2})
: JSON.parse(request_body)
-    if input['addressTemplate'] and input["addressTemplate"]["href"] #by reference
-      address_template = CIMI::Model::AddressTemplate.find(context.href_id(input["addressTemplate"]["href"],
:address_templates), context)
-    else
-      case type
-        when :json
-          address_template = CIMI::Model::AddressTemplate.from_json(JSON.generate(input["addressTemplate"]))
-        when :xml
-          xml = XmlSimple.xml_in(request_body, {"NormaliseSpace"=>2})
-          address_template = CIMI::Model::AddressTemplate.from_xml(XmlSimple.xml_out(xml["addressTemplate"][0]))
-      end
-    end
-    params = {:name=>input["name"], :description=>input["description"], :address_template=>address_template,
:env=>context }
-    raise CIMI::Model::BadRequest.new("Bad request - missing required parameters. Client
sent: #{request_body} which produced #{params.inspect}")  if params.has_value?(nil)
-    address = context.driver.create_address(context.credentials, params)
-    result = from_address(address, context)
-    result.name = input['name'] if input['name']
-    result.description = input['description'] if input['description']
-    result.extract_properties!(input)
-    result.save
-    result
-  end
-
   def self.delete!(id, context)
     context.driver.delete_address(context.credentials, id)
     new(:id => id).destroy
@@ -86,16 +62,13 @@ class CIMI::Model::Address < CIMI::Model::Base
       :id => context.address_url(address.id),
       :description => "Address #{address.id}",
       :ip => address.id,
-      :allocation => "dynamic", #or "static"
-      :default_gateway => "unknown", #wtf
-      :dns => "unknown", #wtf
+      :allocation => "dynamic",
+      :default_gateway => "unknown",
+      :dns => "unknown",
       :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 =>
-      #:
+      :network => nil
     )
   end
 

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/bb6aed45/server/lib/cimi/models/address_create.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/models/address_create.rb b/server/lib/cimi/models/address_create.rb
new file mode 100644
index 0000000..a20613f
--- /dev/null
+++ b/server/lib/cimi/models/address_create.rb
@@ -0,0 +1,51 @@
+# 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::AddressCreate < CIMI::Model::Base
+
+  ref :address_template, :required => true
+
+  def create(context)
+    validate!
+
+    if address_template.href?
+      template = address_template.find(ctx)
+    end
+
+    params = {
+      :name => name,
+      :description => description,
+      :address_template => template,
+      :env => context # FIXME: We should not pass the context to the driver (!)
+    }
+
+    unless context.driver.respond_to? :create_address
+       raise Deltacloud::Exceptions.exception_from_status(
+         501,
+         "Creating Address is not supported by the current driver"
+       )
+    end
+
+    address = context.driver.create_address(context.credentials, params)
+
+    result = CIMI::Model::Address.from_address(address, context)
+    result.name = name if name
+    result.description = description if description
+    result.property = property if property
+    result.save
+    result
+  end
+
+end

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/bb6aed45/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 eea4385..143b9dc 100644
--- a/server/lib/cimi/models/address_template.rb
+++ b/server/lib/cimi/models/address_template.rb
@@ -17,20 +17,8 @@ class CIMI::Model::AddressTemplate < CIMI::Model::Base
 
   acts_as_root_entity
 
-  text :ip
-
-  text :hostname
-
-  text :allocation
-
-  text :default_gateway
-
-  text :dns
-
-  text :protocol
-
-  text :mask
-
+  text :ip, :required => true
+  text :hostname, :allocation, :default_gateway, :dns, :protocol, :mask
   href :network
 
   array :operations do
@@ -55,41 +43,6 @@ class CIMI::Model::AddressTemplate < CIMI::Model::Base
     end
   end
 
-  def self.create_from_json(body, context)
-    json = JSON.parse(body)
-    new_template = current_db.add_address_template(
-      :name => json['name'],
-      :description => json['description'],
-      :hostname => json['hostname'],
-      :ip => json['ip'],
-      :allocation => json['allocation'],
-      :default_gateway => json['default_gateway'],
-      :dns => json['dns'],
-      :protocol => json['protocol'],
-      :mask => json['mask'],
-      :ent_properties => json['properties'] ? json['properties'].to_json : {}
-    )
-    from_db(new_template, context)
-  end
-
-  def self.create_from_xml(body, context)
-    xml = XmlSimple.xml_in(body)
-    xml['property'] ||= []
-    new_template = current_db.add_address_template(
-      :name => xml['name'].first,
-      :description => xml['description'].first,
-      :ip => xml['ip'].first,
-      :hostname => xml['hostname'].first,
-      :allocation => xml['allocation'].first,
-      :default_gateway => xml['default_gateway'].first,
-      :dns => xml['dns'].first,
-      :protocol => xml['protocol'].nil? ? nil : xml['protocol'].first,
-      :mask => xml['mask'].first,
-      :ent_properties => xml['property'] ? JSON::dump(xml['property'].inject({}) { |r,
p| r[p['key']]=p['content']; r }) : {}
-    )
-    from_db(new_template, context)
-  end
-
   def self.delete!(id, context)
     current_db.address_templates.first(:id => id).destroy
   end
@@ -110,7 +63,10 @@ class CIMI::Model::AddressTemplate < CIMI::Model::Base
       :mask => model.mask,
       :property => (model.ent_properties ? JSON::parse(model.ent_properties) :  nil),
       :operations => [
-        { :href => context.destroy_address_template_url(model.id), :rel => 'http://schemas.dmtf.org/cimi/1/action/delete'
}
+        {
+          :href => context.destroy_address_template_url(model.id),
+          :rel => 'http://schemas.dmtf.org/cimi/1/action/delete'
+        }
       ]
     )
   end

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/bb6aed45/server/lib/cimi/models/address_template_create.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/models/address_template_create.rb b/server/lib/cimi/models/address_template_create.rb
new file mode 100644
index 0000000..e9ce3d3
--- /dev/null
+++ b/server/lib/cimi/models/address_template_create.rb
@@ -0,0 +1,44 @@
+# 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::AddressTemplateCreate < CIMI::Model::Base
+
+  text :ip, :required => true
+  text :hostname, :required => true
+  text :allocation, :required => true
+  text :default_gateway, :required => true
+  text :dns, :required => true
+  text :protocol, :required => true
+  text :mask, :required => true
+
+  href :network
+
+  def create(context)
+    validate!
+    new_template = context.current_db.add_address_template(
+      :name => name,
+      :description => description,
+      :hostname => hostname,
+      :ip => ip,
+      :allocation => allocation,
+      :default_gateway => default_gateway,
+      :dns => dns,
+      :protocol => protocol,
+      :mask => mask,
+      :ent_properties => property.to_json
+    )
+    CIMI::Model::AddressTemplate.from_db(new_template, context)
+  end
+end

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/bb6aed45/server/lib/cimi/models/base.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/models/base.rb b/server/lib/cimi/models/base.rb
index a9264ef..2e3351d 100644
--- a/server/lib/cimi/models/base.rb
+++ b/server/lib/cimi/models/base.rb
@@ -81,7 +81,7 @@ module CIMI::Model
   class ValidationError < StandardError
 
     def initialize(attr_list, format)
-      @lst = attr_list.map { |a| a.send("#{format}_name") }
+      @lst = attr_list
       super("Required attributes not set: #{name}")
     end
 
@@ -142,15 +142,10 @@ module CIMI::Model
     end
 
     def validate!(format=:xml)
-      failed_attrs = []
-      self.class.required_attributes.each do |attr|
-        unless attr.valid?(send(attr.name))
-          failed_attrs << attr
-        end
-      end
-      unless failed_attrs.empty?
-        raise CIMI::Model::ValidationError.new(failed_attrs, format)
-      end
+      failed_attrs = self.class.required_attributes.map do |attr|
+        attr.send("#{format}_name") unless attr.valid?(send(attr.name))
+      end.compact
+      raise CIMI::Model::ValidationError.new(failed_attrs, format) unless failed_attrs.empty?
     end
 
     # FIXME: Kludge around the fact that we do not have proper *Create

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/bb6aed45/server/lib/cimi/models/credential.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/models/credential.rb b/server/lib/cimi/models/credential.rb
index f363d06..872248f 100644
--- a/server/lib/cimi/models/credential.rb
+++ b/server/lib/cimi/models/credential.rb
@@ -17,7 +17,7 @@ class CIMI::Model::Credential < CIMI::Model::Base
 
   acts_as_root_entity
 
-  text :username
+  text :username, :password, :key
   text :password
   text :key
 

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/bb6aed45/server/lib/cimi/models/credential_create.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/models/credential_create.rb b/server/lib/cimi/models/credential_create.rb
new file mode 100644
index 0000000..6479769
--- /dev/null
+++ b/server/lib/cimi/models/credential_create.rb
@@ -0,0 +1,46 @@
+# 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::CredentialCreate < CIMI::Model::Base
+
+  ref :credential_template, :required => true
+
+  def create(context)
+    validate!
+
+    unless context.driver.respond_to? :create_key
+       raise Deltacloud::Exceptions.exception_from_status(
+         501,
+         "Creating Credential is not supported by the current driver"
+       )
+    end
+
+    if credential_template.href?
+      template = credential_template.find(ctx)
+    else
+      template = credential_template
+    end
+
+    key = context.driver.create_key(context.credentials, :key_name => name)
+
+    result = CIMI::Model::Credential.from_key(key, context)
+    result.name = name if name
+    result.description = description if description
+    result.property = property if property
+    result.save
+    result
+
+  end
+end

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/bb6aed45/server/lib/cimi/models/credential_template.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/models/credential_template.rb b/server/lib/cimi/models/credential_template.rb
new file mode 100644
index 0000000..1148c42
--- /dev/null
+++ b/server/lib/cimi/models/credential_template.rb
@@ -0,0 +1,24 @@
+# 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::CredentialTemplate < CIMI::Model::Base
+
+  text :username, :required => true
+  text :password, :required => true
+  text :key, :required => true
+
+  # TODO: tbd
+
+end

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/bb6aed45/server/lib/cimi/models/machine_image.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/models/machine_image.rb b/server/lib/cimi/models/machine_image.rb
index a44a721..74f48ef 100644
--- a/server/lib/cimi/models/machine_image.rb
+++ b/server/lib/cimi/models/machine_image.rb
@@ -44,34 +44,11 @@ class CIMI::Model::MachineImage < CIMI::Model::Base
       :description => image.description,
       :state => image.state || 'UNKNOWN',
       :type => "IMAGE",
-      :created => image.creation_time.nil? ? Time.now.xmlschema : Time.parse(image.creation_time.to_s).xmlschema
+      :created => image.creation_time.nil? ?
+        Time.now.xmlschema : Time.parse(image.creation_time.to_s).xmlschema
     )
   end
 
-  def self.create(request_body, context)
-    # The 'imageLocation' attribute is mandatory in CIMI, however in Deltacloud
-    # there is no way how to figure out from what Machine the MachineImage was
-    # created from. For that we need to store this attribute in properties.
-    #
-    if context.current_content_type == :xml
-      input = XmlSimple.xml_in(request_body.read, {"ForceArray"=>false,"NormaliseSpace"=>2})
-      raise 'imageLocation attribute is mandatory' unless input['imageLocation']
-      input['property'] ||= {}
-    else
-      input = JSON.parse(request_body.read)
-      raise 'imageLocation attribute is mandatory' unless input['imageLocation']
-      input['properties'] ||= []
-    end
-    params = {:id => context.href_id(input["imageLocation"], :machines), :name=>input["name"],
:description=>input["description"]}
-    image = context.driver.create_image(context.credentials, params)
-    result = from_image(image, context)
-    result.name = input['name'] if input['name']
-    result.description = input['description'] if input['description']
-    result.extract_properties!(input)
-    result.save
-    result
-  end
-
   def self.delete!(image_id, context)
     context.driver.destroy_image(context.credentials, image_id)
     new(:id => image_id).destroy

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/bb6aed45/server/lib/cimi/models/machine_image_create.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/models/machine_image_create.rb b/server/lib/cimi/models/machine_image_create.rb
new file mode 100644
index 0000000..365d640
--- /dev/null
+++ b/server/lib/cimi/models/machine_image_create.rb
@@ -0,0 +1,41 @@
+# 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::MachineImageCreate < CIMI::Model::Base
+
+  text :type, :required => true
+  text :image_location, :required => true
+  href :related_image
+
+  def create(context)
+    validate!
+
+    params = {
+      :id => context.href_id(image_location, :machines),
+      :name => name,
+      :description => description
+    }
+
+    img = context.driver.create_image(context.credentials, params)
+
+    result = CIMI::Model::MachineImage.from_image(img, context)
+    result.name = name if name
+    result.description = description if description
+    result.property = property if property
+    result.save
+    result
+  end
+
+end

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/bb6aed45/server/lib/cimi/models/network.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/models/network.rb b/server/lib/cimi/models/network.rb
index e9d133f..789e83f 100644
--- a/server/lib/cimi/models/network.rb
+++ b/server/lib/cimi/models/network.rb
@@ -52,25 +52,6 @@ class CIMI::Model::Network < CIMI::Model::Base
     networks
   end
 
-  def self.create(request_body, context, type)
-    input = (type == :xml)? XmlSimple.xml_in(request_body, {"ForceArray"=>false,"NormaliseSpace"=>2})
: JSON.parse(request_body)
-    if input["networkTemplate"]["href"] #template by reference
-      network_config, forwarding_group = get_by_reference(input, context)
-    else
-      if input["networkTemplate"]["networkConfig"]["href"] # configuration by reference
-        network_config = CIMI::Model::NetworkConfiguration.find(context.href_id(input["networkTemplate"]["networkConfig"]["href"],
-                                                                                :network_configurations),
context)
-      else #configuration by value
-        network_config = get_by_value(request_body, type)
-      end
-      forwarding_group = CIMI::Model::ForwardingGroup.find(context.href_id(input["networkTemplate"]["forwardingGroup"]["href"],
-                                                                     :forwarding_groups),
context)
-    end
-    params = {:network_config => network_config, :forwarding_group => forwarding_group,
:name=>input["name"],
-              :description=>input["description"], :env=>context}
-    raise CIMI::Model::BadRequest.new("Bad request - missing required parameters. Client
sent: #{request_body} which produced #{params.inspect}")  if params.has_value?(nil)
-    context.driver.create_network(context.credentials, params)
-  end
 
   def self.delete!(id, context)
     context.driver.delete_network(context.credentials, id)
@@ -88,23 +69,4 @@ class CIMI::Model::Network < CIMI::Model::Base
     end
   end
 
-  private
-
-  def self.get_by_reference(input, context)
-    network_template = CIMI::Model::NetworkTemplate.find(context.href_id(input["networkTemplate"]["href"],
:network_templates), context)
-    network_config = CIMI::Model::NetworkConfiguration.find(context.href_id(network_template.network_config.href,
:network_configurations), context)
-    forwarding_group = CIMI::Model::ForwardingGroup.find(context.href_id(network_template.forwarding_group.href,
:forwarding_groups), context)
-    return network_config, forwarding_group
-  end
-
-  def self.get_by_value(request_body, type)
-    if type == :xml
-      xml_arrays = XmlSimple.xml_in(request_body, {"NormaliseSpace"=>2})
-      network_config = CIMI::Model::NetworkConfiguration.from_xml(XmlSimple.xml_out(xml_arrays["networkTemplate"][0]["networkConfig"][0]))
-    else
-     json = JSON.parse(request_body)
-      network_config = CIMI::Model::NetworkConfiguration.from_json(JSON.generate(json["networkTemplate"]["networkConfig"]))
-    end
-  end
-
 end

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/bb6aed45/server/lib/cimi/models/network_create.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/models/network_create.rb b/server/lib/cimi/models/network_create.rb
new file mode 100644
index 0000000..006a064
--- /dev/null
+++ b/server/lib/cimi/models/network_create.rb
@@ -0,0 +1,41 @@
+# 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::Network < CIMI::Model::Base
+
+  ref :network_template, :required => true
+
+  def create(context)
+    validate!
+
+    if network_template.href?
+      template = network_template.find(context)
+    end
+
+    params = {
+      :network_config => template.network_config.find(context),
+      :forwarding_group => template.forwarding_group.find(context),
+      :name => name,
+      :description => description,
+      :env => context # FIXME: We should not pass the context to the driver (!)
+    }
+
+    network = context.driver.create_network(context.credentials, params)
+    network.property = property if property
+    network.save
+    network
+  end
+
+end

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/bb6aed45/server/lib/cimi/models/network_template.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/models/network_template.rb b/server/lib/cimi/models/network_template.rb
index 09eadd0..a16c094 100644
--- a/server/lib/cimi/models/network_template.rb
+++ b/server/lib/cimi/models/network_template.rb
@@ -17,9 +17,8 @@ class CIMI::Model::NetworkTemplate < CIMI::Model::Base
 
   acts_as_root_entity
 
-  href :network_config
-
-  href :forwarding_group
+  ref :network_config, :required => true
+  ref :forwarding_group, :required => true
 
   array :operations do
     scalar :rel, :href

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/bb6aed45/server/lib/cimi/models/schema.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/models/schema.rb b/server/lib/cimi/models/schema.rb
index 39f4a13..215ebfc 100644
--- a/server/lib/cimi/models/schema.rb
+++ b/server/lib/cimi/models/schema.rb
@@ -217,7 +217,6 @@ class CIMI::Model::Schema
         a.valid?(value.send(a.name))
       }
     end
-
   end
 
   class Array < Attribute

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/bb6aed45/server/support/cimi/address_template.xml
----------------------------------------------------------------------
diff --git a/server/support/cimi/address_template.xml b/server/support/cimi/address_template.xml
index 828c47c..8762627 100644
--- a/server/support/cimi/address_template.xml
+++ b/server/support/cimi/address_template.xml
@@ -3,7 +3,7 @@
   <ip>10.0.0.1</ip>
   <hostname>my-example.hostname.com</hostname>
   <allocation>static</allocation>
-  <default_gateway>10.0.0.250</default_gateway>
+  <defaultGateway>10.0.0.250</defaultGateway>
   <dns>8.8.8.8</dns>
   <mask>255.255.255.0</mask>
   <protocol>ipv4</protocol>

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/bb6aed45/server/support/cimi/credential.json
----------------------------------------------------------------------
diff --git a/server/support/cimi/credential.json b/server/support/cimi/credential.json
new file mode 100644
index 0000000..b884915
--- /dev/null
+++ b/server/support/cimi/credential.json
@@ -0,0 +1,10 @@
+{
+  "resourceURI": "http://schemas.dmtf.org/cimi/1/CredentialCreate",
+  "name": "myCredential",
+  "description": "A super secret credential",
+  "credentialTemplate": {
+    "username" : "mockuser",
+    "password" : "mockpassword",
+    "key" : "testkey"
+  }
+}

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/bb6aed45/server/support/cimi/machine_image.xml
----------------------------------------------------------------------
diff --git a/server/support/cimi/machine_image.xml b/server/support/cimi/machine_image.xml
index 8ec28a6..e00f2b1 100644
--- a/server/support/cimi/machine_image.xml
+++ b/server/support/cimi/machine_image.xml
@@ -3,5 +3,4 @@
   <description>Description of my new Machine</description>
   <type>IMAGE</type>
   <imageLocation>http://localhost:3001/cimi/machines/inst1</imageLocation>
-  <property key="test_image">image_value</property>
 </MachineImageCreate>

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/bb6aed45/server/support/cimi/network.json
----------------------------------------------------------------------
diff --git a/server/support/cimi/network.json b/server/support/cimi/network.json
new file mode 100644
index 0000000..8d48cd6
--- /dev/null
+++ b/server/support/cimi/network.json
@@ -0,0 +1,9 @@
+{
+  "resourceURI": "http://schemas.dmtf.org/cimi/1/NetworkCreate",
+  "name": "myAwesomeNetwork",
+  "description": "Sample network description",
+  "networkTemplate": {
+    "networkConfig" : { 'href' => 'http://localhost:3001/cimi/network_configurations/network_config1'
}
+    "forwardingGroup" : { 'href' => 'http://localhost:3001/cimi/forwarding_groups/group1'
}
+  }
+}


Mime
View raw message