From 4dbc572e3f12c761dcbad60834931c55fe8ee7b7 Mon Sep 17 00:00:00 2001 From: Hector Sanjuan Date: Mon, 16 Jan 2012 11:42:08 +0100 Subject: [PATCH 01/17] SelfService: remove usage of resource_str Helper. Disallow creation of VMs with empty name. (cherry picked from commit 33dd4ac3139e9a250d14b13c94222df5fb7d045f) --- src/cloud/occi/lib/ui/public/js/occi.js | 65 ------------------- .../occi/lib/ui/public/js/plugins/compute.js | 5 +- .../occi/lib/ui/public/js/plugins/storage.js | 2 +- 3 files changed, 4 insertions(+), 68 deletions(-) diff --git a/src/cloud/occi/lib/ui/public/js/occi.js b/src/cloud/occi/lib/ui/public/js/occi.js index b5444a50c7..004938dc67 100644 --- a/src/cloud/occi/lib/ui/public/js/occi.js +++ b/src/cloud/occi/lib/ui/public/js/occi.js @@ -64,71 +64,6 @@ var OCCI = { }, "Helper": { - "resource_state": function(type, value) - { - switch(type) - { - case "HOST","host": - return ["INIT", - "MONITORING", - "MONITORED", - "ERROR", - "DISABLED"][value]; - break; - case "HOST_SIMPLE","host_simple": - return ["ON", - "ON", - "ON", - "ERROR", - "OFF"][value]; - break; - case "VM","vm": - return ["INIT", - "PENDING", - "HOLD", - "ACTIVE", - "STOPPED", - "SUSPENDED", - "DONE", - "FAILED"][value]; - break; - case "VM_LCM","vm_lcm": - return ["LCM_INIT", - "PROLOG", - "BOOT", - "RUNNING", - "MIGRATE", - "SAVE_STOP", - "SAVE_SUSPEND", - "SAVE_MIGRATE", - "PROLOG_MIGRATE", - "PROLOG_RESUME", - "EPILOG_STOP", - "EPILOG", - "SHUTDOWN", - "CANCEL", - "FAILURE", - "CLEANUP", - "UNKNOWN"][value]; - break; - case "IMAGE","image": - return ["INIT", - "READY", - "USED", - "DISABLED", - "LOCKED", - "ERROR"][value]; - break; - default: - return; - } - }, - - "image_type": function(value) - { - return ["OS", "CDROM", "DATABLOCK"][value]; - }, - "action": function(action, params) { obj = { diff --git a/src/cloud/occi/lib/ui/public/js/plugins/compute.js b/src/cloud/occi/lib/ui/public/js/plugins/compute.js index aaab2fc1c4..c5bc985d1b 100644 --- a/src/cloud/occi/lib/ui/public/js/plugins/compute.js +++ b/src/cloud/occi/lib/ui/public/js/plugins/compute.js @@ -523,7 +523,7 @@ function updateVMInfo(request,vm){ \ \ '+tr("Instance type")+'\ - '+vm_info.INSTANCE_TYPE+'\ + '+(vm_info.INSTANCE_TYPE ? vm_info.INSTANCE_TYPE : "--")+'\ \ \ '+tr("State")+'\ @@ -739,6 +739,7 @@ function popUpCreateVMDialog(){ if (!vm_name.length){ notifyError("Please specify a name for the virtual machine"); + return false; }; var vm = { @@ -1043,7 +1044,7 @@ function vncCallback(request,response){ function vncIcon(vm){ var graphics = vm.TEMPLATE.GRAPHICS; - var state = OCCI.Helper.resource_state("vm_lcm",vm.LCM_STATE); + var state = vm.STATE; var gr_icon; if (graphics && graphics.TYPE == "vnc" && state == "RUNNING"){ gr_icon = ''; diff --git a/src/cloud/occi/lib/ui/public/js/plugins/storage.js b/src/cloud/occi/lib/ui/public/js/plugins/storage.js index 5b7f768d40..b4542daa82 100644 --- a/src/cloud/occi/lib/ui/public/js/plugins/storage.js +++ b/src/cloud/occi/lib/ui/public/js/plugins/storage.js @@ -373,7 +373,7 @@ function updateImageInfo(request,img){ \ \ '+tr("Type")+'\ - '+OCCI.Helper.image_type(img_info.TYPE)+'\ + '+img_info.TYPE+'\ \ \ '+tr("Persistent")+'\ From ef241ba919bccf997961a99844e8dfaed96ae43a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Wed, 18 Jan 2012 18:13:19 +0100 Subject: [PATCH 02/17] Fix description in xml-rpc chmod methods --- include/RequestManagerChmod.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/include/RequestManagerChmod.h b/include/RequestManagerChmod.h index 815ba561a7..60282af845 100644 --- a/include/RequestManagerChmod.h +++ b/include/RequestManagerChmod.h @@ -31,7 +31,7 @@ class RequestManagerChmod : public Request protected: RequestManagerChmod(const string& method_name, const string& help, - const string& params = "A:siii") + const string& params = "A:siiiiiiiiii") :Request(method_name,params,help){}; ~RequestManagerChmod(){}; @@ -50,7 +50,7 @@ class VirtualMachineChmod : public RequestManagerChmod public: VirtualMachineChmod(): RequestManagerChmod("VirtualMachineChmod", - "Changes ownership of a virtual machine") + "Changes permission bits of a virtual machine") { Nebula& nd = Nebula::instance(); pool = nd.get_vmpool(); @@ -68,7 +68,7 @@ class TemplateChmod : public RequestManagerChmod public: TemplateChmod(): RequestManagerChmod("TemplateChmod", - "Changes ownership of a virtual machine template") + "Changes permission bits of a virtual machine template") { Nebula& nd = Nebula::instance(); pool = nd.get_tpool(); @@ -87,7 +87,7 @@ class VirtualNetworkChmod: public RequestManagerChmod public: VirtualNetworkChmod(): RequestManagerChmod("VirtualNetworkChmod", - "Changes ownership of a virtual network") + "Changes permission bits of a virtual network") { Nebula& nd = Nebula::instance(); pool = nd.get_vnpool(); @@ -106,7 +106,7 @@ class ImageChmod: public RequestManagerChmod public: ImageChmod(): RequestManagerChmod("ImageChmod", - "Changes ownership of an image") + "Changes permission bits of an image") { Nebula& nd = Nebula::instance(); pool = nd.get_ipool(); From 89a82988df37152a0481a0835b7bdb7c98764609 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Wed, 18 Jan 2012 23:37:36 +0100 Subject: [PATCH 03/17] bug: Fixed number of restricted attributes constant (cherry picked from commit 38f67ef27b891e34eab91fe38f25ac4eb054d81e) --- src/vm/VirtualMachineTemplate.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/vm/VirtualMachineTemplate.cc b/src/vm/VirtualMachineTemplate.cc index 20fdf122c0..1f9686e294 100644 --- a/src/vm/VirtualMachineTemplate.cc +++ b/src/vm/VirtualMachineTemplate.cc @@ -28,7 +28,7 @@ const string VirtualMachineTemplate::RESTRICTED_ATTRIBUTES[] = { "RANK" }; -const int VirtualMachineTemplate::RS_ATTRS_LENGTH = 3; +const int VirtualMachineTemplate::RS_ATTRS_LENGTH = 5; /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ @@ -83,4 +83,4 @@ bool VirtualMachineTemplate::check(string& rs_attr) } return false; -} \ No newline at end of file +} From e38ebccd724645bb86905404c8d5ac697f81bfa7 Mon Sep 17 00:00:00 2001 From: Tino Vazquez Date: Thu, 19 Jan 2012 12:35:06 +0100 Subject: [PATCH 04/17] Add STATE to Image OCCI resources --- src/cloud/occi/lib/ImageOCCI.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cloud/occi/lib/ImageOCCI.rb b/src/cloud/occi/lib/ImageOCCI.rb index 8f873aaa93..c15cd97c0e 100755 --- a/src/cloud/occi/lib/ImageOCCI.rb +++ b/src/cloud/occi/lib/ImageOCCI.rb @@ -22,7 +22,8 @@ class ImageOCCI < Image OCCI_IMAGE = %q{ <%= self.id.to_s %> - <%= self.name %> + <%= self.name %><%= self.state_str %> <% if self['TYPE'] != nil %> <%= self.type_str %> <% end %> From 3e078c1725d4316db6c4904becd125f93f606f54 Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Thu, 19 Jan 2012 17:00:26 +0100 Subject: [PATCH 05/17] bug #1064: close connection after action finishes (VMM) (cherry picked from commit 7bace8a793c96dd60c8624200ca16d0ced1475a6) --- src/mad/ruby/ssh_stream.rb | 4 ++++ src/vmm_mad/exec/one_vmm_exec.rb | 3 +++ 2 files changed, 7 insertions(+) diff --git a/src/mad/ruby/ssh_stream.rb b/src/mad/ruby/ssh_stream.rb index f4ac1da47d..42ada93462 100644 --- a/src/mad/ruby/ssh_stream.rb +++ b/src/mad/ruby/ssh_stream.rb @@ -193,6 +193,10 @@ class SshStreamCommand < RemotesCommand return self end + + def close + @stream.close + end end diff --git a/src/vmm_mad/exec/one_vmm_exec.rb b/src/vmm_mad/exec/one_vmm_exec.rb index e26787c032..3570203cef 100755 --- a/src/vmm_mad/exec/one_vmm_exec.rb +++ b/src/vmm_mad/exec/one_vmm_exec.rb @@ -94,6 +94,9 @@ class VmmAction def run(steps, info_on_success = nil) result = execute_steps(steps) + @ssh_src.close if @ssh_src + @ssh_dst.close if @ssh_dst + #Prepare the info for the OpenNebula core if DriverExecHelper.failed?(result) info = @data[:failed_info] From d76deaeb2da7b2c704b2fb4f28627adf25d1648c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Thu, 19 Jan 2012 09:40:41 -0800 Subject: [PATCH 06/17] Avoid redefinition of oss variable for readability --- src/authm/AuthManager.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/authm/AuthManager.cc b/src/authm/AuthManager.cc index cbfb2741fc..348782c68a 100644 --- a/src/authm/AuthManager.cc +++ b/src/authm/AuthManager.cc @@ -88,7 +88,7 @@ void AuthRequest::add_auth(Operation op, if ( auth == false ) { - ostringstream oss; + oss.str(""); oss << message; From cfb7ed569151604705bc2e49e77e613409cd9798 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Thu, 19 Jan 2012 09:41:36 -0800 Subject: [PATCH 07/17] Update core tests for 3.2 --- src/authm/test/AuthManagerTest.cc | 21 ++-- src/host/test/HostPoolTest.cc | 8 +- src/image/test/ImagePoolTest.cc | 17 ++- src/um/test/UserPoolTest.cc | 2 +- src/vm/test/VirtualMachinePoolTest.cc | 30 ++--- src/vm_template/test/VMTemplatePoolTest.cc | 99 ++------------- src/vnm/test/VirtualNetworkPoolTest.cc | 138 +++++---------------- 7 files changed, 71 insertions(+), 244 deletions(-) diff --git a/src/authm/test/AuthManagerTest.cc b/src/authm/test/AuthManagerTest.cc index d0a82b8f86..38635216ff 100644 --- a/src/authm/test/AuthManagerTest.cc +++ b/src/authm/test/AuthManagerTest.cc @@ -180,10 +180,11 @@ public: //OBJECT:OBJECT_ID:ACTION:OWNER:PUBLIC:CORE_RESULT - string astr = "VM:VGhpcyBpcyBhIHRlbXBsYXRlCg==:CREATE:-1:0:0 " - "IMAGE:2:USE:3:0:0 " - "NET:4:MANAGE:5:1:0 " - "HOST:6:MANAGE:7:1:0 0"; + string astr = "VM:VGhpcyBpcyBhIHRlbXBsYXRlCg==:CREATE:2:0 " + "IMAGE:2:USE:3:0 " + "NET:4:MANAGE:5:0 " + "HOST:6:MANAGE:7:0 " + "0"; PoolObjectAuth perm; @@ -230,7 +231,7 @@ public: AuthRequest ar1(2, 2); - string astr1= "VM:VGhpcyBpcyBhIHRlbXBsYXRlCg==:CREATE:-1:0:0 0"; + string astr1= "VM:VGhpcyBpcyBhIHRlbXBsYXRlCg==:CREATE:2:0 0"; ar1.add_create_auth(PoolObjectSQL::VM, "This is a template\n"); @@ -259,15 +260,15 @@ public: am->trigger(AuthManager::AUTHORIZE,&ar2); ar2.wait(); //* - if ( ar1.result != false ) + if ( ar2.result != false ) { - cout << endl << "ar.result: " << ar1.result << endl; + cout << endl << "ar2.result: " << ar2.result << endl; } - if ( ar1.message != astr1 ) + if ( ar2.message != astr2 ) { - cout << endl << "ar.message: " << ar1.message; - cout << endl << "expected: " << astr1 << endl; + cout << endl << "ar2.message: " << ar2.message; + cout << endl << "expected: " << astr2 << endl; } //*/ CPPUNIT_ASSERT(ar2.result==false); diff --git a/src/host/test/HostPoolTest.cc b/src/host/test/HostPoolTest.cc index 1e87ecbde0..044d154d63 100644 --- a/src/host/test/HostPoolTest.cc +++ b/src/host/test/HostPoolTest.cc @@ -181,7 +181,7 @@ protected: host->to_xml(xml_str); // A little help for debugging -/* +//* if( xml_str != xmls[index] ) { cout << endl << xml_str << endl << "========" @@ -284,7 +284,7 @@ public: string result = oss.str(); // A little help for debugging -/* +//* if( result != xml_dump ) { cout << endl << result << endl << "========" @@ -311,14 +311,14 @@ public: ostringstream oss; - rc = ((HostPool*)pool)->dump(oss, "name LIKE 'a%' ORDER BY oid"); + rc = ((HostPool*)pool)->dump(oss, "name LIKE 'a%'"); CPPUNIT_ASSERT(rc == 0); string result = oss.str(); // A little help for debugging -/* +//* if( result != xml_dump_like_a ) { cout << endl << result << endl << "========" diff --git a/src/image/test/ImagePoolTest.cc b/src/image/test/ImagePoolTest.cc index c127433492..feb835aea9 100644 --- a/src/image/test/ImagePoolTest.cc +++ b/src/image/test/ImagePoolTest.cc @@ -40,7 +40,6 @@ const string templates[] = "NAME = \"Second Image\"\n" "PATH = /tmp/image_second_test\n" - "PUBLIC = YES\n" "DESCRIPTION = \"This is a rather short description.\"\n", "NAME = \"The third image\"\n" @@ -52,20 +51,20 @@ const string templates[] = const string xmls[] = { -"001oneoneadminImage one0010000000000/tmp/image_test040", +"001oneoneadminImage one110000000010000000000/tmp/image_test040", -"111twooneadminSecond Image0100000000000/tmp/image_second_test040", +"111twooneadminSecond Image110000000000000000000/tmp/image_second_test040", -"021threeusersThe third image0000000000000/tmp/image_test040", +"021threeusersThe third image110000000000000000000/tmp/image_test040", }; // This xml dump result has the STIMEs modified to 0000000000 const string xml_dump = -"001oneoneadminImage one0010000000000/tmp/image_test040111twooneadminSecond Image0100000000000/tmp/image_second_test040221threeusersThe third image0000000000000/tmp/image_test040"; +"001oneoneadminImage one110000000010000000000/tmp/image_test040111twooneadminSecond Image110000000000000000000/tmp/image_second_test040221threeusersThe third image110000000000000000000/tmp/image_test040"; const string xml_dump_where = -"001oneoneadminImage one0010000000000/tmp/image_test040111twooneadminSecond Image0100000000000/tmp/image_second_test040"; +"001oneoneadminImage one110000000010000000000/tmp/image_test040111twooneadminSecond Image110000000000000000000/tmp/image_second_test040"; /* ************************************************************************* */ /* ************************************************************************* */ @@ -190,7 +189,7 @@ protected: ((Image*)obj)->to_xml(xml_str); fix_regtimes(xml_str); -/* +//* if( xml_str != xmls[index] ) { cout << endl << xml_str << endl << xmls[index] << endl; @@ -860,7 +859,7 @@ public: string result = oss.str(); fix_regtimes(result); -/* +//* if( result != xml_dump ) { cout << endl << result << endl << xml_dump << endl; @@ -893,7 +892,7 @@ public: string result = oss.str(); fix_regtimes(result); -/* +//* if( result != xml_dump_where ) { cout << endl << result << endl << xml_dump_where << endl; diff --git a/src/um/test/UserPoolTest.cc b/src/um/test/UserPoolTest.cc index 8e37a4d080..9ae1b6f78b 100644 --- a/src/um/test/UserPoolTest.cc +++ b/src/um/test/UserPoolTest.cc @@ -362,7 +362,7 @@ public: // by" is a dirty fix (SQL injection, actually) because MySQL orders the // results by user_name ostringstream oss; - ((UserPool*)pool)->dump(oss, "name LIKE 'a%' ORDER BY oid"); + ((UserPool*)pool)->dump(oss, "name LIKE 'a%'"); //* if( oss.str() != dump_where_result ) diff --git a/src/vm/test/VirtualMachinePoolTest.cc b/src/vm/test/VirtualMachinePoolTest.cc index 75e93edd45..ae6ecd8b1d 100644 --- a/src/vm/test/VirtualMachinePoolTest.cc +++ b/src/vm/test/VirtualMachinePoolTest.cc @@ -46,19 +46,9 @@ const string templates[] = const string xmls[] = { - "01231the_userusersVM one010000000000000000", + "01231the_userusersVM one110000000010000000000000000", - "12611the_userusersSecond VM0" - "1000000000000<" - "/ETIME>0000", + "12611the_userusersSecond VM110000000010000000000000000", "01231the_userusersVM one01000000000000011the_userusersVM one010000000000000000121the_userusersSecond VM020000000000000000"; + "011the_userusersVM one110000000010000000000000000121the_userusersSecond VM110000000020000000000000000"; const string xml_dump_where = - "011the_userusersVM one010000000000000000"; + "011the_userusersVM one110000000010000000000000000"; const string xml_history_dump = - "001the_userusersVM one010000000000000000101the_userusersSecond VM0200000000000000000A_hostnameA_vm_dir000A_vmm_madA_vnm_madA_tm_mad0000000201the_userusersVM one0200000000000000001C_hostnameC_vm_dir200C_vmm_madC_vnm_madC_tm_mad0000000311the_userusersVM one060000000000000000"; + "001the_userusersVM one110000000010000000000000000101the_userusersSecond VM1100000000200000000000000000A_hostnameA_vm_dir000A_vmm_madA_vnm_madA_tm_mad0000000201the_userusersVM one1100000000200000000000000001C_hostnameC_vm_dir200C_vmm_madC_vnm_madC_tm_mad0000000311the_userusersVM one110000000060000000000000000"; /* ************************************************************************* */ /* ************************************************************************* */ @@ -169,7 +159,7 @@ protected: ((VirtualMachine*)obj)->to_xml(xml_str); fix_stimes(xml_str); -/* +//* if( xml_str != xmls[index] ) { cout << endl << xml_str << endl << "========" @@ -260,13 +250,11 @@ public: string result = oss.str(); fix_stimes(result); -/* if( result != xml_dump ) { cout << endl << result << endl << "========" << endl << xml_dump << endl << "--------"; } -*/ CPPUNIT_ASSERT( result == xml_dump ); } @@ -290,6 +278,12 @@ public: string result = oss.str(); fix_stimes(result); + if( result != xml_dump_where ) + { + cout << endl << result << endl << "========" + << endl << xml_dump_where << endl << "--------"; + } + CPPUNIT_ASSERT( result == xml_dump_where ); } diff --git a/src/vm_template/test/VMTemplatePoolTest.cc b/src/vm_template/test/VMTemplatePoolTest.cc index 142d6f7a8f..5e5c074b9d 100644 --- a/src/vm_template/test/VMTemplatePoolTest.cc +++ b/src/vm_template/test/VMTemplatePoolTest.cc @@ -45,9 +45,9 @@ const string templates[] = const string xmls[] = { - "000the_useroneadminTemplate one00000000000", + "000the_useroneadminTemplate one1100000000000000000", - "110the_useroneadminSecond Template00000000000", + "110the_useroneadminSecond Template1100000000000000000", "220the_useroneadminThird Template00000000000" }; @@ -55,9 +55,9 @@ const string xmls[] = // This xml dump result has the STIMEs modified to 0000000000 const string xml_dump = - "000the_useroneadminTemplate one00000000000110the_useroneadminSecond Template00000000000220the_useroneadminThird Template00000000000"; + "000the_useroneadminTemplate one1100000000000000000110the_useroneadminSecond Template1100000000000000000220the_useroneadminThird Template1100000000000000000"; const string xml_dump_where = - "000the_useroneadminTemplate one00000000000110the_useroneadminSecond Template00000000000"; + "000the_useroneadminTemplate one1100000000000000000110the_useroneadminSecond Template1100000000000000000"; class VMTemplatePoolFriend : public VMTemplatePool { @@ -108,7 +108,6 @@ class VMTemplatePoolTest : public PoolTest CPPUNIT_TEST ( get_using_name ); CPPUNIT_TEST ( wrong_get_name ); CPPUNIT_TEST ( duplicates ); -// CPPUNIT_TEST ( public_attribute ); CPPUNIT_TEST ( dump ); CPPUNIT_TEST ( dump_where ); @@ -146,7 +145,7 @@ protected: ((VMTemplate*)obj)->to_xml(xml_str); fix_regtimes( xml_str ); -/* +//* if( xml_str != xmls[index] ) { cout << endl << xml_str << endl << xmls[index] << endl; @@ -384,90 +383,6 @@ public: CPPUNIT_ASSERT( oid == rc ); } -/* -------------------------------------------------------------------------- */ -/* -------------------------------------------------------------------------- */ -/* - void public_attribute() - { - int oid; - VMTemplatePoolFriend * tpool = static_cast(pool); - VMTemplate * temp; - - string templates[] = - { - // false - "NAME = \"name A\"\n", - - // true - "NAME = \"name B\"\n" - "PUBLIC = YES", - - // false - "NAME = \"name C\"\n" - "PUBLIC = NO", - - // false - "NAME = \"name D\"\n" - "PUBLIC = 1", - - // true - "NAME = \"name E\"\n" - "PUBLIC = Yes", - - // false - "NAME = \"name F\"\n" - "PUBLIC = TRUE", - - // true - "NAME = \"name G\"\n" - "PUBLIC = yes", - - // false - "NAME = \"name H\"\n" - "PUBLIC = 'YES'", - - // true - "NAME = \"name I\"\n" - "PUBLIC = \"YES\"", - - "END" - }; - - bool results[] = { false, true, false, false, - true, false, true, false, true }; - - int i = 0; - while( templates[i] != "END" ) - { - - tpool->allocate(0, templates[i], &oid); - - CPPUNIT_ASSERT( oid >= 0 ); - - temp = tpool->get( oid, false ); - CPPUNIT_ASSERT( temp != 0 ); -//cout << endl << i << " : exp. " << results[i] << " got " << temp->is_public(); - - CPPUNIT_ASSERT( temp->isPublic() == results[i] ); - - i++; - } - - int success; - - // temp 0 is not public. - temp = tpool->get( 0, false ); - CPPUNIT_ASSERT( temp != 0 ); - - success = temp->publish(false); - CPPUNIT_ASSERT( success == 0 ); - CPPUNIT_ASSERT( temp->isPublic() == false ); - - success = temp->publish(true); - CPPUNIT_ASSERT( success == 0 ); - CPPUNIT_ASSERT( temp->isPublic() == true ); - } -*/ /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ @@ -489,7 +404,7 @@ public: string result = oss.str(); fix_regtimes(result); -/* +//* if( result != xml_dump ) { cout << endl << result << endl << xml_dump << endl; @@ -522,7 +437,7 @@ public: string result = oss.str(); fix_regtimes(result); -/* +//* if( result != xml_dump_where ) { cout << endl << result << endl << xml_dump_where << endl; diff --git a/src/vnm/test/VirtualNetworkPoolTest.cc b/src/vnm/test/VirtualNetworkPoolTest.cc index d63cf50dcd..a88378a321 100644 --- a/src/vnm/test/VirtualNetworkPoolTest.cc +++ b/src/vnm/test/VirtualNetworkPoolTest.cc @@ -43,8 +43,7 @@ const string templates[] = "TYPE = RANGED\n" "BRIDGE = br0\n" "NETWORK_SIZE = C\n" - "NETWORK_ADDRESS = 192.168.0.0\n" - "PUBLIC = YES", + "NETWORK_ADDRESS = 192.168.0.0", "NAME = \"Net number two\"\n" "TYPE = fixed\n" @@ -71,18 +70,18 @@ const string templates[] = const string xmls[] = { - "01230the_useroneadminNet number one1br1000130.10.0.150:20:20:20:20:200-1", + "01230the_useroneadminNet number one1100000001br100130.10.0.150:20:20:20:20:200-1", - "12610the_useroneadminA virtual network0br00192.168.0.1192.168.0.25410", + "12610the_useroneadminA virtual network1100000000br00192.168.0.1192.168.0.2540", - "01330the_useroneadminNet number two1br1000130.10.2.150:20:20:20:20:200-1", + "01330the_useroneadminNet number two1100000001br100130.10.2.150:20:20:20:20:200-1", }; const string xml_dump = - "010the_useroneadminNet number one1br1000120the_useroneadminA virtual network0br00192.168.0.1192.168.0.25410"; + "010the_useroneadminNet number one1100000001br100120the_useroneadminA virtual network1100000000br00192.168.0.1192.168.0.2540"; const string xml_dump_where = - "120the_useroneadminA virtual network0br00192.168.0.1192.168.0.25410"; + "120the_useroneadminA virtual network1100000000br00192.168.0.1192.168.0.2540"; /* ************************************************************************* */ /* ************************************************************************* */ @@ -165,7 +164,6 @@ class VirtualNetworkPoolTest : public PoolTest CPPUNIT_TEST (overlapping_leases_rf); CPPUNIT_TEST (overlapping_leases_rr); CPPUNIT_TEST (drop_leases); -// CPPUNIT_TEST (public_attribute); CPPUNIT_TEST (vnpool_nic_attribute); CPPUNIT_TEST (add_lease_fixed); @@ -213,7 +211,7 @@ protected: ((VirtualNetwork*)obj)->to_xml_extended(xml_str); -/* +//* if( xml_str != xmls[index] ) { cout << endl << xml_str << endl << "========" @@ -312,8 +310,8 @@ public: }; string phydev_xml[] = { - "000the_useroneadminBRIDGE and PHYDEV1br00eth000130.10.0.150:20:20:20:20:200-1", - "100the_useroneadminNo BRIDGE only PHYDEV1onebr10eth000130.10.0.150:20:20:20:20:200-1" + "000the_useroneadminBRIDGE and PHYDEV1100000001br01eth00130.10.0.150:20:20:20:20:200-1", + "100the_useroneadminNo BRIDGE only PHYDEV1100000001onebr11eth00130.10.0.150:20:20:20:20:200-1" }; // test vm with bridge and phydev @@ -325,6 +323,14 @@ public: ((VirtualNetwork*)vn)->to_xml_extended(xml_str); +//* + if( xml_str != phydev_xml[0] ) + { + cout << endl << xml_str << endl << "========" + << endl << phydev_xml[0] << endl << "--------"; + } +//*/ + CPPUNIT_ASSERT( xml_str == phydev_xml[0] ); // test vm with phydev only @@ -337,6 +343,15 @@ public: CPPUNIT_ASSERT( vn != 0 ); ((VirtualNetwork*)vn)->to_xml_extended(xml_str); + +//* + if( xml_str != phydev_xml[1] ) + { + cout << endl << xml_str << endl << "========" + << endl << phydev_xml[1] << endl << "--------"; + } +//*/ + CPPUNIT_ASSERT( xml_str == phydev_xml[1] ); } @@ -522,7 +537,7 @@ public: string result = oss.str(); -/* +//* if( result != xml_dump ) { cout << endl << result << endl << "========" @@ -553,7 +568,7 @@ public: string result = oss.str(); -/* +//* if( result != xml_dump_where ) { cout << endl << result << endl << "========" @@ -1039,103 +1054,6 @@ public: CPPUNIT_ASSERT(results.size() == 0); } -/* -------------------------------------------------------------------------- */ -/* -------------------------------------------------------------------------- */ -/* - void public_attribute() - { - int oid; - VirtualNetworkPoolFriend * vnp = - static_cast(pool); - VirtualNetwork * vn; - - string templates[] = - { - // false - "NAME = \"name A\"\n" - "TYPE = FIXED\n" - "BRIDGE = br1\n" - "LEASES = [IP=130.10.0.1, MAC=50:20:20:20:20:20]\n", - - // true - "NAME = \"name B\"\n" - "TYPE = FIXED\n" - "BRIDGE = br1\n" - "LEASES = [IP=130.10.0.1, MAC=50:20:20:20:20:20]\n" - "PUBLIC = YES", - - // false - "NAME = \"name C\"\n" - "TYPE = FIXED\n" - "BRIDGE = br1\n" - "LEASES = [IP=130.10.0.1, MAC=50:20:20:20:20:20]\n" - "PUBLIC = NO", - - // false - "NAME = \"name D\"\n" - "TYPE = FIXED\n" - "BRIDGE = br1\n" - "LEASES = [IP=130.10.0.1, MAC=50:20:20:20:20:20]\n" - "PUBLIC = 1", - - // true - "NAME = \"name E\"\n" - "TYPE = FIXED\n" - "BRIDGE = br1\n" - "LEASES = [IP=130.10.0.1, MAC=50:20:20:20:20:20]\n" - "PUBLIC = Yes", - - // false - "NAME = \"name F\"\n" - "TYPE = FIXED\n" - "BRIDGE = br1\n" - "LEASES = [IP=130.10.0.1, MAC=50:20:20:20:20:20]\n" - "PUBLIC = TRUE", - - // true - "NAME = \"name G\"\n" - "TYPE = FIXED\n" - "BRIDGE = br1\n" - "LEASES = [IP=130.10.0.1, MAC=50:20:20:20:20:20]\n" - "PUBLIC = yes", - - // false - "NAME = \"name H\"\n" - "TYPE = FIXED\n" - "BRIDGE = br1\n" - "LEASES = [IP=130.10.0.1, MAC=50:20:20:20:20:20]\n" - "PUBLIC = 'YES'", - - // true - "NAME = \"name I\"\n" - "TYPE = FIXED\n" - "BRIDGE = br1\n" - "LEASES = [IP=130.10.0.1, MAC=50:20:20:20:20:20]\n" - "PUBLIC = \"YES\"", - - "END" - }; - - bool results[] = { false, true, false, false, - true, false, true, false, true }; - - int i = 0; - while( templates[i] != "END" ) - { - - vnp->allocate(0, templates[i], &oid); - - CPPUNIT_ASSERT( oid >= 0 ); - - vn = vnp->get( oid, false ); - CPPUNIT_ASSERT( vn != 0 ); - -//cout << endl << i << ":expected " << results[i] << " got " << vn->is_public(); - CPPUNIT_ASSERT( vn->isPublic() == results[i] ); - i++; - } - } -*/ /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ From 5d357af63a58f032675dcb6e160b41642094bfe0 Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Fri, 20 Jan 2012 17:23:08 +0100 Subject: [PATCH 08/17] bug #1060: fix parameter order in ganglia poll(cherry picked from commit cd9f6d670545d1d69aeb36ed65ff12bf7373d4fd) --- src/vmm_mad/remotes/poll_ganglia.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/vmm_mad/remotes/poll_ganglia.rb b/src/vmm_mad/remotes/poll_ganglia.rb index c9eaa91180..cac5400e74 100755 --- a/src/vmm_mad/remotes/poll_ganglia.rb +++ b/src/vmm_mad/remotes/poll_ganglia.rb @@ -50,9 +50,8 @@ GANGLIA_PORT=8649 domain=ARGV[0] -dom_id=ARGV[1] -host=ARGV[2] - +dom_id=ARGV[2] +host=ARGV[1] # Gets monitoring data from ganglia or file begin From 6060d4821de121e632468b150261c1febdde6132 Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Fri, 20 Jan 2012 17:23:36 +0100 Subject: [PATCH 09/17] bug #1060: set VM to unknown when it cannot be monitoried(cherry picked from commit 2f4bf9bbe214bb84e138bb57fa354a0e3e7cefa8) --- src/vmm_mad/remotes/poll_ganglia.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/vmm_mad/remotes/poll_ganglia.rb b/src/vmm_mad/remotes/poll_ganglia.rb index cac5400e74..94a74cb946 100755 --- a/src/vmm_mad/remotes/poll_ganglia.rb +++ b/src/vmm_mad/remotes/poll_ganglia.rb @@ -68,6 +68,12 @@ end doms_info=ganglia.get_vms_information dom_id=domain.split('-').last +# Unknown state when the VM is not found +if !doms_info || !(doms_info[domain] || doms_info[dom_id]) + puts "STATE=d" + exit(0) +end + # Get key one- or key from the hash dom_info=doms_info[domain] dom_info=doms_info[dom_id] if !dom_info From 5bd2e8fa543d9f03ca45c16251ab696f57f16057 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Fri, 20 Jan 2012 17:45:14 +0100 Subject: [PATCH 10/17] Feature #940: Add restricted attributes for Images --- include/ImageTemplate.h | 14 ++++++ include/Template.h | 7 +++ include/VirtualMachineTemplate.h | 22 ++++---- src/image/Image.cc | 22 ++++++++ src/template/Template.cc | 54 ++++++++++++++++++++ src/vm/SConstruct | 3 +- src/vm/VirtualMachineTemplate.cc | 86 -------------------------------- 7 files changed, 108 insertions(+), 100 deletions(-) delete mode 100644 src/vm/VirtualMachineTemplate.cc diff --git a/include/ImageTemplate.h b/include/ImageTemplate.h index df7661e96a..7bd1b867ed 100644 --- a/include/ImageTemplate.h +++ b/include/ImageTemplate.h @@ -30,6 +30,20 @@ public: ImageTemplate() : Template(true,'=',"TEMPLATE"){}; ~ImageTemplate(){}; + + /** + * Checks the template for RESTRICTED ATTRIBUTES + * @param rs_attr the first restricted attribute found if any + * @return true if a restricted attribute is found in the template + */ + bool check(string& rs_attr) + { + vector restricted_attributes; + + restricted_attributes.push_back("SOURCE"); + + return Template::check(rs_attr, restricted_attributes); + }; }; /* -------------------------------------------------------------------------- */ diff --git a/include/Template.h b/include/Template.h index 79d2ec45bb..8a1dbe8b9a 100644 --- a/include/Template.h +++ b/include/Template.h @@ -221,6 +221,13 @@ protected: */ Attribute* vector_xml_att(const xmlNode * node); + /** + * Checks the template for RESTRICTED ATTRIBUTES + * @param rs_attr the first restricted attribute found if any + * @return true if a restricted attribute is found in the template + */ + bool check(string& rs_attr, const vector &restricted_attributes); + private: bool replace_mode; diff --git a/include/VirtualMachineTemplate.h b/include/VirtualMachineTemplate.h index 394de28d7f..f60cbca9a1 100644 --- a/include/VirtualMachineTemplate.h +++ b/include/VirtualMachineTemplate.h @@ -41,20 +41,18 @@ public: * @param rs_attr the first restricted attribute found if any * @return true if a restricted attribute is found in the template */ - bool check(string& rs_attr); + bool check(string& rs_attr) + { + vector restricted_attributes; -private: - /** - * Number of restricted attributes - */ - const static int RS_ATTRS_LENGTH; + restricted_attributes.push_back("CONTEXT/FILES"); + restricted_attributes.push_back("DISK/SOURCE"); + restricted_attributes.push_back("NIC/MAC"); + restricted_attributes.push_back("NIC/VLAN_ID"); + restricted_attributes.push_back("RANK"); - /** - * Restricted template attributes in the form - * 'SINGLE' or 'VECTOR/ATTR'. Restricted attributes are only - * allowed for ONE_ADMIN Group. - */ - const static string RESTRICTED_ATTRIBUTES[]; + return Template::check(rs_attr, restricted_attributes); + }; friend class VirtualMachine; }; diff --git a/src/image/Image.cc b/src/image/Image.cc index dca65bf838..181300ce56 100644 --- a/src/image/Image.cc +++ b/src/image/Image.cc @@ -93,6 +93,23 @@ int Image::insert(SqlDB *db, string& error_str) string persistent_attr; string dev_prefix; string source_attr; + string aname; + + ostringstream oss; + + // ------------------------------------------------------------------------ + // Check template for restricted attributes + // ------------------------------------------------------------------------ + + if ( uid != 0 && gid != GroupPool::ONEADMIN_ID ) + { + ImageTemplate *img_template = static_cast(obj_template); + + if (img_template->check(aname)) + { + goto error_restricted; + } + } // --------------------------------------------------------------------- // Check default image attributes @@ -204,6 +221,11 @@ error_path_and_source: error_str = "Template malformed, PATH and SOURCE are mutually exclusive."; goto error_common; +error_restricted: + oss << "Template includes a restricted attribute " << aname << "."; + error_str = oss.str(); + goto error_common; + error_common: NebulaLog::log("IMG", Log::ERROR, error_str); return -1; diff --git a/src/template/Template.cc b/src/template/Template.cc index bc4fe03011..71ea6b0539 100644 --- a/src/template/Template.cc +++ b/src/template/Template.cc @@ -533,3 +533,57 @@ void Template::rebuild_attributes(const xmlNode * root_element) /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ +bool Template::check(string& rs_attr, const vector &restricted_attributes) +{ + size_t pos; + string avector, vattr; + vector values; + + for (uint i=0; i < restricted_attributes.size(); i++) + { + pos = restricted_attributes[i].find("/"); + + if (pos != string::npos) //Vector Attribute + { + int num; + + avector = restricted_attributes[i].substr(0,pos); + vattr = restricted_attributes[i].substr(pos+1); + + if ((num = get(avector,values)) > 0 ) //Template contains the attr + { + const VectorAttribute * attr; + + for (int j=0; j(values[j]); + + if (attr == 0) + { + continue; + } + + if ( !attr->vector_value(vattr.c_str()).empty() ) + { + rs_attr = restricted_attributes[i]; + return true; + } + } + } + } + else //Single Attribute + { + if (get(avector,values) > 0 ) + { + rs_attr = restricted_attributes[i]; + return true; + } + } + } + + return false; +} + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + diff --git a/src/vm/SConstruct b/src/vm/SConstruct index bc041d804e..b69822ff24 100644 --- a/src/vm/SConstruct +++ b/src/vm/SConstruct @@ -40,8 +40,7 @@ source_files=[ 'vm_var_parser.c', 'vm_var_syntax.cc', 'VirtualMachinePool.cc', - 'VirtualMachineHook.cc', - 'VirtualMachineTemplate.cc' + 'VirtualMachineHook.cc' ] # Build library diff --git a/src/vm/VirtualMachineTemplate.cc b/src/vm/VirtualMachineTemplate.cc deleted file mode 100644 index 20fdf122c0..0000000000 --- a/src/vm/VirtualMachineTemplate.cc +++ /dev/null @@ -1,86 +0,0 @@ -/* -------------------------------------------------------------------------- */ -/* Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) */ -/* */ -/* 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. */ -/* -------------------------------------------------------------------------- */ - -#include "VirtualMachineTemplate.h" -#include - -/* -------------------------------------------------------------------------- */ -/* -------------------------------------------------------------------------- */ - -const string VirtualMachineTemplate::RESTRICTED_ATTRIBUTES[] = { - "CONTEXT/FILES", - "DISK/SOURCE", - "NIC/MAC", - "NIC/VLAN_ID", - "RANK" -}; - -const int VirtualMachineTemplate::RS_ATTRS_LENGTH = 3; - -/* -------------------------------------------------------------------------- */ -/* -------------------------------------------------------------------------- */ - -bool VirtualMachineTemplate::check(string& rs_attr) -{ - size_t pos; - string avector, vattr; - vector values; - - for (int i=0; i < RS_ATTRS_LENGTH ;i++) - { - pos = RESTRICTED_ATTRIBUTES[i].find("/"); - - if (pos != string::npos) //Vector Attribute - { - int num; - - avector = RESTRICTED_ATTRIBUTES[i].substr(0,pos); - vattr = RESTRICTED_ATTRIBUTES[i].substr(pos+1); - - if ((num = get(avector,values)) > 0 ) //Template contains the attr - { - const VectorAttribute * attr; - - for (int j=0; j(values[j]); - - if (attr == 0) - { - continue; - } - - if ( !attr->vector_value(vattr.c_str()).empty() ) - { - rs_attr = RESTRICTED_ATTRIBUTES[i]; - return true; - } - } - - } - } - else //Single Attribute - { - if (get(avector,values) > 0 ) - { - rs_attr = RESTRICTED_ATTRIBUTES[i]; - return true; - } - } - } - - return false; -} \ No newline at end of file From c38bfca2198a8a9dca89f4fec27718af33a7d64d Mon Sep 17 00:00:00 2001 From: Daniel Molina Date: Mon, 23 Jan 2012 15:24:42 +0100 Subject: [PATCH 11/17] bug #1079: Image quota error with ruby 1.8.7 --- src/authm_mad/remotes/quota/quota.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/authm_mad/remotes/quota/quota.rb b/src/authm_mad/remotes/quota/quota.rb index c86854526e..fedddd5f3e 100644 --- a/src/authm_mad/remotes/quota/quota.rb +++ b/src/authm_mad/remotes/quota/quota.rb @@ -82,7 +82,7 @@ class Quota if template['TYPE'] == 'DATABLOCK' template['SIZE'].to_i elsif template['PATH'] - (File.size(template['PATH']).to_f / 2**20).round(2) + (File.size(template['PATH']).to_f / 2**20).round elsif template['SAVED_VM_ID'] vm_id = template['SAVED_VM_ID'].to_i disk_id = template['SAVED_DISK_ID'].to_i From 6d4f4903da09314ada7f1f4aac318b2c35fad235 Mon Sep 17 00:00:00 2001 From: Hector Sanjuan Date: Mon, 23 Jan 2012 10:11:47 +0100 Subject: [PATCH 12/17] Bug #1077: Fix selfservice reaction to click on menu
  • items --- src/cloud/occi/lib/ui/public/js/plugins/compute.js | 2 +- src/cloud/occi/lib/ui/public/js/plugins/configuration.js | 2 +- src/cloud/occi/lib/ui/public/js/plugins/dashboard.js | 2 +- src/cloud/occi/lib/ui/public/js/plugins/network.js | 2 +- src/cloud/occi/lib/ui/public/js/plugins/storage.js | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/cloud/occi/lib/ui/public/js/plugins/compute.js b/src/cloud/occi/lib/ui/public/js/plugins/compute.js index c5bc985d1b..5550566e49 100644 --- a/src/cloud/occi/lib/ui/public/js/plugins/compute.js +++ b/src/cloud/occi/lib/ui/public/js/plugins/compute.js @@ -1101,7 +1101,7 @@ $(document).ready(function(){ tableCheckboxesListener(dataTable_vMachines); vMachineInfoListener(); - $('#li_vms_tab a').click(function(){ + $('#li_vms_tab').click(function(){ popUpVMDashboard(); }); diff --git a/src/cloud/occi/lib/ui/public/js/plugins/configuration.js b/src/cloud/occi/lib/ui/public/js/plugins/configuration.js index e25007fe91..c92844ac1e 100644 --- a/src/cloud/occi/lib/ui/public/js/plugins/configuration.js +++ b/src/cloud/occi/lib/ui/public/js/plugins/configuration.js @@ -55,7 +55,7 @@ $(document).ready(function(){ setLang($(this).val()); }); - $('#li_config_tab a').click(function(){ + $('#li_config_tab').click(function(){ hideDialog(); }); diff --git a/src/cloud/occi/lib/ui/public/js/plugins/dashboard.js b/src/cloud/occi/lib/ui/public/js/plugins/dashboard.js index 9e733ecb38..47b53d6278 100644 --- a/src/cloud/occi/lib/ui/public/js/plugins/dashboard.js +++ b/src/cloud/occi/lib/ui/public/js/plugins/dashboard.js @@ -169,7 +169,7 @@ $(document).ready(function(){ quickstart_setup(); - $('#li_dashboard_tab a').click(function(){ + $('#li_dashboard_tab').click(function(){ hideDialog(); }); diff --git a/src/cloud/occi/lib/ui/public/js/plugins/network.js b/src/cloud/occi/lib/ui/public/js/plugins/network.js index 257eb9cf04..98853b4202 100644 --- a/src/cloud/occi/lib/ui/public/js/plugins/network.js +++ b/src/cloud/occi/lib/ui/public/js/plugins/network.js @@ -445,7 +445,7 @@ $(document).ready(function(){ tableCheckboxesListener(dataTable_vNetworks); vNetworkInfoListener(); - $('#li_vnets_tab a').click(function(){ + $('#li_vnets_tab').click(function(){ popUpVNetDashboard(); //return false; }); diff --git a/src/cloud/occi/lib/ui/public/js/plugins/storage.js b/src/cloud/occi/lib/ui/public/js/plugins/storage.js index b4542daa82..f505615b1e 100644 --- a/src/cloud/occi/lib/ui/public/js/plugins/storage.js +++ b/src/cloud/occi/lib/ui/public/js/plugins/storage.js @@ -631,7 +631,7 @@ $(document).ready(function(){ tableCheckboxesListener(dataTable_images); imageInfoListener(); - $('#li_images_tab a').click(function(){ + $('#li_images_tab').click(function(){ popUpImageDashboard(); //return false; }); From f2e8103d35bbd7e950c93b379141047a2e2cbcae Mon Sep 17 00:00:00 2001 From: Hector Sanjuan Date: Mon, 23 Jan 2012 10:10:44 +0100 Subject: [PATCH 13/17] Bug #1078: Fix login redirection problems in SelfService --- src/cloud/occi/lib/occi-server.rb | 2 +- src/sunstone/public/js/sunstone-util.js | 9 ++++++++- src/sunstone/public/js/sunstone.js | 6 +++--- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/cloud/occi/lib/occi-server.rb b/src/cloud/occi/lib/occi-server.rb index cfadd287a2..5eb9a97846 100755 --- a/src/cloud/occi/lib/occi-server.rb +++ b/src/cloud/occi/lib/occi-server.rb @@ -324,7 +324,7 @@ post '/config' do end get '/ui/login' do - File.read(File.dirname(__FILE__)+'/ui/templates/login.html') + redirect to('ui') end post '/ui/login' do diff --git a/src/sunstone/public/js/sunstone-util.js b/src/sunstone/public/js/sunstone-util.js index b09f67013d..24a4cf81ae 100644 --- a/src/sunstone/public/js/sunstone-util.js +++ b/src/sunstone/public/js/sunstone-util.js @@ -326,7 +326,14 @@ function onError(request,error_json) { //redirect to login if unauthenticated if (error_json.error.http_status=="401") { - window.location.href = "login"; + switch (whichUI()){ + case "selfservice": + window.location.href = "ui"; + break; + default: + window.location.href = "login"; + }; + onError.disabled=false; return false; }; diff --git a/src/sunstone/public/js/sunstone.js b/src/sunstone/public/js/sunstone.js index bc9770fa5d..73cb79fd84 100644 --- a/src/sunstone/public/js/sunstone.js +++ b/src/sunstone/public/js/sunstone.js @@ -403,7 +403,7 @@ function setLogin(){ case "ozones": username = cookie["ozones-user"]; break; - case "occi": + case "selfservice": username = cookie["occi-user"]; break; }; @@ -420,7 +420,7 @@ function setLogin(){ case "ozones": oZones.Auth.logout({success:redirect}); break; - case "occi": + case "selfservice": OCCI.Auth.logout({success:function(){window.location.href = "ui";}}); break; } @@ -436,7 +436,7 @@ function whichUI(){ if (typeof(oZones)!="undefined") return "ozones"; if (typeof(OCCI)!="undefined") - return "occi"; + return "selfservice"; }; //Inserts all main tabs in the DOM From 177cad9136d6dd8d02a832976d59f96794bedfd8 Mon Sep 17 00:00:00 2001 From: Hector Sanjuan Date: Mon, 23 Jan 2012 11:59:53 +0100 Subject: [PATCH 14/17] Bug #1071: Several ozones GUI fixes * Wrong dashboard counts * Wrong listing of aggregated resources * Error when showing VMs in pending state in a zone view * Remove 'public' column from views, not used anymore, showed "no" all the time (cherry picked from commit 2c60d204f6e51c873258f231c527f4dd77cd6b7c) --- src/ozones/Server/public/js/ozones-util.js | 32 +++++++-------- .../public/js/plugins/aggregated-tab.js | 41 +++++++++++++------ .../Server/public/js/plugins/dashboard-tab.js | 33 --------------- .../Server/public/js/plugins/zones-tab.js | 11 ++--- 4 files changed, 47 insertions(+), 70 deletions(-) diff --git a/src/ozones/Server/public/js/ozones-util.js b/src/ozones/Server/public/js/ozones-util.js index fb3dcb36df..f7edb069d1 100644 --- a/src/ozones/Server/public/js/ozones-util.js +++ b/src/ozones/Server/public/js/ozones-util.js @@ -70,15 +70,15 @@ function updateVMsList(req,list,tag,zone_id,zone_name){ state, vm.CPU, humanize_size(vm.MEMORY), - vm.HISTORY_RECORDS ? vm.HISTORY_RECORDS.HISTORY.HOSTNAME : "--", + hostname, pretty_time(vm.STIME) ]); }; }); - updateView(vms_array,vmsDataTable); - -} + vmsDataTable.fnAddData(vms_array); + vmsDataTable.fnDraw(false); +}; function updateVNsList(req,list,tag,zone_id,zone_name){ var vnDataTable = $(tag).dataTable(); @@ -103,7 +103,6 @@ function updateVNsList(req,list,tag,zone_id,zone_name){ network.NAME, parseInt(network.TYPE) ? "FIXED" : "RANGED", network.BRIDGE, - parseInt(network.PUBLIC) ? "yes" : "no", total_leases ]); } else { @@ -114,14 +113,14 @@ function updateVNsList(req,list,tag,zone_id,zone_name){ network.NAME, parseInt(network.TYPE) ? "FIXED" : "RANGED", network.BRIDGE, - parseInt(network.PUBLIC) ? "yes" : "no", total_leases ]); } }); - updateView(vn_array,vnDataTable); -} + vnDataTable.fnAddData(vn_array); + vnDataTable.fnDraw(false); +}; function updateTemplatesList(req,list,tag,zone_id,zone_name){ var templateDataTable = $(tag).dataTable(); @@ -138,7 +137,6 @@ function updateTemplatesList(req,list,tag,zone_id,zone_name){ template.GNAME, template.NAME, pretty_time(template.REGTIME), - parseInt(template.PUBLIC) ? "yes" : "no" ]); } else { template_array.push([ @@ -147,11 +145,11 @@ function updateTemplatesList(req,list,tag,zone_id,zone_name){ template.GNAME, template.NAME, pretty_time(template.REGTIME), - parseInt(template.PUBLIC) ? "yes" : "no" ]); }; }); - updateView(template_array,templateDataTable); + templateDataTable.fnAddData(template_array); + templateDataTable.fnDraw(false); } function updateUsersList(req,list,tag, zone_id,zone_name){ @@ -186,8 +184,9 @@ function updateUsersList(req,list,tag, zone_id,zone_name){ } }); - updateView(user_array,userDataTable); -} + userDataTable.fnAddData(user_array); + userDataTable.fnDraw(false); +}; function updateImagesList(req,list,tag,zone_id,zone_name){ var imageDataTable = $(tag).dataTable(); @@ -206,7 +205,6 @@ function updateImagesList(req,list,tag,zone_id,zone_name){ image.NAME, oZones.Helper.image_type(image.TYPE), pretty_time(image.REGTIME), - parseInt(image.PUBLIC) ? "yes" : "no", parseInt(image.PERSISTENT) ? "yes" : "no", oZones.Helper.resource_state("image",image.STATE), image.RUNNING_VMS @@ -219,15 +217,15 @@ function updateImagesList(req,list,tag,zone_id,zone_name){ image.NAME, oZones.Helper.image_type(image.TYPE), pretty_time(image.REGTIME), - parseInt(image.PUBLIC) ? "yes" : "no", parseInt(image.PERSISTENT) ? "yes" : "no", oZones.Helper.resource_state("image",image.STATE), image.RUNNING_VMS ]); }; }); - updateView(image_array,imageDataTable); -} + imageDataTable.fnAddData(image_array); + imageDataTable.fnDraw(false); +}; function hostElementArray(host,zone_id,zone_name){ diff --git a/src/ozones/Server/public/js/plugins/aggregated-tab.js b/src/ozones/Server/public/js/plugins/aggregated-tab.js index 5afb381c3a..3286773632 100644 --- a/src/ozones/Server/public/js/plugins/aggregated-tab.js +++ b/src/ozones/Server/public/js/plugins/aggregated-tab.js @@ -70,7 +70,6 @@ var aggregated_vns_tab_content = Name\ Type\ Bridge\ - Public?\ Total Leases\ \ \ @@ -91,7 +90,6 @@ var aggregated_images_tab_content = Name\ Type\ Registration time\ - Public\ Persistent\ State\ #VMS\ @@ -129,7 +127,6 @@ var aggregated_templates_tab_content = Group\ Name\ Registration time\ - Public\ \ \ \ @@ -410,80 +407,98 @@ Sunstone.addMainTab("agg_templates_tab",templates_tab); function hostsListCB(req,list){ dataTable_agg_hosts.fnClearTable(); + var total_hosts = []; $.each(list,function(){ if (this.ZONE.error){ notifyError(this.ZONE.error.message); return; }; var host_json = oZones.Helper.pool("HOST",this.ZONE); + total_hosts = total_hosts.concat(host_json); updateHostsList(req, host_json,'#datatable_agg_hosts',this.ZONE.ID,this.ZONE.NAME); - updateZonesDashboard("hosts",host_json); }); + + updateZonesDashboard("hosts",total_hosts); } function vmsListCB(req,list){ dataTable_agg_vms.fnClearTable(); + var total_vms = []; $.each(list,function(){ if (this.ZONE.error){ notifyError(this.ZONE.error.message); return; }; var vms_json = oZones.Helper.pool("VM",this.ZONE); + total_vms = total_vms.concat(vms_json); updateVMsList(req, vms_json,'#datatable_agg_vms',this.ZONE.ID,this.ZONE.NAME); - updateZonesDashboard("vms",vms_json); }); + + updateZonesDashboard("vms",total_vms); } function vnsListCB(req,list){ dataTable_agg_vns.fnClearTable(); + var total_vns = []; $.each(list,function(){ if (this.ZONE.error){ notifyError(this.ZONE.error.message); return; }; var vn_json = oZones.Helper.pool("VNET",this.ZONE); + total_vns = total_vns.concat(vn_json); updateVNsList(req, vn_json,'#datatable_agg_vnets',this.ZONE.ID,this.ZONE.NAME); - updateZonesDashboard("vnets",vn_json); }); + + updateZonesDashboard("vnets",total_vns); } function imagesListCB(req,list){ dataTable_agg_images.fnClearTable(); + total_images = []; $.each(list,function(){ if (this.ZONE.error){ notifyError(this.ZONE.error.message); return; }; var image_json = oZones.Helper.pool("IMAGE",this.ZONE); + total_images = total_images.concat(image_json); updateImagesList(req,image_json,'#datatable_agg_images',this.ZONE.ID,this.ZONE.NAME); - updateZonesDashboard("images",image_json); }); + + updateZonesDashboard("images",total_images); } function usersListCB(req,list){ dataTable_agg_users.fnClearTable(); + var total_users = []; $.each(list,function(){ if (this.ZONE.error){ notifyError(this.ZONE.error.message); return; }; var user_json = oZones.Helper.pool("USER",this.ZONE); + total_users = total_users.concat(user_json); updateUsersList(req,user_json,'#datatable_agg_users',this.ZONE.ID,this.ZONE.NAME); - updateZonesDashboard("users",user_json); }); + + updateZonesDashboard("users",total_users); } function templatesListCB(req,list){ dataTable_agg_templates.fnClearTable(); + var total_templates = []; $.each(list,function(){ if (this.ZONE.error){ notifyError(this.ZONE.error.message); return; }; var template_json = oZones.Helper.pool("VMTEMPLATE",this.ZONE); + total_templates = total_templates.concat(template_json); updateTemplatesList(req,template_json,'#datatable_agg_templates',this.ZONE.ID,this.ZONE.NAME); - updateZonesDashboard("templates",template_json); }); + + updateZonesDashboard("templates",total_templates); } function setAutorefreshes(){ @@ -566,7 +581,7 @@ $(document).ready(function(){ "bAutoWidth":false, "sPaginationType": "full_numbers", "aoColumnDefs": [ - { "sWidth": "60px", "aTargets": [6,7,8,9] }, + { "sWidth": "60px", "aTargets": [6,7,8] }, { "sWidth": "35px", "aTargets": [0,2] }, { "sWidth": "100px", "aTargets": [1,3,4] } ] @@ -578,8 +593,8 @@ $(document).ready(function(){ "bAutoWidth":false, "sPaginationType": "full_numbers", "aoColumnDefs": [ - { "sWidth": "60px", "aTargets": [10] }, - { "sWidth": "35px", "aTargets": [0,2,8,9,11] }, + { "sWidth": "60px", "aTargets": [9] }, + { "sWidth": "35px", "aTargets": [0,2,8,10] }, { "sWidth": "100px", "aTargets": [1,3,4,6,7] } ] }); @@ -590,7 +605,7 @@ $(document).ready(function(){ "bAutoWidth":false, "sPaginationType": "full_numbers", "aoColumnDefs": [ - { "sWidth": "35px", "aTargets": [0,2,7] }, + { "sWidth": "35px", "aTargets": [0,2] }, { "sWidth": "100px", "aTargets": [1,3,4,6] } ] }); diff --git a/src/ozones/Server/public/js/plugins/dashboard-tab.js b/src/ozones/Server/public/js/plugins/dashboard-tab.js index 46eec7465b..4403394e5c 100644 --- a/src/ozones/Server/public/js/plugins/dashboard-tab.js +++ b/src/ozones/Server/public/js/plugins/dashboard-tab.js @@ -81,10 +81,6 @@ var dashboard_tab_content = Total\ \ \ - \ - Public\ - \ - \ \ \ \ @@ -124,10 +120,6 @@ var dashboard_tab_content = Total\ \ \ - \ - Public\ - \ - \ \ \ \ @@ -146,10 +138,6 @@ var dashboard_tab_content = Total\ \ \ - \ - Public\ - \ - \ \ \ \ @@ -180,7 +168,6 @@ var dashboard_tab = { Sunstone.addMainTab('dashboard_tab',dashboard_tab); $(document).ready(function(){ - //Dashboard link listener $("#dashboard_table h3 a").live("click", function (){ var tab = $(this).attr('href'); showTab(tab); @@ -220,15 +207,7 @@ function updateZonesDashboard(what,json_info){ break; case "templates": var total_templates=json_info.length; - var public_templates=0; - $.each(json_info,function(){ - if (parseInt(this.VMTEMPLATE.PUBLIC)){ - public_templates++; - }; - }); - $('#total_templates',db).html(total_templates); - $('#public_templates',db).html(public_templates); break; case "vms": var total_vms=json_info.length; @@ -248,14 +227,8 @@ function updateZonesDashboard(what,json_info){ $('#failed_vms',db).html(failed_vms); break; case "vnets": - var public_vnets=0; var total_vnets=json_info.length; - $.each(json_info,function(){ - if (parseInt(this.VNET.PUBLIC)){ - public_vnets++;} - }); $('#total_vnets',db).html(total_vnets); - $('#public_vnets',db).html(public_vnets); break; case "users": var total_users=json_info.length; @@ -263,13 +236,7 @@ function updateZonesDashboard(what,json_info){ break; case "images": var total_images=json_info.length; - var public_images=0; - $.each(json_info,function(){ - if (parseInt(this.IMAGE.PUBLIC)){ - public_images++;} - }); $('#total_images',db).html(total_images); - $('#public_images',db).html(public_images); break; } } diff --git a/src/ozones/Server/public/js/plugins/zones-tab.js b/src/ozones/Server/public/js/plugins/zones-tab.js index d8ea22a55a..4fbb8daeb4 100644 --- a/src/ozones/Server/public/js/plugins/zones-tab.js +++ b/src/ozones/Server/public/js/plugins/zones-tab.js @@ -352,7 +352,6 @@ function updateZoneInfo(req,zone_json){ Group\ Name\ Registration time\ - Public\ \ \ \ @@ -396,7 +395,6 @@ function updateZoneInfo(req,zone_json){ Name\ Type\ Bridge\ - Public?\ Total Leases\ \ \ @@ -418,7 +416,6 @@ function updateZoneInfo(req,zone_json){ Name\ Type\ Registration time\ - Public\ Persistent\ State\ #VMS\ @@ -490,7 +487,7 @@ function updateZoneInfo(req,zone_json){ "bAutoWidth":false, "sPaginationType": "full_numbers", "aoColumnDefs": [ - { "sWidth": "60px", "aTargets": [4,5,6,7] }, + { "sWidth": "60px", "aTargets": [4,5,6] }, { "sWidth": "35px", "aTargets": [0] }, { "sWidth": "100px", "aTargets": [1,2] } ] @@ -502,8 +499,8 @@ function updateZoneInfo(req,zone_json){ "bAutoWidth":false, "sPaginationType": "full_numbers", "aoColumnDefs": [ - { "sWidth": "60px", "aTargets": [8] }, - { "sWidth": "35px", "aTargets": [0,6,7,9] }, + { "sWidth": "60px", "aTargets": [7] }, + { "sWidth": "35px", "aTargets": [0,6,8] }, { "sWidth": "100px", "aTargets": [1,2,4,5] } ] }); @@ -514,7 +511,7 @@ function updateZoneInfo(req,zone_json){ "bAutoWidth":false, "sPaginationType": "full_numbers", "aoColumnDefs": [ - { "sWidth": "35px", "aTargets": [0,5] }, + { "sWidth": "35px", "aTargets": [0] }, { "sWidth": "100px", "aTargets": [1,2,4] } ] }); From deb244c1b655404432e73fcb9772bbed787a1913 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Mon, 23 Jan 2012 08:18:12 -0800 Subject: [PATCH 15/17] Feature #1070: Make VM and IMG restricted attributes configurable in oned.conf --- include/ImagePool.h | 3 ++- include/ImageTemplate.h | 11 +++++++---- include/VirtualMachinePool.h | 3 ++- include/VirtualMachineTemplate.h | 16 +++++++--------- share/etc/oned.conf | 17 +++++++++++++++- src/image/ImagePool.cc | 15 ++++++++++++++- src/image/ImageTemplate.cc | 33 ++++++++++++++++++++++++++++++++ src/image/SConstruct | 3 ++- src/nebula/Nebula.cc | 11 +++++++++-- src/template/Template.cc | 4 ++-- src/vm/SConstruct | 3 ++- src/vm/VirtualMachinePool.cc | 15 ++++++++++++++- src/vm/VirtualMachineTemplate.cc | 33 ++++++++++++++++++++++++++++++++ 13 files changed, 143 insertions(+), 24 deletions(-) create mode 100644 src/image/ImageTemplate.cc create mode 100644 src/vm/VirtualMachineTemplate.cc diff --git a/include/ImagePool.h b/include/ImagePool.h index 3a7b4bd05d..a2a54a2b04 100644 --- a/include/ImagePool.h +++ b/include/ImagePool.h @@ -40,7 +40,8 @@ public: ImagePool(SqlDB * db, const string& _default_type, - const string& _default_dev_prefix); + const string& _default_dev_prefix, + vector restricted_attrs); ~ImagePool(){}; diff --git a/include/ImageTemplate.h b/include/ImageTemplate.h index 7bd1b867ed..a7f141bd0d 100644 --- a/include/ImageTemplate.h +++ b/include/ImageTemplate.h @@ -38,12 +38,15 @@ public: */ bool check(string& rs_attr) { - vector restricted_attributes; - - restricted_attributes.push_back("SOURCE"); - return Template::check(rs_attr, restricted_attributes); }; + +private: + friend class ImagePool; + + static vector restricted_attributes; + + static void add_restricted_attribute(string& attr); }; /* -------------------------------------------------------------------------- */ diff --git a/include/VirtualMachinePool.h b/include/VirtualMachinePool.h index 2b90c15002..a8faa5570e 100644 --- a/include/VirtualMachinePool.h +++ b/include/VirtualMachinePool.h @@ -35,7 +35,8 @@ public: VirtualMachinePool(SqlDB * db, vector hook_mads, const string& hook_location, - const string& remotes_location); + const string& remotes_location, + vector restricted_attrs); ~VirtualMachinePool(){}; diff --git a/include/VirtualMachineTemplate.h b/include/VirtualMachineTemplate.h index f60cbca9a1..5475503294 100644 --- a/include/VirtualMachineTemplate.h +++ b/include/VirtualMachineTemplate.h @@ -43,18 +43,16 @@ public: */ bool check(string& rs_attr) { - vector restricted_attributes; - - restricted_attributes.push_back("CONTEXT/FILES"); - restricted_attributes.push_back("DISK/SOURCE"); - restricted_attributes.push_back("NIC/MAC"); - restricted_attributes.push_back("NIC/VLAN_ID"); - restricted_attributes.push_back("RANK"); - return Template::check(rs_attr, restricted_attributes); }; - friend class VirtualMachine; +private: + + friend class VirtualMachinePool; + + static vector restricted_attributes; + + static void add_restricted_attribute(string& attr); }; /* -------------------------------------------------------------------------- */ diff --git a/share/etc/oned.conf b/share/etc/oned.conf index 63c0b70e62..88fd8c0b29 100644 --- a/share/etc/oned.conf +++ b/share/etc/oned.conf @@ -471,4 +471,19 @@ AUTH_MAD = [ SESSION_EXPIRATION_TIME = 900 -#ENABLE_OTHER_PERMISSIONS = "YES" \ No newline at end of file +#ENABLE_OTHER_PERMISSIONS = "YES" + + +#******************************************************************************* +# Restricted Attributes Configuration +#******************************************************************************* +# The following attributes are restricted to users outside the oneadmin group +#******************************************************************************* + +VM_RESTRICTED_ATTR = "CONTEXT/FILES" +VM_RESTRICTED_ATTR = "DISK/SOURCE" +VM_RESTRICTED_ATTR = "NIC/MAC" +VM_RESTRICTED_ATTR = "NIC/VLAN_ID" +VM_RESTRICTED_ATTR = "RANK" + +IMAGE_RESTRICTED_ATTR = "SOURCE" diff --git a/src/image/ImagePool.cc b/src/image/ImagePool.cc index bebcfdf35c..ec7ccb0feb 100644 --- a/src/image/ImagePool.cc +++ b/src/image/ImagePool.cc @@ -33,10 +33,12 @@ string ImagePool::_default_dev_prefix; ImagePool::ImagePool(SqlDB * db, const string& __default_type, - const string& __default_dev_prefix): + const string& __default_dev_prefix, + vector restricted_attrs): PoolSQL(db,Image::table) { ostringstream sql; + const SingleAttribute * sattr; // Init static defaults _default_type = __default_type; @@ -50,6 +52,17 @@ ImagePool::ImagePool(SqlDB * db, NebulaLog::log("IMG", Log::ERROR, "Bad default for type, setting OS"); _default_type = "OS"; } + + // Set restricted attributes + for (unsigned int i = 0 ; i < restricted_attrs.size() ; i++ ) + { + sattr = static_cast(restricted_attrs[i]); + + string attr = sattr->value(); + transform (attr.begin(),attr.end(),attr.begin(),(int(*)(int))toupper); + + ImageTemplate::add_restricted_attribute(attr); + } } /* -------------------------------------------------------------------------- */ diff --git a/src/image/ImageTemplate.cc b/src/image/ImageTemplate.cc new file mode 100644 index 0000000000..2236e1bc39 --- /dev/null +++ b/src/image/ImageTemplate.cc @@ -0,0 +1,33 @@ +/* -------------------------------------------------------------------------- */ +/* Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) */ +/* */ +/* 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. */ +/* -------------------------------------------------------------------------- */ + +#include "ImageTemplate.h" + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + +vector ImageTemplate::restricted_attributes; + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + +void ImageTemplate::add_restricted_attribute(string& attr) +{ + restricted_attributes.push_back(attr); +} + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ diff --git a/src/image/SConstruct b/src/image/SConstruct index c906501b31..26d5f70e35 100644 --- a/src/image/SConstruct +++ b/src/image/SConstruct @@ -26,7 +26,8 @@ source_files=[ 'ImagePool.cc', 'ImageManagerDriver.cc', 'ImageManager.cc', - 'ImageManagerActions.cc' + 'ImageManagerActions.cc', + 'ImageTemplate.cc' ] # Build library diff --git a/src/nebula/Nebula.cc b/src/nebula/Nebula.cc index 785e485ab6..96523349dd 100644 --- a/src/nebula/Nebula.cc +++ b/src/nebula/Nebula.cc @@ -276,14 +276,20 @@ void Nebula::start() vector vm_hooks; vector host_hooks; + vector vm_restricted_attrs; + vector img_restricted_attrs; nebula_configuration->get("VM_HOOK", vm_hooks); nebula_configuration->get("HOST_HOOK", host_hooks); + nebula_configuration->get("VM_RESTRICTED_ATTR", vm_restricted_attrs); + nebula_configuration->get("IMAGE_RESTRICTED_ATTR", img_restricted_attrs); + vmpool = new VirtualMachinePool(db, vm_hooks, hook_location, - remotes_location); + remotes_location, + vm_restricted_attrs); hpool = new HostPool(db, host_hooks, hook_location, remotes_location); nebula_configuration->get("MAC_PREFIX", mac_prefix); @@ -301,7 +307,8 @@ void Nebula::start() ipool = new ImagePool(db, default_image_type, - default_device_prefix); + default_device_prefix, + img_restricted_attrs); tpool = new VMTemplatePool(db); } diff --git a/src/template/Template.cc b/src/template/Template.cc index 71ea6b0539..73e4f829d8 100644 --- a/src/template/Template.cc +++ b/src/template/Template.cc @@ -539,7 +539,7 @@ bool Template::check(string& rs_attr, const vector &restricted_attribute string avector, vattr; vector values; - for (uint i=0; i < restricted_attributes.size(); i++) + for (unsigned int i=0; i < restricted_attributes.size(); i++) { pos = restricted_attributes[i].find("/"); @@ -573,7 +573,7 @@ bool Template::check(string& rs_attr, const vector &restricted_attribute } else //Single Attribute { - if (get(avector,values) > 0 ) + if (get(restricted_attributes[i],values) > 0 ) { rs_attr = restricted_attributes[i]; return true; diff --git a/src/vm/SConstruct b/src/vm/SConstruct index b69822ff24..bc041d804e 100644 --- a/src/vm/SConstruct +++ b/src/vm/SConstruct @@ -40,7 +40,8 @@ source_files=[ 'vm_var_parser.c', 'vm_var_syntax.cc', 'VirtualMachinePool.cc', - 'VirtualMachineHook.cc' + 'VirtualMachineHook.cc', + 'VirtualMachineTemplate.cc' ] # Build library diff --git a/src/vm/VirtualMachinePool.cc b/src/vm/VirtualMachinePool.cc index f56a74301d..3e40eaf0e3 100644 --- a/src/vm/VirtualMachinePool.cc +++ b/src/vm/VirtualMachinePool.cc @@ -27,10 +27,12 @@ VirtualMachinePool::VirtualMachinePool(SqlDB * db, vector hook_mads, const string& hook_location, - const string& remotes_location) + const string& remotes_location, + vector restricted_attrs) : PoolSQL(db,VirtualMachine::table) { const VectorAttribute * vattr; + const SingleAttribute * sattr; string name; string on; @@ -182,6 +184,17 @@ VirtualMachinePool::VirtualMachinePool(SqlDB * db, add_hook(hook); } + + // Set restricted attributes + for (unsigned int i = 0 ; i < restricted_attrs.size() ; i++ ) + { + sattr = static_cast(restricted_attrs[i]); + + string attr = sattr->value(); + transform (attr.begin(),attr.end(),attr.begin(),(int(*)(int))toupper); + + VirtualMachineTemplate::add_restricted_attribute(attr); + } } /* -------------------------------------------------------------------------- */ diff --git a/src/vm/VirtualMachineTemplate.cc b/src/vm/VirtualMachineTemplate.cc new file mode 100644 index 0000000000..59ecf1a003 --- /dev/null +++ b/src/vm/VirtualMachineTemplate.cc @@ -0,0 +1,33 @@ +/* -------------------------------------------------------------------------- */ +/* Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) */ +/* */ +/* 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. */ +/* -------------------------------------------------------------------------- */ + +#include "VirtualMachineTemplate.h" + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + +vector VirtualMachineTemplate::restricted_attributes; + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + +void VirtualMachineTemplate::add_restricted_attribute(string& attr) +{ + restricted_attributes.push_back(attr); +} + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ From 2173fae04847cfb5424583cd5dca6acb74d3bab9 Mon Sep 17 00:00:00 2001 From: Daniel Molina Date: Mon, 23 Jan 2012 17:18:43 +0100 Subject: [PATCH 16/17] bug #1080: acctd error when monitoring VMs with no history --- src/acct/accounting.rb | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/src/acct/accounting.rb b/src/acct/accounting.rb index 3b8b7ce5c5..b30be641d6 100644 --- a/src/acct/accounting.rb +++ b/src/acct/accounting.rb @@ -93,29 +93,30 @@ module OneWatch last_register = vm_sql.registers.last seq = last_register ? last_register.seq : 0 - if hr = vm['HISTORY_RECORDS'] - unless hr['HISTORY'].instance_of?(Array) - if hr['HISTORY']['SEQ'] == seq - # The VM has not moved from the Host - insert_register(vm_sql, last_register, hr['HISTORY']) - return - else + hr = vm['HISTORY_RECORDS'] + if hr and !hr.empty? + if hr['HISTORY']['SEQ'] == seq + # The VM has not moved from the Host + insert_register(vm_sql, last_register, hr['HISTORY']) + return + else + unless hr['HISTORY'].instance_of?(Array) # Get the full HISTORY vm = OpenNebula::VirtualMachine.new_with_id(vm['ID'], @client) vm.info vm_hash = vm.to_hash['VM'] hr = vm_hash['HISTORY_RECORDS'] - - # Insert a new entry for each new history record - [hr['HISTORY']].flatten.each { |history| - if history['SEQ'].to_i < seq - next - else - insert_register(vm_sql, last_register, history) - end - } end + + # Insert a new entry for each new history record + [hr['HISTORY']].flatten.each { |history| + if history['SEQ'].to_i < seq + next + else + insert_register(vm_sql, last_register, history) + end + } end end end From 6d156731849972f97c1bc9d77ce12af690581468 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Mon, 23 Jan 2012 23:09:47 +0100 Subject: [PATCH 17/17] feature #1070: Moved some logic to Template classes --- include/ImagePool.h | 2 +- include/ImageTemplate.h | 2 +- include/VirtualMachinePool.h | 2 +- include/VirtualMachineTemplate.h | 2 +- src/image/ImagePool.cc | 13 ++----------- src/image/ImageTemplate.cc | 15 +++++++++++++-- src/vm/VirtualMachinePool.cc | 13 ++----------- src/vm/VirtualMachineTemplate.cc | 16 ++++++++++++++-- 8 files changed, 35 insertions(+), 30 deletions(-) diff --git a/include/ImagePool.h b/include/ImagePool.h index a2a54a2b04..2530fcb20c 100644 --- a/include/ImagePool.h +++ b/include/ImagePool.h @@ -41,7 +41,7 @@ public: ImagePool(SqlDB * db, const string& _default_type, const string& _default_dev_prefix, - vector restricted_attrs); + vector& restricted_attrs); ~ImagePool(){}; diff --git a/include/ImageTemplate.h b/include/ImageTemplate.h index a7f141bd0d..243e9f3f45 100644 --- a/include/ImageTemplate.h +++ b/include/ImageTemplate.h @@ -46,7 +46,7 @@ private: static vector restricted_attributes; - static void add_restricted_attribute(string& attr); + static void set_restricted_attributes(vector& rattrs); }; /* -------------------------------------------------------------------------- */ diff --git a/include/VirtualMachinePool.h b/include/VirtualMachinePool.h index a8faa5570e..7e3ea7e6e2 100644 --- a/include/VirtualMachinePool.h +++ b/include/VirtualMachinePool.h @@ -36,7 +36,7 @@ public: vector hook_mads, const string& hook_location, const string& remotes_location, - vector restricted_attrs); + vector& restricted_attrs); ~VirtualMachinePool(){}; diff --git a/include/VirtualMachineTemplate.h b/include/VirtualMachineTemplate.h index 5475503294..422a73cfa4 100644 --- a/include/VirtualMachineTemplate.h +++ b/include/VirtualMachineTemplate.h @@ -52,7 +52,7 @@ private: static vector restricted_attributes; - static void add_restricted_attribute(string& attr); + static void set_restricted_attributes(vector& rattrs); }; /* -------------------------------------------------------------------------- */ diff --git a/src/image/ImagePool.cc b/src/image/ImagePool.cc index ec7ccb0feb..7e023b3868 100644 --- a/src/image/ImagePool.cc +++ b/src/image/ImagePool.cc @@ -34,11 +34,10 @@ string ImagePool::_default_dev_prefix; ImagePool::ImagePool(SqlDB * db, const string& __default_type, const string& __default_dev_prefix, - vector restricted_attrs): + vector& restricted_attrs): PoolSQL(db,Image::table) { ostringstream sql; - const SingleAttribute * sattr; // Init static defaults _default_type = __default_type; @@ -54,15 +53,7 @@ ImagePool::ImagePool(SqlDB * db, } // Set restricted attributes - for (unsigned int i = 0 ; i < restricted_attrs.size() ; i++ ) - { - sattr = static_cast(restricted_attrs[i]); - - string attr = sattr->value(); - transform (attr.begin(),attr.end(),attr.begin(),(int(*)(int))toupper); - - ImageTemplate::add_restricted_attribute(attr); - } + ImageTemplate::set_restricted_attributes(restricted_attrs); } /* -------------------------------------------------------------------------- */ diff --git a/src/image/ImageTemplate.cc b/src/image/ImageTemplate.cc index 2236e1bc39..6df1942c3d 100644 --- a/src/image/ImageTemplate.cc +++ b/src/image/ImageTemplate.cc @@ -24,9 +24,20 @@ vector ImageTemplate::restricted_attributes; /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ -void ImageTemplate::add_restricted_attribute(string& attr) +void ImageTemplate::set_restricted_attributes(vector& rattrs) { - restricted_attributes.push_back(attr); + const SingleAttribute * sattr; + string attr; + + for (unsigned int i = 0 ; i < rattrs.size() ; i++ ) + { + sattr = static_cast(rattrs[i]); + + attr = sattr->value(); + transform (attr.begin(),attr.end(),attr.begin(),(int(*)(int))toupper); + + restricted_attributes.push_back(attr); + } } /* -------------------------------------------------------------------------- */ diff --git a/src/vm/VirtualMachinePool.cc b/src/vm/VirtualMachinePool.cc index 3e40eaf0e3..65beced047 100644 --- a/src/vm/VirtualMachinePool.cc +++ b/src/vm/VirtualMachinePool.cc @@ -28,11 +28,10 @@ VirtualMachinePool::VirtualMachinePool(SqlDB * db, vector hook_mads, const string& hook_location, const string& remotes_location, - vector restricted_attrs) + vector& restricted_attrs) : PoolSQL(db,VirtualMachine::table) { const VectorAttribute * vattr; - const SingleAttribute * sattr; string name; string on; @@ -186,15 +185,7 @@ VirtualMachinePool::VirtualMachinePool(SqlDB * db, } // Set restricted attributes - for (unsigned int i = 0 ; i < restricted_attrs.size() ; i++ ) - { - sattr = static_cast(restricted_attrs[i]); - - string attr = sattr->value(); - transform (attr.begin(),attr.end(),attr.begin(),(int(*)(int))toupper); - - VirtualMachineTemplate::add_restricted_attribute(attr); - } + VirtualMachineTemplate::set_restricted_attributes(restricted_attrs); } /* -------------------------------------------------------------------------- */ diff --git a/src/vm/VirtualMachineTemplate.cc b/src/vm/VirtualMachineTemplate.cc index 59ecf1a003..4a199ac7e7 100644 --- a/src/vm/VirtualMachineTemplate.cc +++ b/src/vm/VirtualMachineTemplate.cc @@ -24,9 +24,21 @@ vector VirtualMachineTemplate::restricted_attributes; /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ -void VirtualMachineTemplate::add_restricted_attribute(string& attr) +void VirtualMachineTemplate::set_restricted_attributes( + vector& rattrs) { - restricted_attributes.push_back(attr); + const SingleAttribute * sattr; + string attr; + + for (unsigned int i = 0 ; i < rattrs.size() ; i++ ) + { + sattr = static_cast(rattrs[i]); + + attr = sattr->value(); + transform (attr.begin(),attr.end(),attr.begin(),(int(*)(int))toupper); + + restricted_attributes.push_back(attr); + } } /* -------------------------------------------------------------------------- */