mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-21 14:50:08 +03:00
Update VNET render in OCCI
This commit is contained in:
parent
843c6722dd
commit
4c1832ff4e
@ -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
|
||||
|
@ -317,7 +317,7 @@ 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
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user