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

Feature #790: Update oZones create VDC dialog

By default the new dialog only shows the hosts of the selected zone which are not part of a different VDC.

An option exists to force addition of hosts which do not complain with the uniqueness requirement.
(cherry picked from commit 776c18825733c7f9fe9c18bd4aa78fb377cefb39)

Conflicts:

	src/ozones/Server/models/OzonesServer.rb
(cherry picked from commit cbec09ab8c53d4b4ab8b795e04bb33d71f38ea7a)
This commit is contained in:
Hector Sanjuan 2011-09-23 21:07:27 +02:00 committed by Tino Vazquez
parent 958c757ecb
commit 244ef19153
2 changed files with 93 additions and 21 deletions

View File

@ -165,12 +165,13 @@ class OzonesServer
return [404, error.to_json]
end
if (!vdc_data[:force] or vdc_data[:force].upcase!="YES") and
if (!defined? vdc_data[:force] or
(defined? vdc_data[:force] and vdc_data[:force]!="yes")) and
!host_uniqueness?(zone, vdc_data[:hosts])
return [403, OZones::Error.new(
"Error: Couldn't create resource #{kind}. " +
"Hosts are not unique, and no force option" +
" was given.").to_json]
"One or several hosts belong to a different VDC "+
"and no force option was provided.").to_json]
end
vdcadminname = vdc_data[:vdcadminname]
@ -265,7 +266,7 @@ class OzonesServer
return [404, error.to_json]
end
end
############################################################################
# Update resources
############################################################################
@ -289,7 +290,7 @@ class OzonesServer
}
# Check parameters
if !vdc_data[:hosts] || !vdc_id
if !vdc_data[:hosts] || !vdc_id
return [400, OZones::Error.new(
"Error: Couldn't update resource #{kind}. " +
"Need ID and HOSTS to update.").to_json]
@ -302,7 +303,7 @@ class OzonesServer
"#{vdc_id} not found, cannot update Vdc.")
return [404, error.to_json]
end
# Get the zone where the Vdc belongs
zone=OZones::Zones.get(vdc.zones.id)
if !zone
@ -310,24 +311,25 @@ class OzonesServer
"#{vdc.zones.id} not found, cannot update Vdc.")
return [404, error.to_json]
end
if (!vdc_data[:force] or vdc_data[:force].upcase!="YES") and
!host_uniqueness?(zone, vdc_data[:hosts], vdc_id.to_i)
if (!defined? vdc_data[:force] or
(defined? vdc_data[:force] and vdc_data[:force]!="yes")) and
!host_uniqueness?(zone, vdc_data[:hosts], vdc_id.to_i)
return [403, OZones::Error.new(
"Error: Couldn't update resource #{kind}. " +
"Hosts are not unique, and no force option" +
" was given.").to_json]
"One or several hosts belong to a different VDC "+
"and no force option was provided.").to_json]
end
rc = @ocaInt.update_vdc_hosts(zone, vdc, vdc_data[:hosts])
if !OpenNebula.is_error?(rc)
vdc.hosts = vdc_data[:hosts]
vdc.get_host_acls!(rc)
vdc.save
if vdc.saved?
if vdc.saved?
return [200, vdc.to_json]
else
return [500, OZones::Error.new(
@ -378,7 +380,7 @@ class OzonesServer
############################################################################
# Helper functions
############################################################################
# Check if hosts are already include in any Vdc of the zone
def host_uniqueness?(zone, host_list, vdc_id = -1)
all_hosts = ""

View File

@ -25,6 +25,7 @@ var vdcs_tab_content =
<th>ID</th>\
<th>Name</th>\
<th>Zone ID</th>\
<th>Hosts</th>\
</tr>\
</thead>\
<tbody id="tbodyvdcs">\
@ -44,7 +45,12 @@ var create_vdc_tmpl =
<input type="password" name="vdcadminpass" id="vdcadminpass" />\
<label for="zone">Zone:</label>\
<select id="zoneid" name="zone">\
</select>\
</select><br />\
<div class="clear"></div>\
<label for="vdc_force_hosts">Host multiplacement:</label>\
<input type="checkbox" name="vdc_force_hosts" id="vdc_force_hosts" />\
<div class="tip">Allows hosts belonging to other VDCs to be re-added to this one. They will appear marked with * in the list.</div>\
<div class="clear"></div>\
<label style="margin-left:205px;font-size:0.8em;color:#bbbbbb">Drag & Drop</label>\
<label style="margin-left:195px;font-size:0.8em;color:#bbbbbb">Available / Selected</label>\
<label>Hosts:</label>\
@ -81,6 +87,19 @@ var vdc_actions = {
call: openCreateVDCDialog
},
"VDC.update" : {
type: "create",
call: oZones.VDC.update,
callback: updateVDCElement,
error: onError,
notify: true
},
"VDC.update_dialog" : {
type: "custom",
call: openUpdateVDCDialog
},
"VDC.list" : {
type: "list",
call: oZones.VDC.list,
@ -169,7 +188,8 @@ function vdcElementArray(vdc_json){
'<input type="checkbox" id="vdc_'+vdc.id+'" name="selected_items" value="'+vdc.id+'"/>',
vdc.id,
vdc.name,
vdc.zones_id
vdc.zones_id,
vdc.hosts ? vdc.hosts : "none"
];
}
@ -230,6 +250,18 @@ function updateVDCInfo(req,vdc_json){
<td class="key_td">Hosts</td>\
<td class="value_td">'+(vdc.hosts? vdc.hosts : "none")+'</td>\
</tr>\
<tr>\
<td class="key_td">Admin name</td>\
<td class="value_td">'+vdc.vdcadminname+'</td>\
</tr>\
<tr>\
<td class="key_td">Group ID</td>\
<td class="value_td">'+vdc.group_id+'</td>\
</tr>\
<tr>\
<td class="key_td">ACLs</td>\
<td class="value_td">'+vdc.acls+'</td>\
</tr>\
</tbody>\
</table>'
};
@ -239,13 +271,41 @@ function updateVDCInfo(req,vdc_json){
}
function fillHostList(req, host_list_json){
list = "";
var list = "";
var force = $('div#create_vdc_dialog #vdc_force_hosts:checked').length ?
true : false;
var zone_id = req.request.data[0];
var free;
$.each(host_list_json,function(){
list+='<li host_id="'+this.HOST.ID+'">'+this.HOST.NAME+'</li>';
free = isHostFree(this.HOST.ID,zone_id);
if (force || free){
list+='<li host_id="'+this.HOST.ID+'">'+(free? this.HOST.NAME : this.HOST.NAME+'*')+'</li>';
}
});
$('div#create_vdc_dialog #vdc_available_hosts_list').html(list);
}
function isHostFree(id,zone_id){//strings
var data = dataTable_vdcs.fnGetData();
var result = true;
var hosts;
for (var i=0; i<data.length; i++){
//this vdc is not in the interesting zone:
if (data[i][3] != zone_id) continue;
//note it is an array of strings
hosts = data[i][4].split(',');
if ($.inArray(id,hosts) >= 0){
result = false;
break;
}
}
return result;
}
function setupCreateVDCDialog(){
$('div#dialogs').append('<div title="Create VDC" id="create_vdc_dialog"></div>');
var dialog = $('div#create_vdc_dialog');
@ -266,6 +326,12 @@ function setupCreateVDCDialog(){
containment: dialog
});
$('input#vdc_force_hosts').change(function(){
select = $('select#zoneid');
if (select.val().length){
select.trigger("change");
}
});
//load zone hosts
$('select#zoneid').change(function(){
@ -289,6 +355,7 @@ function setupCreateVDCDialog(){
var vdcadminname = $('#vdcadminname',$(this)).val();
var vdcadminpass = $('#vdcadminpass',$(this)).val();
var zoneid = $('select#zoneid',$(this)).val();
var force = $('#vdc_force_hosts',$(this)).length ? "yes" : "please no";
if (!name.length || !vdcadminname.length
|| !vdcadminpass.length || !zoneid.length){
notifyError("Name, administrator credentials or zones are missing");
@ -308,6 +375,7 @@ function setupCreateVDCDialog(){
"zoneid" : zoneid,
"vdcadminname" : vdcadminname,
"vdcadminpass" : vdcadminpass,
"force" : force
}
};
if (hosts.length){
@ -347,15 +415,17 @@ $(document).ready(function(){
"aoColumnDefs": [
{ "bSortable": false, "aTargets": ["check"] },
{ "sWidth": "60px", "aTargets": [0] },
{ "sWidth": "150px", "aTargets": [4] },
{ "sWidth": "35px", "aTargets": [1,3] }
]
});
dataTable_vdcs.fnClearTable();
addElement([spinner,'','',''],dataTable_vdcs);
addElement([spinner,'','','',''],dataTable_vdcs);
Sunstone.runAction("VDC.list");
setupCreateVDCDialog();
setupTips($('#create_vdc_dialog'));
setVDCAutorefresh();
initCheckAllBoxes(dataTable_vdcs);
tableCheckboxesListener(dataTable_vdcs);