diff --git a/include/VirtualMachine.h b/include/VirtualMachine.h index 0b6fe56480..66246f4fb0 100644 --- a/include/VirtualMachine.h +++ b/include/VirtualMachine.h @@ -1262,10 +1262,12 @@ public: * * @param nic NIC to be released * @param vmid Virtual Machine oid + * @param vrid Virtual Router id if the VM is a VR, or -1 * * @return 0 on success, -1 otherwise */ - static int release_network_leases(VectorAttribute const * nic, int vmid); + static int release_network_leases( + VectorAttribute const * nic, int vmid, int vrid); /** * Releases all disk images taken by this Virtual Machine @@ -1317,6 +1319,16 @@ public: */ const VectorAttribute* get_disk(int disk_id) const; + // ------------------------------------------------------------------------ + // Virtual Router related functions + // ------------------------------------------------------------------------ + + /** + * Returns the Virtual Router ID if this VM is a VR, or -1 + * @return VR ID or -1 + */ + int get_vrouter_id(); + // ------------------------------------------------------------------------ // Context related functions // ------------------------------------------------------------------------ @@ -1532,6 +1544,7 @@ public: * * @param vm_id Id of the VM where this nic will be attached * @param vm_sgs the securty group ids already present in the VM + * @param vm_vrid Virtual Router id if the VM is a VR, or -1 * @param new_nic New NIC vector attribute, obtained from get_attach_nic_info * @param rules Security Group rules will be added at the end of this * vector. If not used, the VectorAttributes must be freed by the calling @@ -1544,6 +1557,7 @@ public: static int set_up_attach_nic( int vm_id, set& vm_sgs, + int vm_vrid, VectorAttribute * new_nic, vector &rules, int max_nic_id, @@ -1954,6 +1968,13 @@ private: */ int parse_defaults(string& error_str); + /** + * Parse virtual router related attributes + * @param error_str Returns the error reason, if any + * @return 0 on success + */ + int parse_vrouter(string& error_str); + /** * Known attributes for network contextualization rendered as: * ETH__ = $NETWORK[context[1], vnet_name] diff --git a/include/VirtualNetwork.h b/include/VirtualNetwork.h index 424c35563a..2febc3f722 100644 --- a/include/VirtualNetwork.h +++ b/include/VirtualNetwork.h @@ -22,6 +22,7 @@ #include "VirtualNetworkTemplate.h" #include "Clusterable.h" #include "AddressRangePool.h" +#include "ObjectCollection.h" #include #include @@ -199,21 +200,33 @@ public: * Release previously given address lease * @param arid of the address range where the address was leased from * @param vid the ID of the VM + * @param vrid Virtual Router id if the VM is a VR, or -1 * @param mac MAC address identifying the lease */ - void free_addr(unsigned int arid, int vid, const string& mac) + void free_addr(unsigned int arid, int vid, int vrid, const string& mac) { ar_pool.free_addr(arid, PoolObjectSQL::VM, vid, mac); + + if (vrid != -1) + { + vrouters.del_collection_id(vrid); + } } /** * Release previously given address lease * @param vid the ID of the VM + * @param vrid Virtual Router id if the VM is a VR, or -1 * @param mac MAC address identifying the lease */ - void free_addr(int vid, const string& mac) + void free_addr(int vid, int vrid, const string& mac) { ar_pool.free_addr(PoolObjectSQL::VM, vid, mac); + + if (vrid != -1) + { + vrouters.del_collection_id(vrid); + } } /** @@ -246,6 +259,7 @@ public: * * BRIDGE: for this virtual network * @param nic attribute for the VM template * @param vid of the VM getting the lease + * @param vrid Virtual Router id if the VM is a VR, or -1 * @param inherit_attrs Attributes to be inherited from the vnet template * into the nic * @return 0 on success @@ -253,6 +267,7 @@ public: int nic_attribute( VectorAttribute * nic, int vid, + int vrid, const vector& inherit_attrs); /** @@ -458,6 +473,11 @@ private: */ AddressRangePool ar_pool; + /** + * Set of Virtual Router IDs + */ + ObjectCollection vrouters; + // ************************************************************************* // DataBase implementation (Private) // ************************************************************************* diff --git a/include/VirtualNetworkPool.h b/include/VirtualNetworkPool.h index e175f41742..cfc3298c9c 100644 --- a/include/VirtualNetworkPool.h +++ b/include/VirtualNetworkPool.h @@ -107,6 +107,7 @@ public: * @param nic_id the id for this NIC * @param uid of the VM owner * @param vid of the VM requesting the lease + * @param vrid Virtual Router id if the VM is a VR, or -1 * @param error_str string describing the error * @return 0 on success, * -1 error, @@ -117,6 +118,7 @@ public: int nic_id, int uid, int vid, + int vrid, string& error_str); /** diff --git a/include/VirtualRouter.h b/include/VirtualRouter.h index 40a512a459..53146e29df 100644 --- a/include/VirtualRouter.h +++ b/include/VirtualRouter.h @@ -37,6 +37,16 @@ public: */ string& to_xml(string& xml) const; + int get_vmid() + { + return vmid; + } + + void set_vmid(int vmid) + { + this->vmid = vmid; + } + // ------------------------------------------------------------------------ // Template Contents // ------------------------------------------------------------------------ @@ -66,6 +76,13 @@ private: friend class VirtualRouterPool; + + // ************************************************************************* + // Attributes + // ************************************************************************* + + int vmid; + // ************************************************************************* // DataBase implementation (Private) // ************************************************************************* diff --git a/src/acl/AclRule.cc b/src/acl/AclRule.cc index e6e49fa686..f3cc487266 100644 --- a/src/acl/AclRule.cc +++ b/src/acl/AclRule.cc @@ -28,7 +28,7 @@ const long long AclRule::CLUSTER_ID = 0x0000000800000000LL; const long long AclRule::NONE_ID = 0x1000000000000000LL; -const int AclRule::num_pool_objects = 13; +const int AclRule::num_pool_objects = 14; const PoolObjectSQL::ObjectType AclRule::pool_objects[] = { PoolObjectSQL::VM, PoolObjectSQL::HOST, @@ -42,7 +42,8 @@ const PoolObjectSQL::ObjectType AclRule::pool_objects[] = { PoolObjectSQL::DOCUMENT, PoolObjectSQL::ZONE, PoolObjectSQL::SECGROUP, - PoolObjectSQL::VDC + PoolObjectSQL::VDC, + PoolObjectSQL::VROUTER }; const int AclRule::num_auth_operations = 4; @@ -57,7 +58,7 @@ const long long AclRule::INVALID_CLUSTER_OBJECTS = PoolObjectSQL::VM | PoolObjectSQL::IMAGE | PoolObjectSQL::USER | PoolObjectSQL::TEMPLATE | PoolObjectSQL::GROUP | PoolObjectSQL::ACL | PoolObjectSQL::CLUSTER | PoolObjectSQL::DOCUMENT | PoolObjectSQL::ZONE | - PoolObjectSQL::SECGROUP | PoolObjectSQL::VDC; + PoolObjectSQL::SECGROUP | PoolObjectSQL::VDC | PoolObjectSQL::VROUTER; const long long AclRule::INVALID_GROUP_OBJECTS = PoolObjectSQL::HOST | PoolObjectSQL::GROUP | PoolObjectSQL::CLUSTER | @@ -233,7 +234,7 @@ bool AclRule::malformed(string& error_str) const oss << "[resource] type is missing"; } - if ( (resource & 0xFFFC000000000000LL) != 0 ) + if ( (resource & 0xFFF8000000000000LL) != 0 ) { if ( error ) { diff --git a/src/cli/etc/oneacl.yaml b/src/cli/etc/oneacl.yaml index 0a1e3a5d35..b860218bb7 100644 --- a/src/cli/etc/oneacl.yaml +++ b/src/cli/etc/oneacl.yaml @@ -9,9 +9,9 @@ :size: 8 :right: true -:RES_VHNIUTGDCOZSv: +:RES_VHNIUTGDCOZSvR: :desc: Which resource the rule applies to - :size: 17 + :size: 18 :RID: :desc: Resource ID @@ -31,7 +31,7 @@ :default: - :ID - :USER -- :RES_VHNIUTGDCOZSv +- :RES_VHNIUTGDCOZSvR - :RID - :OPE_UMAC - :ZONE diff --git a/src/cli/etc/onevrouter.yaml b/src/cli/etc/onevrouter.yaml index 4ccb9028dc..92404405d5 100644 --- a/src/cli/etc/onevrouter.yaml +++ b/src/cli/etc/onevrouter.yaml @@ -3,6 +3,10 @@ :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 @@ -20,6 +24,7 @@ :default: - :ID +- :VMID - :USER - :GROUP - :NAME diff --git a/src/cli/one_helper/oneacl_helper.rb b/src/cli/one_helper/oneacl_helper.rb index e9b2e1da3a..c3f868711b 100644 --- a/src/cli/one_helper/oneacl_helper.rb +++ b/src/cli/one_helper/oneacl_helper.rb @@ -44,7 +44,7 @@ private def self.resource_mask(str) resource_type=str.split("/")[0] - mask = "-------------" + mask = "--------------" resource_type.split("+").each{|type| case type @@ -74,6 +74,8 @@ private mask[11] = "S" when "VDC" mask[12] = "v" + when "VROUTER" + mask[13] = "R" end } mask @@ -113,8 +115,8 @@ private d['STRING'].split(" ")[0] end - column :RES_VHNIUTGDCOZSv, "Resource to which the rule applies", - :size => 17 do |d| + column :RES_VHNIUTGDCOZSvR, "Resource to which the rule applies", + :size => 18 do |d| OneAclHelper::resource_mask d['STRING'].split(" ")[1] end @@ -131,7 +133,7 @@ private OneAclHelper::right_mask d['STRING'].split(" ")[2] end - default :ID, :USER, :RES_VHNIUTGDCOZSv, :RID, :OPE_UMAC, :ZONE + default :ID, :USER, :RES_VHNIUTGDCOZSvR, :RID, :OPE_UMAC, :ZONE end table diff --git a/src/cli/one_helper/onevnet_helper.rb b/src/cli/one_helper/onevnet_helper.rb index e422527517..c92a160d87 100644 --- a/src/cli/one_helper/onevnet_helper.rb +++ b/src/cli/one_helper/onevnet_helper.rb @@ -324,6 +324,13 @@ class OneVNetHelper < OpenNebulaHelper::OneHelper end end.show(leases, {}) + puts + + CLIHelper.print_header("%-15s" % "VIRTUAL ROUTERS") + vn.vrouter_ids.each do |id| + puts "%-15s" % [id] + end + if options[:show_ar] ar_list.each do |ar_id| puts diff --git a/src/cli/one_helper/onevrouter_helper.rb b/src/cli/one_helper/onevrouter_helper.rb index 05a03ebf12..a2fbaf3804 100644 --- a/src/cli/one_helper/onevrouter_helper.rb +++ b/src/cli/one_helper/onevrouter_helper.rb @@ -52,6 +52,10 @@ 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 @@ -65,7 +69,7 @@ class OneVirtualRouterHelper < OpenNebulaHelper::OneHelper helper.group_name(d, options) end - default :ID, :USER, :GROUP, :NAME + default :ID, :VMID, :USER, :GROUP, :NAME end table @@ -94,6 +98,7 @@ 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 diff --git a/src/dm/DispatchManagerActions.cc b/src/dm/DispatchManagerActions.cc index 66a5aac144..5160854b3c 100644 --- a/src/dm/DispatchManagerActions.cc +++ b/src/dm/DispatchManagerActions.cc @@ -1442,6 +1442,7 @@ int DispatchManager::attach_nic( int max_nic_id; int uid; int oid; + int vrid; int rc; set vm_sgs; @@ -1496,8 +1497,9 @@ int DispatchManager::attach_nic( vm->set_resched(false); - uid = vm->get_uid(); - oid = vm->get_oid(); + uid = vm->get_uid(); + oid = vm->get_oid(); + vrid = vm->get_vrouter_id(); vmpool->update(vm); @@ -1505,6 +1507,7 @@ int DispatchManager::attach_nic( rc = VirtualMachine::set_up_attach_nic(oid, vm_sgs, + vrid, nic, sg_rules, max_nic_id, @@ -1518,7 +1521,7 @@ int DispatchManager::attach_nic( if ( rc == 0 ) { - VirtualMachine::release_network_leases(nic, vid); + VirtualMachine::release_network_leases(nic, vid, vrid); vector::iterator it; for(it = sg_rules.begin(); it != sg_rules.end(); it++) diff --git a/src/group/Group.cc b/src/group/Group.cc index c2c6f9e117..354b14726d 100644 --- a/src/group/Group.cc +++ b/src/group/Group.cc @@ -380,7 +380,7 @@ void Group::add_admin_rules(int user_id) NebulaLog::log("GROUP",Log::ERROR,error_msg); } - // # VM+NET+IMAGE+TEMPLATE+DOCUMENT+SECGROUP/@ USE+MANAGE * + // # VM+NET+IMAGE+TEMPLATE+DOCUMENT+SECGROUP+VROUTER/@ USE+MANAGE * rc = aclm->add_rule( AclRule::INDIVIDUAL_ID | user_id, @@ -391,6 +391,7 @@ void Group::add_admin_rules(int user_id) PoolObjectSQL::TEMPLATE | PoolObjectSQL::DOCUMENT | PoolObjectSQL::SECGROUP | + PoolObjectSQL::VROUTER | AclRule::GROUP_ID | oid, @@ -463,7 +464,7 @@ void Group::del_admin_rules(int user_id) NebulaLog::log("GROUP",Log::ERROR,error_msg); } - // # VM+NET+IMAGE+TEMPLATE+DOCUMENT+SECGROUP/@ USE+MANAGE * + // # VM+NET+IMAGE+TEMPLATE+DOCUMENT+SECGROUP+VROUTER/@ USE+MANAGE * rc = aclm->del_rule( AclRule::INDIVIDUAL_ID | user_id, @@ -474,6 +475,7 @@ void Group::del_admin_rules(int user_id) PoolObjectSQL::TEMPLATE | PoolObjectSQL::DOCUMENT | PoolObjectSQL::SECGROUP | + PoolObjectSQL::VROUTER | AclRule::GROUP_ID | oid, diff --git a/src/oca/java/src/org/opennebula/client/acl/Acl.java b/src/oca/java/src/org/opennebula/client/acl/Acl.java index ddb15ba7a5..c4424662a0 100644 --- a/src/oca/java/src/org/opennebula/client/acl/Acl.java +++ b/src/oca/java/src/org/opennebula/client/acl/Acl.java @@ -71,6 +71,7 @@ public class Acl extends PoolElement{ tmpResources.put("ZONE" , 0x0000800000000000L); tmpResources.put("SECGROUP" , 0x0001000000000000L); tmpResources.put("VDC" , 0x0002000000000000L); + tmpResources.put("VROUTER" , 0x0004000000000000L); RESOURCES = Collections.unmodifiableMap(tmpResources); diff --git a/src/oca/ruby/opennebula/acl.rb b/src/oca/ruby/opennebula/acl.rb index d1e0b5d009..dc529453b0 100644 --- a/src/oca/ruby/opennebula/acl.rb +++ b/src/oca/ruby/opennebula/acl.rb @@ -61,7 +61,8 @@ module OpenNebula "DOCUMENT" => 0x400000000000, "ZONE" => 0x800000000000, "SECGROUP" => 0x1000000000000, - "VDC" => 0x2000000000000 + "VDC" => 0x2000000000000, + "VROUTER" => 0x4000000000000 } RIGHTS = diff --git a/src/oca/ruby/opennebula/virtual_network.rb b/src/oca/ruby/opennebula/virtual_network.rb index d13a333a79..463e372eba 100644 --- a/src/oca/ruby/opennebula/virtual_network.rb +++ b/src/oca/ruby/opennebula/virtual_network.rb @@ -324,6 +324,17 @@ module OpenNebula end end + # Returns an array with the numeric virtual router ids + def vrouter_ids + array = Array.new + + self.each("VROUTERS/ID") do |id| + array << id.text.to_i + end + + return array + end + private def set_publish(published) group_u = published ? 1 : 0 diff --git a/src/sunstone/etc/sunstone-views/admin.yaml b/src/sunstone/etc/sunstone-views/admin.yaml index 057cf30468..a6d4bb6663 100644 --- a/src/sunstone/etc/sunstone-views/admin.yaml +++ b/src/sunstone/etc/sunstone-views/admin.yaml @@ -381,6 +381,7 @@ tabs: vnet_ar_list_tab: true vnet_leases_tab: true vnet_sg_list_tab: true + vnet_vr_list_tab: true table_columns: - 0 # Checkbox - 1 # ID @@ -433,9 +434,10 @@ tabs: table_columns: - 0 # Checkbox - 1 # ID - - 2 # Owner - - 3 # Group - - 4 # Name + - 2 # VMID + - 3 # Owner + - 4 # Group + - 5 # 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 47c59f245f..c01cccf4c2 100644 --- a/src/sunstone/etc/sunstone-views/admin_vcenter.yaml +++ b/src/sunstone/etc/sunstone-views/admin_vcenter.yaml @@ -381,6 +381,7 @@ tabs: vnet_ar_list_tab: true vnet_leases_tab: true vnet_sg_list_tab: true + vnet_vr_list_tab: true table_columns: - 0 # Checkbox - 1 # ID @@ -433,9 +434,10 @@ tabs: table_columns: - 0 # Checkbox - 1 # ID - - 2 # Owner - - 3 # Group - - 4 # Name + - 2 # VMID + - 3 # Owner + - 4 # Group + - 5 # 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 a61e9bfc9c..4d820d9016 100644 --- a/src/sunstone/etc/sunstone-views/user.yaml +++ b/src/sunstone/etc/sunstone-views/user.yaml @@ -382,6 +382,7 @@ tabs: vnet_ar_list_tab: true vnet_leases_tab: true vnet_sg_list_tab: true + vnet_vr_list_tab: true table_columns: - 0 # Checkbox - 1 # ID @@ -434,9 +435,10 @@ tabs: table_columns: - 0 # Checkbox - 1 # ID - - 2 # Owner - - 3 # Group - - 4 # Name + - 2 # VMID + - 3 # Owner + - 4 # Group + - 5 # Name actions: VirtualRouter.refresh: true VirtualRouter.create_dialog: true diff --git a/src/sunstone/models/SunstoneServer.rb b/src/sunstone/models/SunstoneServer.rb index fd6e709317..f10bb25545 100644 --- a/src/sunstone/models/SunstoneServer.rb +++ b/src/sunstone/models/SunstoneServer.rb @@ -119,7 +119,7 @@ class SunstoneServer < CloudServer when "vnet" then VirtualNetworkJSON.new(VirtualNetwork.build_xml, @client) when "user" then UserJSON.new(User.build_xml, @client) when "acl" then AclJSON.new(Acl.build_xml, @client) - when "datastore" then DatastoreJSON.new(Acl.build_xml, @client) + when "datastore" then DatastoreJSON.new(Datastore.build_xml, @client) when "zone" then ZoneJSON.new(Zone.build_xml, @client) when "security_group" then SecurityGroupJSON.new(SecurityGroup.build_xml, @client) when "vdc" then VdcJSON.new(Vdc.build_xml, @client) diff --git a/src/sunstone/public/app/tabs/acls-tab/datatable.js b/src/sunstone/public/app/tabs/acls-tab/datatable.js index 4d3b4dafc7..423eacbeb0 100644 --- a/src/sunstone/public/app/tabs/acls-tab/datatable.js +++ b/src/sunstone/public/app/tabs/acls-tab/datatable.js @@ -171,6 +171,9 @@ define(function(require) { case "VDC": resources_str+=Locale.tr("VDCs")+", "; break; + case "VROUTER": + resources_str+=Locale.tr("Virtual Routers")+", "; + break; } } //remove ", " from end diff --git a/src/sunstone/public/app/tabs/acls-tab/form-panels/create/wizard.hbs b/src/sunstone/public/app/tabs/acls-tab/form-panels/create/wizard.hbs index ae847c8fa6..5155069c60 100644 --- a/src/sunstone/public/app/tabs/acls-tab/form-panels/create/wizard.hbs +++ b/src/sunstone/public/app/tabs/acls-tab/form-panels/create/wizard.hbs @@ -116,6 +116,10 @@ +
+ + +
diff --git a/src/sunstone/public/app/tabs/vnets-tab.js b/src/sunstone/public/app/tabs/vnets-tab.js index 095464034f..603ac35726 100644 --- a/src/sunstone/public/app/tabs/vnets-tab.js +++ b/src/sunstone/public/app/tabs/vnets-tab.js @@ -33,7 +33,8 @@ define(function(require) { require('./vnets-tab/panels/info'), require('./vnets-tab/panels/ar'), require('./vnets-tab/panels/leases'), - require('./vnets-tab/panels/secgroups') + require('./vnets-tab/panels/secgroups'), + require('./vnets-tab/panels/vrouters') ]; var _panelsHooks = [ diff --git a/src/sunstone/public/app/tabs/vnets-tab/panels/vrouters.js b/src/sunstone/public/app/tabs/vnets-tab/panels/vrouters.js new file mode 100644 index 0000000000..6df69d6455 --- /dev/null +++ b/src/sunstone/public/app/tabs/vnets-tab/panels/vrouters.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 VirtualRoutersTable = require('tabs/vrouters-tab/datatable'); + + /* + CONSTANTS + */ + + var PANEL_ID = require('./vrouters/panelId'); + var VR_TABLE_ID = PANEL_ID + "VirtualRoutersTable"; + var RESOURCE = "Network"; + var XML_ROOT = "VNET"; + + /* + CONSTRUCTOR + */ + + function Panel(info) { + this.title = Locale.tr("V. Routers"); + this.icon = "fa-random"; + + 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 vrs = []; + + if (this.element.VROUTERS.ID != undefined){ + vrs = this.element.VROUTERS.ID; + + if (!$.isArray(vrs)){ + vrs = [vrs]; + } + } + + var opts = { + info: true, + select: true, + selectOptions: { + read_only: true, + fixed_ids: vrs + } + }; + + this.vroutersTable = new VirtualRoutersTable(VR_TABLE_ID, opts); + + return this.vroutersTable.dataTableHTML; + } + + function _setup(context) { + this.vroutersTable.initialize(); + this.vroutersTable.refreshResourceTableSelect(); + + return false; + } +}); diff --git a/src/sunstone/public/app/tabs/vnets-tab/panels/vrouters/panelId.js b/src/sunstone/public/app/tabs/vnets-tab/panels/vrouters/panelId.js new file mode 100644 index 0000000000..a189897582 --- /dev/null +++ b/src/sunstone/public/app/tabs/vnets-tab/panels/vrouters/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 'vnet_vr_list_tab'; +}) diff --git a/src/sunstone/public/app/tabs/vrouters-tab/datatable.js b/src/sunstone/public/app/tabs/vrouters-tab/datatable.js index c9a6b79610..edced70510 100644 --- a/src/sunstone/public/app/tabs/vrouters-tab/datatable.js +++ b/src/sunstone/public/app/tabs/vrouters-tab/datatable.js @@ -56,6 +56,7 @@ define(function(require) { this.columns = [ Locale.tr("ID"), + Locale.tr("VMID"), Locale.tr("Owner"), Locale.tr("Group"), Locale.tr("Name") @@ -63,7 +64,7 @@ define(function(require) { this.selectOptions = { "id_index": 1, - "name_index": 4, + "name_index": 5, "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"), @@ -91,6 +92,7 @@ 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 9bddedcf31..877baf34ae 100644 --- a/src/sunstone/public/app/tabs/vrouters-tab/panels/info.js +++ b/src/sunstone/public/app/tabs/vrouters-tab/panels/info.js @@ -24,6 +24,8 @@ define(function(require) { var PermissionsTable = require('utils/panel/permissions-table'); var RenameTr = require('utils/panel/rename-tr'); var OpenNebulaVirtualRouter = require('opennebula/virtualrouter'); + var Sunstone = require('sunstone'); + var Config = require('sunstone-config'); /* TEMPLATES @@ -65,6 +67,13 @@ 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? @@ -78,12 +87,22 @@ define(function(require) { return TemplateInfo({ 'element': this.element, 'renameTrHTML': renameTrHTML, + 'vmid': vmid, 'permissionsTableHTML': permissionsTableHTML, 'templateTableHTML': templateTableHTML }); } function _setup(context) { + $("a.vmid", context).on("click", function(){ + // TODO: this should be checked internally in showElement, + // but it won't work because of bug #4198 + + if (Config.isTabEnabled("vms-tab")){ + Sunstone.showElement("vms-tab", "VM.show", $(this).text()); + } + }); + RenameTr.setup(TAB_ID, RESOURCE, this.element.ID, context); PermissionsTable.setup(TAB_ID, RESOURCE, this.element, context); 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 cdf7437679..c4846490f1 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 @@ -18,7 +18,7 @@
- + @@ -28,6 +28,16 @@ {{{renameTrHTML}}} + + + +
{{tr "Information"}}
{{element.ID}}
{{tr "VM ID"}} + {{#if vmid}} + {{vmid}} + {{else}} + -- + {{/if}} +
diff --git a/src/vm/VirtualMachine.cc b/src/vm/VirtualMachine.cc index 13f2ea549d..e04e66cd16 100644 --- a/src/vm/VirtualMachine.cc +++ b/src/vm/VirtualMachine.cc @@ -428,6 +428,17 @@ int VirtualMachine::insert(SqlDB * db, string& error_str) goto error_defaults; } + // ------------------------------------------------------------------------ + // Parse the virtual router attributes + // ------------------------------------------------------------------------ + + rc = parse_vrouter(error_str); + + if ( rc != 0 ) + { + goto error_vrouter; + } + // ------------------------------------------------------------------------ // Get network leases // ------------------------------------------------------------------------ @@ -584,6 +595,7 @@ error_one_vms: error_os: error_defaults: +error_vrouter: error_public: error_name: error_common: @@ -823,6 +835,32 @@ error_cleanup: return -1; } +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + +int VirtualMachine::parse_vrouter(string& error_str) +{ + string st; + + user_obj_template->get("VROUTER", st); + + if (!st.empty()) + { + obj_template->replace("VROUTER", st); + } + + user_obj_template->get("VROUTER_ID", st); + + if (!st.empty()) + { + obj_template->replace("VROUTER_ID", st); + } + + user_obj_template->erase("VROUTER"); + user_obj_template->erase("VROUTER_ID"); + + return 0; +} /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ @@ -2551,6 +2589,7 @@ VectorAttribute * VirtualMachine::get_attach_nic_info( int VirtualMachine::set_up_attach_nic( int vm_id, set& vm_sgs, + int vm_vrid, VectorAttribute * new_nic, vector &rules, int max_nic_id, @@ -2562,7 +2601,8 @@ int VirtualMachine::set_up_attach_nic( set nic_sgs; - int rc = vnpool->nic_attribute(new_nic, max_nic_id+1, uid, vm_id, error_str); + int rc = vnpool->nic_attribute(new_nic, max_nic_id+1, uid, vm_id, + vm_vrid, error_str); if ( rc == -1 ) //-2 is not using a pre-defined network { @@ -2962,7 +3002,7 @@ int VirtualMachine::get_network_leases(string& estr) merge_nic_defaults(nic); - rc = vnpool->nic_attribute(nic, i, uid, oid, estr); + rc = vnpool->nic_attribute(nic, i, uid, oid, get_vrouter_id(), estr); if (rc == -1) { @@ -3028,14 +3068,15 @@ void VirtualMachine::release_network_leases() VectorAttribute const * nic = dynamic_cast(nics[i]); - release_network_leases(nic, oid); + release_network_leases(nic, oid, get_vrouter_id()); } } /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ -int VirtualMachine::release_network_leases(VectorAttribute const * nic, int vmid) +int VirtualMachine::release_network_leases( + VectorAttribute const * nic, int vmid, int vrid) { VirtualNetworkPool* vnpool = Nebula::instance().get_vnpool(); VirtualNetwork* vn; @@ -3073,11 +3114,11 @@ int VirtualMachine::release_network_leases(VectorAttribute const * nic, int vmid if (nic->vector_value("AR_ID", ar_id) == 0) { - vn->free_addr(ar_id, vmid, mac); + vn->free_addr(ar_id, vmid, vrid, mac); } else { - vn->free_addr(vmid, mac); + vn->free_addr(vmid, vrid, mac); } vnpool->update(vn); @@ -3207,6 +3248,21 @@ void VirtualMachine::release_security_groups(int id, const VectorAttribute *nic) /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ +int VirtualMachine::get_vrouter_id() +{ + int vrid; + + if (!obj_template->get("VROUTER_ID", vrid)) + { + vrid = -1; + } + + return vrid; +} + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + int VirtualMachine::generate_context(string &files, int &disk_id, string& token_password) { diff --git a/src/vm/VirtualMachinePool.cc b/src/vm/VirtualMachinePool.cc index b3c4a7220e..bba8042927 100644 --- a/src/vm/VirtualMachinePool.cc +++ b/src/vm/VirtualMachinePool.cc @@ -1119,6 +1119,7 @@ void VirtualMachinePool::delete_attach_nic(int vid) int uid; int gid; int oid; + int vrid; vm = get(vid,true); @@ -1127,10 +1128,11 @@ void VirtualMachinePool::delete_attach_nic(int vid) return; } - nic = vm->delete_attach_nic(); - uid = vm->get_uid(); - gid = vm->get_gid(); - oid = vm->get_oid(); + nic = vm->delete_attach_nic(); + uid = vm->get_uid(); + gid = vm->get_gid(); + oid = vm->get_oid(); + vrid = vm->get_vrouter_id(); update(vm); @@ -1144,6 +1146,6 @@ void VirtualMachinePool::delete_attach_nic(int vid) Quotas::quota_del(Quotas::NETWORK, uid, gid, &tmpl); - VirtualMachine::release_network_leases(nic, oid); + VirtualMachine::release_network_leases(nic, oid, vrid); } } diff --git a/src/vnm/VirtualNetwork.cc b/src/vnm/VirtualNetwork.cc index 5db50b9557..7068f4d9d2 100644 --- a/src/vnm/VirtualNetwork.cc +++ b/src/vnm/VirtualNetwork.cc @@ -46,7 +46,8 @@ VirtualNetwork::VirtualNetwork(int _uid, PoolObjectSQL(-1,NET,"",_uid,_gid,_uname,_gname,table), Clusterable(_cluster_id, _cluster_name), bridge(""), - parent_vid(_pvid) + parent_vid(_pvid), + vrouters("VROUTERS") { if (_vn_template != 0) { @@ -418,6 +419,7 @@ string& VirtualNetwork::to_xml_extended(string& xml, bool extended, { ostringstream os; + string vrouters_xml; string template_xml; string leases_xml; string perm_str; @@ -464,6 +466,8 @@ string& VirtualNetwork::to_xml_extended(string& xml, bool extended, } os << ""<< ar_pool.get_used_addr() << ""; + os << vrouters.to_xml(vrouters_xml); + os << obj_template->to_xml(template_xml); os << ar_pool.to_xml(leases_xml, extended, vms, vnets); @@ -506,6 +510,18 @@ int VirtualNetwork::from_xml(const string &xml_str) xpath(vlan_id,"/VNET/VLAN_ID",""); xpath(parent_vid,"/VNET/PARENT_NETWORK_ID",-1); + ObjectXML::get_nodes("/VNET/VROUTERS", content); + + if (content.empty()) + { + return -1; + } + + rc += vrouters.from_xml_node(content[0]); + + ObjectXML::free_nodes(content); + content.clear(); + // Virtual Network template ObjectXML::get_nodes("/VNET/TEMPLATE", content); @@ -553,6 +569,7 @@ int VirtualNetwork::from_xml(const string &xml_str) int VirtualNetwork::nic_attribute( VectorAttribute * nic, int vid, + int vrid, const vector& inherit_attrs) { string inherit_val; @@ -642,6 +659,11 @@ int VirtualNetwork::nic_attribute( nic->replace("SECURITY_GROUPS", one_util::join(nic_sgs.begin(), nic_sgs.end(), ',')); + if (rc == 0 && vrid != -1) + { + vrouters.add_collection_id(vrid); + } + return rc; } diff --git a/src/vnm/VirtualNetworkPool.cc b/src/vnm/VirtualNetworkPool.cc index c38724a835..1b702d2c78 100644 --- a/src/vnm/VirtualNetworkPool.cc +++ b/src/vnm/VirtualNetworkPool.cc @@ -243,6 +243,7 @@ int VirtualNetworkPool::nic_attribute(VectorAttribute * nic, int nic_id, int uid, int vid, + int vrid, string& error) { string network; @@ -268,7 +269,7 @@ int VirtualNetworkPool::nic_attribute(VectorAttribute * nic, return -1; } - int rc = vnet->nic_attribute(nic, vid, inherit_attrs); + int rc = vnet->nic_attribute(nic, vid, vrid, inherit_attrs); if ( rc == 0 ) { diff --git a/src/vrouter/VirtualRouter.cc b/src/vrouter/VirtualRouter.cc index 6c91771bda..0dc8c7f94b 100644 --- a/src/vrouter/VirtualRouter.cc +++ b/src/vrouter/VirtualRouter.cc @@ -27,7 +27,8 @@ VirtualRouter::VirtualRouter( int id, const string& _gname, int _umask, Template * _template_contents): - PoolObjectSQL(id,VROUTER,"",_uid,_gid,_uname,_gname,table) + PoolObjectSQL(id,VROUTER,"",_uid,_gid,_uname,_gname,table), + vmid(-1) { if (_template_contents != 0) { @@ -197,6 +198,7 @@ string& VirtualRouter::to_xml(string& xml) const << "" << uname << "" << "" << gname << "" << "" << name << "" + << "" << vmid << "" << perms_to_xml(perm_str) << obj_template->to_xml(template_xml) << ""; @@ -224,6 +226,7 @@ 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();