1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-16 22:50:10 +03:00

F #4089: Firecracker vm actions in Sunstone (#4704)

Signed-off-by: Jorge Lobo <jlobo@opennebula.systems>
This commit is contained in:
Jorge Lobo 2020-05-12 11:45:52 +02:00 committed by GitHub
parent 24de19bf4e
commit 0a72628318
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 101 additions and 49 deletions

View File

@ -823,8 +823,6 @@ define(function(require) {
// Return a dropdown with all the
function ipsDropdown(element, divider) {
var ipsStr = this.ipsStr(element,divider,groupByIpsDropdown);
console.log(ipsStr);
const ips = ipsStr.split('<br>');
if ((ips.length < 2) && (!~ipsStr.indexOf("li"))) return ipsStr;
var html = '<ul class="dropdown menu ips-dropdown" data-dropdown-menu><li><a>Show IPs</a><ul class="menu" style="max-height: 25em; overflow: scroll;">';

View File

@ -863,6 +863,7 @@ define(function(require) {
SunstoneCfg["tabs"][tabName]["panelInstances"][panelName] = panelInstance;
templatePanelsParams.push({
"panelName": panelName,
"class": panelInstance.class,
"icon": panelInstance.icon,
"title": panelInstance.title,
"html": panelInstance.html(),

View File

@ -56,7 +56,7 @@
<ul id='{{customId}}lock_buttons' class='lock-sunstone-info only-sunstone-info only-sunstone-list dropdown-pane menu vertical' data-dropdown></ul>
<button type='button' data-toggle='{{customId}}vmspause_buttons' class='only-sunstone-info only-sunstone-list top_button button secondary dropdown'>
<button type='button' data-toggle='{{customId}}vmspause_buttons' class='not_firecracker only-sunstone-info only-sunstone-list top_button button secondary dropdown'>
<i class='fas fa-pause'/>
</button>
<ul id='{{customId}}vmspause_buttons' class='only-sunstone-info only-sunstone-list dropdown-pane menu vertical' data-dropdown></ul>
@ -66,7 +66,7 @@
</button>
<ul id='{{customId}}vmsstop_buttons' class='only-sunstone-info only-sunstone-list dropdown-pane menu vertical' data-dropdown></ul>
<button type='button' data-toggle='{{customId}}vmsrepeat_buttons' class='only-sunstone-info only-sunstone-list top_button button secondary dropdown'>
<button type='button' data-toggle='{{customId}}vmsrepeat_buttons' class='not_firecracker only-sunstone-info only-sunstone-list top_button button secondary dropdown'>
<i class='fas fa-redo-alt'/>
</button>
<ul id='{{customId}}vmsrepeat_buttons' class='only-sunstone-info only-sunstone-list dropdown-pane menu vertical' data-dropdown></ul>

View File

@ -17,7 +17,7 @@
<div id="{{containerId}}">
<ul id="{{containerId}}Tabs" class="tabs sunstone-info-tabs text-center" data-tabs>
{{#each panels}}
<li class="tabs-title {{#if active}}is-active{{/if}}">
<li class="{{class}} tabs-title {{#if active}}is-active{{/if}}">
<a href="#{{panelName}}">
{{#if icon}}
<i class="fas {{icon}}"></i>

View File

@ -46,6 +46,7 @@ define(function(require) {
type: "single",
call: OpenNebulaVM.show,
callback: function(request, response) {
$(".not_firecracker").removeClass("hide");
if (Config.isTabEnabled("provision-tab")) {
$(".provision_refresh_info", ".provision_list_vms").click();
} else {
@ -54,6 +55,13 @@ define(function(require) {
Sunstone.insertPanels(TAB_ID, response);
}
}
if(response &&
response.VM &&
response.VM.USER_TEMPLATE &&
response.VM.USER_TEMPLATE.HYPERVISOR &&
response.VM.USER_TEMPLATE.HYPERVISOR === "firecracker"){
$(".not_firecracker").addClass("hide");
}
},
error: Notifier.onError
},

View File

@ -76,7 +76,7 @@ define(function(require) {
type: "action",
text: Locale.tr("Migrate") + ' <span class="label secondary radius">' + Locale.tr("live") + '</span>',
layout: "vmsmigration_buttons",
custom_classes : "state-dependent"
custom_classes : "state-dependent not_firecracker"
},
"VM.hold" : {
type: "action",

View File

@ -84,7 +84,6 @@ define(function(require) {
if (memoryCost == undefined){
memoryCost = Config.onedConf.DEFAULT_COST.MEMORY_COST;
}
console.log("element ->",this.element);
return TemplateInfo({
'element': this.element,
'resizeStateEnabled': resizeStateEnabled,

View File

@ -42,6 +42,22 @@ define(function(require) {
var RESOURCE = "VM";
var XML_ROOT = "VM";
var isFirecracker = function(context){
return context &&
context.element &&
context.element.USER_TEMPLATE &&
context.element.USER_TEMPLATE.HYPERVISOR &&
context.element.USER_TEMPLATE.HYPERVISOR === "firecracker"
}
var validateState = function(context, state){
var rtn = false;
if(context && state && context.element && context.element.STATE && context.element.LCM_STATE){
rtn = StateActions.enabledStateAction(state, context.element.STATE, context.element.LCM_STATE)
}
return rtn;
}
/*
CONSTRUCTOR
*/
@ -50,7 +66,6 @@ define(function(require) {
this.panelId = PANEL_ID;
this.title = Locale.tr("Network");
this.icon = "fa-globe";
this.element = info[XML_ROOT];
return this;
@ -62,7 +77,6 @@ define(function(require) {
Panel.prototype.onShow = _onShow;
Panel.prototype.getState = _getState;
Panel.prototype.setState = _setState;
return Panel;
/*
@ -86,18 +100,17 @@ define(function(require) {
<th>" + Locale.tr("IPv6 ULA") + "</th>\
<th>" + Locale.tr("IPv6 Global") + "</th>\
<th colspan=\"\">" + Locale.tr("Actions") + "</th>\
<th>" ;
<th>";
if (Config.isTabActionEnabled("vms-tab", "VM.attachnic")) {
if (StateActions.enabledStateAction("VM.attachnic",
that.element.STATE,
that.element.LCM_STATE) &&
OpenNebulaVM.isNICAttachSupported(that.element)) {
html += "\
<button id=\"attach_nic\" class=\"button small success right radius\" >" + Locale.tr("Attach nic") + "</button>";
var renderButton = function(disable){
var renderDisable = disable? "disabled='disabled'" : "";
return "<button id='attach_nic' class='button small success right radius' "+renderDisable+">" + Locale.tr("Attach nic") + "</button>";
}
if (validateState(that,"VM.attachnic") && OpenNebulaVM.isNICAttachSupported(that.element)) {
html += renderButton(isFirecracker(that))
} else {
html += "\
<button id=\"attach_nic\" class=\"button small success right radius\" disabled=\"disabled\">" + Locale.tr("Attach nic") + "</button>";
html += renderButton(!isFirecracker(that));
}
}
@ -290,14 +303,16 @@ define(function(require) {
) {
actions = Locale.tr("attach/detach in progress");
} else {
if (
Config.isTabActionEnabled("vms-tab", "VM.detachnic") &&
StateActions.enabledStateAction("VM.detachnic", that.element.STATE, that.element.LCM_STATE)
) {
if(Config.isTabActionEnabled("vms-tab", "VM.detachnic")){
var icon = $("<i/>",{class:"fas fa-times"});
var anchorAttributes = {class: "detachnic"}
var anchor = $("<a/>",anchorAttributes).append(icon);
actions += anchor.get(0).outerHTML; //"<a href=\"VM.detachnic\" class=\"detachnic PEPE\" ><i class=\"fas fa-times\"/></a>";
var anchorAttributes = {class: "detachnic", href: "VM.detachnic"};
var anchor = $("<a/>",anchorAttributes).append(icon); //"<a href=\"VM.detachnic\" class=\"detachnic\" ><i class=\"fas fa-times\"/></a>";
if (validateState(that,"VM.attachnic") && OpenNebulaVM.isNICAttachSupported(that.element)) {
html += isFirecracker(that) && anchor.get(0).outerHTML;
} else {
html += !isFirecracker(that) && anchor.get(0).outerHTML;
}
}
}
}

View File

@ -46,6 +46,7 @@ define(function(require) {
this.panelId = PANEL_ID;
this.title = Locale.tr("Snapshots");
this.icon = "fa-laptop";
this.class = "not_firecracker";
this.element = info[XML_ROOT];

View File

@ -49,6 +49,22 @@ define(function(require) {
var RESOURCE = "VM"
var XML_ROOT = "VM"
var isFirecracker = function(context){
return context &&
context.element &&
context.element.USER_TEMPLATE &&
context.element.USER_TEMPLATE.HYPERVISOR &&
context.element.USER_TEMPLATE.HYPERVISOR === "firecracker"
}
var validateState = function(context, state){
var rtn = false;
if(context && state && context.element && context.element.STATE && context.element.LCM_STATE){
rtn = StateActions.enabledStateAction(state, context.element.STATE, context.element.LCM_STATE)
}
return rtn;
}
/*
CONSTRUCTOR
*/
@ -255,7 +271,6 @@ define(function(require) {
var disk_dt_data = [];
if (disks.length) {
for (var i = 0; i < disks.length; i++) {
var disk = disks[i];
@ -285,21 +300,23 @@ define(function(require) {
} else {
actions = '';
if (Config.isTabActionEnabled("vms-tab", "VM.disk_saveas")) {
// Check if it's volatile
if (disk.IMAGE_ID &&
StateActions.enabledStateAction("VM.disk_saveas", that.element.STATE, that.element.LCM_STATE)) {
if(Array.isArray(that.element.HISTORY_RECORDS.HISTORY)){
var historyLenght = that.element.HISTORY_RECORDS.HISTORY.length - 1;
if(that.element.LCM_STATE != "3" || that.element.HISTORY_RECORDS.HISTORY[historyLenght].VM_MAD != "vcenter"){
actions += '<a href="VM.disk_saveas" class="disk_saveas nowrap" >\
<i class="fas fa-save fa-fw" title="Saveas"></i></a> &emsp;';
}
} else {
if(that.element.LCM_STATE != "3" || that.element.HISTORY_RECORDS.HISTORY.VM_MAD != "vcenter"){
actions += '<a href="VM.disk_saveas" class="disk_saveas nowrap" >\
<i class="fas fa-save fa-fw" title="Saveas"></i></a> &emsp;';
if (disk.IMAGE_ID && validateState(that,"VM.disk_saveas")) {
if(Array.isArray(that.element.HISTORY_RECORDS.HISTORY)){
var historyLenght = that.element.HISTORY_RECORDS.HISTORY.length - 1;
if(that.element.LCM_STATE != "3" || that.element.HISTORY_RECORDS.HISTORY[historyLenght].VM_MAD != "vcenter"){
var render = '<a href="VM.disk_saveas" class="disk_saveas nowrap" >\
<i class="fas fa-save fa-fw" title="Saveas"></i>\
</a> &emsp;';
actions += !isFirecracker(that)? render : "";
}
} else {
if(that.element.LCM_STATE != "3" || that.element.HISTORY_RECORDS.HISTORY.VM_MAD != "vcenter"){
var render ='<a href="VM.disk_saveas" class="disk_saveas nowrap" >\
<i class="fas fa-save fa-fw" title="Saveas"></i>\
</a> &emsp;';
actions += !isFirecracker(that)? render : "";
}
}
//+ Locale.tr("Save as") + ';'
@ -308,23 +325,29 @@ define(function(require) {
if (Config.isTabActionEnabled("vms-tab", "VM.detachdisk")) {
if (StateActions.enabledStateAction("VM.detachdisk", that.element.STATE, that.element.LCM_STATE) && !disk.CONTEXT) {
actions += ('<a href="VM.detachdisk" class="detachdisk nowrap" >\
<i class="fas fa-times fa-fw" title="Detach"></i></a> &emsp;');// + Locale.tr("Detach") +
var vmState = validateState(that,"VM.detachdisk");
var render = (
'<a href="VM.detachdisk" class="detachdisk nowrap" >\
<i class="fas fa-times fa-fw" title="Detach"></i>\
</a> &emsp;'
);
if(isFirecracker(that) && !vmState){
actions += render;
}
if(!isFirecracker(that) && vmState && !disk.CONTEXT){
actions += render;
}
}
if (Config.isTabActionEnabled("vms-tab", "VM.disk_snapshot_create")) {
if (StateActions.enabledStateAction("VM.disk_snapshot_create", that.element.STATE, that.element.LCM_STATE) && disk.IMAGE_ID) {
if (validateState(that,"VM.disk_snapshot_create") && disk.IMAGE_ID) {
actions += ('<a href="VM.disk_snapshot_create" class="disk_snapshot_create nowrap" >\
<i class="fas fa-camera fa-fw" title="Snapshot"></i></a> &emsp;');//+ Locale.tr("Snapshot") +
}
}
if (Config.isTabActionEnabled("vms-tab", "VM.disk_resize")) {
if (StateActions.enabledStateAction("VM.disk_resize", that.element.STATE, that.element.LCM_STATE) && !disk.CONTEXT) {
if (validateState(that,"VM.disk_resize") && !disk.CONTEXT) {
if(Array.isArray(that.element.HISTORY_RECORDS.HISTORY)){
var historyLenght = that.element.HISTORY_RECORDS.HISTORY.length - 1;
if(that.element.LCM_STATE != "3" || that.element.HISTORY_RECORDS.HISTORY[historyLenght].VM_MAD != "vcenter"){
@ -450,7 +473,9 @@ define(function(require) {
}
if (Config.isTabActionEnabled("vms-tab", "VM.attachdisk")) {
if (!StateActions.enabledStateAction("VM.attachdisk", that.element.STATE, that.element.LCM_STATE)){
var vmState = validateState(that,"VM.attachdisk");
if((isFirecracker(that) && vmState) || (!isFirecracker(that) && !vmState)){
$('#attach_disk', context).attr("disabled", "disabled");
}
@ -741,6 +766,11 @@ define(function(require) {
function _onShow(context) {
var that = this;
var vmState = validateState(that,"VM.attachdisk");
if((isFirecracker(that) && vmState)){
$('#attach_disk', context).attr("disabled", "disabled");
}
if (OpenNebulaVM.isDiskGraphsSupported(that.element)) {
OpenNebulaVM.monitor({
data: {

View File

@ -18,7 +18,7 @@
<div class="row collapse">
<div class="large-12 columns" style="padding-bottom: 1em;">
{{#isTabActionEnabled "vms-tab" "VM.disk_saveas"}}
<button class="disk_snapshot_saveas button secondary small radius" disabled="disabled">
<button class="disk_snapshot_saveas button secondary small radius not_firecracker" disabled="disabled">
<span class="fas fa-save fa-fw"></span>{{tr "Save as"}}
</button>
{{/isTabActionEnabled}}

View File

@ -29,7 +29,7 @@
<th>{{tr "Actions"}}
{{#isTabActionEnabled "vms-tab" "VM.attachdisk"}}
<span class="right">
<button id="attach_disk" class="button small success right radius">
<button id="attach_disk" class="attach_disk button small success right radius">
{{tr "Attach disk"}}
</button>
</span>