diff --git a/src/cloud/occi/etc/occi-server.conf b/src/cloud/occi/etc/occi-server.conf index dfca56bb37..4b525a05bf 100644 --- a/src/cloud/occi/etc/occi-server.conf +++ b/src/cloud/occi/etc/occi-server.conf @@ -14,14 +14,10 @@ PORT=4567 # Configuration for the image repository DATABASE=/var/occi.db -IMAGE_DIR= # Configuration for OpenNebula's Virtual Networks BRIDGE= -# Default format for FS -FS_FORMAT=ext3 - # VM types allowed and its template file (inside templates directory) VM_TYPE=[NAME=small, TEMPLATE=small.erb] VM_TYPE=[NAME=medium, TEMPLATE=medium.erb] diff --git a/src/cloud/occi/etc/templates/large.erb b/src/cloud/occi/etc/templates/large.erb index cbc429b343..e59ed9a0f2 100644 --- a/src/cloud/occi/etc/templates/large.erb +++ b/src/cloud/occi/etc/templates/large.erb @@ -7,11 +7,11 @@ NAME = <%= vm_info['NAME'] %> <% vm_info['DISK'].each do |disk| %> <% if disk['STORAGE'] && disk['STORAGE']['href'] %> DISK = [ IMAGE_ID = <%= disk['STORAGE']['href'].split('/').last %> - <% if disk['OVERWRITE'] %> - OVERWRITE = yes + <% if disk.key?('OVERWRITE') %> + ,OVERWRITE = "yes" <% end %> <% if disk['SAVE_AS'] %> - SAVE_AS = "<%= disk['SAVE_AS'] %>" + ,SAVE_AS = "<%= disk['SAVE_AS'] %>" <% end %> ] <% end %> @@ -21,14 +21,13 @@ NAME = <%= vm_info['NAME'] %> <% if vm_info['NIC'] %> <% vm_info['NIC'].each do |nic| %> <% if nic['NETWORK'] && nic['NETWORK']['href'] %> - NIC = [ NETWORK_ID = <%= nic['NETWORK']['href'].split('/').last %>, + NIC = [ NETWORK_ID = <%= nic['NETWORK']['href'].split('/').last %> <% if nic['IP'] %> - IP = <%= nic['IP'] %> + ,IP = <%= nic['IP'] %> <% end %> ] <% end %> <% end %> <% end %> -INSTANCE_TYPE = <%= vm_info['INSTANCE_TYPE']%> - +INSTANCE_TYPE = <%= vm_info['INSTANCE_TYPE']%> \ No newline at end of file diff --git a/src/cloud/occi/etc/templates/medium.erb b/src/cloud/occi/etc/templates/medium.erb index 1fa7f80b75..6263c34cf9 100644 --- a/src/cloud/occi/etc/templates/medium.erb +++ b/src/cloud/occi/etc/templates/medium.erb @@ -1,55 +1,33 @@ -NAME = <%= vm_info['NAME']%> - CPU = 4 MEMORY = 4096 -OS = [ kernel = /vmlinuz, - initrd = /initrd.img, - root = sda1, - kernel_cmd = "ro xencons=tty console=tty1"] - -<% if vm_info['STORAGE'] - vm_info['STORAGE'].each do |key, image| - image=[image].flatten -case key - when "SWAP" - image.each do |img| -%> -DISK = [ type = "swap", - size=<%= img['size']%>, - target=<%= img['dev']%> ] -<% - end - when "DISK" - image.each do |img| -%> -DISK = [ type = "disk", - target=<%= img['dev']%>, - source=<%= img['source']%>, - image_id=<%= img['image']%> ] -<% - end - when "FS" - image.each do |img| -%> -DISK = [ type = "fs", - target=<%= img['dev']%>, - size=<%= img['size']%>, - format=<%= @config[:fs_format]||"ext3"%> ] -<% end %> -<% end %> -<% end %> -<% end %> -<% if vm_info['NETWORK'] and vm_info['NETWORK']['NIC'] %> -<% vm_info['NETWORK']['NIC'].each do |nic| %> -NIC = [ -<% if nic['ip'] %> - IP=<%= nic['ip'] %>, -<% end %> - NETWORK="<%= nic['network']%>", - NETWORK_ID=<%= nic['network_id'] %> -] -<% end %> -<% end %> -INSTANCE_TYPE = <%= vm_info[:instance_type ]%> +NAME = <%= vm_info['NAME'] %> +<% if vm_info['DISK'] %> + <% vm_info['DISK'].each do |disk| %> + <% if disk['STORAGE'] && disk['STORAGE']['href'] %> + DISK = [ IMAGE_ID = <%= disk['STORAGE']['href'].split('/').last %> + <% if disk.key?('OVERWRITE') %> + ,OVERWRITE = "yes" + <% end %> + <% if disk['SAVE_AS'] %> + ,SAVE_AS = "<%= disk['SAVE_AS'] %>" + <% end %> + ] + <% end %> + <% end %> +<% end %> + +<% if vm_info['NIC'] %> + <% vm_info['NIC'].each do |nic| %> + <% if nic['NETWORK'] && nic['NETWORK']['href'] %> + NIC = [ NETWORK_ID = <%= nic['NETWORK']['href'].split('/').last %> + <% if nic['IP'] %> + ,IP = <%= nic['IP'] %> + <% end %> + ] + <% end %> + <% end %> +<% end %> + +INSTANCE_TYPE = <%= vm_info['INSTANCE_TYPE']%> \ No newline at end of file diff --git a/src/cloud/occi/etc/templates/small.erb b/src/cloud/occi/etc/templates/small.erb index 84ec3648c0..fb28e17cb2 100644 --- a/src/cloud/occi/etc/templates/small.erb +++ b/src/cloud/occi/etc/templates/small.erb @@ -1,55 +1,33 @@ -NAME = <%= vm_info['NAME']%> - CPU = 1 MEMORY = 1024 -OS = [ kernel = /vmlinuz, - initrd = /initrd.img, - root = sda1, - kernel_cmd = "ro xencons=tty console=tty1"] - -<% if vm_info['STORAGE'] - vm_info['STORAGE'].each do |key, image| - image=[image].flatten -case key - when "SWAP" - image.each do |img| -%> -DISK = [ type = "swap", - size=<%= img['size']%>, - target=<%= img['dev']%> ] -<% - end - when "DISK" - image.each do |img| -%> -DISK = [ type = "disk", - target=<%= img['dev']%>, - source=<%= img['source']%>, - image_id=<%= img['image']%> ] -<% - end - when "FS" - image.each do |img| -%> -DISK = [ type = "fs", - target=<%= img['dev']%>, - size=<%= img['size']%>, - format=<%= @config[:fs_format]||"ext3"%> ] -<% end %> -<% end %> -<% end %> -<% end %> -<% if vm_info['NETWORK'] and vm_info['NETWORK']['NIC'] %> -<% vm_info['NETWORK']['NIC'].each do |nic| %> -NIC = [ -<% if nic['ip'] %> - IP=<%= nic['ip'] %>, -<% end %> - NETWORK="<%= nic['network']%>", - NETWORK_ID=<%= nic['network_id'] %> -] -<% end %> -<% end %> -INSTANCE_TYPE = <%= vm_info[:instance_type ]%> +NAME = <%= vm_info['NAME'] %> +<% if vm_info['DISK'] %> + <% vm_info['DISK'].each do |disk| %> + <% if disk['STORAGE'] && disk['STORAGE']['href'] %> + DISK = [ IMAGE_ID = <%= disk['STORAGE']['href'].split('/').last %> + <% if disk.key?('OVERWRITE') %> + ,OVERWRITE = "yes" + <% end %> + <% if disk['SAVE_AS'] %> + ,SAVE_AS = "<%= disk['SAVE_AS'] %>" + <% end %> + ] + <% end %> + <% end %> +<% end %> + +<% if vm_info['NIC'] %> + <% vm_info['NIC'].each do |nic| %> + <% if nic['NETWORK'] && nic['NETWORK']['href'] %> + NIC = [ NETWORK_ID = <%= nic['NETWORK']['href'].split('/').last %> + <% if nic['IP'] %> + ,IP = <%= nic['IP'] %> + <% end %> + ] + <% end %> + <% end %> +<% end %> + +INSTANCE_TYPE = <%= vm_info['INSTANCE_TYPE']%> \ No newline at end of file diff --git a/src/cloud/occi/lib/ImagePoolOCCI.rb b/src/cloud/occi/lib/ImagePoolOCCI.rb index ebc73dd0b3..8087249db4 100755 --- a/src/cloud/occi/lib/ImagePoolOCCI.rb +++ b/src/cloud/occi/lib/ImagePoolOCCI.rb @@ -21,22 +21,15 @@ include OpenNebula class ImagePoolOCCI < ImagePool OCCI_IMAGE_POOL = %q{ - <% if pool_hash['IMAGE_POOL'] && pool_hash['IMAGE_POOL']['IMAGE'] %> - <% imagelist=[pool_hash['IMAGE_POOL']['IMAGE']].flatten %> - <% imagelist.each{ |image| %> - + <% self.each{ |im| %> + <% } %> - <% end %> } # Creates the OCCI representation of a Virtual Machine Pool - def to_occi(base_url) - pool_hash = self.to_hash - return pool_hash, 500 if OpenNebula.is_error?(pool_hash) - - begin + def to_occi(base_url)begin occi = ERB.new(OCCI_IMAGE_POOL) occi_text = occi.result(binding) rescue Exception => e diff --git a/src/cloud/occi/lib/VirtualMachineOCCI.rb b/src/cloud/occi/lib/VirtualMachineOCCI.rb index 1f9954cab6..379d8a4424 100755 --- a/src/cloud/occi/lib/VirtualMachineOCCI.rb +++ b/src/cloud/occi/lib/VirtualMachineOCCI.rb @@ -30,11 +30,10 @@ class VirtualMachineOCCI < VirtualMachine <% if template['DISK'] %> <% template['DISK'].each do |disk| %> - - <%= disk['NAME'] %> + <%= disk['TYPE'] %> <%= disk['TARGET'] %> - <% if disk['CLONE'] %> + <% if disk['CLONE']=='NO' %> <% end %> <% if disk['SAVE_AS'] %> @@ -46,10 +45,13 @@ class VirtualMachineOCCI < VirtualMachine <% if template['NIC'] %> <% template['NIC'].each do |nic| %> - + <% if nic['IP'] %> <%= nic['IP'] %> <% end %> + <% if nic['MAC'] %> + <%= nic['MAC'] %> + <% end %> <% end %> <% end %> diff --git a/src/cloud/occi/lib/VirtualMachinePoolOCCI.rb b/src/cloud/occi/lib/VirtualMachinePoolOCCI.rb index 40f2910a0d..0638cd4702 100755 --- a/src/cloud/occi/lib/VirtualMachinePoolOCCI.rb +++ b/src/cloud/occi/lib/VirtualMachinePoolOCCI.rb @@ -21,21 +21,15 @@ include OpenNebula class VirtualMachinePoolOCCI < VirtualMachinePool OCCI_VM_POOL = %q{ - <% if pool_hash['VM_POOL'] && pool_hash['VM_POOL']['VM'] %> - <% vmlist=[pool_hash['VM_POOL']['VM']].flatten %> - <% vmlist.each{ |vm| %> - + <% self.each{ |vm| %> + <% } %> - <% end %> } # Creates the OCCI representation of a Virtual Machine Pool def to_occi(base_url) - pool_hash = self.to_hash - return pool_hash, 500 if OpenNebula.is_error?(pool_hash) - begin occi = ERB.new(OCCI_VM_POOL) occi_text = occi.result(binding) diff --git a/src/cloud/occi/lib/VirtualNetworkPoolOCCI.rb b/src/cloud/occi/lib/VirtualNetworkPoolOCCI.rb index da1941271a..c8deffea37 100755 --- a/src/cloud/occi/lib/VirtualNetworkPoolOCCI.rb +++ b/src/cloud/occi/lib/VirtualNetworkPoolOCCI.rb @@ -21,22 +21,15 @@ include OpenNebula class VirtualNetworkPoolOCCI < VirtualNetworkPool OCCI_NETWORK_POOL = %q{ - <% if pool_hash['VNET_POOL'] && pool_hash['VNET_POOL']['VNET'] %> - <% vnlist=[pool_hash['VNET_POOL']['VNET']].flatten %> - <% vnlist.each{ |vn| %> - + <% self.each{ |vn| %> + <% } %> - <% end %> } # Creates the OCCI representation of a Virtual Machine Pool - def to_occi(base_url) - pool_hash = self.to_hash - return pool_hash, 500 if OpenNebula.is_error?(pool_hash) - - begin + def to_occi(base_url)begin occi = ERB.new(OCCI_NETWORK_POOL) occi_text = occi.result(binding) rescue Exception => e