1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-01-12 09:17:41 +03:00

Feature #4215: VRs now have a collection of VM IDs

This commit is contained in:
Carlos Martín 2015-12-11 11:45:34 +01:00
parent 43a8034f52
commit 3991404826
15 changed files with 167 additions and 58 deletions

View File

@ -19,6 +19,7 @@
#include "PoolObjectSQL.h" #include "PoolObjectSQL.h"
#include "Template.h" #include "Template.h"
#include "ObjectCollection.h"
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
@ -37,14 +38,9 @@ public:
*/ */
string& to_xml(string& xml) const; string& to_xml(string& xml) const;
int get_vmid() int add_vmid(int vmid)
{ {
return vmid; return vms.add_collection_id(vmid);
}
void set_vmid(int vmid)
{
this->vmid = vmid;
} }
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
@ -81,7 +77,7 @@ private:
// Attributes // Attributes
// ************************************************************************* // *************************************************************************
int vmid; ObjectCollection vms;
// ************************************************************************* // *************************************************************************
// DataBase implementation (Private) // DataBase implementation (Private)

View File

@ -3,10 +3,6 @@
:desc: ONE identifier for the Virtual Router :desc: ONE identifier for the Virtual Router
:size: 4 :size: 4
:VMID:
:desc: VM associated with the Virtual Router
:size: 4
:NAME: :NAME:
:desc: Name of the Virtual Router :desc: Name of the Virtual Router
:size: 27 :size: 27
@ -24,7 +20,6 @@
:default: :default:
- :ID - :ID
- :VMID
- :USER - :USER
- :GROUP - :GROUP
- :NAME - :NAME

View File

@ -52,10 +52,6 @@ class OneVirtualRouterHelper < OpenNebulaHelper::OneHelper
d["ID"] d["ID"]
end end
column :VMID, "VM associated with the Virtual Router", :size=>4 do |d|
d["VMID"]
end
column :NAME, "Name of the Virtual Router", :left, :size=>27 do |d| column :NAME, "Name of the Virtual Router", :left, :size=>27 do |d|
d["NAME"] d["NAME"]
end end
@ -69,7 +65,7 @@ class OneVirtualRouterHelper < OpenNebulaHelper::OneHelper
helper.group_name(d, options) helper.group_name(d, options)
end end
default :ID, :VMID, :USER, :GROUP, :NAME default :ID, :USER, :GROUP, :NAME
end end
table table
@ -98,7 +94,6 @@ class OneVirtualRouterHelper < OpenNebulaHelper::OneHelper
str_h1 % "VIRTUAL ROUTER #{obj['ID']} INFORMATION") str_h1 % "VIRTUAL ROUTER #{obj['ID']} INFORMATION")
puts str % ["ID", obj.id.to_s] puts str % ["ID", obj.id.to_s]
puts str % ["NAME", obj.name] puts str % ["NAME", obj.name]
puts str % ["VIRTUAL MACHINE", obj['VMID']]
puts str % ["USER", obj['UNAME']] puts str % ["USER", obj['UNAME']]
puts str % ["GROUP", obj['GNAME']] puts str % ["GROUP", obj['GNAME']]
puts puts
@ -117,5 +112,12 @@ class OneVirtualRouterHelper < OpenNebulaHelper::OneHelper
CLIHelper.print_header(str_h1 % "TEMPLATE CONTENTS",false) CLIHelper.print_header(str_h1 % "TEMPLATE CONTENTS",false)
puts obj.template_str puts obj.template_str
puts
CLIHelper.print_header("%-15s" % "VIRTUAL MACHINES")
obj.vm_ids.each do |id|
puts "%-15s" % [id]
end
end end
end end

View File

@ -163,5 +163,16 @@ module OpenNebula
def owner_id def owner_id
self['UID'].to_i self['UID'].to_i
end end
# Returns an array with the numeric VM ids
def vm_ids
array = Array.new
self.each("VMS/ID") do |id|
array << id.text.to_i
end
return array
end
end end
end end

View File

