From: Dies Koper <di...@fast.au.fujitsu.com> --- server/lib/cimi/models/system.rb | 4 ++- server/lib/cimi/models/system_template.rb | 19 ++++++------ server/lib/deltacloud/drivers/fgcp/fgcp_client.rb | 4 +++ .../drivers/fgcp/fgcp_driver_cimi_methods.rb | 36 ++++++++++++++++++++-- .../mock/data/cimi/system_template/template1.json | 25 ++++++++++----- .../drivers/mock/mock_driver_cimi_methods.rb | 32 +++++++++++++++++++ 6 files changed, 100 insertions(+), 20 deletions(-)
diff --git a/server/lib/cimi/models/system.rb b/server/lib/cimi/models/system.rb index e238259..2d5b656 100644 --- a/server/lib/cimi/models/system.rb +++ b/server/lib/cimi/models/system.rb @@ -17,7 +17,9 @@ class CIMI::Model::System < CIMI::Model::Base acts_as_root_entity - text :state + resource_attr :system_template, :required => false, :type => :href + + text :state, :required => true # collection :systems, :class => CIMI::Model::SystemSystem # collection :machines, :class => CIMI::Model::SystemMachine diff --git a/server/lib/cimi/models/system_template.rb b/server/lib/cimi/models/system_template.rb index 09cd9b0..49e0797 100644 --- a/server/lib/cimi/models/system_template.rb +++ b/server/lib/cimi/models/system_template.rb @@ -20,16 +20,17 @@ class CIMI::Model::SystemTemplate < CIMI::Model::Base array :component_descriptors do text :name, :description hash :properties - text :type + 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 +#TODO: add the rest +# 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/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..9f94ad5 100644 --- a/server/lib/deltacloud/drivers/fgcp/fgcp_driver_cimi_methods.rb +++ b/server/lib/deltacloud/drivers/fgcp/fgcp_driver_cimi_methods.rb @@ -57,11 +57,41 @@ module Deltacloud::Drivers::Fgcp 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| + { + :volume_config => {:capacity => "#{vdisk['size'][0].to_i}"} + } +# {:href=>context.volume_url(snapshot.storage_volume_id)}, +# { +# :volume_template => "#{vdisk['size'][0].to_i}" +# } +# CIMI::Model::VolumeTemplate.new( +# :volume_config => CIMI::Model::VolumeConfiguration.new(:capacity => vdisk['size'][0].to_i) +# ) + end if vserver['vdisks'] + puts "volume_templates: #{volume_templates}" + { + :name => desc['vsysdescriptorName'][0], + :description => desc['description'][0], + :type => "http://schemas.dmtf.org/cimi/1/Machine", + :machine_template => CIMI::Model::MachineTemplate.new( + :name => vserver['vserverName'][0], + :machine_config => CIMI::Model::MachineConfiguration.find(vserver['vserverType'][0], context), + :machine_image => { :href => context.machine_image_url(vserver['diskimageId'][0]) }, + :volume_templates => volume_templates + ) + } + 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_template/template1.json b/server/lib/deltacloud/drivers/mock/data/cimi/system_template/template1.json index 495fc24..c8c095b 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,21 +4,32 @@ "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 network", - "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": "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" } } + }, + { "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" } } ], "operations": [ 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..13987f2 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,38 @@ 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_templates(credentials, opts={}) check_credentials(credentials) if opts[:id].nil? -- 1.8.0.msysgit.0