mirror of
https://github.com/OpenNebula/one.git
synced 2026-11-20 20:02:38 +09:00
Merge branch 'feature-1004' into feature-992
Conflicts: src/cloud/occi/etc/occi-server.conf src/cloud/occi/lib/OCCIServer.rb
This commit is contained in:
commit
ef13f05ca7
252 files changed
+10829
-5209
No files matched your search
@@ -33,7 +33,8 @@ class CloudAuth
|
||||
|
||||
# Default interval for timestamps. Tokens will be generated using the same
|
||||
# timestamp for this interval of time.
|
||||
EXPIRE_DELTA = 36000
|
||||
# THIS VALUE CANNOT BE LOWER THAN EXPIRE_MARGIN
|
||||
EXPIRE_DELTA = 1800
|
||||
|
||||
# Tokens will be generated if time > EXPIRE_TIME - EXPIRE_MARGIN
|
||||
EXPIRE_MARGIN = 300
|
||||
@@ -44,8 +45,7 @@ class CloudAuth
|
||||
def initialize(conf)
|
||||
@conf = conf
|
||||
|
||||
@token_expiration_delta = @conf[:token_expiration_delta] || EXPIRE_DELTA
|
||||
@token_expiration_time = Time.now.to_i + @token_expiration_delta
|
||||
@token_expiration_time = Time.now.to_i + EXPIRE_DELTA
|
||||
|
||||
if AUTH_MODULES.include?(@conf[:auth])
|
||||
require 'CloudAuth/' + AUTH_MODULES[@conf[:auth]]
|
||||
@@ -64,27 +64,47 @@ class CloudAuth
|
||||
begin
|
||||
require core_auth[0]
|
||||
@server_auth = Kernel.const_get(core_auth[1]).new_client
|
||||
|
||||
token = @server_auth.login_token(expiration_time)
|
||||
@oneadmin_client ||= OpenNebula::Client.new(token, @conf[:one_xmlrpc])
|
||||
rescue => e
|
||||
raise e.message
|
||||
end
|
||||
end
|
||||
|
||||
def client(username)
|
||||
# Generate a new OpenNebula client for the target User, if the username
|
||||
# is nil the Client is generated for the server_admin
|
||||
# ussername:: _String_ Name of the User
|
||||
# [return] _Client_
|
||||
def client(username=nil)
|
||||
token = @server_auth.login_token(expiration_time,username)
|
||||
Client.new(token,@conf[:one_xmlrpc])
|
||||
end
|
||||
|
||||
def update_userpool_cache
|
||||
@user_pool = OpenNebula::UserPool.new(client)
|
||||
|
||||
rc = @user_pool.info
|
||||
if OpenNebula.is_error?(rc)
|
||||
raise rc.message
|
||||
end
|
||||
end
|
||||
|
||||
def auth(env, params={})
|
||||
username = do_auth(env, params)
|
||||
|
||||
if username.nil?
|
||||
update_userpool_cache
|
||||
do_auth(env, params)
|
||||
else
|
||||
username
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def expiration_time
|
||||
time_now = Time.now.to_i
|
||||
|
||||
if time_now > @token_expiration_time - EXPIRE_MARGIN
|
||||
update_userpool_cache
|
||||
@token_expiration_time = time_now + @token_expiration_delta
|
||||
@token_expiration_time = time_now + EXPIRE_DELTA
|
||||
end
|
||||
|
||||
@token_expiration_time
|
||||
@@ -96,15 +116,6 @@ class CloudAuth
|
||||
@user_pool
|
||||
end
|
||||
|
||||
def update_userpool_cache
|
||||
@user_pool ||= OpenNebula::UserPool.new(@oneadmin_client)
|
||||
|
||||
rc = @user_pool.info
|
||||
if OpenNebula.is_error?(rc)
|
||||
raise rc.message
|
||||
end
|
||||
end
|
||||
|
||||
def get_password(username, non_public_user=false)
|
||||
if non_public_user == true
|
||||
xp="USER[NAME=\"#{username}\" and AUTH_DRIVER!=\"public\"]/PASSWORD"
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
module EC2CloudAuth
|
||||
def auth(env, params={})
|
||||
def do_auth(env, params={})
|
||||
username = params['AWSAccessKeyId']
|
||||
one_pass = get_password(username)
|
||||
return nil unless one_pass
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
module OCCICloudAuth
|
||||
def auth(env, params={})
|
||||
def do_auth(env, params={})
|
||||
auth = Rack::Auth::Basic::Request.new(env)
|
||||
|
||||
if auth.provided? && auth.basic?
|
||||
@@ -28,6 +28,6 @@ module OCCICloudAuth
|
||||
end
|
||||
end
|
||||
|
||||
return nil
|
||||
end
|
||||
return nil
|
||||
end
|
||||
end
|
||||
@@ -15,7 +15,7 @@
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
module SunstoneCloudAuth
|
||||
def auth(env, params={})
|
||||
def do_auth(env, params={})
|
||||
auth = Rack::Auth::Basic::Request.new(env)
|
||||
|
||||
if auth.provided? && auth.basic?
|
||||
@@ -28,6 +28,6 @@ module SunstoneCloudAuth
|
||||
end
|
||||
end
|
||||
|
||||
return nil
|
||||
end
|
||||
return nil
|
||||
end
|
||||
end
|
||||
@@ -15,7 +15,7 @@
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
module X509CloudAuth
|
||||
def auth(env, params={})
|
||||
def do_auth(env, params={})
|
||||
# For https, the web service should be set to include the user cert in the environment.
|
||||
cert_line = env['HTTP_SSL_CLIENT_CERT']
|
||||
cert_line = nil if cert_line == '(null)' # For Apache mod_ssl
|
||||
|
||||
@@ -173,7 +173,7 @@ module CloudCLI
|
||||
|
||||
def version_text
|
||||
version=<<EOT
|
||||
OpenNebula 3.1.0
|
||||
OpenNebula 3.1.80
|
||||
Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org)
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
|
||||
@@ -33,8 +33,6 @@
|
||||
# cipher, for symmetric cipher encryption of tokens
|
||||
# x509, for x509 certificate encryption of tokens
|
||||
:core_auth: cipher
|
||||
# Life-time in seconds for token renewal (that used to handle OpenNebula auths)
|
||||
:token_expiration_delta: 1800
|
||||
|
||||
# VM types allowed and its template file (inside templates directory)
|
||||
:instance_types:
|
||||
|
||||
@@ -24,9 +24,6 @@
|
||||
# SSL proxy that serves the API (set if is being used)
|
||||
#:ssl_server: fqdm.of.the.server
|
||||
|
||||
# Configuration for OpenNebula's Virtual Networks
|
||||
#:bridge: NAME_OF_DEFAULT_BRIDGE
|
||||
|
||||
# Authentication driver for incomming requests
|
||||
# occi, for OpenNebula's user-password scheme
|
||||
# x509, for x509 certificates based authentication
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
#
|
||||
# This template is processed by the OCCI Server to include specific data for
|
||||
# the VNET, you should not need to modify the ruby code.
|
||||
# You can add common attributes for your VNET templates (e.g. VLAN, PHYDEV)
|
||||
#
|
||||
|
||||
NAME = "<%= @vnet_info['NAME'] %>"
|
||||
TYPE = RANGED
|
||||
|
||||
NETWORK_ADDRESS = <%= @vnet_info['ADDRESS'] %>
|
||||
<% if @vnet_info['SIZE'] != nil %>
|
||||
NETWORK_SIZE = <%= @vnet_info['SIZE']%>
|
||||
<% end %>
|
||||
|
||||
<% if @vnet_info['DESCRIPTION'] != nil %>
|
||||
DESCRIPTION = "<%= @vnet_info['DESCRIPTION'] %>"
|
||||
<% end %>
|
||||
|
||||
<% if @vnet_info['PUBLIC'] != nil %>
|
||||
PUBLIC = "<%= @vnet_info['PUBLIC'] %>"
|
||||
<% end %>
|
||||
|
||||
#BRIDGE = NAME_OF_DEFAULT_BRIDGE
|
||||
#PHYDEV = NAME_OF_PHYSICAL_DEVICE
|
||||
#VLAN = YES|NO
|
||||
@@ -23,17 +23,15 @@ class ImageOCCI < Image
|
||||
<STORAGE href="<%= base_url %>/storage/<%= self.id.to_s %>">
|
||||
<ID><%= self.id.to_s %></ID>
|
||||
<NAME><%= self.name %></NAME>
|
||||
<% if self['TEMPLATE/TYPE'] != nil %>
|
||||
<TYPE><%= self['TEMPLATE/TYPE'] %></TYPE>
|
||||
<% if self['TYPE'] != nil %>
|
||||
<TYPE><%= self['TYPE'] %></TYPE>
|
||||
<% end %>
|
||||
<% if self['TEMPLATE/DESCRIPTION'] != nil %>
|
||||
<DESCRIPTION><%= self['TEMPLATE/DESCRIPTION'] %></DESCRIPTION>
|
||||
<% end %>
|
||||
<% if size != nil %>
|
||||
<SIZE><%= size.to_i / 1024 %></SIZE>
|
||||
<% end %>
|
||||
<% if fstype != nil %>
|
||||
<FSTYPE><%= fstype %></FSTYPE>
|
||||
<SIZE><%= self['SIZE'] %></SIZE>
|
||||
<% if self['FSTYPE'] != nil and !self['FSTYPE'].empty? %>
|
||||
<FSTYPE><%= self['FSTYPE'] %></FSTYPE>
|
||||
<% end %>
|
||||
<PUBLIC><%= self['PUBLIC'] == "0" ? "NO" : "YES"%></PUBLIC>
|
||||
<PERSISTENT><%= self['PERSISTENT'] == "0" ? "NO" : "YES"%></PERSISTENT>
|
||||
@@ -84,25 +82,18 @@ class ImageOCCI < Image
|
||||
|
||||
# Creates the OCCI representation of an Image
|
||||
def to_occi(base_url)
|
||||
size = nil
|
||||
|
||||
begin
|
||||
if self['SOURCE'] != nil and File.exists?(self['SOURCE'])
|
||||
size = File.stat(self['SOURCE']).size
|
||||
size = size / 1024
|
||||
end
|
||||
|
||||
fstype = self['TEMPLATE/FSTYPE'] if self['TEMPLATE/FSTYPE']
|
||||
occi_im = ERB.new(OCCI_IMAGE)
|
||||
occi_im_text = occi_im.result(binding)
|
||||
rescue Exception => e
|
||||
error = OpenNebula::Error.new(e.message)
|
||||
return error
|
||||
end
|
||||
|
||||
occi = ERB.new(OCCI_IMAGE)
|
||||
return occi.result(binding).gsub(/\n\s*/,'')
|
||||
return occi_im_text.gsub(/\n\s*/,'')
|
||||
end
|
||||
|
||||
def to_one_template()
|
||||
def to_one_template
|
||||
if @image_info == nil
|
||||
error_msg = "Missing STORAGE section in the XML body"
|
||||
error = OpenNebula::Error.new(error_msg)
|
||||
|
||||
@@ -40,6 +40,9 @@ require 'pp'
|
||||
|
||||
COLLECTIONS = ["compute", "instance_type", "network", "storage"]
|
||||
|
||||
# FLAG that will filter the elements retrieved from the Pools
|
||||
POOL_FILTER = Pool::INFO_GROUP
|
||||
|
||||
class OCCIServer < CloudServer
|
||||
# Server initializer
|
||||
# config_file:: _String_ path of the config file
|
||||
@@ -109,21 +112,14 @@ class OCCIServer < CloudServer
|
||||
# [return] _String_,_Integer_ Pool Representation or error, status code
|
||||
def get_computes(request)
|
||||
# --- Get User's VMs ---
|
||||
user_flag = -1
|
||||
|
||||
vmpool = VirtualMachinePoolOCCI.new(
|
||||
@client,
|
||||
user_flag)
|
||||
POOL_FILTER)
|
||||
|
||||
# --- Prepare XML Response ---
|
||||
rc = vmpool.info
|
||||
|
||||
if OpenNebula.is_error?(rc)
|
||||
if rc.message.match("Error getting")
|
||||
return rc, 404
|
||||
else
|
||||
return rc, 500
|
||||
end
|
||||
return rc, CloudServer::HTTP_ERROR_CODE[rc.errno]
|
||||
end
|
||||
|
||||
return to_occi_xml(vmpool, 200)
|
||||
@@ -136,21 +132,14 @@ class OCCIServer < CloudServer
|
||||
# => status code
|
||||
def get_networks(request)
|
||||
# --- Get User's VNETs ---
|
||||
user_flag = -1
|
||||
|
||||
network_pool = VirtualNetworkPoolOCCI.new(
|
||||
@client,
|
||||
user_flag)
|
||||
POOL_FILTER)
|
||||
|
||||
# --- Prepare XML Response ---
|
||||
rc = network_pool.info
|
||||
|
||||
if OpenNebula.is_error?(rc)
|
||||
if rc.message.match("Error getting")
|
||||
return rc, 404
|
||||
else
|
||||
return rc, 500
|
||||
end
|
||||
return rc, CloudServer::HTTP_ERROR_CODE[rc.errno]
|
||||
end
|
||||
|
||||
return to_occi_xml(network_pool, 200)
|
||||
@@ -162,21 +151,14 @@ class OCCIServer < CloudServer
|
||||
# status code
|
||||
def get_storages(request)
|
||||
# --- Get User's Images ---
|
||||
user_flag = -1
|
||||
|
||||
image_pool = ImagePoolOCCI.new(
|
||||
@client,
|
||||
user_flag)
|
||||
POOL_FILTER)
|
||||
|
||||
# --- Prepare XML Response ---
|
||||
rc = image_pool.info
|
||||
|
||||
if OpenNebula.is_error?(rc)
|
||||
if rc.message.match("Error getting")
|
||||
return rc, 404
|
||||
else
|
||||
return rc, 500
|
||||
end
|
||||
return rc, CloudServer::HTTP_ERROR_CODE[rc.errno]
|
||||
end
|
||||
|
||||
return to_occi_xml(image_pool, 200)
|
||||
@@ -192,7 +174,6 @@ class OCCIServer < CloudServer
|
||||
|
||||
# --- Prepare XML Response ---
|
||||
rc = user_pool.info
|
||||
|
||||
if OpenNebula.is_error?(rc)
|
||||
return rc, CloudServer::HTTP_ERROR_CODE[rc.errno]
|
||||
end
|
||||
@@ -227,7 +208,9 @@ class OCCIServer < CloudServer
|
||||
return template, 500 if OpenNebula.is_error?(template)
|
||||
|
||||
rc = vm.allocate(template)
|
||||
return rc, 500 if OpenNebula.is_error?(rc)
|
||||
if OpenNebula.is_error?(rc)
|
||||
return rc, CloudServer::HTTP_ERROR_CODE[rc.errno]
|
||||
end
|
||||
|
||||
# --- Prepare XML Response ---
|
||||
vm.info
|
||||
@@ -246,13 +229,8 @@ class OCCIServer < CloudServer
|
||||
|
||||
# --- Prepare XML Response ---
|
||||
rc = vm.info
|
||||
|
||||
if OpenNebula.is_error?(rc)
|
||||
if rc.message.match("Error getting")
|
||||
return rc, 404
|
||||
else
|
||||
return rc, 500
|
||||
end
|
||||
return rc, CloudServer::HTTP_ERROR_CODE[rc.errno]
|
||||
end
|
||||
|
||||
return to_occi_xml(vm, 200)
|
||||
@@ -269,12 +247,11 @@ class OCCIServer < CloudServer
|
||||
VirtualMachine.build_xml(params[:id]),
|
||||
@client)
|
||||
|
||||
rc = vm.info
|
||||
return rc, 404 if OpenNebula::is_error?(rc)
|
||||
|
||||
# --- Finalize the VM ---
|
||||
result = vm.finalize
|
||||
return result, 500 if OpenNebula::is_error?(result)
|
||||
if OpenNebula.is_error?(result)
|
||||
return result, CloudServer::HTTP_ERROR_CODE[result.errno]
|
||||
end
|
||||
|
||||
return "", 204
|
||||
end
|
||||
@@ -317,14 +294,16 @@ class OCCIServer < CloudServer
|
||||
VirtualNetwork.build_xml,
|
||||
@client,
|
||||
request.body,
|
||||
@config[:bridge])
|
||||
@config[:template_location])
|
||||
|
||||
# --- Generate the template and Allocate the new Instance ---
|
||||
template = network.to_one_template
|
||||
return template, 500 if OpenNebula.is_error?(template)
|
||||
|
||||
rc = network.allocate(template)
|
||||
return rc, 500 if OpenNebula.is_error?(rc)
|
||||
if OpenNebula.is_error?(rc)
|
||||
return rc, CloudServer::HTTP_ERROR_CODE[rc.errno]
|
||||
end
|
||||
|
||||
# --- Prepare XML Response ---
|
||||
network.info
|
||||
@@ -342,13 +321,8 @@ class OCCIServer < CloudServer
|
||||
|
||||
# --- Prepare XML Response ---
|
||||
rc = network.info
|
||||
|
||||
if OpenNebula.is_error?(rc)
|
||||
if rc.message.match("Error getting")
|
||||
return rc, 404
|
||||
else
|
||||
return rc, 500
|
||||
end
|
||||
return rc, CloudServer::HTTP_ERROR_CODE[rc.errno]
|
||||
end
|
||||
|
||||
return to_occi_xml(network, 200)
|
||||
@@ -363,12 +337,11 @@ class OCCIServer < CloudServer
|
||||
VirtualNetwork.build_xml(params[:id]),
|
||||
@client)
|
||||
|
||||
rc = network.info
|
||||
return rc, 404 if OpenNebula::is_error?(rc)
|
||||
|
||||
# --- Delete the VNET ---
|
||||
rc = network.delete
|
||||
return rc, 500 if OpenNebula::is_error?(rc)
|
||||
if OpenNebula.is_error?(rc)
|
||||
return rc, CloudServer::HTTP_ERROR_CODE[rc.errno]
|
||||
end
|
||||
|
||||
return "", 204
|
||||
end
|
||||
@@ -385,15 +358,15 @@ class OCCIServer < CloudServer
|
||||
VirtualNetwork.build_xml(params[:id]),
|
||||
@client)
|
||||
|
||||
rc = vnet.info
|
||||
return rc, 400 if OpenNebula.is_error?(rc)
|
||||
|
||||
rc = nil
|
||||
if vnet_info['PUBLIC'] == 'YES'
|
||||
rc = vnet.publish
|
||||
return rc, 400 if OpenNebula.is_error?(rc)
|
||||
elsif vnet_info['PUBLIC'] == 'NO'
|
||||
rc = vnet.unpublish
|
||||
return rc, 400 if OpenNebula.is_error?(rc)
|
||||
end
|
||||
|
||||
if OpenNebula.is_error?(rc)
|
||||
return rc, CloudServer::HTTP_ERROR_CODE[rc.errno]
|
||||
end
|
||||
|
||||
# --- Prepare XML Response ---
|
||||
@@ -432,7 +405,9 @@ class OCCIServer < CloudServer
|
||||
return template, 500 if OpenNebula.is_error?(template)
|
||||
|
||||
rc = image.allocate(template)
|
||||
return rc, 500 if OpenNebula.is_error?(rc)
|
||||
if OpenNebula.is_error?(rc)
|
||||
return rc, CloudServer::HTTP_ERROR_CODE[rc.errno]
|
||||
end
|
||||
|
||||
# --- Prepare XML Response ---
|
||||
image.info
|
||||
@@ -450,13 +425,8 @@ class OCCIServer < CloudServer
|
||||
@client)
|
||||
|
||||
rc = image.info
|
||||
|
||||
if OpenNebula.is_error?(rc)
|
||||
if rc.message.match("Error getting")
|
||||
return rc, 404
|
||||
else
|
||||
return rc, 500
|
||||
end
|
||||
return rc, CloudServer::HTTP_ERROR_CODE[rc.errno]
|
||||
end
|
||||
|
||||
# --- Prepare XML Response ---
|
||||
@@ -473,12 +443,11 @@ class OCCIServer < CloudServer
|
||||
Image.build_xml(params[:id]),
|
||||
@client)
|
||||
|
||||
rc = image.info
|
||||
return rc, 404 if OpenNebula::is_error?(rc)
|
||||
|
||||
# --- Delete the Image ---
|
||||
rc = image.delete
|
||||
return rc, 500 if OpenNebula::is_error?(rc)
|
||||
if OpenNebula.is_error?(rc)
|
||||
return rc, CloudServer::HTTP_ERROR_CODE[rc.errno]
|
||||
end
|
||||
|
||||
return "", 204
|
||||
end
|
||||
@@ -495,24 +464,22 @@ class OCCIServer < CloudServer
|
||||
Image.build_xml(params[:id]),
|
||||
@client)
|
||||
|
||||
rc = image.info
|
||||
return rc, 400 if OpenNebula.is_error?(rc)
|
||||
|
||||
rc = nil
|
||||
if image_info['PERSISTENT'] && image_info['PUBLIC']
|
||||
error_msg = "It is not allowed more than one change per request"
|
||||
return OpenNebula::Error.new(error_msg), 400
|
||||
elsif image_info['PERSISTENT'] == 'YES'
|
||||
rc = image.persistent
|
||||
return rc, 400 if OpenNebula.is_error?(rc)
|
||||
elsif image_info['PERSISTENT'] == 'NO'
|
||||
rc = image.nonpersistent
|
||||
return rc, 400 if OpenNebula.is_error?(rc)
|
||||
elsif image_info['PUBLIC'] == 'YES'
|
||||
rc = image.publish
|
||||
return rc, 400 if OpenNebula.is_error?(rc)
|
||||
elsif image_info['PUBLIC'] == 'NO'
|
||||
rc = image.unpublish
|
||||
return rc, 400 if OpenNebula.is_error?(rc)
|
||||
end
|
||||
|
||||
if OpenNebula.is_error?(rc)
|
||||
return rc, CloudServer::HTTP_ERROR_CODE[rc.errno]
|
||||
end
|
||||
|
||||
# --- Prepare XML Response ---
|
||||
@@ -532,7 +499,6 @@ class OCCIServer < CloudServer
|
||||
|
||||
# --- Prepare XML Response ---
|
||||
rc = user.info
|
||||
|
||||
if OpenNebula.is_error?(rc)
|
||||
return rc, CloudServer::HTTP_ERROR_CODE[rc.errno]
|
||||
end
|
||||
|
||||
@@ -100,11 +100,11 @@ class VirtualMachineOCCI < VirtualMachine
|
||||
def to_one_template()
|
||||
if @vm_info == nil
|
||||
error_msg = "Missing COMPUTE section in the XML body"
|
||||
return OpenNebula::Error.new(error_msg), 400
|
||||
return OpenNebula::Error.new(error_msg)
|
||||
end
|
||||
|
||||
if @template == nil
|
||||
return OpenNebula::Error.new("Bad instance type"), 500
|
||||
return OpenNebula::Error.new("Bad instance type")
|
||||
end
|
||||
|
||||
begin
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
require 'OpenNebula'
|
||||
require 'ipaddr'
|
||||
|
||||
include OpenNebula
|
||||
|
||||
@@ -26,35 +27,23 @@ class VirtualNetworkOCCI < VirtualNetwork
|
||||
<% if self['TEMPLATE/DESCRIPTION'] != nil %>
|
||||
<DESCRIPTION><%= self['TEMPLATE/DESCRIPTION'] %></DESCRIPTION>
|
||||
<% end %>
|
||||
<ADDRESS><%= self['TEMPLATE/NETWORK_ADDRESS'] %></ADDRESS>
|
||||
<% if self['TEMPLATE/NETWORK_SIZE'] %>
|
||||
<SIZE><%= self['TEMPLATE/NETWORK_SIZE'] %></SIZE>
|
||||
<% if network_address != nil %>
|
||||
<ADDRESS><%= network_address %></ADDRESS>
|
||||
<% end %>
|
||||
<% if network_size != nil %>
|
||||
<SIZE><%= network_size %></SIZE>
|
||||
<% end %>
|
||||
<USED_LEASES><%= self['TOTAL_LEASES'] %></USED_LEASES>
|
||||
<PUBLIC><%= self['PUBLIC'] == "0" ? "NO" : "YES"%></PUBLIC>
|
||||
</NETWORK>
|
||||
}
|
||||
|
||||
ONE_NETWORK = %q{
|
||||
NAME = "<%= @vnet_info['NAME'] %>"
|
||||
TYPE = RANGED
|
||||
<% if @vnet_info['DESCRIPTION'] != nil %>
|
||||
DESCRIPTION = "<%= @vnet_info['DESCRIPTION'] %>"
|
||||
<% end %>
|
||||
<% if @vnet_info['PUBLIC'] != nil %>
|
||||
PUBLIC = "<%= @vnet_info['PUBLIC'] %>"
|
||||
<% end %>
|
||||
<% if @bridge %>
|
||||
BRIDGE = <%= @bridge %>
|
||||
<% end %>
|
||||
NETWORK_ADDRESS = <%= @vnet_info['ADDRESS'] %>
|
||||
NETWORK_SIZE = <%= @vnet_info['SIZE']%>
|
||||
}.gsub(/^ /, '')
|
||||
|
||||
# Class constructor
|
||||
def initialize(xml, client, xml_info=nil, bridge=nil)
|
||||
#
|
||||
def initialize(xml, client, xml_info=nil, base=nil)
|
||||
super(xml, client)
|
||||
@bridge = bridge
|
||||
@vnet_info = nil
|
||||
@common_template = base + '/network.erb' if base
|
||||
|
||||
if xml_info != nil
|
||||
xmldoc = XMLElement.build_xml(xml_info, 'NETWORK')
|
||||
@@ -64,6 +53,18 @@ class VirtualNetworkOCCI < VirtualNetwork
|
||||
|
||||
# Creates the OCCI representation of a Virtual Network
|
||||
def to_occi(base_url)
|
||||
network_address = nil
|
||||
network_size = nil
|
||||
|
||||
if self['RANGE/IP_START']
|
||||
network_address = self['RANGE/IP_START']
|
||||
|
||||
ip_start = IPAddr.new(network_address, Socket::AF_INET)
|
||||
ip_end = IPAddr.new(self['RANGE/IP_END'], Socket::AF_INET)
|
||||
|
||||
network_size = ip_end.to_i - ip_start.to_i
|
||||
end
|
||||
|
||||
begin
|
||||
occi = ERB.new(OCCI_NETWORK)
|
||||
occi_text = occi.result(binding)
|
||||
@@ -78,11 +79,16 @@ class VirtualNetworkOCCI < VirtualNetwork
|
||||
def to_one_template()
|
||||
if @vnet_info == nil
|
||||
error_msg = "Missing NETWORK section in the XML body"
|
||||
error = OpenNebula::Error.new(error_msg)
|
||||
return OpenNebula::Error.new(error_msg), 400
|
||||
end
|
||||
|
||||
begin
|
||||
template = ERB.new(File.read(@common_template)).result(binding)
|
||||
rescue Exception => e
|
||||
error = OpenNebula::Error.new(e.message)
|
||||
return error
|
||||
end
|
||||
|
||||
one = ERB.new(ONE_NETWORK)
|
||||
return one.result(binding)
|
||||
return template
|
||||
end
|
||||
end
|
||||
Reference in new issue
Block a user