From: Dies Koper <di...@fast.au.fujitsu.com> --- server/lib/cimi/collections/systems.rb | 58 +++++++++-- server/lib/cimi/models.rb | 12 ++- server/lib/cimi/models/machine_template.rb | 6 +- server/lib/cimi/models/network_template.rb | 4 +- server/lib/cimi/models/system.rb | 24 ++--- server/lib/cimi/models/system_address.rb | 26 +++++ server/lib/cimi/models/system_credential.rb | 26 +++++ server/lib/cimi/models/system_forwarding_group.rb | 26 +++++ server/lib/cimi/models/system_machine.rb | 91 ++++++++++++++++ server/lib/cimi/models/system_network.rb | 26 +++++ server/lib/cimi/models/system_network_port.rb | 26 +++++ server/lib/cimi/models/system_system.rb | 26 +++++ server/lib/cimi/models/system_template.rb | 20 ++-- server/lib/cimi/models/system_volume.rb | 26 +++++ server/lib/cimi/models/volume_template.rb | 4 +- server/lib/cimi/service.rb | 2 + server/lib/cimi/service/system_machine.rb | 35 +++++++ server/lib/cimi/service/system_volume.rb | 34 ++++++ server/lib/deltacloud/drivers/fgcp/fgcp_client.rb | 4 + .../drivers/fgcp/fgcp_driver_cimi_methods.rb | 116 +++++++++++++++++---- .../mock/data/cimi/system_machine/sysmach1.json | 8 ++ .../mock/data/cimi/system_template/template1.json | 31 +++++- .../mock/data/cimi/system_volume/sysvol1.json | 8 ++ .../drivers/mock/mock_driver_cimi_methods.rb | 64 ++++++++++++ .../cimi/collections/system_templates_test.rb | 47 +++++++++ 25 files changed, 687 insertions(+), 63 deletions(-) create mode 100644 server/lib/cimi/models/system_address.rb create mode 100644 server/lib/cimi/models/system_credential.rb create mode 100644 server/lib/cimi/models/system_forwarding_group.rb create mode 100644 server/lib/cimi/models/system_machine.rb create mode 100644 server/lib/cimi/models/system_network.rb create mode 100644 server/lib/cimi/models/system_network_port.rb create mode 100644 server/lib/cimi/models/system_system.rb create mode 100644 server/lib/cimi/models/system_volume.rb create mode 100644 server/lib/cimi/service/system_machine.rb create mode 100644 server/lib/cimi/service/system_volume.rb create mode 100644 server/lib/deltacloud/drivers/mock/data/cimi/system_machine/sysmach1.json create mode 100644 server/lib/deltacloud/drivers/mock/data/cimi/system_volume/sysvol1.json
diff --git a/server/lib/cimi/collections/systems.rb b/server/lib/cimi/collections/systems.rb index 5c3903e..d9a1e75 100644 --- a/server/lib/cimi/collections/systems.rb +++ b/server/lib/cimi/collections/systems.rb @@ -107,10 +107,37 @@ module CIMI::Collections end end + #use rabbit subcollections for machines index/show: + collection :machines, :with_id => :machine_id do + + operation :index, :with_capability => :system_machines do + description "Retrieve the System's SystemMachineCollection" + control do + volumes = SystemMachine.collection_for_system(params[:id], self) + respond_to do |format| + format.json {volumes.to_json} + format.xml {volumes.to_xml} + end + end + end + + operation :show, :with_capability => :system_machines do + description "Retrieve a System's specific SystemMachine" + control do + volume = SystemMachine.find(params[:id], self, params[:machine_id]) + respond_to do |format| + format.json {volume.to_json} + format.xml {volume.to_xml} + end + end + end + + end + #use rabbit subcollections for volumes index/show: collection :volumes, :with_id => :vol_id do - operation :index, :with_capability => :storage_volumes do + operation :index, :with_capability => :system_volumes do description "Retrieve the System's SystemVolumeCollection" control do volumes = SystemVolume.collection_for_system(params[:id], self) @@ -121,7 +148,7 @@ module CIMI::Collections end end - operation :show, :with_capability => :storage_volumes do + operation :show, :with_capability => :system_volumes do description "Retrieve a System's specific SystemVolume" control do volume = SystemVolume.find(params[:id], self, params[:vol_id]) @@ -131,16 +158,29 @@ module CIMI::Collections end end end + end - operation :destroy, :with_capability => :detach_storage_volume do - description "Remove/detach a volume from the System's SystemVolumeCollection" + #use rabbit subcollections for networks index/show: + collection :networks, :with_id => :network_id do + + operation :index, :with_capability => :system_networks do + description "Retrieve the System's SystemNetworkCollection" control do - system_volume = SystemVolume.find(params[:id], self, params[:vol_id]) - location = system_volume.initial_location - system_volumes = System.detach_volume(params[:vol_id], location, self) + volumes = SystemNetwork.collection_for_system(params[:id], self) respond_to do |format| - format.json{ system_volumes.to_json} - format.xml{ system_volumes.to_xml} + format.json {volumes.to_json} + format.xml {volumes.to_xml} + end + end + end + + operation :show, :with_capability => :system_networks do + description "Retrieve a System's specific SystemNetwork" + control do + volume = SystemNetwork.find(params[:id], self, params[:network_id]) + respond_to do |format| + format.json {volume.to_json} + format.xml {volume.to_xml} end end end diff --git a/server/lib/cimi/models.rb b/server/lib/cimi/models.rb index 8eeb96c..c8f138c 100644 --- a/server/lib/cimi/models.rb +++ b/server/lib/cimi/models.rb @@ -79,7 +79,15 @@ 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' -require_relative './models/system' require_relative './models/network_template' require_relative './models/network_create' +require_relative './models/system_template' +require_relative './models/system_network_port' +require_relative './models/system_network' +require_relative './models/system_address' +require_relative './models/system_forwarding_group' +require_relative './models/system_machine' +require_relative './models/system_volume' +require_relative './models/system_credential' +require_relative './models/system_system' +require_relative './models/system' diff --git a/server/lib/cimi/models/machine_template.rb b/server/lib/cimi/models/machine_template.rb index 68e865b..c167555 100644 --- a/server/lib/cimi/models/machine_template.rb +++ b/server/lib/cimi/models/machine_template.rb @@ -28,10 +28,12 @@ class CIMI::Model::MachineTemplate < CIMI::Model::Base scalar :href, :initial_location end - array :volume_templates do - scalar :href, :initial_location + class CIMI::Model::VolumeTemplateWithLocation < CIMI::Model::VolumeTemplate + text :initial_location end + array :volume_templates, :ref => CIMI::Model::VolumeTemplateWithLocation + array :network_interfaces do href :vsp text :hostname, :mac_address, :state, :protocol, :allocation diff --git a/server/lib/cimi/models/network_template.rb b/server/lib/cimi/models/network_template.rb index 4f69f52..4515351 100644 --- a/server/lib/cimi/models/network_template.rb +++ b/server/lib/cimi/models/network_template.rb @@ -17,8 +17,8 @@ class CIMI::Model::NetworkTemplate < CIMI::Model::Base acts_as_root_entity - ref :network_config, :required => true - ref :forwarding_group, :required => true + ref :network_config, :class => CIMI::Model::NetworkConfiguration + ref :forwarding_group, :class => CIMI::Model::ForwardingGroup array :operations do scalar :rel, :href diff --git a/server/lib/cimi/models/system.rb b/server/lib/cimi/models/system.rb index 118f9f5..dbab95b 100644 --- a/server/lib/cimi/models/system.rb +++ b/server/lib/cimi/models/system.rb @@ -17,18 +17,18 @@ class CIMI::Model::System < CIMI::Model::Base acts_as_root_entity - text :state - - # FIXME: Any reason for these comments? - - # collection :systems, :class => CIMI::Model::SystemSystem - # collection :machines, :class => CIMI::Model::SystemMachine - # collection :credentials, :class => CIMI::Model::SystemCredential - # collection :volumes, :class => CIMI::Model::SystemVolume - # collection :networks, :class => CIMI::Model::SystemNetwork - # collection :network_ports, :class => CIMI::Model::SystemNetworkPort - # collection :addresses, :class => CIMI::Model::SystemAddress - # collection :forwarding_groups, :class => CIMI::Model::SystemForwardingGroup + text :state, :required => true + + collection :systems, :class => CIMI::Model::SystemSystem + collection :machines, :class => CIMI::Model::SystemMachine + collection :credentials, :class => CIMI::Model::SystemCredential + collection :volumes, :class => CIMI::Model::SystemVolume + collection :networks, :class => CIMI::Model::SystemNetwork + collection :network_ports, :class => CIMI::Model::SystemNetworkPort + collection :addresses, :class => CIMI::Model::SystemAddress + collection :forwarding_groups, :class => CIMI::Model::SystemForwardingGroup + + #TODO: implement the attributes commented out # array :meters do # scalar :href diff --git a/server/lib/cimi/models/system_address.rb b/server/lib/cimi/models/system_address.rb new file mode 100644 index 0000000..0709ff8 --- /dev/null +++ b/server/lib/cimi/models/system_address.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::Model::SystemAddress < CIMI::Model::Base + + acts_as_root_entity + + href :address + + array :operations do + scalar :rel, :href + end + +end diff --git a/server/lib/cimi/models/system_credential.rb b/server/lib/cimi/models/system_credential.rb new file mode 100644 index 0000000..8967867 --- /dev/null +++ b/server/lib/cimi/models/system_credential.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::Model::SystemCredential < CIMI::Model::Base + + acts_as_root_entity + + href :credential + + array :operations do + scalar :rel, :href + end + +end diff --git a/server/lib/cimi/models/system_forwarding_group.rb b/server/lib/cimi/models/system_forwarding_group.rb new file mode 100644 index 0000000..f9e5225 --- /dev/null +++ b/server/lib/cimi/models/system_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::Model::SystemForwardingGroup < CIMI::Model::Base + + acts_as_root_entity + + href :forwarding_group + + array :operations do + scalar :rel, :href + end + +end diff --git a/server/lib/cimi/models/system_machine.rb b/server/lib/cimi/models/system_machine.rb new file mode 100644 index 0000000..2568bc6 --- /dev/null +++ b/server/lib/cimi/models/system_machine.rb @@ -0,0 +1,91 @@ +# 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::SystemMachine < CIMI::Model::Base + + acts_as_root_entity + + href :machine + + array :operations do + scalar :rel, :href + end + + # find machine with id (or all if :all) belonging to specified system + def self.find(system_id, context, id=:all) + if id == :all + puts "system_machine#self.find #{system_id} / #{id}" + instances = context.driver.instances(context.credentials, {:system_id=>id}) + instances.inject([]) do |machines, instance| + id = context.system_url(system_id)+"/machines/#{instance.id}" + machines << self.new( + :id => id, + :name => instance.name, + :description => "SystemMachine #{instance.id} for System #{system_id}", + :created =>instance.launch_time.nil? ? nil : Time.parse(instance.launch_time).xmlschema, + :operations => [{:href=>id, :rel => "delete" }] + ) + machines + end + else + puts "system_machine#self.find #{system_id} / #{id}" + 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( + :id => id, + :name => vol.id, + :description => "MachineVolume #{vol.id} for Machine #{machine_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.collection_for_system(system_id, context) + context.params[:system_id] = system_id + machines = CIMI::Model::Machine.find(:all, context) + puts "machines: #{machines}" + puts "machines.size: #{machines.size}" + machines_url = context.url("/systems/#{system_id}/machines") + machine_refs = machines.collect do |m| + puts m[:id] + machine_url = m[:id] + machine_url[context.machines_url] = "" + puts machine_url + m[:operations] = [ +# { :href => machines_url, :rel => "edit" }, + { :href => machines_url + machine_url, :rel => "delete" } + ] + {:href => m[:id]} + end + unless CIMI::Model.const_defined?('SystemMachineCollection') + collection_class = CIMI::Model::Collection.generate(self) + else + collection_class = CIMI::Model::SystemMachineCollection + end + collection_class.new( + :id => machines_url, + :name => 'default', + :count => machines.size, + :description => "Machine collection for System #{system_id}", + :entries => machines, + :operations => [{ :href => machines_url.singularize+"_add", :rel => "add" }] + ) + end + +end diff --git a/server/lib/cimi/models/system_network.rb b/server/lib/cimi/models/system_network.rb new file mode 100644 index 0000000..1bf10d5 --- /dev/null +++ b/server/lib/cimi/models/system_network.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::Model::SystemNetwork < CIMI::Model::Base + + acts_as_root_entity + + href :network + + array :operations do + scalar :rel, :href + end + +end diff --git a/server/lib/cimi/models/system_network_port.rb b/server/lib/cimi/models/system_network_port.rb new file mode 100644 index 0000000..3a0c812 --- /dev/null +++ b/server/lib/cimi/models/system_network_port.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::Model::SystemNetworkPort < CIMI::Model::Base + + acts_as_root_entity + + href :network_port + + array :operations do + scalar :rel, :href + end + +end diff --git a/server/lib/cimi/models/system_system.rb b/server/lib/cimi/models/system_system.rb new file mode 100644 index 0000000..b94ec18 --- /dev/null +++ b/server/lib/cimi/models/system_system.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::Model::SystemSystem < CIMI::Model::Base + + acts_as_root_entity + + href :system + + array :operations do + scalar :rel, :href + end + +end diff --git a/server/lib/cimi/models/system_template.rb b/server/lib/cimi/models/system_template.rb index 82e418b..c60f759 100644 --- a/server/lib/cimi/models/system_template.rb +++ b/server/lib/cimi/models/system_template.rb @@ -20,19 +20,17 @@ class CIMI::Model::SystemTemplate < CIMI::Model::Base array :component_descriptors do text :name, :description hash_map :properties - text :type - - # FIXME: Any reasons for these comments? + text :type, :required => true #component_template, comprises: - # struct :machine_template, :class => CIMI::Model::MachineTemplate - # struct :system_template, :class => CIMI::Model::SystemTemplate - # struct :credential_template, :class => CIMI::Model::CredentialTemplate - # struct :volume_template, :class => CIMI::Model::VolumeTemplate - # struct :network_template, :class => CIMI::Model::NetworkTemplate - # struct :network_port_template, :class => CIMI::Model::NetworkPortTemplate - # struct :forwarding_group_template, :class => CIMI::Model::ForwardingGroupTemplate - # struct :address_template, :class => CIMI::Model::AddressTemplate + ref :machine_template, :class => CIMI::Model::MachineTemplate + ref :system_template, :class => CIMI::Model::SystemTemplate + ref :credential_template, :class => CIMI::Model::CredentialTemplate + ref :volume_template, :class => CIMI::Model::VolumeTemplate + ref :network_template, :class => CIMI::Model::NetworkTemplate + ref :network_port_template, :class => CIMI::Model::NetworkPortTemplate + ref :forwarding_group_template, :class => CIMI::Model::ForwardingGroupTemplate + ref :address_template, :class => CIMI::Model::AddressTemplate text :quantity end diff --git a/server/lib/cimi/models/system_volume.rb b/server/lib/cimi/models/system_volume.rb new file mode 100644 index 0000000..be31846 --- /dev/null +++ b/server/lib/cimi/models/system_volume.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::Model::SystemVolume < CIMI::Model::Base + + acts_as_root_entity + + href :volume + + array :operations do + scalar :rel, :href + end + +end diff --git a/server/lib/cimi/models/volume_template.rb b/server/lib/cimi/models/volume_template.rb index bda4657..43e9c86 100644 --- a/server/lib/cimi/models/volume_template.rb +++ b/server/lib/cimi/models/volume_template.rb @@ -17,8 +17,8 @@ class CIMI::Model::VolumeTemplate < CIMI::Model::Base acts_as_root_entity - ref :volume_config, :required => true - ref :volume_image, :required => true + ref :volume_config, :required => true, :class => CIMI::Model::VolumeConfiguration + ref :volume_image array :meter_templates do end diff --git a/server/lib/cimi/service.rb b/server/lib/cimi/service.rb index 8176532..9dbd85c 100644 --- a/server/lib/cimi/service.rb +++ b/server/lib/cimi/service.rb @@ -45,6 +45,8 @@ require_relative './service/network_create' require_relative './service/network' require_relative './service/forwarding_group' require_relative './service/volume_template_create' +require_relative './service/system_machine' +require_relative './service/system_volume' require_relative './service/system' require_relative './service/address_template_create' require_relative './service/volume' diff --git a/server/lib/cimi/service/system_machine.rb b/server/lib/cimi/service/system_machine.rb new file mode 100644 index 0000000..78d2cc1 --- /dev/null +++ b/server/lib/cimi/service/system_machine.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::SystemMachine < CIMI::Service::Base + + def self.find(system_id, context, id=:all) + puts "context: #{context.expand?(:machines)}" + if id == :all + machines = context.driver.system_machines(context.credentials, {:env=>context, :system_id=>system_id}) + else + machines = context.driver.system_machines(context.credentials, {:env=>context, :system_id=>system_id, :id=>id}) + raise CIMI::Model::NotFound if machines.empty? + machines.first + end + end + + def self.collection_for_system(system_id, context) + system_machines = self.find(system_id, context) + machines_url = context.url("/system/#{system_id}/machines") + CIMI::Model::SystemMachine.list(machines_url, system_machines, :add_url => machines_url) + end + +end diff --git a/server/lib/cimi/service/system_volume.rb b/server/lib/cimi/service/system_volume.rb new file mode 100644 index 0000000..c95ce79 --- /dev/null +++ b/server/lib/cimi/service/system_volume.rb @@ -0,0 +1,34 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. The +# ASF licenses this file to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance with the +# License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +class CIMI::Service::SystemVolume < CIMI::Service::Base + + def self.find(system_id, context, id=:all) + if id == :all + vols = context.driver.system_volumes(context.credentials, {:env=>context, :system_id=>system_id}) + else + vols = context.driver.system_volumes(context.credentials, {:env=>context, :system_id=>system_id, :id=>id}) + raise CIMI::Model::NotFound if vols.empty? + vols.first + end + end + + def self.collection_for_system(system_id, context) + system_volumes = self.find(system_id, context) + volumes_url = context.url("/system/#{system_id}/volumes") + CIMI::Model::SystemVolume.list(volumes_url, system_volumes, :add_url => volumes_url) + end + +end diff --git a/server/lib/deltacloud/drivers/fgcp/fgcp_client.rb b/server/lib/deltacloud/drivers/fgcp/fgcp_client.rb index fed3b70..9597c13 100644 --- a/server/lib/deltacloud/drivers/fgcp/fgcp_client.rb +++ b/server/lib/deltacloud/drivers/fgcp/fgcp_client.rb @@ -94,6 +94,10 @@ class FgcpClient request('ListVSYSDescriptor') end + def get_vsys_descriptor_configuration(vsys_descriptor_id) + request('GetVSYSDescriptorConfiguration', {'vsysDescriptorId' => vsys_descriptor_id}) + end + def list_vservers(vsys_id) request('ListVServer', {'vsysId' => vsys_id}) end diff --git a/server/lib/deltacloud/drivers/fgcp/fgcp_driver_cimi_methods.rb b/server/lib/deltacloud/drivers/fgcp/fgcp_driver_cimi_methods.rb index b4d31f6..b1a4a5b 100644 --- a/server/lib/deltacloud/drivers/fgcp/fgcp_driver_cimi_methods.rb +++ b/server/lib/deltacloud/drivers/fgcp/fgcp_driver_cimi_methods.rb @@ -29,39 +29,117 @@ module Deltacloud::Drivers::Fgcp def systems(credentials, opts={}) safely do client = new_client(credentials) + xml = client.list_vsys['vsyss'] + return [] if xml.nil? + context = opts[:env] - if opts and opts[:id] - vsys_ids = [opts[:id]] - else - xml = client.list_vsys['vsyss'] - return [] if xml.nil? - vsys_ids = xml[0]['vsys'].collect { |vsys| vsys['vsysId'][0] } - end - - vsys_ids.collect do |vsys_id| - vsys = client.get_vsys_configuration(vsys_id)['vsys'][0] + systems = xml[0]['vsys'].collect do |vsys| + vsys_id = vsys['vsysId'][0] vsys_description_el = vsys['description'] CIMI::Model::System.new( - :id => vsys['vsysId'][0], + :id => vsys_id, :name => vsys['vsysName'][0], -# :machines => "http://cimi.example.org/systems/#{vsys['vsysId'][0]}/machines?realm_id=#{vsys['vsysId'][0]}", -# :volumes => "http://cimi.example.org/systems/#{vsys['vsysId'][0]}/volumes?realm_id=#{vsys['vsysId'][0]}", -# :networks => "http://cimi.example.org/systems/#{vsys['vsysId'][0]}/networks?realm_id=#{vsys['vsysId'][0]}", -# :addresses => "http://cimi.example.org/systems/#{vsys['vsysId'][0]}/addresses?realm_id=#{vsys['vsysId'][0]}", - :description => vsys_description_el ? vsys_description_el[0] : nil + :description => vsys_description_el ? vsys_description_el[0] : nil, + :machines => { :href => context.system_url("#{vsys_id}/machines") }, + :volumes => { :href => context.system_url("#{vsys_id}/volumes") }, + :networks => { :href => context.system_url("#{vsys_id}/networks") }, + :addresses => { :href => context.system_url("#{vsys_id}/addresses") } ) end + systems = systems.select { |s| opts[:id] == s[:id] } if opts[:id] + # now add system state + systems.each do |system| + xml = client.list_vservers(system[:id])['vservers'] + if xml.nil? + system[:state] = 'MIXED' + else + xml[0]['vserver'].each do |vserver| + state = @@INSTANCE_STATE_MAP[client.get_vserver_status(vserver['vserverId'][0])['vserverStatus'][0]] + state = 'STARTED' if state == 'RUNNING' + system[:state] ||= state + if system[:state] != state + system[:state] = 'MIXED' + break + end + end + end + end + systems + end + end + + def system_machines(credentials, opts={}) + safely do + client = new_client(credentials) + #if :expand not specified, list of hrefs only, else convert from :instances? + xml = client.list_vservers(opts[:system_id])['vservers'] + return [] if xml.nil? + context = opts[:env] + + machines = xml[0]['vserver'].collect do |vserver| + vserver_id = vserver['vserverId'][0] + CIMI::Model::SystemMachine.new( + :id => context.machine_url(vserver_id), + :name => vserver['vserverName'][0], + :machine => { :href => context.machine_url(vserver_id)} + ) unless opts[:id] and opts[:id] != vserver_id + end + machines.compact + machines.each { |m| puts m.inspect} end end def system_templates(credentials, opts={}) safely do client = new_client(credentials) + context = opts[:env] templates = client.list_vsys_descriptor['vsysdescriptors'][0]['vsysdescriptor'].collect do |desc| + conf = client.get_vsys_descriptor_configuration(desc['vsysdescriptorId'][0])['vsysdescriptor'][0] + components = conf['vservers'][0]['vserver'].collect do |vserver| + next if vserver['vserverType'][0] == 'firewall' + volume_templates = vserver['vdisks'][0]['vdisk'].collect do |vdisk| + CIMI::Model::VolumeTemplateWithLocation.new( +# :volume_config => {:capacity => "#{vdisk['size'][0].to_i * 1024 * 1024}"} + :volume_config => CIMI::Model::VolumeConfiguration.new(:capacity => vdisk['size'][0].to_i * 1024 * 1024) + ) + end if vserver['vdisks'] + { + :name => desc['vsysdescriptorName'][0], + :description => '', + :type => "http://schemas.dmtf.org/cimi/1/Machine", + :machine_template => CIMI::Model::MachineTemplate.new( + :name => vserver['vserverName'][0], + :description => '', + :machine_config => CIMI::Service::MachineConfiguration.find(vserver['vserverType'][0], context), + :machine_image => { :href => context.machine_image_url(vserver['diskimageId'][0]) }, + :volume_templates => volume_templates + ) + } + end + # add network templates + if conf['vsysdescriptorId'][0] =~ /(1|2|3)-tier Skeleton/ + tiers = ['DMZ', 'Secure1', 'Secure2'] + components += 1.upto($1.to_i).collect do |n| + { + :name => tiers[n], + :description => "Network tier #{n}", + :type => "http://schemas.dmtf.org/cimi/1/Network", + :network_template => CIMI::Model::NetworkTemplate.new( + :name => 'Private network', + :description => '', + :network_config => CIMI::Model::NetworkConfiguration.new( + :network_type => 'PRIVATE', + :class_of_service => 'BRONZE' + ) + ) + } + end + end CIMI::Model::SystemTemplate.new( - :id => desc['vsysdescriptorId'][0], - :name => desc['vsysdescriptorName'][0], - :description => desc['description'][0] + :id => desc['vsysdescriptorId'][0], + :name => desc['vsysdescriptorName'][0], + :description => desc['description'][0], + :component_descriptors => components.compact ) end templates = templates.select { |t| opts[:id] == t[:id] } if opts[:id] diff --git a/server/lib/deltacloud/drivers/mock/data/cimi/system_machine/sysmach1.json b/server/lib/deltacloud/drivers/mock/data/cimi/system_machine/sysmach1.json new file mode 100644 index 0000000..8fe2a92 --- /dev/null +++ b/server/lib/deltacloud/drivers/mock/data/cimi/system_machine/sysmach1.json @@ -0,0 +1,8 @@ +{ "id": "http://cimi.example.org/systems/system1/machines/inst0", + "name": "sysmach1", + "created": "Fri Feb 08 12:15:15 EET 2013", + "machine": { "href": "http://cimi.example.org/machines/inst0" }, + "operations": [ + { "rel": "delete", "href": "http://cimi.example.org/systems/system1/machines/inst0" } + ] +} diff --git a/server/lib/deltacloud/drivers/mock/data/cimi/system_template/template1.json b/server/lib/deltacloud/drivers/mock/data/cimi/system_template/template1.json index 495fc24..913252b 100644 --- a/server/lib/deltacloud/drivers/mock/data/cimi/system_template/template1.json +++ b/server/lib/deltacloud/drivers/mock/data/cimi/system_template/template1.json @@ -4,20 +4,43 @@ "created": "Fri Feb 08 12:15:15 EET 2013", "componentDescriptors": [ { "name": "my machine", - "type": "http://schemas.dmtf.org/cimi/1/Machine", "description": "an inline mock machine template", + "type": "http://schemas.dmtf.org/cimi/1/Machine", "machineTemplate": { "name": "machine in mock system", "description": "machine in system", "machineConfig": { "href": "http://example.com/configs/m1-small" }, - "machineImage": { "href": "http://example.com/images/img1" } + "machineImage": { "href": "http://example.com/images/img1" }, + "volumeTemplates": [ + { "href": "http://example.com/volumes/sysvol1" } + ] } }, + { "name": "my second machine", + "description": "another inline mock machine template", + "type": "http://schemas.dmtf.org/cimi/1/Machine", + "machineTemplate": { + "name": "machine in mock system", + "description": "machine in system", + "machineConfig": { "href": "http://example.com/configs/m1-small" }, + "machineImage": { "href": "http://example.com/images/img1" }, + "volumeTemplates": [ + { "volumeConfig": {"capacity": 10485760} } + ] + } + }, + { "name": "my third machine", + "description": "a reference to a mock machine template", + "type": "http://schemas.dmtf.org/cimi/1/Machine", + "machineTemplate": { "href" : "http://example.com/machine_templates/template1" } + }, { "name": "my network", + "description": "an inline network template", "type": "http://schemas.dmtf.org/cimi/1/Network", - "description": "a reference to an existing mock network template", "networkTemplate": { - "href": "http://cimi.example.org/network_templates/template1" + "name": "network in mock system", + "description": "network in system", + "networkConfig": { "networkType": "PRIVATE", "classOfService": "GOLD" } } } ], diff --git a/server/lib/deltacloud/drivers/mock/data/cimi/system_volume/sysvol1.json b/server/lib/deltacloud/drivers/mock/data/cimi/system_volume/sysvol1.json new file mode 100644 index 0000000..12e3554 --- /dev/null +++ b/server/lib/deltacloud/drivers/mock/data/cimi/system_volume/sysvol1.json @@ -0,0 +1,8 @@ +{ "id": "http://cimi.example.org/systems/system1/volumes/vol1", + "name": "sysvol1", + "created": "Fri Feb 08 12:15:15 EET 2013", + "volume": { "href": "http://cimi.example.org/volumes/vol1" }, + "operations": [ + { "rel": "delete", "href": "http://cimi.example.org/systems/system1/volumes/vol1" } + ] +} diff --git a/server/lib/deltacloud/drivers/mock/mock_driver_cimi_methods.rb b/server/lib/deltacloud/drivers/mock/mock_driver_cimi_methods.rb index b1c57c8..d2c1d78 100644 --- a/server/lib/deltacloud/drivers/mock/mock_driver_cimi_methods.rb +++ b/server/lib/deltacloud/drivers/mock/mock_driver_cimi_methods.rb @@ -35,6 +35,70 @@ module Deltacloud::Drivers::Mock systems.map{|sys|convert_cimi_mock_urls(:system, sys ,opts[:env])}.flatten end + def create_system(credentials, opts={}) + check_credentials(credentials) + id = "#{opts[:env].send("systems_url")}/#{opts[:name]}" + sys_hsh = { "id"=> id, + "name" => opts[:name], + "description" => opts[:description], + "created" => Time.now, + "state" => "STOPPED", + "systemTemplate"=> { "href" => opts[:system_template].id }, + "operations" => [{"rel"=>"edit", "href"=> id}, + {"rel"=>"delete", "href"=> id}] } + system = CIMI::Model::System.from_json(JSON.generate(sys_hsh)) + + @client.store_cimi(:system, system) + system + end + + def delete_system(credentials, id) + check_credentials(credentials) + @client.destroy_cimi(:system, id) + end + + def start_system(credentials, id) + check_credentials(credentials) + update_object_state(id, "System", "STARTED") + end + + def stop_system(credentials, id) + check_credentials(credentials) + update_object_state(id, "System", "STOPPED") + end + + def system_machines(credentials, opts={}) + check_credentials(credentials) + if opts[:id].nil? + machines = @client.load_all_cimi(:system_machine).map{|mach| CIMI::Model::SystemMachine.from_json(mach)} + else + begin + machines = [CIMI::Model::SystemMachine.from_json(@client.load_cimi(:system_machine, opts[:id]))] + rescue Errno::ENOENT + return [] + end + end + #FIXME: with ":machines", delete url becomes 'http://localhost:3001/cimi/machines?id=sysmach1' + #with ":system_machine"/":system_machines", undefined method `system_machine_url' for #<CIMI::Collections::Systems:0x44fe338> in mock_driver_cimi_methods.rb:261 + machines.map{|mach|convert_cimi_mock_urls(:machines, mach, opts[:env])}.flatten + end + + def system_volumes(credentials, opts={}) + check_credentials(credentials) + if opts[:id].nil? + volumes = @client.load_all_cimi(:system_volume).map{|vol| CIMI::Model::SystemVolume.from_json(vol)} + else + begin + volumes = [CIMI::Model::SystemVolume.from_json(@client.load_cimi(:system_volume, opts[:id]))] + rescue Errno::ENOENT + return [] + end + end + #FIXME: with ":volumes", delete url becomes 'http://localhost:3001/cimi/volumes?id=sysvol1' + #with ":system_volume"/":system_volumes", undefined method `system_volume_url' for #<CIMI::Collections::Systems:0x44fe338> in mock_driver_cimi_methods.rb:261 + volumes.map{|vol|convert_cimi_mock_urls(:volumes, vol, opts[:env])}.flatten + end + def system_templates(credentials, opts={}) check_credentials(credentials) if opts[:id].nil? diff --git a/server/tests/cimi/collections/system_templates_test.rb b/server/tests/cimi/collections/system_templates_test.rb index 8c4f1a7..87488b4 100644 --- a/server/tests/cimi/collections/system_templates_test.rb +++ b/server/tests/cimi/collections/system_templates_test.rb @@ -38,4 +38,51 @@ describe CIMI::Collections::SystemTemplates do status.must_equal 404 end + it 'should allow to retrieve system template\'s machine template\'s ref details' do + get root_url '/system_templates/template1' + (xml/'SystemTemplate/componentDescriptor').each do |c| + if (c/'name').inner_text == 'my third machine' + (c/'machineTemplate').wont_be_empty + (c/'machineTemplate').to_s.must_equal '<machineTemplate href="http://example.com/machine_templates/template1"/>' + end + end + end + + it 'should allow to retrieve system template\'s machine template\'s inline details' do + get root_url '/system_templates/template1' + (xml/'SystemTemplate/componentDescriptor').each do |c| + if (c/'name').inner_text == 'my machine' + (c/'machineTemplate').wont_be_empty + (c/'machineTemplate/name').inner_text.must_equal 'machine in mock system' + (c/'machineTemplate/description').inner_text.must_equal 'machine in system' + (c/'machineTemplate/machineConfig').to_s.must_equal '<machineConfig href="http://example.com/configs/m1-small"/>' + (c/'machineTemplate/machineImage').to_s.must_equal '<machineImage href="http://example.com/images/img1"/>' + (c/'machineTemplate/volumeTemplate').to_s.must_equal '<volumeTemplate href="http://example.com/volumes/sysvol1"/>' + end + end + end + + it 'should allow to retrieve system template\'s machine template\'s inline volume template' do + get root_url '/system_templates/template1' + (xml/'SystemTemplate/componentDescriptor').each do |c| + if (c/'name').inner_text == 'my second machine' + (c/'machineTemplate').wont_be_empty + (c/'machineTemplate/description').inner_text.must_equal 'another inline mock machine template' + (c/'machineTemplate/volumeTemplate').wont_be_empty + (c/'machineTemplate/volumeTemplate/volumeConfig').wont_be_empty + (c/'machineTemplate/volumeTemplate/volumeConfig/capacity').inner_text.must_equal '10485760' + end + end + end + + it 'should allow to retrieve system template\'s network' do + get root_url '/system_templates/template1' + (xml/'SystemTemplate/componentDescriptor').each do |c| + if (c/'name').inner_text == 'network in mock system' + (c/'networkTemplate').inner_text.must_equal 'my network' + (c/'networkTemplate/networkConfig/networkType').inner_text.must_equal 'GOLD' + end + end + end + end -- 1.8.0.msysgit.0