You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltacloud.apache.org by lu...@apache.org on 2013/03/14 19:19:04 UTC
[4/15] CIMI: Migrated service methods from CIMI::Model to
CIMI::Service
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/fa200948/server/lib/cimi/service/forwarding_group.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/service/forwarding_group.rb b/server/lib/cimi/service/forwarding_group.rb
new file mode 100644
index 0000000..ef12350
--- /dev/null
+++ b/server/lib/cimi/service/forwarding_group.rb
@@ -0,0 +1,26 @@
+# 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::Service::ForwardingGroup < CIMI::Service::Base
+
+ def self.find(id, context)
+ if id==:all
+ context.driver.forwarding_groups(context.credentials, {:env=>context})
+ else
+ context.driver.forwarding_groups(context.credentials, {:env=>context, :id=>id})
+ end
+ end
+
+end
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/fa200948/server/lib/cimi/service/forwarding_group_template.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/service/forwarding_group_template.rb b/server/lib/cimi/service/forwarding_group_template.rb
new file mode 100644
index 0000000..32e7388
--- /dev/null
+++ b/server/lib/cimi/service/forwarding_group_template.rb
@@ -0,0 +1,26 @@
+# 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::Service::ForwardingGroupTemplate < CIMI::Service::Base
+
+ def self.find(id, context)
+ if id==:all
+ context.driver.forwarding_group_templates(context.credentials, {:env=>context})
+ else
+ context.driver.forwarding_group_templates(context.credentials, {:env=>context, :id=>id})
+ end
+ end
+
+end
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/fa200948/server/lib/cimi/service/machine.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/service/machine.rb b/server/lib/cimi/service/machine.rb
index 72e5346..7112486 100644
--- a/server/lib/cimi/service/machine.rb
+++ b/server/lib/cimi/service/machine.rb
@@ -52,19 +52,19 @@ class CIMI::Service::Machine < CIMI::Service::Base
def self.attach_volume(volume, location, context)
context.driver.attach_storage_volume(context.credentials,
{:id=>volume, :instance_id=>context.params[:id], :device=>location})
- CIMI::Model::MachineVolume.find(context.params[:id], context, volume)
+ CIMI::Service::MachineVolume.find(context.params[:id], context, volume)
end
#returns the machine_volume_collection for the given machine
def self.detach_volume(volume, location, context)
context.driver.detach_storage_volume(context.credentials,
{:id=>volume, :instance_id=>context.params[:id], :device=>location})
- CIMI::Model::MachineVolume.collection_for_instance(context.params[:id], context)
+ CIMI::Service::MachineVolume.collection_for_instance(context.params[:id], context)
end
def self.from_instance(instance, context)
cpu = memory = (instance.instance_profile.id == "opaque")? "n/a" : nil
- machine_conf = CIMI::Model::MachineConfiguration.find(instance.instance_profile.name, context)
+ machine_conf = CIMI::Service::MachineConfiguration.find(instance.instance_profile.name, context)
machine_spec = {
:name => instance.name,
:created => instance.launch_time.nil? ? Time.now.xmlschema : Time.parse(instance.launch_time.to_s).xmlschema,
@@ -78,10 +78,10 @@ class CIMI::Service::Machine < CIMI::Service::Base
:operations => convert_instance_actions(instance, context)
}
if context.expand? :disks
- machine_spec[:disks] = CIMI::Model::Disk.find(instance, machine_conf, context, :all)
+ machine_spec[:disks] = CIMI::Service::Disk.find(instance, machine_conf, context, :all)
end
if context.expand? :volumes
- machine_spec[:volumes] = CIMI::Model::MachineVolume.find(instance.id, context, :all)
+ machine_spec[:volumes] = CIMI::Service::MachineVolume.find(instance.id, context, :all)
end
machine_spec[:realm] = instance.realm_id if instance.realm_id
machine_spec[:machine_image] = { :href => context.machine_image_url(instance.image_id) } if instance.image_id
@@ -102,14 +102,14 @@ class CIMI::Service::Machine < CIMI::Service::Base
def self.convert_instance_cpu(profile, context)
cpu_override = profile.overrides.find { |p, v| p == :cpu }
if cpu_override.nil?
- CIMI::Model::MachineConfiguration.find(profile.id, context).cpu
+ CIMI::Service::MachineConfiguration.find(profile.id, context).cpu
else
cpu_override[1]
end
end
def self.convert_instance_memory(profile, context)
- machine_conf = CIMI::Model::MachineConfiguration.find(profile.name, context)
+ machine_conf = CIMI::Service::MachineConfiguration.find(profile.name, context)
memory_override = profile.overrides.find { |p, v| p == :memory }
memory_override.nil? ? machine_conf.memory.to_i : context.to_kibibyte(memory_override[1].to_i,"MB")
end
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/fa200948/server/lib/cimi/service/machine_configuration.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/service/machine_configuration.rb b/server/lib/cimi/service/machine_configuration.rb
new file mode 100644
index 0000000..d4ddf20
--- /dev/null
+++ b/server/lib/cimi/service/machine_configuration.rb
@@ -0,0 +1,54 @@
+# 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::Service::MachineConfiguration < CIMI::Service::Base
+
+ def self.find(id, context)
+ profiles = []
+ if id == :all
+ profiles = context.driver.hardware_profiles(context.credentials)
+ profiles.map { |profile| from_hardware_profile(profile, context) }.compact
+ else
+ profile = context.driver.hardware_profile(context.credentials, id)
+ from_hardware_profile(profile, context)
+ end
+ end
+
+ private
+ def self.from_hardware_profile(profile, context)
+ # We accept just profiles with all properties set
+ return unless profile.memory or profile.cpu or profile.storage
+ memory = profile.memory ?
+ context.to_kibibyte((profile.memory.value || profile.memory.default), profile.memory.unit) : nil
+ cpu = (profile.cpu ? (profile.cpu.value || profile.cpu.default) : nil )
+ storage = profile.storage ?
+ context.to_kibibyte((profile.storage.value || profile.storage.default), profile.storage.unit) : nil
+ machine_hash = {
+ :name => profile.name,
+ :description => "Machine Configuration with #{memory} KiB of memory and #{cpu} CPU",
+ :cpu => ( cpu.to_i.to_s if cpu ) ,
+ :created => Time.now.xmlschema, # FIXME: DC hardware_profile has no mention about created_at
+ :memory => (memory if memory),
+ :disks => ( [ {
+ :capacity => storage,
+ :format => (profile.storage.respond_to?(:format) ? profile.storage.format : "unknown") }
+ ] if storage ), # no format attr for hwp - may be added if providers support...,
+ :id => context.machine_configuration_url(profile.id)
+ }
+ self.new(context, :values => machine_hash)
+ end
+
+
+end
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/fa200948/server/lib/cimi/service/machine_create.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/service/machine_create.rb b/server/lib/cimi/service/machine_create.rb
new file mode 100644
index 0000000..1e5b637
--- /dev/null
+++ b/server/lib/cimi/service/machine_create.rb
@@ -0,0 +1,49 @@
+# 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::Service::MachineCreate < CIMI::Service::Base
+
+ def create
+ params = {}
+ if machine_template.href
+ template = resolve(machine_template)
+ params[:hwp_id] = ref_id(template.machine_config.href)
+ params[:initial_state] = template.initial_state
+ image_id = ref_id(template.machine_image.href)
+ else
+ # FIXME: What if either of these href's isn't there ? What if the user
+ # tries to override some aspect of the machine_config/machine_image ?
+ params[:hwp_id] = ref_id(machine_template.machine_config.href)
+ params[:initial_state] = machine_template.initial_state
+ image_id = ref_id(machine_template.machine_image.href)
+ if machine_template.credential.href
+ params[:keyname] = ref_id(machine_template.credential.href)
+ end
+ end
+
+ params[:name] = name if name
+ params[:realm_id] = realm if realm
+ instance = context.driver.create_instance(context.credentials, image_id, params)
+
+ result = CIMI::Service::Machine::from_instance(instance, 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/fa200948/server/lib/cimi/service/machine_image.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/service/machine_image.rb b/server/lib/cimi/service/machine_image.rb
index dad26a8..17d9220 100644
--- a/server/lib/cimi/service/machine_image.rb
+++ b/server/lib/cimi/service/machine_image.rb
@@ -15,10 +15,6 @@
class CIMI::Service::MachineImage < CIMI::Service::Base
- def initialize(ctx, opts)
- super
- end
-
def self.find(id, context)
images = []
if id == :all
@@ -44,7 +40,7 @@ class CIMI::Service::MachineImage < CIMI::Service::Base
def self.delete!(image_id, context)
context.driver.destroy_image(context.credentials, image_id)
- new(:id => image_id).destroy
+ self.new(context, :values => { :id => image_id }).destroy
end
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/fa200948/server/lib/cimi/service/machine_image_create.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/service/machine_image_create.rb b/server/lib/cimi/service/machine_image_create.rb
new file mode 100644
index 0000000..7cd1a01
--- /dev/null
+++ b/server/lib/cimi/service/machine_image_create.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::Service::MachineImageCreate < CIMI::Service::Base
+
+ def create
+ params = {
+ :id => context.href_id(image_location, :machines),
+ :name => name,
+ :description => description
+ }
+
+ img = context.driver.create_image(context.credentials, params)
+
+ result = CIMI::Service::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/fa200948/server/lib/cimi/service/machine_template.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/service/machine_template.rb b/server/lib/cimi/service/machine_template.rb
new file mode 100644
index 0000000..e790e89
--- /dev/null
+++ b/server/lib/cimi/service/machine_template.rb
@@ -0,0 +1,61 @@
+# 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::Service::MachineTemplate < CIMI::Service::Base
+
+ def initialize(ctx, opts)
+ super
+ end
+
+ class << self
+ def find(id, context)
+ if id == :all
+ current_db.machine_templates.map { |t| from_db(t, context) }
+ else
+ template = current_db.machine_templates_dataset.first(:id => id)
+ raise CIMI::Model::NotFound unless template
+ from_db(template, context)
+ end
+ end
+
+ def delete!(id, context)
+ current_db.machine_templates.first(:id => id).destroy
+ end
+
+ def from_db(model, context)
+ self.new(context, :values => {
+ :id => context.machine_template_url(model.id),
+ :name => model.name,
+ :description => model.description,
+ :machine_config => { :href => model.machine_config },
+ :machine_image => { :href => model.machine_image },
+ :realm => model.realm,
+ :property => (model.ent_properties ? JSON::parse(model.ent_properties) : nil),
+ :created => Time.parse(model.created_at.to_s).xmlschema,
+ :operations => [
+ {
+ :href => context.destroy_machine_template_url(model.id),
+ :rel => 'http://schemas.dmtf.org/cimi/1/action/delete'
+ }
+ ]
+ })
+ end
+ end
+
+ protected
+ def attributes_to_copy
+ super + [ :machine_config, :machine_image ]
+ end
+end
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/fa200948/server/lib/cimi/service/machine_template_create.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/service/machine_template_create.rb b/server/lib/cimi/service/machine_template_create.rb
new file mode 100644
index 0000000..a47aa6c
--- /dev/null
+++ b/server/lib/cimi/service/machine_template_create.rb
@@ -0,0 +1,29 @@
+# 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::Service::MachineTemplateCreate < CIMI::Service::Base
+
+ def create
+ new_template = self.class.current_db.add_machine_template(
+ :name => name,
+ :description => description,
+ :machine_config => machine_config.href,
+ :machine_image => machine_image.href,
+ :ent_properties => property.to_json
+ )
+ CIMI::Service::MachineTemplate.from_db(new_template, context)
+ end
+
+end
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/fa200948/server/lib/cimi/service/machine_volume.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/service/machine_volume.rb b/server/lib/cimi/service/machine_volume.rb
new file mode 100644
index 0000000..77c545b
--- /dev/null
+++ b/server/lib/cimi/service/machine_volume.rb
@@ -0,0 +1,74 @@
+# 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::Service::MachineVolume < CIMI::Service::Base
+
+ def self.find(instance_id, context, id=:all)
+ if id == :all
+ volumes = context.driver.storage_volumes(context.credentials)
+ volumes.inject([]) do |attached, vol|
+ id = context.machine_url(instance_id)+"/volumes/#{vol.id}"
+ attached << self.new(context, :values => {
+ :id => id,
+ :name => vol.id,
+ :description => "MachineVolume #{vol.id} for Machine #{instance_id}",
+ :created => vol.created.nil? ? nil : Time.parse(vol.created).xmlschema,
+ :initial_location => vol.device,
+ :volume => {:href=>context.volume_url(vol.id)},
+ :operations => [{:href=>id, :rel => "delete" }]
+ }) if vol.instance_id == instance_id
+ attached
+ end
+ else
+ vol = context.driver.storage_volume(context.credentials, {:id=>id})
+ id = context.machine_url(instance_id)+"/volumes/#{vol.id}"
+ raise CIMI::Model::NotFound unless vol.instance_id == instance_id
+ self.new(context, :values => {
+ :id => id,
+ :name => vol.id,
+ :description => "MachineVolume #{vol.id} for Machine #{instance_id}",
+ :created => vol.created.nil? ? nil : Time.parse(vol.created).xmlschema,
+ :initial_location => vol.device,
+ :volume => {:href=>context.volume_url(vol.id)},
+ :operations => [{:href=>id, :rel => "delete" }]
+ })
+ end
+ end
+
+ def self.find_to_attach_from_xml(xml_in, context)
+ xml = XmlSimple.xml_in(xml_in)
+ vol_id = xml["volume"].first["href"].split("/").last
+ location = xml["initialLocation"].first.strip
+ [vol_id, location]
+ end
+
+ def self.find_to_attach_from_json(json_in, context)
+ json = JSON.parse(json_in)
+ vol_id = json["volume"]["href"].split("/").last
+ location = json["initialLocation"]
+ [vol_id, location]
+ end
+
+
+ def self.collection_for_instance(instance_id, context)
+ machine_volumes = self.find(instance_id, context)
+ volumes_url = context.url("/machines/#{instance_id}/volumes")
+ # FIXME: Really ???
+ attach_url = volumes_url.singularize+"_attach"
+ CIMI::Model::MachineVolume.list(volumes_url, machine_volumes, :add_url => attach_url)
+ end
+
+
+end
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/fa200948/server/lib/cimi/service/network.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/service/network.rb b/server/lib/cimi/service/network.rb
new file mode 100644
index 0000000..a58aa1e
--- /dev/null
+++ b/server/lib/cimi/service/network.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::Service::Network < CIMI::Service::Base
+
+ def self.find(id, context)
+ networks=[]
+ if id==:all
+ networks = context.driver.networks(context.credentials, {:env=>context})
+ else
+ networks = context.driver.networks(context.credentials, {:id=>id, :env=>context})
+ end
+ if context.expand? :networkPorts
+ networks.each do |network|
+ network.network_ports = CIMI::Service::NetworkPort.collection_for_network(network.id, context)
+ end
+ end
+ networks
+ end
+
+
+ def self.delete!(id, context)
+ context.driver.delete_network(context.credentials, id)
+ end
+
+ def perform(action, context, &block)
+ begin
+ if context.driver.send(:"#{action.name}_network", context.credentials, self.name)
+ block.callback :success
+ else
+ raise "Operation #{action.name} failed to execute on the Network #{self.name} "
+ end
+ rescue => e
+ block.callback :failure, e.message
+ end
+ end
+
+
+end
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/fa200948/server/lib/cimi/service/network_configuration.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/service/network_configuration.rb b/server/lib/cimi/service/network_configuration.rb
new file mode 100644
index 0000000..a133c94
--- /dev/null
+++ b/server/lib/cimi/service/network_configuration.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::Service::NetworkConfiguration < CIMI::Service::Base
+
+ def self.find(id, context)
+ network_configs = []
+ if id==:all
+ network_configs = context.driver.network_configurations(context.credentials, {:env=>context})
+ else
+ network_configs = context.driver.network_configurations(context.credentials, {:env=>context, :id=>id})
+ end
+ network_configs
+ end
+
+ def self.create_from_xml(request_body, context)
+ warn "This method should go into NetworkConfigurationCreate model"
+ end
+
+ def self.create_from_json(request_body, context)
+ warn "This method should go into NetworkConfigurationCreate model"
+ end
+
+end
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/fa200948/server/lib/cimi/service/network_create.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/service/network_create.rb b/server/lib/cimi/service/network_create.rb
new file mode 100644
index 0000000..f191833
--- /dev/null
+++ b/server/lib/cimi/service/network_create.rb
@@ -0,0 +1,39 @@
+# 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::Service::NetworkCreate < CIMI::Service::Base
+
+ def create
+ if network_template.href?
+ template = resolve(network_template)
+ network_config = resolve(template.network_config)
+ forwarding_group = resolve(template.forwarding_group)
+ else
+ network_config = CIMI::Service::NetworkConfiguration.find(context.href_id(network_template.network_config.href, :network_configurations), context)
+ forwarding_group = CIMI::Service::ForwardingGroup.find(context.href_id(network_template.forwarding_group.href, :forwarding_groups), context)
+ end
+ params = {
+ :network_config => network_config,
+ :forwarding_group => forwarding_group,
+ :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/fa200948/server/lib/cimi/service/network_port.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/service/network_port.rb b/server/lib/cimi/service/network_port.rb
new file mode 100644
index 0000000..d400411
--- /dev/null
+++ b/server/lib/cimi/service/network_port.rb
@@ -0,0 +1,97 @@
+# 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::Service::NetworkPort < CIMI::Service::Base
+
+ def self.find(id, context)
+ if id==:all
+ context.driver.network_ports(context.credentials, {:env=>context})
+ else
+ context.driver.network_ports(context.credentials, {:id=>id, :env=>context})
+ end
+ end
+
+ # FIXME: This should go into NetworkPortCreate model
+ #
+ 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["networkPortTemplate"]["href"] #template by reference
+ network_port_config, network = get_by_reference(input, context)
+ else
+ if input["networkPortTemplate"]["networkPortConfig"]["href"] # configuration by reference
+ network_port_config = CIMI::Service::NetworkPortConfiguration.find(context.href_id(input["networkPortTemplate"]["networkPortConfig"]["href"],:network_port_configurations), context)
+ else #configuration by value
+ network_port_config = get_by_value(request_body, type)
+ end
+ network = CIMI::Service::Network.find(context.href_id(input["networkPortTemplate"]["network"]["href"], :networks), context)
+ end
+ params = {:network_port_config => network_port_config, :network => network, :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_port(context.credentials, params)
+ end
+
+ def self.delete!(id, context)
+ context.driver.delete_network_port(context.credentials, id)
+ end
+
+ def perform(action, context, &block)
+ begin
+ if context.driver.send(:"#{action.name}_network_port", context.credentials, self.name)
+ block.callback :success
+ else
+ raise "Operation #{action.name} failed to execute on the NetworkPort #{self.name} "
+ end
+ rescue => e
+ block.callback :failure, e.message
+ end
+ end
+
+ def self.collection_for_network(network_id, context)
+ net_url = context.network_url(network_id)
+ network_ports = CIMI::Service::NetworkPort.all(context)
+ ports_collection = network_ports.inject([]){|res, current| res << current if current.network.href == net_url ; res}
+ CIMI::Service::NetworkPortCollection.new(context, :values => {
+ :id => net_url+"/network_ports",
+ :name => 'default',
+ :created => Time.now,
+ :description => "#{context.driver.name.capitalize} NetworkPortCollection",
+ :count => ports_collection.size,
+ :network_ports => ports_collection
+ })
+ end
+
+ private
+
+ # FIXME: Are the methods below really needed???
+
+ def self.get_by_reference(input, context)
+ network_port_template = CIMI::Service::NetworkPortTemplate.find(context.href_id(input["networkPortTemplate"]["href"], :network_port_templates), context)
+ network_port_config = CIMI::Service::NetworkPortConfiguration.find(context.href_id(network_port_template.network_port_config.href, :network_port_configurations), context)
+ network = CIMI::Service::Network.find(context.href_id(network_port_template.network.href, :networks), context)
+ return network_port_config, network
+ end
+
+ def self.get_by_value(request_body, type)
+ if type == :xml
+ xml_arrays = XmlSimple.xml_in(request_body, {"NormaliseSpace"=>2})
+ network_port_config = CIMI::Service::NetworkPortConfiguration.from_xml(XmlSimple.xml_out(xml_arrays["networkPortTemplate"][0]["networkPortConfig"][0]))
+ else
+ json = JSON.parse(request_body)
+ network_port_config = CIMI::Service::NetworkPortConfiguration.from_json(JSON.generate(json["networkPortTemplate"]["networkPortConfig"]))
+ end
+ end
+
+
+end
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/fa200948/server/lib/cimi/service/network_port_configuration.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/service/network_port_configuration.rb b/server/lib/cimi/service/network_port_configuration.rb
new file mode 100644
index 0000000..2d5c1ba
--- /dev/null
+++ b/server/lib/cimi/service/network_port_configuration.rb
@@ -0,0 +1,26 @@
+# 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::Service::NetworkPortConfiguration < CIMI::Service::Base
+
+ def self.find(id, context)
+ if id==:all
+ context.driver.network_port_configurations(context.credentials, {:env=>context})
+ else
+ context.driver.network_port_configurations(context.credentials, {:env=>context, :id=>id})
+ end
+ end
+
+end
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/fa200948/server/lib/cimi/service/network_port_template.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/service/network_port_template.rb b/server/lib/cimi/service/network_port_template.rb
new file mode 100644
index 0000000..9f60493
--- /dev/null
+++ b/server/lib/cimi/service/network_port_template.rb
@@ -0,0 +1,26 @@
+# 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::Service::NetworkPortTemplate < CIMI::Service::Base
+
+ def self.find(id, context)
+ if id==:all
+ context.driver.network_port_templates(context.credentials, {:env=>context})
+ else
+ context.driver.network_port_templates(context.credentials, {:env=>context, :id=>id})
+ end
+ end
+
+end
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/fa200948/server/lib/cimi/service/network_template.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/service/network_template.rb b/server/lib/cimi/service/network_template.rb
new file mode 100644
index 0000000..afe79f6
--- /dev/null
+++ b/server/lib/cimi/service/network_template.rb
@@ -0,0 +1,28 @@
+# 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::Service::NetworkTemplate < CIMI::Service::Base
+
+ 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
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/fa200948/server/lib/cimi/service/resource_metadata.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/service/resource_metadata.rb b/server/lib/cimi/service/resource_metadata.rb
new file mode 100644
index 0000000..23924fb
--- /dev/null
+++ b/server/lib/cimi/service/resource_metadata.rb
@@ -0,0 +1,110 @@
+# 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::Service::ResourceMetadata < CIMI::Service::Base
+
+ def initialize(ctx, opts)
+ super
+ end
+
+ def self.find(id, context)
+ if id == :all
+ resource_metadata = []
+ CIMI::Model.root_entities.each do |resource_class|
+ meta = resource_metadata_for(resource_class, context)
+ resource_metadata << meta unless none_defined(meta)
+ end
+ return resource_metadata
+ else
+ resource_class = CIMI::Model.const_get("#{id.camelize}")
+ resource_metadata_for(resource_class, context)
+ end
+ end
+
+ def self.resource_metadata_for(resource_class, context)
+ attributes = rm_attributes_for(resource_class, context)
+ capabilities = rm_capabilities_for(resource_class, context)
+ actions = rm_actions_for(resource_class, context)
+ cimi_resource = resource_class.name.split("::").last
+ self.new(context, :values => {
+ :id => context.resource_metadata_url(cimi_resource.underscore),
+ :name => cimi_resource,
+ :type_uri => resource_class.resource_uri,
+ :attributes => attributes,
+ :capabilities => capabilities,
+ :actions => actions
+ })
+ end
+
+ private
+
+ def self.rm_attributes_for(resource_class, context)
+ return [] if resource_attributes[resource_class.name].nil?
+ resource_attributes[resource_class.name].map do |attr_name, attr_def|
+ if attr_def.has_key? :constraints
+ constraints = attr_def[:constraints].call(context)
+ else
+ constraints = []
+ end
+ {
+ :name => attr_name.to_s,
+ # TODO: We need to make this URI return description of this 'non-CIMI'
+ # attribute
+ :namespace => "http://deltacloud.org/cimi/#{resource_class.name.split('::').last}/#{attr_name}",
+ :type => translate_attr_type(attr_def[:type]),
+ :required => attr_def[:required] ? 'true' : 'false',
+ :constraints => constraints.map { |v| { :value => v }}
+ }
+ end
+ end
+
+ # FIXME: This method is srsly a nightmare ;-)
+ #
+ def self.rm_capabilities_for(resource_class,context)
+ cimi_object = resource_class.name.split("::").last.underscore.pluralize.to_sym
+ (context.driver.class.features[cimi_object] || []).inject([]) do |res, cur|
+ feat = CIMI::FakeCollection.feature(cur)
+ values = (context.driver.class.constraints[cimi_object][feat.name][:values] || []).inject([]) do |vals, val|
+ vals << val
+ vals
+ end
+ res << {:name => feat.name.to_s.camelize,
+ :uri => CMWG_NAMESPACE+"/capability/#{cimi_object.to_s.camelize.singularize}/#{feat.name.to_s.camelize}",
+ :description => feat.description,
+ :value => values.join(",") }
+ res
+ end
+ end
+
+ def self.rm_actions_for(resource_class, context)
+ []
+ end
+
+ def self.translate_attr_type(type)
+ case type
+ when :href then 'URI'
+ when :text then 'string'
+ when :boolean then 'boolean'
+ else 'text'
+ end
+ end
+
+ def self.none_defined(metadata)
+ return true if metadata.capabilities.empty? && metadata.capabilities.empty? && metadata.attributes.empty?
+ return false
+ end
+
+
+end
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/fa200948/server/lib/cimi/service/system.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/service/system.rb b/server/lib/cimi/service/system.rb
new file mode 100644
index 0000000..daad428
--- /dev/null
+++ b/server/lib/cimi/service/system.rb
@@ -0,0 +1,45 @@
+# 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::Service::System < CIMI::Service::Base
+
+ def self.find(id, context)
+ if id == :all
+ systems = context.driver.systems(context.credentials, {:env=>context})
+ else
+ systems = context.driver.systems(context.credentials, {:env=>context, :id=>id})
+ raise CIMI::Model::NotFound unless systems.first
+ systems.first
+ end
+ end
+
+ def perform(action, context, &block)
+ begin
+ if context.driver.send(:"#{action.name}_system", context.credentials, self.id.split("/").last)
+ block.callback :success
+ else
+ raise "Operation failed to execute on given System"
+ end
+ rescue => e
+ block.callback :failure, e.message
+ end
+ end
+
+ def self.delete!(id, context)
+ context.driver.destroy_system(context.credentials, id)
+ end
+
+
+end
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/fa200948/server/lib/cimi/service/system_template.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/service/system_template.rb b/server/lib/cimi/service/system_template.rb
new file mode 100644
index 0000000..785f79d
--- /dev/null
+++ b/server/lib/cimi/service/system_template.rb
@@ -0,0 +1,32 @@
+# 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::Service::SystemTemplate < CIMI::Service::Base
+
+ def self.find(id, context)
+ if id == :all
+ templates = context.driver.system_templates(context.credentials, {:env=>context})
+ else
+ templates = context.driver.system_templates(context.credentials, {:env=>context, :id=>id})
+ raise CIMI::Model::NotFound unless templates.first
+ templates.first
+ end
+ end
+
+ def self.delete!(id, context)
+ context.driver.destroy_system_template(context.credentials, id)
+ end
+
+end
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/fa200948/server/lib/cimi/service/volume.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/service/volume.rb b/server/lib/cimi/service/volume.rb
new file mode 100644
index 0000000..2e38691
--- /dev/null
+++ b/server/lib/cimi/service/volume.rb
@@ -0,0 +1,81 @@
+# 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::Service::Volume < CIMI::Service::Base
+
+ def self.find(id, context)
+ creds = context.credentials
+ if id == :all
+ volumes = context.driver.storage_volumes(creds)
+ volumes.collect{ |volume| from_storage_volume(volume, context) }
+ else
+ volume = context.driver.storage_volumes(creds, :id => id).first
+ raise CIMI::Model::NotFound unless volume
+ from_storage_volume(volume, context)
+ end
+ end
+
+ def self.all(context); find(:all, context); end
+
+ def self.delete!(id, context)
+ context.driver.destroy_storage_volume(context.credentials, {:id=>id} )
+ new(context, :values => { :id => id }).destroy
+ end
+
+ def self.find_to_attach_from_json(json_in, context)
+ json = JSON.parse(json_in)
+ json["volumes"].map{|v| {:volume=>self.find(v["volume"]["href"].split("/volumes/").last, context),
+ :initial_location=>v["initialLocation"] }}
+ end
+
+ def self.find_to_attach_from_xml(xml_in, context)
+ xml = XmlSimple.xml_in(xml_in)
+ xml["volume"].map{|v| {:volume => self.find(v["href"].split("/volumes/").last, context),
+ :initial_location=>v["initialLocation"] }}
+ end
+
+ def self.from_storage_volume(volume, context)
+ self.new(context, :values => {
+ :name => volume.id,
+ :created => volume.created.nil? ? nil : Time.parse(volume.created).xmlschema,
+ :id => context.volume_url(volume.id),
+ :capacity => context.to_kibibyte(volume.capacity, 'GB'),
+ :bootable => "false", #fixme ... will vary... ec2 doesn't expose this
+ :snapshots => [], #fixme...
+ :type => 'http://schemas.dmtf.org/cimi/1/mapped',
+ :state => volume.state == 'IN-USE' ? 'AVAILABLE' : volume.state,
+ :meters => [],
+ :operations => [{:href=> context.volume_url(volume.id), :rel => "delete"}]
+ })
+ end
+
+ def self.collection_for_instance(instance_id, context)
+ instance = context.driver.instance(context.credentials, :id => instance_id)
+ volumes = instance.storage_volumes.map do |mappings|
+ mappings.keys.map do |volume_id|
+ from_storage_volume(context.driver.storage_volume(context.credentials, :id => volume_id), context)
+ end
+ end.flatten
+ CIMI::Service::VolumeCollection.new(context, :values => {
+ :id => context.url("/machines/#{instance_id}/volumes"),
+ :name => 'default',
+ :count => volumes.size,
+ :description => "Volume collection for Machine #{instance_id}",
+ :entries => volumes
+ })
+ end
+
+
+end
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/fa200948/server/lib/cimi/service/volume_configuration.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/service/volume_configuration.rb b/server/lib/cimi/service/volume_configuration.rb
new file mode 100644
index 0000000..ebb2c7c
--- /dev/null
+++ b/server/lib/cimi/service/volume_configuration.rb
@@ -0,0 +1,92 @@
+# 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::Service::VolumeConfiguration < CIMI::Service::Base
+
+ # FIXME: These two should go into VolumeConfigurationCreate
+ #
+ def self.create_from_json(body, context)
+ json = JSON.parse(body)
+ new_config = current_db.add_volume_configuration(
+ :name => json['name'],
+ :description => json['description'],
+ :format => json['format'],
+ :capacity => json['capacity'],
+ :ent_properties => (json['properties'] || {}).to_json
+ )
+ from_db(new_config, context)
+ end
+
+ def self.create_from_xml(body, context)
+ xml = XmlSimple.xml_in(body)
+ xml['property'] ||= []
+ new_config = current_db.add_volume_configuration(
+ :name => xml['name'].first,
+ :description => xml['description'].first,
+ :format => xml['format'].first,
+ :capacity => xml['capacity'].first,
+ :ent_properties => JSON::dump((xml['property'] || {}).inject({}){ |r, p| r[p['key']]=p['content']; r })
+ )
+ from_db(new_config, context)
+ end
+
+ def self.delete!(id, context)
+ current_db.volume_configurations.first(:id => id).destroy
+ end
+
+ def self.find(id, context)
+ if id==:all
+ if context.driver.respond_to? :volume_configurations
+ context.driver.volume_configurations(context.credentials, {:env=>context})
+ else
+ current_db.volume_configurations.map { |t| from_db(t, context) }
+ end
+ else
+ if context.driver.respond_to? :volume_configuration
+ context.driver.volume_configuration(context.credentials, id, :env=>context)
+ else
+ config = current_db.volume_configurations_dataset.first(:id => id)
+ raise CIMI::Model::NotFound unless config
+ from_db(config, context)
+ end
+ end
+ end
+
+ protected
+ def attributes_to_copy
+ super + [ :format, :capacity ]
+ end
+
+ private
+
+ def self.from_db(model, context)
+ self.new(context, :values => {
+ :id => context.volume_configuration_url(model.id),
+ :name => model.name,
+ :description => model.description,
+ :format => model.format,
+ :capacity => context.to_kibibyte(model.capacity, "GB"),
+ :property => (model.ent_properties ? JSON::parse(model.ent_properties) : nil),
+ :operations => [
+ {
+ :href => context.destroy_volume_configuration_url(model.id),
+ :rel => 'http://schemas.dmtf.org/cimi/1/action/delete'
+ }
+ ]
+ })
+ end
+
+
+end
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/fa200948/server/lib/cimi/service/volume_create.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/service/volume_create.rb b/server/lib/cimi/service/volume_create.rb
new file mode 100644
index 0000000..6d9f3d0
--- /dev/null
+++ b/server/lib/cimi/service/volume_create.rb
@@ -0,0 +1,47 @@
+# 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::Service::VolumeCreate < CIMI::Service::Base
+
+ def create
+ template = resolve(volume_template)
+ volume_image = resolve(template.volume_image)
+ volume_config = resolve(template.volume_config)
+
+ params = {
+ :name => name,
+ :capacity => volume_config.capacity,
+ :snapshot_id => ref_id(volume_image.id),
+ }
+
+ unless context.driver.respond_to? :create_storage_volume
+ raise Deltacloud::Exceptions.exception_from_status(
+ 501,
+ "Creating Volume is not supported by the current driver"
+ )
+ end
+
+ volume = context.driver.create_storage_volume(context.credentials, params)
+
+ result = CIMI::Service::Volume.from_storage_volume(volume, 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/fa200948/server/lib/cimi/service/volume_image.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/service/volume_image.rb b/server/lib/cimi/service/volume_image.rb
new file mode 100644
index 0000000..5d57368
--- /dev/null
+++ b/server/lib/cimi/service/volume_image.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::Service::VolumeImage < CIMI::Service::Base
+
+ def self.find(id, context)
+ creds = context.credentials
+ if id == :all
+ snapshots = context.driver.storage_snapshots(creds)
+ snapshots.collect{ |snapshot| from_storage_snapshot(snapshot, context) }
+ else
+ snapshot = context.driver.storage_snapshots(creds, id => :id).first
+ raise CIMI::Model::NotFound unless snapshot
+ from_storage_snapshot(snapshot, context)
+ end
+ end
+
+ def self.delete!(vol_image_id, context)
+ context.driver.destroy_storage_snapshot(context.credentials, {:id=>vol_image_id})
+ end
+
+ def self.from_storage_snapshot(snapshot, context)
+ self.new( context, :values => {
+ :name => snapshot.name,
+ :description => snapshot.description,
+ :created => snapshot.created.nil? ? nil : Time.parse(snapshot.created).xmlschema,
+ :id => context.volume_image_url(snapshot.id),
+ :image_location => {:href=>context.volume_url(snapshot.storage_volume_id)},
+ :bootable => "false" #FIXME
+ } )
+ end
+end
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/fa200948/server/lib/cimi/service/volume_image_create.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/service/volume_image_create.rb b/server/lib/cimi/service/volume_image_create.rb
new file mode 100644
index 0000000..f75b2ef
--- /dev/null
+++ b/server/lib/cimi/service/volume_image_create.rb
@@ -0,0 +1,42 @@
+# 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::Service::VolumeImageCreate < CIMI::Service::Base
+
+ def create
+ params = {
+ :volume_id => context.href_id(image_location.href, :volumes),
+ :name => name,
+ :description => description
+ }
+
+ unless context.driver.respond_to? :create_storage_snapshot
+ raise Deltacloud::Exceptions.exception_from_status(
+ 501,
+ 'Creating VolumeImage is not supported by the current driver'
+ )
+ end
+
+ new_snapshot = context.driver.create_storage_snapshot(context.credentials, params)
+ result = CIMI::Service::VolumeImage.from_storage_snapshot(new_snapshot, context)
+ result.name= name unless new_snapshot.name
+ result.description = description unless new_snapshot.description
+ result.property = property if property
+ result.save
+ result
+ end
+
+
+end
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/fa200948/server/lib/cimi/service/volume_template.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/service/volume_template.rb b/server/lib/cimi/service/volume_template.rb
new file mode 100644
index 0000000..d95ba72
--- /dev/null
+++ b/server/lib/cimi/service/volume_template.rb
@@ -0,0 +1,61 @@
+# 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::Service::VolumeTemplate < CIMI::Service::Base
+
+ def self.find(id, context)
+ if id==:all
+ if context.driver.respond_to? :volume_templates
+ context.driver.volume_templates(context.credentials, {:env=>context})
+ else
+ current_db.volume_templates.map { |t| from_db(t, context) }
+ end
+ else
+ if context.driver.respond_to? :volume_template
+ context.driver.volume_template(context.credentials, id, :env=>context)
+ else
+ template = current_db.volume_templates_dataset.first(:id => id)
+ raise CIMI::Model::NotFound unless template
+ from_db(template, context)
+ end
+ end
+ end
+
+ def self.delete!(id, context)
+ current_db.volume_templates.first(:id => id).destroy
+ end
+
+ def self.from_db(model, context)
+ self.new(context, :values => {
+ :id => context.volume_template_url(model.id),
+ :name => model.name,
+ :description => model.description,
+ :volume_config => {:href => model.volume_config},
+ :volume_image => {:href => model.volume_image},
+ :property => (model.ent_properties ? JSON::parse(model.ent_properties) : nil),
+ :operations => [
+ {
+ :href => context.destroy_volume_template_url(model.id),
+ :rel => 'http://schemas.dmtf.org/cimi/1/action/delete'
+ }
+ ]
+ })
+ end
+
+ protected
+ def attributes_to_copy
+ super + [ :machine_config, :machine_image ]
+ end
+end
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/fa200948/server/lib/cimi/service/volume_template_create.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/service/volume_template_create.rb b/server/lib/cimi/service/volume_template_create.rb
new file mode 100644
index 0000000..b05e0f4
--- /dev/null
+++ b/server/lib/cimi/service/volume_template_create.rb
@@ -0,0 +1,29 @@
+# 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::Service::VolumeTemplateCreate < CIMI::Service::Base
+
+ def create
+ new_template = self.class.current_db.add_volume_template(
+ :name => name,
+ :description => description,
+ :volume_config => volume_config.href,
+ :volume_image => volume_image.href,
+ :ent_properties => property.to_json
+ )
+ CIMI::Service::VolumeTemplate.from_db(new_template, context)
+ end
+
+end