diff --git a/include/VirtualRouter.h b/include/VirtualRouter.h index 53146e29df..d9b613bdd9 100644 --- a/include/VirtualRouter.h +++ b/include/VirtualRouter.h @@ -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) diff --git a/src/cli/etc/onevrouter.yaml b/src/cli/etc/onevrouter.yaml index 92404405d5..4ccb9028dc 100644 --- a/src/cli/etc/onevrouter.yaml +++ b/src/cli/etc/onevrouter.yaml @@ -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 diff --git a/src/cli/one_helper/onevrouter_helper.rb b/src/cli/one_helper/onevrouter_helper.rb index a2fbaf3804..098b3e80ed 100644 --- a/src/cli/one_helper/onevrouter_helper.rb +++ b/src/cli/one_helper/onevrouter_helper.rb @@ -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 diff --git a/src/oca/ruby/opennebula/virtual_router.rb b/src/oca/ruby/opennebula/virtual_router.rb index e3b9829c3a..fb6f11970d 100644 --- a/src/oca/ruby/opennebula/virtual_router.rb +++ b/src/oca/ruby/opennebula/virtual_router.rb @@ -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 diff --git a/src/rm/RequestManagerVMTemplate.cc b/src/rm/RequestManagerVMTemplate.cc index 606daeadaa..b3d0afefc7 100644 --- a/src/rm/RequestManagerVMTemplate.cc +++ b/src/rm/RequestManagerVMTemplate.cc @@ -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); diff --git a/src/sunstone/etc/sunstone-views/admin.yaml b/src/sunstone/etc/sunstone-views/admin.yaml index 73709ebbd9..06e9fa6c2d 100644 --- a/src/sunstone/etc/sunstone-views/admin.yaml +++ b/src/sunstone/etc/sunstone-views/admin.yaml @@ -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 diff --git a/src/sunstone/etc/sunstone-views/admin_vcenter.yaml b/src/sunstone/etc/sunstone-views/admin_vcenter.yaml index c01cccf4c2..488a67b080 100644 --- a/src/sunstone/etc/sunstone-views/admin_vcenter.yaml +++ b/src/sunstone/etc/sunstone-views/admin_vcenter.yaml @@ -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 diff --git a/src/sunstone/etc/sunstone-views/user.yaml b/src/sunstone/etc/sunstone-views/user.yaml index 4d820d9016..6ba2462f11 100644 --- a/src/sunstone/etc/sunstone-views/user.yaml +++ b/src/sunstone/etc/sunstone-views/user.yaml @@ -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 diff --git a/src/sunstone/public/app/tabs/vrouters-tab.js b/src/sunstone/public/app/tabs/vrouters-tab.js index f54e7e5e27..aac508e532 100644 --- a/src/sunstone/public/app/tabs/vrouters-tab.js +++ b/src/sunstone/public/app/tabs/vrouters-tab.js @@ -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 = [ diff --git a/src/sunstone/public/app/tabs/vrouters-tab/datatable.js b/src/sunstone/public/app/tabs/vrouters-tab/datatable.js index edced70510..c9a6b79610 100644 --- a/src/sunstone/public/app/tabs/vrouters-tab/datatable.js +++ b/src/sunstone/public/app/tabs/vrouters-tab/datatable.js @@ -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 diff --git a/src/sunstone/public/app/tabs/vrouters-tab/panels/info.js b/src/sunstone/public/app/tabs/vrouters-tab/panels/info.js index 877baf34ae..05a7baa90e 100644 --- a/src/sunstone/public/app/tabs/vrouters-tab/panels/info.js +++ b/src/sunstone/public/app/tabs/vrouters-tab/panels/info.js @@ -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 }); diff --git a/src/sunstone/public/app/tabs/vrouters-tab/panels/info/html.hbs b/src/sunstone/public/app/tabs/vrouters-tab/panels/info/html.hbs index c4846490f1..04f34b052e 100644 --- a/src/sunstone/public/app/tabs/vrouters-tab/panels/info/html.hbs +++ b/src/sunstone/public/app/tabs/vrouters-tab/panels/info/html.hbs @@ -28,16 +28,6 @@ {{element.ID}} {{{renameTrHTML}}} - - {{tr "VM ID"}} - - {{#if vmid}} - {{vmid}} - {{else}} - -- - {{/if}} - - diff --git a/src/sunstone/public/app/tabs/vrouters-tab/panels/vms.js b/src/sunstone/public/app/tabs/vrouters-tab/panels/vms.js new file mode 100644 index 0000000000..e3b87e5cfc --- /dev/null +++ b/src/sunstone/public/app/tabs/vrouters-tab/panels/vms.js @@ -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; + } +}); diff --git a/src/sunstone/public/app/tabs/vrouters-tab/panels/vms/panelId.js b/src/sunstone/public/app/tabs/vrouters-tab/panels/vms/panelId.js new file mode 100644 index 0000000000..3cac7cb55c --- /dev/null +++ b/src/sunstone/public/app/tabs/vrouters-tab/panels/vms/panelId.js @@ -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'; +}) diff --git a/src/vrouter/VirtualRouter.cc b/src/vrouter/VirtualRouter.cc index 0dc8c7f94b..a94584a0c1 100644 --- a/src/vrouter/VirtualRouter.cc +++ b/src/vrouter/VirtualRouter.cc @@ -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 << "" @@ -198,8 +199,8 @@ string& VirtualRouter::to_xml(string& xml) const << "" << uname << "" << "" << gname << "" << "" << name << "" - << "" << vmid << "" << perms_to_xml(perm_str) + << vms.to_xml(vm_collection_xml) << obj_template->to_xml(template_xml) << ""; @@ -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) {