1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-26 06:50:09 +03:00

Added Image and ImagePool OCCI classes

git-svn-id: http://svn.opennebula.org/one/trunk@862 3034c82b-c49b-4eb3-8279-a7acafdc01c0
This commit is contained in:
Constantino Vázquez Blanco 2009-10-15 17:37:25 +00:00
parent d7b65286c1
commit 27396a24be
8 changed files with 108 additions and 32 deletions

View File

@ -477,7 +477,9 @@ OCCI_LIB_FILES="src/cloud/occi/lib/OCCI.rb \
src/cloud/occi/lib/VirtualMachineOCCI.rb \
src/cloud/occi/lib/VirtualMachinePoolOCCI.rb \
src/cloud/occi/lib/VirtualNetworkOCCI.rb \
src/cloud/occi/lib/VirtualNetworkPoolOCCI.rb"
src/cloud/occi/lib/VirtualNetworkPoolOCCI.rb \
src/cloud/occi/lib/ImageOCCI.rb \
src/cloud/occi/lib/ImagePoolOCCI.rb"
OCCI_BIN_FILES="src/cloud/occi/bin/occi-server \
src/cloud/occi/bin/occi-compute \

39
src/cloud/occi/lib/ImageOCCI.rb Executable file
View File

@ -0,0 +1,39 @@
# -------------------------------------------------------------------------- #
# Copyright 2002-2009, Distributed Systems Architecture Group, Universidad #
# Complutense de Madrid (dsa-research.org) #
# #
# Licensed 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. #
#--------------------------------------------------------------------------- #
require 'OpenNebula'
require 'erb'
include OpenNebula
module ImageOCCI
OCCI_IMAGE = %q{
<DISK>
<ID><%= uuid %></ID>
<NAME><%= name %></NAME>
<SIZE><%= ((size/1024)/1024).to_s %></ADDRESS>
<URL><%= description %></SIZE>
</DISK>
}.gsub(/^ /, '')
# Creates the OCCI representation of a Virtual Network
def to_occi()
occi = ERB.new(OCCI_IMAGE)
return occi.result(binding)
end
end

View File

@ -0,0 +1,41 @@
# -------------------------------------------------------------------------- #
# Copyright 2002-2009, Distributed Systems Architecture Group, Universidad #
# Complutense de Madrid (dsa-research.org) #
# #
# Licensed 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. #
#--------------------------------------------------------------------------- #
require 'OpenNebula'
include OpenNebula
class ImagePoolOCCI
OCCI_IMAGE_POOL = %q{
<STORAGE><%
for image in @images do %>
<DISK href="<%= CONFIG[:server]%>:<%=CONFIG[:port]%>/storage/<%= image[:uuid]%>"\><%
end %>
</STORAGE>
}.gsub(/^ /, '')
def initialize(user_id)
@images=Image.filter(:owner => user_id)
end
def to_occi
occi = ERB.new(OCCI_IMAGE_POOL)
return occi.result(binding)
end
end

View File

@ -2,5 +2,10 @@ require 'VirtualMachineOCCI'
require 'VirtualMachinePoolOCCI'
require 'VirtualNetworkOCCI'
require 'VirtualNetworkPoolOCCI'
require 'ImageOCCI'
require 'ImagePoolOCCI'
require 'OCCIConfiguration'
include ImageOCCI

View File

@ -358,13 +358,10 @@ post '/storage' do
img.get_image_info
img.change_metadata(:name=>image_info['DISK']['NAME'])
img.change_metadata(:description=>image_info['DISK']['URL'])
xml_response = "<DISK><ID>" + img.uuid + "</ID>" +
"<NAME>" + image_info['DISK']['NAME'] + "</NAME>" +
"<SIZE>" + ((img.size/1024)/1024).to_s + "</SIZE>" +
"<URL>" + image_info['DISK']['URL'] + "<URL>" +
"</DISK>"
img.extend(ImageOCCI)
xml_response = img.to_occi
status 201
xml_response
end
@ -374,14 +371,9 @@ get '/storage' do
protected!
# Retrieve images owned by this user
user = get_user(@auth.credentials[0])
images=Image.filter(:owner => user[:id])
image_pool = "<STORAGE>"
for image in images do
image_pool += "<DISK href=\"http://#{CONFIG[:server]}:#{CONFIG[:port]}/storage/#{image[:uuid]}\">"
end
image_pool += "</STORAGE>"
image_pool
image_pool = ImagePoolOCCI.new(user[:id])
image_pool.to_occi
end
###################################################
@ -465,12 +457,9 @@ get '/storage/:id' do
if image
image.get_image_info
xml_response = "<DISK><ID>" + image.uuid + "</ID>" +
"<NAME>" + image.name + "</NAME>" +
"<SIZE>" + ((image.size/1024)/1024).to_s + "</SIZE>" +
"<URL>" + image.description + "<URL>" +
"</DISK>"
image.extend(ImageOCCI)
image.to_occi
else
status 404
"Disk with id = \"" + params[:id] + "\" not found"

View File

@ -14,11 +14,11 @@ class VirtualMachineOCCI < VirtualMachine
next if !disk
case disk['TYPE']
when "disk"%>
<DISK type="disk" href="<%= base_url%>/storage/<%= disk['IMAGE_ID']%>" dev="<%= disk['DEV']%>"/><%
<DISK type="disk" href="<%= base_url%>/storage/<%= disk['IMAGE_ID']%>" dev="<%= disk['DEV']%>"/><%
when "swap"%>
<DISK type="swap" size="<%= disk['SIZE']%>" dev="<%= disk['DEV']%>"/><%
<DISK type="swap" size="<%= disk['SIZE']%>" dev="<%= disk['DEV']%>"/><%
when "fs"%>
<DISK type="fs" size="<%= disk['SIZE']%>" format="<%= disk['FORMAT']%>" dev="<%= disk['DEV']%>"/><%
<DISK type="fs" size="<%= disk['SIZE']%>" format="<%= disk['FORMAT']%>" dev="<%= disk['DEV']%>"/><%
end
end %>
</STORAGE>

View File

@ -4,11 +4,11 @@ include OpenNebula
class VirtualMachinePoolOCCI < VirtualMachinePool
OCCI_VM_POOL = %q{
<COMPUTES>
<% if pool_hash['VM_POOL'] != nil
<COMPUTES><%
if pool_hash['VM_POOL'] != nil
vmlist=[pool_hash['VM_POOL']['VM']].flatten
vmlist.each{|vm|
%><COMPUTE href="<%= base_url %>/compute/<%= vm['ID'].strip %>"/><%
vmlist.each{|vm| %>
<COMPUTE href="<%= base_url %>/compute/<%= vm['ID'].strip %>"/><%
}
end %>
</COMPUTES>

View File

@ -4,11 +4,11 @@ include OpenNebula
class VirtualNetworkPoolOCCI < VirtualNetworkPool
OCCI_NETWORK_POOL = %q{
<NETWORK>
<% if network_pool_hash['VNET_POOL'] != nil
<NETWORK><%
if network_pool_hash['VNET_POOL'] != nil
vnlist=[network_pool_hash['VNET_POOL']['VNET']].flatten
vnlist.each{|network|
%><NIC href="<%= base_url %>/network/<%= network['ID'].strip %>"/><%
vnlist.each{|network|%>
<NIC href="<%= base_url %>/network/<%= network['ID'].strip %>"/><%
}
end %>
</NETWORK>