1
0
mirror of https://github.com/OpenNebula/one.git synced 2024-12-24 21:34:01 +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 "Template.h"
#include "ObjectCollection.h"
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
@ -37,14 +38,9 @@ public:
*/
string& to_xml(string& xml) const;
int get_vmid()
int add_vmid(int vmid)
{
return vmid;
}
void set_vmid(int vmid)
{
this->vmid = vmid;
return vms.add_collection_id(vmid);
}
// ------------------------------------------------------------------------
@ -81,7 +77,7 @@ private:
// Attributes
// *************************************************************************
int vmid;
ObjectCollection vms;
// *************************************************************************
// DataBase implementation (Private)

View File

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

View File

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

View File

@ -163,5 +163,16 @@ module OpenNebula
def owner_id
self['UID'].to_i
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

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
bool is_vrouter;
bool has_vrouter_id;
int vrid;
string vr_error_str;
@ -147,7 +148,9 @@ void VMTemplateInstantiate::request_execute(xmlrpc_c::paramList const& paramList
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;
@ -222,7 +225,7 @@ void VMTemplateInstantiate::request_execute(xmlrpc_c::paramList const& paramList
//--------------------------------------------------------------------------
// 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;
@ -230,7 +233,7 @@ void VMTemplateInstantiate::request_execute(xmlrpc_c::paramList const& paramList
if (vr != 0)
{
vr->set_vmid(vid);
vr->add_vmid(vid);
vrpool->update(vr);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -68,12 +68,6 @@ define(function(require) {
function _html() {
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);
// TODO: simplify interface?
@ -87,7 +81,6 @@ define(function(require) {
return TemplateInfo({
'element': this.element,
'renameTrHTML': renameTrHTML,
'vmid': vmid,
'permissionsTableHTML': permissionsTableHTML,
'templateTableHTML': templateTableHTML
});

View File

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