1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-21 14:50:08 +03:00

Merge branch 'master' of git.opennebula.org:one

This commit is contained in:
Jaime Melis 2011-12-07 18:37:52 +01:00
commit 5dc3797e4c
5 changed files with 62 additions and 164 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -87,11 +87,11 @@ var create_vn_tmpl =
<input type="text" name="net_address" id="net_address" /><br />\
<label for="net_mask">Network Mask:</label>\
<input type="text" name="net_mask" id="net_mask" /><br />\
<label for="custom_pool" style="height:2em;">Enable pool boundaries:</label>\
<label for="custom_pool" style="height:2em;">Define a subnet by IP range:</label>\
<input type="checkbox" name="custom_pool" id="custom_pool" style="margin-bottom:2em;" value="yes" /><br />\
<label for="ip_start">Pool start:</label>\
<label for="ip_start">IP start:</label>\
<input type="text" name="ip_start" id="ip_start" disabled="disabled" /><br />\
<label for="ip_end">Pool end:</label>\
<label for="ip_end">IP end:</label>\
<input type="text" name="ip_end" id="ip_end" disabled="disabled" />\
</fieldset>\
</div>\
@ -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){
</tr>\
</table>';
info_tab_content += printLeases(vn_info);
info_tab_content += '\
<table id="vn_template_table" class="info_table">\
<thead><tr><th colspan="2">Virtual Network template (attributes)</th></tr></thead>'+
prettyPrintJSON(vn_info.TEMPLATE)+
'</table>'
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:
'<table id="vn_template_table" class="info_table" style="width:80%">\
<thead><tr><th colspan="2">Virtual Network template</th></tr></thead>'+
prettyPrintJSON(vn_info.TEMPLATE)+
'</table>'
}
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 ='<form style="display:inline-block;" id="leases_form" vnid="'+vn_info.ID+'"><table id="vn_leases_info_table" class="info_table" style="width:100%;">\
var html ='<form style="display:inline-block;width:80%" id="leases_form" vnid="'+vn_info.ID+'"><table id="vn_leases_info_table" class="info_table" style="width:100%;">\
<thead>\
<tr><th colspan="2">Leases information</th></tr>\
</thead><tbody>';
@ -1013,77 +982,6 @@ function setupLeasesOps(){
});
}
/*
function setupAddRemoveLeaseDialog() {
dialogs_context.append('<div title="Lease management" id="lease_vn_dialog"></div>');
$lease_vn_dialog = $('#lease_vn_dialog',dialogs_context)
var dialog = $lease_vn_dialog;
dialog.html(
'<form id="lease_vn_form" action="javascript:alert(\'js error!\');">\
<fieldset>\
<div>Please specify:</div>\
<label for="add_lease_ip">Lease IP:</label>\
<input type="text" name="add_lease_ip" id="add_lease_ip" /><br />\
<label id="add_lease_mac_label" for="add_lease_mac">Lease MAC:</label>\
<input type="text" name="add_lease_mac" id="add_lease_mac" />\
</select>\
</fieldset>\
<fieldset>\
<div class="form_buttons">\
<button id="lease_vn_proceed" class="" value="">OK</button>\
<button class="confirm_cancel" value="">Cancel</button>\
</div>\
</fieldset>\
</form>'
);
//Prepare the jquery-ui dialog. Set style options here.
dialog.dialog({
autoOpen: false,
modal: true,
width: 410,
height: 220
});
$('button',dialog).button();
$('#lease_vn_form',dialog).submit(function(){
var ip = $('#add_lease_ip',this).val();
var mac = $('#add_lease_mac',this).val();
var obj = {ip: ip, mac: mac};
if (!mac.length) { delete obj.mac; };
Sunstone.runAction("Network.modifyleases",
$('#lease_vn_proceed',this).val(),
obj);
$lease_vn_dialog.dialog('close');
return false;
});
}
function popUpAddLeaseDialog() {
$lease_vn_dialog.dialog("option","title","Add lease");
$('#add_lease_mac',$lease_vn_dialog).show();
$('#add_lease_mac_label',$lease_vn_dialog).show();
$('#lease_vn_proceed',$lease_vn_dialog).val("Network.addleases");
$lease_vn_dialog.dialog("open");
}
function popUpRemoveLeaseDialog() {
$lease_vn_dialog.dialog("option","title","Remove lease");
$('#add_lease_mac',$lease_vn_dialog).hide();
$('#add_lease_mac_label',$lease_vn_dialog).hide();
$('#lease_vn_proceed',$lease_vn_dialog).val("Network.rmleases");
$lease_vn_dialog.dialog("open");
}
*/
function setVNetAutorefresh() {
setInterval(function(){
var checked = $('input.check_item:checked',dataTable_vNetworks);
@ -1097,7 +995,7 @@ function setVNetAutorefresh() {
function is_public_vnet(id) {
var data = getElementData(id,"#vnetwork",dataTable_vNetworks)[7];
return $(data).attr("checked");
return $(data).is(":checked");
};
function setupVNetActionCheckboxes(){