From c49f2ac7daead6cf500706ef7c248004eecbcbdb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Wed, 7 Mar 2012 15:27:43 +0100 Subject: [PATCH 1/6] Feature #1112: Refactor VirtualMachine::automatic_requirements to improve performance when there are no errors --- src/vm/VirtualMachine.cc | 104 ++++++++++++++++++++++++++------------- 1 file changed, 70 insertions(+), 34 deletions(-) diff --git a/src/vm/VirtualMachine.cc b/src/vm/VirtualMachine.cc index 5d5595b7f4..9eb8a42f28 100644 --- a/src/vm/VirtualMachine.cc +++ b/src/vm/VirtualMachine.cc @@ -535,10 +535,9 @@ int VirtualMachine::automatic_requirements(string& error_str) ostringstream oss; string requirements; string cluster_id; + string vatt_cluster_id; bool error = false; - oss << "Incompatible cluster IDs."; - // Get cluster id from all DISK vector attributes num_vatts = obj_template->get("DISK",v_attributes); @@ -552,23 +551,16 @@ int VirtualMachine::automatic_requirements(string& error_str) continue; } - string vatt_cluster_id = vatt->vector_value("CLUSTER_ID"); + vatt_cluster_id = vatt->vector_value("CLUSTER_ID"); if ( !vatt_cluster_id.empty() ) { - oss << endl << "DISK [" << i << "]: IMAGE [" - << vatt->vector_value("IMAGE_ID") << "] from DATASTORE [" - << vatt->vector_value("DATASTORE_ID") << "] requires CLUSTER [" - << vatt_cluster_id << "]"; + if ( cluster_id != vatt_cluster_id ) + { + goto error; + } - if ( cluster_id.empty() ) - { - cluster_id = vatt_cluster_id; - } - else if ( cluster_id != vatt_cluster_id ) - { - error = true; - } + cluster_id = vatt_cluster_id; } } @@ -586,32 +578,19 @@ int VirtualMachine::automatic_requirements(string& error_str) continue; } - string vatt_cluster_id = vatt->vector_value("CLUSTER_ID"); + vatt_cluster_id = vatt->vector_value("CLUSTER_ID"); if ( !vatt_cluster_id.empty() ) { - oss << endl << "NIC [" << i << "]: NETWORK [" - << vatt->vector_value("NETWORK_ID") << "] requires CLUSTER [" - << vatt_cluster_id << "]"; + if ( cluster_id != vatt_cluster_id ) + { + goto error; + } - if ( cluster_id.empty() ) - { - cluster_id = vatt_cluster_id; - } - else if ( cluster_id != vatt_cluster_id ) - { - error = true; - } + cluster_id = vatt_cluster_id; } } - if ( error == true ) - { - error_str = oss.str(); - - return -1; - } - if ( !cluster_id.empty() ) { oss.str(""); @@ -628,6 +607,63 @@ int VirtualMachine::automatic_requirements(string& error_str) } return 0; + +error: + + oss << "Incompatible cluster IDs."; + + // Get cluster id from all DISK vector attributes + + v_attributes.clear(); + num_vatts = obj_template->get("DISK",v_attributes); + + for(int i=0; i(v_attributes[i]); + + if ( vatt == 0 ) + { + continue; + } + + vatt_cluster_id = vatt->vector_value("CLUSTER_ID"); + + if ( !vatt_cluster_id.empty() ) + { + oss << endl << "DISK [" << i << "]: IMAGE [" + << vatt->vector_value("IMAGE_ID") << "] from DATASTORE [" + << vatt->vector_value("DATASTORE_ID") << "] requires CLUSTER [" + << vatt_cluster_id << "]"; + } + } + + // Get cluster id from all NIC vector attributes + + v_attributes.clear(); + num_vatts = obj_template->get("NIC",v_attributes); + + for(int i=0; i(v_attributes[i]); + + if ( vatt == 0 ) + { + continue; + } + + vatt_cluster_id = vatt->vector_value("CLUSTER_ID"); + + if ( !vatt_cluster_id.empty() ) + { + oss << endl << "NIC [" << i << "]: NETWORK [" + << vatt->vector_value("NETWORK_ID") << "] requires CLUSTER [" + << vatt_cluster_id << "]"; + } + } + + error_str = oss.str(); + + return -1; } /* ------------------------------------------------------------------------ */ From 7bede56655487299cd4de07001511a3974400c4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Wed, 7 Mar 2012 15:54:37 +0100 Subject: [PATCH 2/6] Feature #1112: Remove unneeded variable --- src/vm/VirtualMachine.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/src/vm/VirtualMachine.cc b/src/vm/VirtualMachine.cc index 546f109f3b..ba168ec86f 100644 --- a/src/vm/VirtualMachine.cc +++ b/src/vm/VirtualMachine.cc @@ -536,7 +536,6 @@ int VirtualMachine::automatic_requirements(string& error_str) string requirements; string cluster_id; string vatt_cluster_id; - bool error = false; // Get cluster id from all DISK vector attributes From 3a81160c9354ad4184cce1a9a7c1e2fea3c1b337 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Wed, 7 Mar 2012 17:19:08 +0100 Subject: [PATCH 3/6] Feature #1112: Fix segmentation fault when drivers are not defined in oned.conf --- src/authm/AuthManager.cc | 7 +++++-- src/hm/HookManager.cc | 7 +++++-- src/image/ImageManager.cc | 7 +++++-- src/tm/TransferManager.cc | 7 +++++-- 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/authm/AuthManager.cc b/src/authm/AuthManager.cc index 348782c68a..6201ba33e2 100644 --- a/src/authm/AuthManager.cc +++ b/src/authm/AuthManager.cc @@ -429,7 +429,7 @@ void AuthManager::notify_request(int auth_id,bool result,const string& message) void AuthManager::load_mads(int uid) { ostringstream oss; - const VectorAttribute * vattr; + const VectorAttribute * vattr = 0; int rc; string name; AuthManagerDriver * authm_driver = 0; @@ -438,7 +438,10 @@ void AuthManager::load_mads(int uid) NebulaLog::log("AuM",Log::INFO,oss); - vattr = static_cast(mad_conf[0]); + if ( mad_conf.size() > 0 ) + { + vattr = static_cast(mad_conf[0]); + } if ( vattr == 0 ) { diff --git a/src/hm/HookManager.cc b/src/hm/HookManager.cc index 8555d1c4ad..f49a21ea92 100644 --- a/src/hm/HookManager.cc +++ b/src/hm/HookManager.cc @@ -49,12 +49,15 @@ void HookManager::load_mads(int uid) { HookManagerDriver * hm_mad; ostringstream oss; - const VectorAttribute * vattr; + const VectorAttribute * vattr = 0; int rc; NebulaLog::log("HKM",Log::INFO,"Loading Hook Manager driver."); - vattr = static_cast(mad_conf[0]); + if ( mad_conf.size() > 0 ) + { + vattr = static_cast(mad_conf[0]); + } if ( vattr == 0 ) { diff --git a/src/image/ImageManager.cc b/src/image/ImageManager.cc index e0fc6789ff..52c3ab9df8 100644 --- a/src/image/ImageManager.cc +++ b/src/image/ImageManager.cc @@ -50,12 +50,15 @@ void ImageManager::load_mads(int uid) { ImageManagerDriver * imagem_mad; ostringstream oss; - const VectorAttribute * vattr; + const VectorAttribute * vattr = 0; int rc; NebulaLog::log("ImM",Log::INFO,"Loading Image Manager driver."); - vattr = static_cast(mad_conf[0]); + if ( mad_conf.size() > 0 ) + { + vattr = static_cast(mad_conf[0]); + } if ( vattr == 0 ) { diff --git a/src/tm/TransferManager.cc b/src/tm/TransferManager.cc index d3d1212d84..13af39a96b 100644 --- a/src/tm/TransferManager.cc +++ b/src/tm/TransferManager.cc @@ -1288,14 +1288,17 @@ void TransferManager::load_mads(int uid) int rc; string name; - const VectorAttribute * vattr; + const VectorAttribute * vattr = 0; TransferManagerDriver * tm_driver = 0; oss << "Loading Transfer Manager driver."; NebulaLog::log("TM",Log::INFO,oss); - vattr = static_cast(mad_conf[0]); + if ( mad_conf.size() > 0 ) + { + vattr = static_cast(mad_conf[0]); + } if ( vattr == 0 ) { From e522dabcc1db2e8aef96bce9c06e8bd250fcf7f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Wed, 7 Mar 2012 17:45:08 +0100 Subject: [PATCH 4/6] Feature #1112, #962: Fix a bunch of typos in error messages --- src/cli/one_helper/oneuser_helper.rb | 2 +- src/cloud/ec2/bin/econe-server | 2 +- src/cloud/occi/bin/occi-server | 2 +- src/cloud/occi/lib/OCCIClient.rb | 4 ++-- src/datastore_mad/remotes/libfs.sh | 2 +- src/dm/DispatchManagerActions.cc | 4 ++-- src/group/GroupPool.cc | 2 +- src/host/test/HostPoolTest.cc | 2 +- src/image/ImageManagerActions.cc | 12 ++++++------ src/mad/Mad.cc | 6 +++--- src/nebula/oned.cc | 4 ++-- src/oca/java/test/oned.conf | 2 +- src/oca/ruby/OpenNebula/Group.rb | 2 +- src/onedb/test/oned_mysql.conf | 4 ++-- src/onedb/test/oned_sqlite.conf | 4 ++-- src/ozones/Server/bin/ozones-server | 2 +- src/ozones/Server/models/OzonesServer.rb | 4 ++-- src/pool/PoolObjectSQL.cc | 2 +- src/rm/RequestManager.cc | 6 +++--- src/rm/RequestManagerDelete.cc | 6 +++--- src/rm/RequestManagerUpdateTemplate.cc | 2 +- src/rm/RequestManagerVirtualMachine.cc | 4 ++-- src/sunstone/bin/sunstone-server | 2 +- src/tm_mad/vmware/functions.sh | 2 +- src/vm/VirtualMachine.cc | 10 +++++----- src/vm/VirtualMachinePool.cc | 2 +- src/vmm_mad/ec2/one_vmm_ec2.rb | 6 +++--- src/vmm_mad/exec/one_vmm_exec.rb | 2 +- src/vmm_mad/remotes/vmware/vmware_driver.rb | 2 +- 29 files changed, 53 insertions(+), 53 deletions(-) diff --git a/src/cli/one_helper/oneuser_helper.rb b/src/cli/one_helper/oneuser_helper.rb index 82a060b44e..2b1a532919 100644 --- a/src/cli/one_helper/oneuser_helper.rb +++ b/src/cli/one_helper/oneuser_helper.rb @@ -34,7 +34,7 @@ class OneUserHelper < OpenNebulaHelper::OneHelper begin password = File.read(arg).split("\n").first rescue - return -1, "Can not read file: #{arg}" + return -1, "Cannot read file: #{arg}" end else password = arg.dup diff --git a/src/cloud/ec2/bin/econe-server b/src/cloud/ec2/bin/econe-server index 2071c168d7..5b1d23a9f2 100755 --- a/src/cloud/ec2/bin/econe-server +++ b/src/cloud/ec2/bin/econe-server @@ -53,7 +53,7 @@ setup() start() { if [ ! -f "$ECONE_SERVER" ]; then - echo "Can not find $ECONE_SERVER." + echo "Cannot find $ECONE_SERVER." exit 1 fi diff --git a/src/cloud/occi/bin/occi-server b/src/cloud/occi/bin/occi-server index c7306756c7..5218f42e77 100755 --- a/src/cloud/occi/bin/occi-server +++ b/src/cloud/occi/bin/occi-server @@ -53,7 +53,7 @@ setup() start() { if [ ! -x "$OCCI_SERVER" ]; then - echo "Can not find $OCCI_SERVER." + echo "Cannot find $OCCI_SERVER." exit 1 fi diff --git a/src/cloud/occi/lib/OCCIClient.rb b/src/cloud/occi/lib/OCCIClient.rb index 4b30b9fb2c..c600599a18 100755 --- a/src/cloud/occi/lib/OCCIClient.rb +++ b/src/cloud/occi/lib/OCCIClient.rb @@ -131,7 +131,7 @@ module OCCIClient file_path="/"+m[1] end elsif !image_info.elements['TYPE'] == "DATABLOCK" - return CloudClient::Error.new("Can not find URL") + return CloudClient::Error.new("Cannot find URL") end if curb @@ -316,7 +316,7 @@ module OCCIClient end if info.elements['ID'] == nil - return CloudClient::Error.new("Can not find RESOURCE ID") + return CloudClient::Error.new("Cannot find RESOURCE ID") end resource_id = info.elements['ID'].text diff --git a/src/datastore_mad/remotes/libfs.sh b/src/datastore_mad/remotes/libfs.sh index 55d5aada37..02f238e050 100644 --- a/src/datastore_mad/remotes/libfs.sh +++ b/src/datastore_mad/remotes/libfs.sh @@ -23,7 +23,7 @@ # @param $3 - Safe dirs # @param $4 - Umask for new file creation (default: 0007) # @return sets the following environment variables -# - RESTRICTED_DIRS: Paths that can not be used to register images +# - RESTRICTED_DIRS: Paths that cannot be used to register images # - SAFE_DIRS: Paths that are safe to specify image paths # - BASE_PATH: Path where the images will be stored #------------------------------------------------------------------------------ diff --git a/src/dm/DispatchManagerActions.cc b/src/dm/DispatchManagerActions.cc index f945c98944..4907ed7194 100644 --- a/src/dm/DispatchManagerActions.cc +++ b/src/dm/DispatchManagerActions.cc @@ -664,7 +664,7 @@ int DispatchManager::resubmit(int vid) { case VirtualMachine::SUSPENDED: NebulaLog::log("DiM",Log::ERROR, - "Can not resubmit a suspended VM. Resume it first"); + "Cannot resubmit a suspended VM. Resume it first"); rc = -2; break; @@ -688,7 +688,7 @@ int DispatchManager::resubmit(int vid) break; case VirtualMachine::DONE: NebulaLog::log("DiM",Log::ERROR, - "Can not resubmit a VM already in DONE state"); + "Cannot resubmit a VM already in DONE state"); rc = -2; break; } diff --git a/src/group/GroupPool.cc b/src/group/GroupPool.cc index a476669b06..b12cda200f 100644 --- a/src/group/GroupPool.cc +++ b/src/group/GroupPool.cc @@ -22,7 +22,7 @@ /* -------------------------------------------------------------------------- */ /* There are two default groups boostrapped by the core: */ -/* - oneadmin can not be removed */ +/* - oneadmin cannot be removed */ /* - users to place regular users by default */ /* The first 100 group IDs are reserved for system groups. Regular ones start */ /* from ID 100 */ diff --git a/src/host/test/HostPoolTest.cc b/src/host/test/HostPoolTest.cc index d3e81a802d..9f02041dfc 100644 --- a/src/host/test/HostPoolTest.cc +++ b/src/host/test/HostPoolTest.cc @@ -267,7 +267,7 @@ public: CPPUNIT_ASSERT( oid_1 == -1 ); CPPUNIT_ASSERT( rc == oid_1 ); - // the hostname can not be repeated if the drivers change + // the hostname cannot be repeated if the drivers change rc = hp->allocate(&oid_1, names[0], im_mad_2, diff --git a/src/image/ImageManagerActions.cc b/src/image/ImageManagerActions.cc index 3b41c8d2c2..ad1b8e2627 100644 --- a/src/image/ImageManagerActions.cc +++ b/src/image/ImageManagerActions.cc @@ -95,7 +95,7 @@ int ImageManager::acquire_image(Image *img, string& error) case Image::USED: if (img->isPersistent()) { - error = "Cannot aquire persistent image, it is already in use"; + error = "Cannot acquire persistent image, it is already in use"; rc = -1; } else @@ -106,15 +106,15 @@ int ImageManager::acquire_image(Image *img, string& error) break; case Image::DISABLED: - error = "Cannot aquire image, it is disabled"; + error = "Cannot acquire image, it is disabled"; rc = -1; break; case Image::LOCKED: - error = "Cannot aquire image, it is locked"; + error = "Cannot acquire image, it is locked"; rc = -1; break; case Image::ERROR: - error = "Cannot aquire image, it is in an error state"; + error = "Cannot acquire image, it is in an error state"; rc = -1; break; default: @@ -276,13 +276,13 @@ int ImageManager::delete_image(int iid, const string& ds_data) if ( img->get_running() != 0 ) { img->unlock(); - return -1; //Can not remove images in use + return -1; //Cannot remove images in use } break; case Image::USED: img->unlock(); - return -1; //Can not remove images in use + return -1; //Cannot remove images in use break; case Image::INIT: diff --git a/src/mad/Mad.cc b/src/mad/Mad.cc index 98388228ee..e33c04cfdb 100644 --- a/src/mad/Mad.cc +++ b/src/mad/Mad.cc @@ -239,13 +239,13 @@ int Mad::start() error_exec: oss.str(""); - oss << "Can not load driver " << executable << ", " << strerror(errno); + oss << "Cannot load driver " << executable << ", " << strerror(errno); NebulaLog::log("MAD", Log::ERROR, oss); exit(-1); error_dup2: oss.str(""); - oss << "Can not duplicate descriptors, " << strerror(errno); + oss << "Cannot duplicate descriptors, " << strerror(errno); NebulaLog::log("MAD", Log::ERROR, oss); exit(-1); @@ -275,7 +275,7 @@ error_attributes: error_pipes: oss.str(""); - oss << "Can not create driver pipes, " << strerror(errno); + oss << "Cannot create driver pipes, " << strerror(errno); NebulaLog::log("MAD", Log::ERROR, oss); return -1; } diff --git a/src/nebula/oned.cc b/src/nebula/oned.cc index 3076c9f4fe..cfe7968607 100644 --- a/src/nebula/oned.cc +++ b/src/nebula/oned.cc @@ -127,7 +127,7 @@ int main(int argc, char **argv) if( fd == -1) { - cerr<< "Error: Can not start oned, opening lock file " << lockfile + cerr<< "Error: Cannot start oned, opening lock file " << lockfile << endl; exit(-1); @@ -186,7 +186,7 @@ int main(int argc, char **argv) return 0; error_chdir: - cerr << "Error: can not change to dir " << wd << "\n"; + cerr << "Error: cannot change to dir " << wd << "\n"; unlink(lockfile.c_str()); exit(-1); diff --git a/src/oca/java/test/oned.conf b/src/oca/java/test/oned.conf index de3fdf51df..7e88254166 100644 --- a/src/oca/java/test/oned.conf +++ b/src/oca/java/test/oned.conf @@ -6,7 +6,7 @@ # Daemon configuration attributes #------------------------------------------------------------------------------- # MANAGER_TIMER: Time in seconds the core uses to evaluate periodical functions. -# HOST_MONITORING_INTERVAL and VM_POLLING_INTERVAL can not have smaller values +# HOST_MONITORING_INTERVAL and VM_POLLING_INTERVAL cannot have smaller values # than MANAGER_TIMER. # # HOST_MONITORING_INTERVAL: Time in seconds between host monitorization. diff --git a/src/oca/ruby/OpenNebula/Group.rb b/src/oca/ruby/OpenNebula/Group.rb index 74d56ddbf3..3fa5a9a41c 100644 --- a/src/oca/ruby/OpenNebula/Group.rb +++ b/src/oca/ruby/OpenNebula/Group.rb @@ -69,7 +69,7 @@ module OpenNebula # Creates ACLs for the group. The ACL rules are described in a file def create_acls(filename = GROUP_DEFAULT) if !File.readable?(filename) - return -1, "Can not read deafult ACL file for group" + return -1, "Cannot read deafult ACL file for group" end msg = String.new diff --git a/src/onedb/test/oned_mysql.conf b/src/onedb/test/oned_mysql.conf index 164abeaf5d..7275333b2c 100644 --- a/src/onedb/test/oned_mysql.conf +++ b/src/onedb/test/oned_mysql.conf @@ -6,7 +6,7 @@ # Daemon configuration attributes #------------------------------------------------------------------------------- # MANAGER_TIMER: Time in seconds the core uses to evaluate periodical functions. -# HOST_MONITORING_INTERVAL and VM_POLLING_INTERVAL can not have smaller values +# HOST_MONITORING_INTERVAL and VM_POLLING_INTERVAL cannot have smaller values # than MANAGER_TIMER. # # HOST_MONITORING_INTERVAL: Time in seconds between host monitorization. @@ -390,7 +390,7 @@ HM_MAD = [ #-------------------------------- ebtables Hook--------------------------------- # You can use these two hooks to isolate networks at the ethernet level so the -# traffic generated in different virtual networks can not be seen in others. +# traffic generated in different virtual networks cannot be seen in others. # # All the network configuration will be done in the cluster nodes, these are the # additional requisites: diff --git a/src/onedb/test/oned_sqlite.conf b/src/onedb/test/oned_sqlite.conf index e8a6aca4f9..09f4189ba0 100644 --- a/src/onedb/test/oned_sqlite.conf +++ b/src/onedb/test/oned_sqlite.conf @@ -6,7 +6,7 @@ # Daemon configuration attributes #------------------------------------------------------------------------------- # MANAGER_TIMER: Time in seconds the core uses to evaluate periodical functions. -# HOST_MONITORING_INTERVAL and VM_POLLING_INTERVAL can not have smaller values +# HOST_MONITORING_INTERVAL and VM_POLLING_INTERVAL cannot have smaller values # than MANAGER_TIMER. # # HOST_MONITORING_INTERVAL: Time in seconds between host monitorization. @@ -390,7 +390,7 @@ HM_MAD = [ #-------------------------------- ebtables Hook--------------------------------- # You can use these two hooks to isolate networks at the ethernet level so the -# traffic generated in different virtual networks can not be seen in others. +# traffic generated in different virtual networks cannot be seen in others. # # All the network configuration will be done in the cluster nodes, these are the # additional requisites: diff --git a/src/ozones/Server/bin/ozones-server b/src/ozones/Server/bin/ozones-server index 9a637cafbb..720aad1742 100755 --- a/src/ozones/Server/bin/ozones-server +++ b/src/ozones/Server/bin/ozones-server @@ -54,7 +54,7 @@ setup() start() { if [ ! -f "$OZONES_SERVER" ]; then - echo "Can not find $OZONES_SERVER." + echo "Cannot find $OZONES_SERVER." exit 1 fi diff --git a/src/ozones/Server/models/OzonesServer.rb b/src/ozones/Server/models/OzonesServer.rb index 1b43ba887b..4b7a952af5 100644 --- a/src/ozones/Server/models/OzonesServer.rb +++ b/src/ozones/Server/models/OzonesServer.rb @@ -217,7 +217,7 @@ class OzonesServer < CloudServer vdc = OZones::OpenNebulaVdc.new(id) rc = vdc.destroy rescue => e - return [404, OZones::Error.new("Error: Can not delete vdc. " \ + return [404, OZones::Error.new("Error: Cannot delete vdc. " \ "Reason: #{e.message}").to_json] end @@ -237,7 +237,7 @@ class OzonesServer < CloudServer rc = zone.destroy else return [404, - OZones::Error.new("Error: Can not delete " \ + OZones::Error.new("Error: Cannot delete " \ "zone. Reason: zone #{id} not found").to_json] end diff --git a/src/pool/PoolObjectSQL.cc b/src/pool/PoolObjectSQL.cc index 2a1706b171..fc45b17dd1 100644 --- a/src/pool/PoolObjectSQL.cc +++ b/src/pool/PoolObjectSQL.cc @@ -172,7 +172,7 @@ int PoolObjectSQL::replace_template(const string& tmpl_str, string& error) if ( new_tmpl == 0 ) { - error = "Can not allocate a new template"; + error = "Cannot allocate a new template"; return -1; } diff --git a/src/rm/RequestManager.cc b/src/rm/RequestManager.cc index 34a14a82e0..9d2099ea18 100644 --- a/src/rm/RequestManager.cc +++ b/src/rm/RequestManager.cc @@ -114,7 +114,7 @@ int RequestManager::setup_socket() { ostringstream oss; - oss << "Can not open server socket: " << strerror(errno); + oss << "Cannot open server socket: " << strerror(errno); NebulaLog::log("ReM",Log::ERROR,oss); return -1; @@ -126,7 +126,7 @@ int RequestManager::setup_socket() { ostringstream oss; - oss << "Can not set socket options: " << strerror(errno); + oss << "Cannot set socket options: " << strerror(errno); NebulaLog::log("ReM",Log::ERROR,oss); close(socket_fd); @@ -146,7 +146,7 @@ int RequestManager::setup_socket() { ostringstream oss; - oss << "Can not bind to port " << port << " : " << strerror(errno); + oss << "Cannot bind to port " << port << " : " << strerror(errno); NebulaLog::log("ReM",Log::ERROR,oss); close(socket_fd); diff --git a/src/rm/RequestManagerDelete.cc b/src/rm/RequestManagerDelete.cc index 9466768c30..34ec4d0393 100644 --- a/src/rm/RequestManagerDelete.cc +++ b/src/rm/RequestManagerDelete.cc @@ -91,7 +91,7 @@ void RequestManagerDelete::request_execute(xmlrpc_c::paramList const& paramList, if ( rc != 0 ) { failure_response(INTERNAL, - request_error("Can not delete "+object_name(auth_object),error_msg), + request_error("Cannot delete "+object_name(auth_object),error_msg), att); return; } @@ -163,7 +163,7 @@ int ImageDelete::drop(int oid, PoolObjectSQL * object, string& error_msg) if ( ds == 0 ) { - error_msg = "Datastore no longer exists can not remove image"; + error_msg = "Datastore no longer exists cannot remove image"; return -1; } @@ -199,7 +199,7 @@ int UserDelete::drop(int oid, PoolObjectSQL * object, string& error_msg) if (oid == 0) { - error_msg = "oneadmin can not be deleted."; + error_msg = "oneadmin cannot be deleted."; object->unlock(); return -1; diff --git a/src/rm/RequestManagerUpdateTemplate.cc b/src/rm/RequestManagerUpdateTemplate.cc index 07226eb0b6..1c8988ccbb 100644 --- a/src/rm/RequestManagerUpdateTemplate.cc +++ b/src/rm/RequestManagerUpdateTemplate.cc @@ -54,7 +54,7 @@ void RequestManagerUpdateTemplate::request_execute( if ( rc != 0 ) { failure_response(INTERNAL, - request_error("Can not update template",error_str), + request_error("Cannot update template",error_str), att); object->unlock(); diff --git a/src/rm/RequestManagerVirtualMachine.cc b/src/rm/RequestManagerVirtualMachine.cc index 82c3f91640..59ef25b9ef 100644 --- a/src/rm/RequestManagerVirtualMachine.cc +++ b/src/rm/RequestManagerVirtualMachine.cc @@ -160,7 +160,7 @@ int RequestManagerVirtualMachine::add_history(VirtualMachine * vm, if ( rc != 0 ) { failure_response(INTERNAL, - request_error("Can not update virtual machine history",""), + request_error("Cannot update virtual machine history",""), att); return -1; @@ -442,7 +442,7 @@ void VirtualMachineSaveDisk::request_execute(xmlrpc_c::paramList const& paramLis if ( iid_orig == -1 ) { failure_response(INTERNAL, - request_error("Can not used selected DISK", error_str), + request_error("Cannot use selected DISK", error_str), att); return; } diff --git a/src/sunstone/bin/sunstone-server b/src/sunstone/bin/sunstone-server index 155ff26260..171a8a6938 100755 --- a/src/sunstone/bin/sunstone-server +++ b/src/sunstone/bin/sunstone-server @@ -53,7 +53,7 @@ setup() start() { if [ ! -f "$SUNSTONE_SERVER" ]; then - echo "Can not find $SUNSTONE_SERVER." + echo "Cannot find $SUNSTONE_SERVER." exit 1 fi diff --git a/src/tm_mad/vmware/functions.sh b/src/tm_mad/vmware/functions.sh index d55effbd78..e66d89ee44 100644 --- a/src/tm_mad/vmware/functions.sh +++ b/src/tm_mad/vmware/functions.sh @@ -24,7 +24,7 @@ function fix_iso { if [ $? -eq 0 ]; then bname=`basename $dst_path` exec_and_log "ln -s $bname $dst_path/$bname.iso" \ - "Can not link ISO file." + "Cannot link ISO file." fi fi } diff --git a/src/vm/VirtualMachine.cc b/src/vm/VirtualMachine.cc index ba168ec86f..38fd4100f0 100644 --- a/src/vm/VirtualMachine.cc +++ b/src/vm/VirtualMachine.cc @@ -183,7 +183,7 @@ int VirtualMachine::select(SqlDB * db) return 0; error_previous_history: - ose << "Can not get previous history record (seq:" << history->seq + ose << "Cannot get previous history record (seq:" << history->seq << ") for VM id: " << oid; log("ONE", Log::ERROR, ose); @@ -380,7 +380,7 @@ int VirtualMachine::parse_context(string& error_str) if (str == 0) { - NebulaLog::log("ONE",Log::ERROR, "Can not marshall CONTEXT"); + NebulaLog::log("ONE",Log::ERROR, "Cannot marshall CONTEXT"); return -1; } @@ -955,15 +955,15 @@ int VirtualMachine::get_disk_images(string& error_str) return 0; error_max_os: - error_str = "VM can not use more than one OS image."; + error_str = "VM cannot use more than one OS image."; goto error_common; error_max_cd: - error_str = "VM can not use more than one CDROM image."; + error_str = "VM cannot use more than one CDROM image."; goto error_common; error_max_db: - error_str = "VM can not use more than 10 DATABLOCK images."; + error_str = "VM cannot use more than 10 DATABLOCK images."; goto error_common; error_common: diff --git a/src/vm/VirtualMachinePool.cc b/src/vm/VirtualMachinePool.cc index 6c5031389b..206d2b4cb4 100644 --- a/src/vm/VirtualMachinePool.cc +++ b/src/vm/VirtualMachinePool.cc @@ -170,7 +170,7 @@ VirtualMachinePool::VirtualMachinePool(SqlDB * db, { ostringstream oss; - oss << "Unkown VM_HOOK " << on << ". Hook not registered!"; + oss << "Unknown VM_HOOK " << on << ". Hook not registered!"; NebulaLog::log("VM",Log::WARNING,oss); } } diff --git a/src/vmm_mad/ec2/one_vmm_ec2.rb b/src/vmm_mad/ec2/one_vmm_ec2.rb index a4ce862b05..dbcd250245 100755 --- a/src/vmm_mad/ec2/one_vmm_ec2.rb +++ b/src/vmm_mad/ec2/one_vmm_ec2.rb @@ -185,7 +185,7 @@ class EC2Driver < VirtualMachineDriver return unless ec2_info if !ec2_value(ec2_info, 'AMI') - msg = "Can not find AMI in deployment file" + msg = "Cannot find AMI in deployment file" send_message(ACTION[:deploy], RESULT[:failure], id, msg) return end @@ -294,7 +294,7 @@ private if !local_dfile send_message(ACTION[:deploy],RESULT[:failure],id, - "Can not open deployment file #{local_dfile}") + "Cannot open deployment file #{local_dfile}") return end @@ -322,7 +322,7 @@ private ec2 = all_ec2_elements[0] else send_message(ACTION[:deploy],RESULT[:failure],id, - "Can not find EC2 element in deployment file "<< + "Cannot find EC2 element in deployment file "<< "#{local_dfile} or couldn't find any EC2 site matching "<< "one of the template.") return diff --git a/src/vmm_mad/exec/one_vmm_exec.rb b/src/vmm_mad/exec/one_vmm_exec.rb index 3570203cef..bd53cfe49e 100755 --- a/src/vmm_mad/exec/one_vmm_exec.rb +++ b/src/vmm_mad/exec/one_vmm_exec.rb @@ -259,7 +259,7 @@ class ExecDriver < VirtualMachineDriver if !local_dfile || File.zero?(local_dfile) send_message(ACTION[:deploy],RESULT[:failure],id, - "Can not open deployment file #{local_dfile}") + "Cannot open deployment file #{local_dfile}") return end diff --git a/src/vmm_mad/remotes/vmware/vmware_driver.rb b/src/vmm_mad/remotes/vmware/vmware_driver.rb index 570b7b0b81..c5be771f11 100644 --- a/src/vmm_mad/remotes/vmware/vmware_driver.rb +++ b/src/vmm_mad/remotes/vmware/vmware_driver.rb @@ -167,7 +167,7 @@ class VMwareDriver # Define the VM dfile = File.dirname(File.dirname(checkpoint)) + "/deployment.0" rescue => e - OpenNebula.log_error("Can not open checkpoint #{e.message}") + OpenNebula.log_error("Cannot open checkpoint #{e.message}") exit -1 end From 41d3bbe20027e9fc4fd1f7fe1e0386d320d405a1 Mon Sep 17 00:00:00 2001 From: Jaime Melis Date: Wed, 7 Mar 2012 21:13:33 +0100 Subject: [PATCH 5/6] feature #1112: Implement clone, delete, ln, mv, mvds for tm_iscsi --- src/datastore_mad/remotes/iscsi/cp | 5 +- src/datastore_mad/remotes/iscsi/mkfs | 5 +- src/datastore_mad/remotes/iscsi/rm | 11 +--- src/datastore_mad/remotes/libfs.sh | 34 ------------ src/mad/sh/scripts_common.sh | 59 ++++++++++++++++++++ src/tm_mad/iscsi/clone | 68 +++++++++++++++++++++++ src/tm_mad/iscsi/delete | 59 ++++++++++++++++++++ src/tm_mad/iscsi/ln | 80 ++++++++++++++++++++++++++++ src/tm_mad/iscsi/mv | 74 +++++++++++++++++++++++++ src/tm_mad/iscsi/mvds | 50 +++++++++++++++++ 10 files changed, 398 insertions(+), 47 deletions(-) create mode 100755 src/tm_mad/iscsi/clone create mode 100755 src/tm_mad/iscsi/delete create mode 100755 src/tm_mad/iscsi/ln create mode 100755 src/tm_mad/iscsi/mv create mode 100755 src/tm_mad/iscsi/mvds diff --git a/src/datastore_mad/remotes/iscsi/cp b/src/datastore_mad/remotes/iscsi/cp index 5e4a797899..e7de096d11 100755 --- a/src/datastore_mad/remotes/iscsi/cp +++ b/src/datastore_mad/remotes/iscsi/cp @@ -79,8 +79,9 @@ let TID=ID+BASE_TID REGISTER_CMD=$(cat <&2 - exit 1 - fi + $SUDO $(tgtadm_target_delete "$TID") + $SUDO $LVREMOVE -f $VG_NAME/$LV_NAME EOF ) diff --git a/src/datastore_mad/remotes/libfs.sh b/src/datastore_mad/remotes/libfs.sh index 55d5aada37..76a91c6227 100644 --- a/src/datastore_mad/remotes/libfs.sh +++ b/src/datastore_mad/remotes/libfs.sh @@ -136,37 +136,3 @@ function check_restricted { echo 0 } - - -# ------------------------------------------------------------------------------ -# iSCSI functions -# ------------------------------------------------------------------------------ - -#------------------------------------------------------------------------------- -# Returns the command to create a new target -# @param $1 - ID of the image -# @param $2 - Target Host -# @param $3 - Device -# @return the command to create a new target -#------------------------------------------------------------------------------- - -function iscsi_target_new { - ID="$1" - IQN="$2" - - echo "$TGTADM --lld iscsi --op new --mode target --tid $ID "\ - "--targetname $IQN" -} - -function iscsi_logicalunit_new { - ID="$1" - DEV="$2" - - echo "$TGTADM --lld iscsi --op new --mode logicalunit --tid $ID "\ - "--lun 1 --backing-store $DEV" -} - -function iscsi_target_delete { - ID="$1" - echo "$TGTADM --lld iscsi --op delete --mode target --tid $ID" -} diff --git a/src/mad/sh/scripts_common.sh b/src/mad/sh/scripts_common.sh index 6b4ef552d9..1296f3c65a 100755 --- a/src/mad/sh/scripts_common.sh +++ b/src/mad/sh/scripts_common.sh @@ -23,6 +23,7 @@ DATE=date DD=dd DU=du GREP=grep +ISCSIADM=iscsiadm LVCREATE=lvcreate LVREMOVE=lvremove LVS=lvs @@ -244,3 +245,61 @@ EOF` exit $SSH_EXEC_RC fi } + + +# ------------------------------------------------------------------------------ +# iSCSI functions +# ------------------------------------------------------------------------------ + +#------------------------------------------------------------------------------- +# Returns the command to create a new target +# @param $1 - ID of the image +# @param $2 - Target Host +# @param $3 - Device +# @return the command to create a new target +#------------------------------------------------------------------------------- + +function tgtadm_target_new { + ID="$1" + IQN="$2" + + echo "$TGTADM --lld iscsi --op new --mode target --tid $ID "\ + "--targetname $IQN;" +} + +function tgtadm_target_bind_all { + ID="$1" + echo "$TGTADM --lld iscsi --op bind --mode target --tid $ID -I ALL" +} + +function tgtadm_logicalunit_new { + ID="$1" + DEV="$2" + + echo "$TGTADM --lld iscsi --op new --mode logicalunit --tid $ID "\ + "--lun 1 --backing-store $DEV" +} + +function tgtadm_target_delete { + ID="$1" + echo "$TGTADM --lld iscsi --op delete --mode target --tid $ID" +} + +### + +function iscsiadm_discovery { + TARGET_HOST="$1" + echo "$ISCSIADM -m discovery -t st -p $TARGET_HOST" +} + +function iscsiadm_login { + IQN="$1" + TARGET_HOST="$2" + echo "$ISCSIADM -m node --targetname $IQN -p $TARGET_HOST --login" +} + +function iscsiadm_logout { + IQN="$1" + echo "$ISCSIADM -m node --targetname $IQN --logout" +} + diff --git a/src/tm_mad/iscsi/clone b/src/tm_mad/iscsi/clone new file mode 100755 index 0000000000..39edcbe028 --- /dev/null +++ b/src/tm_mad/iscsi/clone @@ -0,0 +1,68 @@ +#!/bin/bash + +# -------------------------------------------------------------------------- # +# 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. # +#--------------------------------------------------------------------------- # + +# clone fe:SOURCE host:remote_system_ds/disk.i size +# - fe is the front-end hostname +# - SOURCE is the path of the disk image in the form DS_BASE_PATH/disk +# - host is the target host to deploy the VM +# - remote_system_ds is the path for the system datastore in the host + +SRC=$1 # iqn.2012-02.org.opennebula:o200.vg-one.lv-one-0 +DST=$2 # o202:/var/lib/one//datastores/0/0/disk.0 + +if [ -z "${ONE_LOCATION}" ]; then + TMCOMMON=/var/lib/one/remotes/tm/tm_common.sh +else + TMCOMMON=$ONE_LOCATION/var/remotes/tm/tm_common.sh +fi + +. $TMCOMMON + +#------------------------------------------------------------------------------- +# Set dst path and dir +#------------------------------------------------------------------------------- + +TARGET=`arg_path $SRC` # o200.vg-one.lv-one-0 +DST_PATH=`arg_path $DST` # /var/lib/one/datastores/0/0/disk.0 +DST_HOST=`arg_host $DST` # o202 +DST_DIR=`dirname $DST_PATH` # /var/lib/one/datastores/0/0 + +BASE_IQN=`echo $SRC|$CUT -d: -f1` +TARGET=`echo $SRC|$CUT -d: -f2` +LV_NAME=`echo $TARGET|$AWK -F. '{print $(NF)}'` +VG_NAME=`echo $TARGET|$AWK -F. '{print $(NF-1)}'` +DEV="/dev/$VG_NAME/$LV_NAME" + +exit +ssh_make_path $DST_HOST $DST_DIR + +#------------------------------------------------------------------------------- +# Copy files to the remote host +#------------------------------------------------------------------------------- +case $SRC in +http://*) + log "Downloading $SRC" + RMT_CMD="$WGET -O $DST_PATH $SRC" + ssh_exec_and_log "$DST_HOST" "$RMT_CMD" "Error downloading $SRC" + ;; + +*) + log "Cloning $SRC in $DST_PATH" + exec_and_log "$SCP $SRC $DST" "Error copying $SRC to $DST" + ;; +esac diff --git a/src/tm_mad/iscsi/delete b/src/tm_mad/iscsi/delete new file mode 100755 index 0000000000..c30639d900 --- /dev/null +++ b/src/tm_mad/iscsi/delete @@ -0,0 +1,59 @@ +#!/bin/bash + +# -------------------------------------------------------------------------- # +# 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. # +#--------------------------------------------------------------------------- # + +# DELETE +# - host is the target host to deploy the VM +# - remote_system_ds is the path for the system datastore in the host + +DST=$1 # o202:/var/lib/one//datastores/0/0/disk.0 + +if [ -z "${ONE_LOCATION}" ]; then + TMCOMMON=/var/lib/one/remotes/tm/tm_common.sh +else + TMCOMMON=$ONE_LOCATION/var/remotes/tm/tm_common.sh +fi + +. $TMCOMMON + +#------------------------------------------------------------------------------- +# Return if deleting a disk, we will delete them when removing the +# remote_system_ds directory for the VM (remotely) +#------------------------------------------------------------------------------- +DST_PATH=`arg_path $DST` +DST_HOST=`arg_host $DST` + +if [ `is_disk $DST_PATH` -eq 1 ]; then + # Disk + LOGOUT_CMD=$(cat < +# +# - hostX is the target host to deploy the VM +# - system_ds is the path for the system datastore in the host + +SRC=$1 +DST=$2 + +if [ -z "${ONE_LOCATION}" ]; then + TMCOMMON=/var/lib/one/remotes/tm/tm_common.sh +else + TMCOMMON=$ONE_LOCATION/var/remotes/tm/tm_common.sh +fi + +. $TMCOMMON + +# {:path=> +# "/var/lib/one/remotes/tm/iscsi/mv o202:/var/lib/one//datastores/0/3/disk.0 rama:/var/lib/one/datastores/0/3/disk.0", +# :result=>"SUCCESS", +# :info=>"-"} + +# {:path=> +# "/var/lib/one/remotes/tm/shared/mv o202:/var/lib/one//datastores/0/3 rama:/var/lib/one/datastores/0/3", +# :result=>"SUCCESS", +# :info=>"-"} + +#------------------------------------------------------------------------------- +# Return if moving a disk, we will move them when moving the whole system_ds +# directory for the VM +#------------------------------------------------------------------------------- +SRC_PATH=`arg_path $SRC` +SRC_HOST=`arg_host $SRC` + +if [ `is_disk $SRC_PATH` -eq 0 ]; then + log "Removing directory" + ssh_exec_and_log "$SRC_HOST" "rm -rf $SRC_PATH" + + exit 0 +fi + +if [ "$SRC" == "$DST" ]; then + log "Not moving $SRC to $DST, they are the same path" + exit 0 +fi + +log "Logging out $IQN" + +LOGOUT_CMD=$(cat < Date: Thu, 8 Mar 2012 19:17:30 +0100 Subject: [PATCH 6/6] Feature #1112: First version of migrator 3.3.0 to 3.3.80 --- install.sh | 1 + src/onedb/3.3.0_to_3.3.80.rb | 277 +++++++++++++++++++++++++++++++++++ 2 files changed, 278 insertions(+) create mode 100644 src/onedb/3.3.0_to_3.3.80.rb diff --git a/install.sh b/install.sh index 52a312ab3d..b7d3b9f60f 100755 --- a/install.sh +++ b/install.sh @@ -839,6 +839,7 @@ ONEDB_MIGRATOR_FILES="src/onedb/2.0_to_2.9.80.rb \ src/onedb/3.1.80_to_3.2.0.rb \ src/onedb/3.2.0_to_3.2.1.rb \ src/onedb/3.2.1_to_3.3.0.rb \ + src/onedb/3.3.0_to_3.3.80.rb \ src/onedb/onedb.rb \ src/onedb/onedb_backend.rb" diff --git a/src/onedb/3.3.0_to_3.3.80.rb b/src/onedb/3.3.0_to_3.3.80.rb new file mode 100644 index 0000000000..7194edc1e5 --- /dev/null +++ b/src/onedb/3.3.0_to_3.3.80.rb @@ -0,0 +1,277 @@ +# -------------------------------------------------------------------------- * +# Copyright 2002-2011, 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. * +# -------------------------------------------------------------------------- * + +require "rexml/document" +include REXML + +module Migrator + def db_version + "3.3.80" + end + + def one_version + "OpenNebula 3.3.80" + end + + def up + one_location = ENV["ONE_LOCATION"] + + if !one_location + var_location = "/var/lib/one" + else + var_location = one_location + "/var" + end + + ######################################################################## + # Get oneadmin user and group names + ######################################################################## + + oneadmin_uname = nil + + @db.fetch("SELECT name FROM user_pool WHERE oid=0") do |row| + oneadmin_uname = row[:name] + end + + if oneadmin_uname == nil + puts "Error trying to read oneadmin's user name ('SELECT name FROM user_pool WHERE oid=0')" + return false + end + + oneadmin_gname = nil + + @db.fetch("SELECT name FROM group_pool WHERE oid=0") do |row| + oneadmin_gname = row[:name] + end + + if oneadmin_gname == nil + puts "Error trying to read oneadmin's group name ('SELECT name FROM group_pool WHERE oid=0')" + return false + end + + ######################################################################## + # Create the cluster and datastore tables + ######################################################################## + + # New table for Clusters + @db.run "CREATE TABLE cluster_pool (oid INTEGER PRIMARY KEY, name VARCHAR(128), body TEXT, uid INTEGER, gid INTEGER, owner_u INTEGER, group_u INTEGER, other_u INTEGER, UNIQUE(name));" + + # New table for Datastores + @db.run "CREATE TABLE datastore_pool (oid INTEGER PRIMARY KEY, name VARCHAR(128), body TEXT, uid INTEGER, gid INTEGER, owner_u INTEGER, group_u INTEGER, other_u INTEGER, UNIQUE(name));" + + # Insert system datastore + + xml = + "" << + " 0" << + " 0" << + " 0" << + " #{oneadmin_uname}" << + " #{oneadmin_gname}" << + " system" << + " " << + " 1" << + " 1" << + " 0" << + " 0" << + " 0" << + " 0" << + " 0" << + " 0" << + " 0" << + " " << + " fs" << + " shared" << + " #{var_location}/datastores/0" << + " -1" << + " none" << + " " << + " " << + "" + + @db[:datastore_pool].insert( + :oid => 0, + :name => 'system', + :body => xml, + :uid => 0, + :gid => 0, + :owner_u => 1, + :group_u => 0, + :other_u => 0) + + # Last oid for cluster_pool and datastore_pool + + @db[:pool_control].insert( + :tablename => 'cluster_pool', + :last_oid => 99) + + @db[:pool_control].insert( + :tablename => 'datastore_pool', + :last_oid => 99) + + ######################################################################## + # Add each Host to Cluster -1 (none) + ######################################################################## + + @db.run "ALTER TABLE host_pool RENAME TO old_host_pool;" + @db.run "CREATE TABLE host_pool (oid INTEGER PRIMARY KEY, name VARCHAR(128), body TEXT, state INTEGER, last_mon_time INTEGER, uid INTEGER, gid INTEGER, owner_u INTEGER, group_u INTEGER, other_u INTEGER, UNIQUE(name));" + + @db.fetch("SELECT * FROM old_host_pool") do |row| + doc = Document.new(row[:body]) + + # Delete TM_MAD elem + doc.root.delete_element("TM_MAD") + + # Add Cluster elements + doc.root.add_element("CLUSTER_ID").text = "-1" + doc.root.add_element("CLUSTER").text = "none" + + @db[:host_pool].insert( + :oid => row[:oid], + :name => row[:name], + :body => doc.root.to_s, + :state => row[:state], + :last_mon_time => row[:last_mon_time], + :uid => row[:uid], + :gid => row[:gid], + :owner_u => row[:owner_u], + :group_u => row[:group_u], + :other_u => row[:other_u]) + end + + @db.run "DROP TABLE old_host_pool;" + + ######################################################################## + # Add each VNet to Cluster -1 (none) + ######################################################################## + + @db.run "ALTER TABLE network_pool RENAME TO old_network_pool;" + @db.run "CREATE TABLE network_pool (oid INTEGER PRIMARY KEY, name VARCHAR(128), body TEXT, uid INTEGER, gid INTEGER, owner_u INTEGER, group_u INTEGER, other_u INTEGER, UNIQUE(name,uid));" + + @db.fetch("SELECT * FROM old_network_pool") do |row| + doc = Document.new(row[:body]) + + # Add Cluster elements + doc.root.add_element("CLUSTER_ID").text = "-1" + doc.root.add_element("CLUSTER").text = "none" + + @db[:network_pool].insert( + :oid => row[:oid], + :name => row[:name], + :body => doc.root.to_s, + :uid => row[:uid], + :gid => row[:gid], + :owner_u => row[:owner_u], + :group_u => row[:group_u], + :other_u => row[:other_u]) + end + + @db.run "DROP TABLE old_network_pool;" + + ######################################################################## + # Add each Image to Datastore 1 (default) + ######################################################################## + + images_element = "" + + @db.run "ALTER TABLE image_pool RENAME TO old_image_pool;" + @db.run "CREATE TABLE image_pool (oid INTEGER PRIMARY KEY, name VARCHAR(128), body TEXT, uid INTEGER, gid INTEGER, owner_u INTEGER, group_u INTEGER, other_u INTEGER, UNIQUE(name,uid) );" + + @db.fetch("SELECT * FROM old_image_pool") do |row| + doc = Document.new(row[:body]) + + # Add Cluster elements + doc.root.add_element("DATASTORE_ID").text = "1" + doc.root.add_element("DATASTORE").text = "default" + + images_element << "#{row[:oid]}" + + # Update SOURCE + doc.root.each_element("SOURCE") { |e| + previous_source = e.text + hash = previous_source.split('/')[-1] + + if ( hash.length == 32 && hash =~ /^[0-9A-F]+$/i ) + e.text = "#{var_location}/datastores/1/#{hash}" + + # TODO: create link, or mv image file? + `ln -s #{previous_source} #{e.text}` + # `mv #{e.text} #{previous_source}` + end + } + + @db[:image_pool].insert( + :oid => row[:oid], + :name => row[:name], + :body => doc.root.to_s, + :uid => row[:uid], + :gid => row[:gid], + :owner_u => row[:owner_u], + :group_u => row[:group_u], + :other_u => row[:other_u]) + end + + @db.run "DROP TABLE old_image_pool;" + + images_element << "" + + # Insert default datastore + + xml = + "" << + " 1" << + " 0" << + " 0" << + " #{oneadmin_uname}" << + " #{oneadmin_gname}" << + " default" << + " " << + " 1" << + " 1" << + " 0" << + " 0" << + " 0" << + " 0" << + " 0" << + " 0" << + " 0" << + " " << + " fs" << # TODO + " shared" << # TODO + " #{var_location}/datastores/1" << + " -1" << + " none" << + images_element << + " " << + "" + + @db[:datastore_pool].insert( + :oid => 1, + :name => 'default', + :body => xml, + :uid => 0, + :gid => 0, + :owner_u => 1, + :group_u => 0, + :other_u => 0) + + return true + end +end