diff --git a/src/cloud/occi/etc/occi-server.conf b/src/cloud/occi/etc/occi-server.conf
index 859329f2df..e803e49788 100644
--- a/src/cloud/occi/etc/occi-server.conf
+++ b/src/cloud/occi/etc/occi-server.conf
@@ -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
diff --git a/src/cloud/occi/lib/OCCIServer.rb b/src/cloud/occi/lib/OCCIServer.rb
index 613ecd5333..86e68c5fd9 100755
--- a/src/cloud/occi/lib/OCCIServer.rb
+++ b/src/cloud/occi/lib/OCCIServer.rb
@@ -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,11 +112,9 @@ 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
@@ -136,11 +137,9 @@ 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
@@ -162,11 +161,9 @@ 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
@@ -317,7 +314,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
diff --git a/src/cloud/occi/lib/VirtualMachineOCCI.rb b/src/cloud/occi/lib/VirtualMachineOCCI.rb
index 73274ba9b0..f05f194920 100755
--- a/src/cloud/occi/lib/VirtualMachineOCCI.rb
+++ b/src/cloud/occi/lib/VirtualMachineOCCI.rb
@@ -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
diff --git a/src/cloud/occi/lib/VirtualNetworkOCCI.rb b/src/cloud/occi/lib/VirtualNetworkOCCI.rb
index eeb7194c92..f996b967d2 100755
--- a/src/cloud/occi/lib/VirtualNetworkOCCI.rb
+++ b/src/cloud/occi/lib/VirtualNetworkOCCI.rb
@@ -15,6 +15,7 @@
#--------------------------------------------------------------------------- #
require 'OpenNebula'
+require 'ipaddr'
include OpenNebula
@@ -26,35 +27,23 @@ class VirtualNetworkOCCI < VirtualNetwork
<% if self['TEMPLATE/DESCRIPTION'] != nil %>
<%= self['TEMPLATE/DESCRIPTION'] %>
<% end %>
-
<%= self['TEMPLATE/NETWORK_ADDRESS'] %>
- <% if self['TEMPLATE/NETWORK_SIZE'] %>
- <%= self['TEMPLATE/NETWORK_SIZE'] %>
+ <% if network_address != nil %>
+ <%= network_address %>
<% end %>
+ <% if network_size != nil %>
+ <%= network_size %>
+ <% end %>
+ <%= self['TOTAL_LEASES'] %>
<%= self['PUBLIC'] == "0" ? "NO" : "YES"%>
}
- 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
diff --git a/src/sunstone/public/js/plugins/vnets-tab.js b/src/sunstone/public/js/plugins/vnets-tab.js
index 21c6150945..cb0df258d2 100644
--- a/src/sunstone/public/js/plugins/vnets-tab.js
+++ b/src/sunstone/public/js/plugins/vnets-tab.js
@@ -87,11 +87,11 @@ var create_vn_tmpl =
\
\
\
- \
+ \
\
- \
+ \
\
- \
+ \
\
\
\
@@ -280,27 +280,7 @@ var vnet_actions = {
error: onError,
notify: false,
},
-/*
- "Network.modifyleases" : {
- type: "custom",
- call: function(action,obj){
- nodes = getSelectedNodes(dataTable_vNetworks);
- $.each(nodes,function(){
- Sunstone.runAction(action,this,obj);
- });
- }
- },
- "Network.addleases_dialog" : {
- type: "custom",
- call: popUpAddLeaseDialog
- },
-
- "Network.rmleases_dialog" : {
- type: "custom",
- call: popUpRemoveLeaseDialog
- },
-*/
"Network.chown" : {
type: "multiple",
call: OpenNebula.Network.chown,
@@ -390,21 +370,7 @@ var vnet_buttons = {
tip: "Select the new group:",
condition: mustBeAdmin,
},
-/*
- "action_list" : {
- type: "select",
- actions: {
- "Network.addleases_dialog" : {
- type: "action",
- text: "Add lease"
- },
- "Network.rmleases_dialog" : {
- type: "action",
- text: "Remove lease"
- }
- }
- },
-*/
+
"Network.delete" : {
type: "action",
text: "Delete"
@@ -416,10 +382,10 @@ var vnet_info_panel = {
title: "Virtual network information",
content: ""
},
- "vnet_template_tab" : {
- title: "Virtual network template",
+ "vnet_leases_tab" : {
+ title: "Lease management",
content: ""
- }
+ },
}
var vnets_tab = {
@@ -547,31 +513,34 @@ function updateVNetworkInfo(request,vn){
\
';
- info_tab_content += printLeases(vn_info);
+ info_tab_content += '\
+ \
+ Virtual Network template (attributes) |
'+
+ prettyPrintJSON(vn_info.TEMPLATE)+
+ '
'
+
+
+ var leases_tab_content = printLeases(vn_info);
var info_tab = {
title: "Virtual Network information",
content: info_tab_content
- }
+ };
- var template_tab = {
- title: "Virtual Network template",
- content:
- '\
- Virtual Network template |
'+
- prettyPrintJSON(vn_info.TEMPLATE)+
- '
'
- }
+ var leases_tab = {
+ title: "Lease management",
+ content: leases_tab_content
+ };
Sunstone.updateInfoPanelTab("vnet_info_panel","vnet_info_tab",info_tab);
- Sunstone.updateInfoPanelTab("vnet_info_panel","vnet_template_tab",template_tab);
+ Sunstone.updateInfoPanelTab("vnet_info_panel","vnet_leases_tab",leases_tab);
Sunstone.popUpInfoPanel("vnet_info_panel");
}
function printLeases(vn_info){
- var html ='