@ -140,6 +140,7 @@ void VMTemplateInstantiate::request_execute(xmlrpc_c::paramList const& paramList
// Temporary code to create Virtual Routers from regular VM Templates // Temporary code to create Virtual Routers from regular VM Templates
bool is_vrouter; bool is_vrouter;
bool has_vrouter_id;
int vrid; int vrid;
string vr_error_str; string vr_error_str;
@ -147,7 +148,9 @@ void VMTemplateInstantiate::request_execute(xmlrpc_c::paramList const& paramList
tmpl->get("VROUTER", is_vrouter); tmpl->get("VROUTER", is_vrouter);
if (is_vrouter) has_vrouter_id = tmpl->get("VROUTER_ID", vrid);
if (is_vrouter && !has_vrouter_id)
{ {
Template * vr_tmpl = new Template; Template * vr_tmpl = new Template;
@ -222,7 +225,7 @@ void VMTemplateInstantiate::request_execute(xmlrpc_c::paramList const& paramList
//-------------------------------------------------------------------------- //--------------------------------------------------------------------------
// Temporary code to create Virtual Routers from regular VM Templates // Temporary code to create Virtual Routers from regular VM Templates
// Final code would need roolback to delete the new VR on error // Final code would need rollback to delete the new VR on error
VirtualRouter * vr; VirtualRouter * vr;
@ -230,7 +233,7 @@ void VMTemplateInstantiate::request_execute(xmlrpc_c::paramList const& paramList
if (vr != 0) if (vr != 0)
{ {
vr->set_vmid(vid); vr->add_vmid(vid);
vrpool->update(vr); vrpool->update(vr);

View File

@ -437,13 +437,13 @@ tabs:
vrouters-tab: vrouters-tab:
panel_tabs: panel_tabs:
virtual_router_info_tab: true virtual_router_info_tab: true
virtual_router_vms_tab: true
table_columns: table_columns:
- 0 # Checkbox - 0 # Checkbox
- 1 # ID - 1 # ID
- 2 # VMID - 2 # Owner
- 3 # Owner - 3 # Group
- 4 # Group - 4 # Name
- 5 # Name
actions: actions:
VirtualRouter.refresh: true VirtualRouter.refresh: true
VirtualRouter.create_dialog: true VirtualRouter.create_dialog: true

View File

@ -431,13 +431,13 @@ tabs:
vrouters-tab: vrouters-tab:
panel_tabs: panel_tabs:
virtual_router_info_tab: true virtual_router_info_tab: true
virtual_router_vms_tab: true
table_columns: table_columns:
- 0 # Checkbox - 0 # Checkbox
- 1 # ID - 1 # ID
- 2 # VMID - 2 # Owner
- 3 # Owner - 3 # Group
- 4 # Group - 4 # Name
- 5 # Name
actions: actions:
VirtualRouter.refresh: true VirtualRouter.refresh: true
VirtualRouter.create_dialog: true VirtualRouter.create_dialog: true

View File

@ -432,13 +432,13 @@ tabs:
vrouters-tab: vrouters-tab:
panel_tabs: panel_tabs:
virtual_router_info_tab: true virtual_router_info_tab: true
virtual_router_vms_tab: true
table_columns: table_columns:
- 0 # Checkbox - 0 # Checkbox
- 1 # ID - 1 # ID
- 2 # VMID - 2 # Owner
- 3 # Owner - 3 # Group
- 4 # Group - 4 # Name
- 5 # Name
actions: actions:
VirtualRouter.refresh: true VirtualRouter.refresh: true
VirtualRouter.create_dialog: true VirtualRouter.create_dialog: true

View File

@ -28,7 +28,8 @@ define(function(require) {
]; ];
var _panels = [ var _panels = [
require('./vrouters-tab/panels/info') require('./vrouters-tab/panels/info'),
require('./vrouters-tab/panels/vms')
]; ];
var _panelsHooks = [ var _panelsHooks = [

View File

@ -56,7 +56,6 @@ define(function(require) {
this.columns = [ this.columns = [
Locale.tr("ID"), Locale.tr("ID"),
Locale.tr("VMID"),
Locale.tr("Owner"), Locale.tr("Owner"),
Locale.tr("Group"), Locale.tr("Group"),
Locale.tr("Name") Locale.tr("Name")
@ -64,7 +63,7 @@ define(function(require) {
this.selectOptions = { this.selectOptions = {
"id_index": 1, "id_index": 1,
"name_index": 5, "name_index": 4,
"select_resource": Locale.tr("Please select a virtual router from the list"), "select_resource": Locale.tr("Please select a virtual router from the list"),
"you_selected": Locale.tr("You selected the following virtual router:"), "you_selected": Locale.tr("You selected the following virtual router:"),
"select_resource_multiple": Locale.tr("Please select one or more virtual routers from the list"), "select_resource_multiple": Locale.tr("Please select one or more virtual routers from the list"),
@ -92,7 +91,6 @@ define(function(require) {
element.ID + '" name="selected_items" value="' + element.ID + '" name="selected_items" value="' +
element.ID + '"/>', element.ID + '"/>',
element.ID, element.ID,
element.VMID,
element.UNAME, element.UNAME,
element.GNAME, element.GNAME,
element.NAME element.NAME

View File

@ -68,12 +68,6 @@ define(function(require) {
function _html() { function _html() {
var renameTrHTML = RenameTr.html(TAB_ID, RESOURCE, this.element.NAME); var renameTrHTML = RenameTr.html(TAB_ID, RESOURCE, this.element.NAME);
var vmid = this.element.VMID;
if (vmid == "-1"){
vmid = undefined; // Change made to use {{#if vmid}} in handlebars
}
var permissionsTableHTML = PermissionsTable.html(TAB_ID, RESOURCE, this.element); var permissionsTableHTML = PermissionsTable.html(TAB_ID, RESOURCE, this.element);
// TODO: simplify interface? // TODO: simplify interface?
@ -87,7 +81,6 @@ define(function(require) {
return TemplateInfo({ return TemplateInfo({
'element': this.element, 'element': this.element,
'renameTrHTML': renameTrHTML, 'renameTrHTML': renameTrHTML,
'vmid': vmid,
'permissionsTableHTML': permissionsTableHTML, 'permissionsTableHTML': permissionsTableHTML,
'templateTableHTML': templateTableHTML 'templateTableHTML': templateTableHTML
}); });

View File

@ -28,16 +28,6 @@
<td class="value_td" colspan="2">{{element.ID}}</td> <td class="value_td" colspan="2">{{element.ID}}</td>
</tr> </tr>
{{{renameTrHTML}}} {{{renameTrHTML}}}
<tr>
<td class="key_td">{{tr "VM ID"}}</td>
<td class="value_td" colspan="2">
{{#if vmid}}
<a class="vmid">{{vmid}}</a>
{{else}}
--
{{/if}}
</td>
</tr>
</tbody> </tbody>
</table> </table>
</div> </div>

View File

@ -0,0 +1,88 @@
/* -------------------------------------------------------------------------- */
/* Copyright 2002-2015, OpenNebula Project, OpenNebula Systems */
/* */
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
/* not use this file except in compliance with the License. You may obtain */
/* a copy of the License at */
/* */
/* http://www.apache.org/licenses/LICENSE-2.0 */
/* */
/* Unless required by applicable law or agreed to in writing, software */
/* distributed under the License is distributed on an "AS IS" BASIS, */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
/* See the License for the specific language governing permissions and */
/* limitations under the License. */
/* -------------------------------------------------------------------------- */
define(function(require){
/*
DEPENDENCIES
*/
var Locale = require('utils/locale');
var VMsTable = require('tabs/vms-tab/datatable');
/*
CONSTANTS
*/
var PANEL_ID = require('./vms/panelId');
var VMS_TABLE_ID = PANEL_ID + "VMsTable";
var RESOURCE = "VirtualRouter";
var XML_ROOT = "VROUTER";
/*
CONSTRUCTOR
*/
function Panel(info) {
this.title = Locale.tr("VMs");
this.icon = "fa-cloud";
this.element = info[XML_ROOT];
return this;
}
Panel.PANEL_ID = PANEL_ID;
Panel.prototype.html = _html;
Panel.prototype.setup = _setup;
return Panel;
/*
FUNCTION DEFINITIONS
*/
function _html() {
var vms = [];
if (this.element.VMS.ID != undefined){
vms = this.element.VMS.ID;
if (!$.isArray(vms)){
vms = [vms];
}
}
var opts = {
info: true,
select: true,
selectOptions: {
read_only: true,
fixed_ids: vms
}
};
this.vmsTable = new VMsTable(VMS_TABLE_ID, opts);
return this.vmsTable.dataTableHTML;
}
function _setup(context) {
this.vmsTable.initialize();
this.vmsTable.refreshResourceTableSelect();
return false;
}
});

View File

@ -0,0 +1,19 @@
/* -------------------------------------------------------------------------- */
/* Copyright 2002-2015, OpenNebula Project, OpenNebula Systems */
/* */
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
/* not use this file except in compliance with the License. You may obtain */
/* a copy of the License at */
/* */
/* http://www.apache.org/licenses/LICENSE-2.0 */
/* */
/* Unless required by applicable law or agreed to in writing, software */
/* distributed under the License is distributed on an "AS IS" BASIS, */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
/* See the License for the specific language governing permissions and */
/* limitations under the License. */
/* -------------------------------------------------------------------------- */
define(function(require){
return 'virtual_router_vms_tab';
})

View File

@ -28,7 +28,7 @@ VirtualRouter::VirtualRouter( int id,
int _umask, int _umask,
Template * _template_contents): Template * _template_contents):
PoolObjectSQL(id,VROUTER,"",_uid,_gid,_uname,_gname,table), PoolObjectSQL(id,VROUTER,"",_uid,_gid,_uname,_gname,table),
vmid(-1) vms("VMS")
{ {
if (_template_contents != 0) if (_template_contents != 0)
{ {
@ -189,6 +189,7 @@ string& VirtualRouter::to_xml(string& xml) const
{ {
ostringstream oss; ostringstream oss;
string template_xml; string template_xml;
string vm_collection_xml;
string perm_str; string perm_str;
oss << "<VROUTER>" oss << "<VROUTER>"
@ -198,8 +199,8 @@ string& VirtualRouter::to_xml(string& xml) const
<< "<UNAME>" << uname << "</UNAME>" << "<UNAME>" << uname << "</UNAME>"
<< "<GNAME>" << gname << "</GNAME>" << "<GNAME>" << gname << "</GNAME>"
<< "<NAME>" << name << "</NAME>" << "<NAME>" << name << "</NAME>"
<< "<VMID>" << vmid << "</VMID>"
<< perms_to_xml(perm_str) << perms_to_xml(perm_str)
<< vms.to_xml(vm_collection_xml)
<< obj_template->to_xml(template_xml) << obj_template->to_xml(template_xml)
<< "</VROUTER>"; << "</VROUTER>";
@ -226,12 +227,23 @@ int VirtualRouter::from_xml(const string& xml)
rc += xpath(uname, "/VROUTER/UNAME", "not_found"); rc += xpath(uname, "/VROUTER/UNAME", "not_found");
rc += xpath(gname, "/VROUTER/GNAME", "not_found"); rc += xpath(gname, "/VROUTER/GNAME", "not_found");
rc += xpath(name, "/VROUTER/NAME", "not_found"); rc += xpath(name, "/VROUTER/NAME", "not_found");
rc += xpath(vmid, "/VROUTER/VMID", -1);
// Permissions // Permissions
rc += perms_from_xml(); rc += perms_from_xml();
// Get associated classes // Get associated classes
ObjectXML::get_nodes("/VROUTER/VMS", content);
if (content.empty())
{
return -1;
}
rc += vms.from_xml_node(content[0]);
ObjectXML::free_nodes(content);
content.clear();
ObjectXML::get_nodes("/VROUTER/TEMPLATE", content); ObjectXML::get_nodes("/VROUTER/TEMPLATE", content);
if (content.empty()) if (content.empty())
@ -243,6 +255,7 @@ int VirtualRouter::from_xml(const string& xml)
rc += obj_template->from_xml_node(content[0]); rc += obj_template->from_xml_node(content[0]);
ObjectXML::free_nodes(content); ObjectXML::free_nodes(content);
content.clear();
if (rc != 0) if (rc != 0)
{ {