From f6ce18bfb4f6d4064cb0ca3b0aa8fcca8c50bc45 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Thu, 10 Nov 2011 11:15:58 +0100 Subject: [PATCH 001/121] feature #863: Change the OpenNebula Core to VMM Driver protocol now all messages have the same format: ACTION ID XML_B64_DATA The B64 data includes the parameters for each action plus a new field for the network driver used by the target host. Also this commit changes the tree for the networking drivers. --- include/PoolObjectSQL.h | 4 +- include/VirtualMachine.h | 26 ++ include/VirtualMachineManager.h | 34 +++ include/VirtualMachineManagerDriver.h | 80 ++---- src/vmm/VirtualMachineManager.cc | 265 +++++++++++++++--- src/vmm/VirtualMachineManagerDriver.cc | 44 ++- src/vmm/XMLDriver.cc | 4 +- .../{ => remotes/802.1Q}/HostManaged.rb | 0 src/vnm_mad/{ => remotes/802.1Q}/hm-vlan | 0 .../{ => remotes}/OpenNebulaNetwork.rb | 0 src/vnm_mad/{ => remotes}/OpenNebulaNic.rb | 0 .../{ => remotes/ebtables}/Ebtables.rb | 0 .../{ => remotes/ebtables}/ebtables-vlan | 0 src/vnm_mad/{ => remotes/fw}/Firewall.rb | 0 src/vnm_mad/{ => remotes/fw}/firewall | 0 .../{ => remotes/ovswtich}/OpenvSwitch.rb | 0 .../{ => remotes/ovswtich}/openvswitch-vlan | 0 .../test/OpenNebulaNetwork_spec.rb | 0 src/vnm_mad/{ => remotes}/test/SystemMock.rb | 0 .../{ => remotes}/test/output/brctl_show | 0 .../{ => remotes}/test/output/kvm_lsmod | 0 .../{ => remotes}/test/output/kvm_uname_a | 0 .../{ => remotes}/test/output/onevm_show | 0 .../test/output/onevm_show_phydev_kvm | 0 .../test/output/onevm_show_vlan_id_kvm | 0 .../{ => remotes}/test/output/onevm_show_xen | 0 .../{ => remotes}/test/output/virsh_dumpxml | 0 .../test/output/virsh_dumpxml_phydev | 0 .../test/output/virsh_dumpxml_vlan_id | 0 .../{ => remotes}/test/output/xen_lsmod | 0 .../{ => remotes}/test/output/xen_uname_a | 0 .../{ => remotes}/test/output/xm_domid | 0 .../{ => remotes}/test/output/xm_network_list | 0 33 files changed, 334 insertions(+), 123 deletions(-) rename src/vnm_mad/{ => remotes/802.1Q}/HostManaged.rb (100%) rename src/vnm_mad/{ => remotes/802.1Q}/hm-vlan (100%) rename src/vnm_mad/{ => remotes}/OpenNebulaNetwork.rb (100%) rename src/vnm_mad/{ => remotes}/OpenNebulaNic.rb (100%) rename src/vnm_mad/{ => remotes/ebtables}/Ebtables.rb (100%) rename src/vnm_mad/{ => remotes/ebtables}/ebtables-vlan (100%) rename src/vnm_mad/{ => remotes/fw}/Firewall.rb (100%) rename src/vnm_mad/{ => remotes/fw}/firewall (100%) rename src/vnm_mad/{ => remotes/ovswtich}/OpenvSwitch.rb (100%) rename src/vnm_mad/{ => remotes/ovswtich}/openvswitch-vlan (100%) rename src/vnm_mad/{ => remotes}/test/OpenNebulaNetwork_spec.rb (100%) rename src/vnm_mad/{ => remotes}/test/SystemMock.rb (100%) rename src/vnm_mad/{ => remotes}/test/output/brctl_show (100%) rename src/vnm_mad/{ => remotes}/test/output/kvm_lsmod (100%) rename src/vnm_mad/{ => remotes}/test/output/kvm_uname_a (100%) rename src/vnm_mad/{ => remotes}/test/output/onevm_show (100%) rename src/vnm_mad/{ => remotes}/test/output/onevm_show_phydev_kvm (100%) rename src/vnm_mad/{ => remotes}/test/output/onevm_show_vlan_id_kvm (100%) rename src/vnm_mad/{ => remotes}/test/output/onevm_show_xen (100%) rename src/vnm_mad/{ => remotes}/test/output/virsh_dumpxml (100%) rename src/vnm_mad/{ => remotes}/test/output/virsh_dumpxml_phydev (100%) rename src/vnm_mad/{ => remotes}/test/output/virsh_dumpxml_vlan_id (100%) rename src/vnm_mad/{ => remotes}/test/output/xen_lsmod (100%) rename src/vnm_mad/{ => remotes}/test/output/xen_uname_a (100%) rename src/vnm_mad/{ => remotes}/test/output/xm_domid (100%) rename src/vnm_mad/{ => remotes}/test/output/xm_network_list (100%) diff --git a/include/PoolObjectSQL.h b/include/PoolObjectSQL.h index 6f357b23e7..4aa66c4235 100644 --- a/include/PoolObjectSQL.h +++ b/include/PoolObjectSQL.h @@ -259,9 +259,9 @@ public: * Generates a XML string for the template of the Object * @param xml the string to store the XML description. */ - void template_to_xml(string &xml) const + string& template_to_xml(string &xml) const { - obj_template->to_xml(xml); + return obj_template->to_xml(xml); } /** diff --git a/include/VirtualMachine.h b/include/VirtualMachine.h index 568c48ceee..7d93020fd8 100644 --- a/include/VirtualMachine.h +++ b/include/VirtualMachine.h @@ -273,6 +273,32 @@ public: return previous_history->vmm_mad_name; }; + /** + * Returns the VNM driver name for the current host. The hasHistory() + * function MUST be called before this one. + * @return the VMM mad name + */ + // const string & get_vnm_mad() const + string get_vnm_mad() const + { + string tmp = "TODO"; + return tmp; + //TODO return history->vnm_mad_name; + }; + + /** + * Returns the VNM driver name for the previous host. The hasPreviousHistory() + * function MUST be called before this one. + * @return the VMM mad name + */ + // const string & get_previous_vnm_mad() const + string get_previous_vnm_mad() const + { + string tmp = "TODO"; + return tmp; + //return previous_history->vnm_mad_name; + }; + /** * Returns the TM driver name for the current host. The hasHistory() * function MUST be called before this one. diff --git a/include/VirtualMachineManager.h b/include/VirtualMachineManager.h index 03fea34a94..1c41918288 100644 --- a/include/VirtualMachineManager.h +++ b/include/VirtualMachineManager.h @@ -175,6 +175,40 @@ private: const string & action, void * arg); + /** + * Function to format a VMM Driver message in the form: + * + * hostname + * net_drv + * m_hostname + * m_net_drv + * domain_id + * dfile + * cfile + * + * VM representation in XML + * + * + * + * @param hostname of the host to perform the action + * @param net_drv name of the vlan driver + * @param m_hostname name of the host to migrate the VM + * @param m_net_drv name of the vlan driver + * @param domain domain id as returned by the hypervisor + * @param dfile deployment file to boot the VM + * @param cfile checkpoint file to save the VM + * @param tmpl the VM information in XML + */ + string * format_message( + const string& hostname, + const string& net_drv, + const string& m_hostname, + const string& m_net_drv, + const string& domain, + const string& dfile, + const string& cfile, + const string& tmpl); + /** * Function executed when a DEPLOY action is received. It deploys a VM on * a Host. diff --git a/include/VirtualMachineManagerDriver.h b/include/VirtualMachineManagerDriver.h index a1f219e4e3..2d75485ed4 100644 --- a/include/VirtualMachineManagerDriver.h +++ b/include/VirtualMachineManagerDriver.h @@ -110,108 +110,76 @@ private: friend class VirtualMachineManager; /** - * Sends a deploy request to the MAD: "DEPLOY ID HOST CONF -" + * Sends a deploy request to the MAD: "DEPLOY ID XML_DRV_MSG" * @param oid the virtual machine id. - * @param host the hostname - * @param conf the filename of the deployment file + * @param drv_msg xml data for the mad operation */ void deploy ( const int oid, - const string& host, - const string& conf) const; + const string& drv_msg) const; /** - * Sends a shutdown request to the MAD: "SHUTDOWN ID HOST NAME -" + * Sends a shutdown request to the MAD: "SHUTDOWN ID XML_DRV_MSG" * @param oid the virtual machine id. - * @param host the hostname - * @param name of the Virtual Machine (deployment id), as returned by the - * driver + * @param drv_msg xml data for the mad operation */ void shutdown ( const int oid, - const string& host, - const string& name) const; + const string& drv_msg) const; /** - * Sends a cancel request to the MAD: "CANCEL ID HOST NAME -" + * Sends a cancel request to the MAD: "CANCEL ID XML_DRV_MSG" * @param oid the virtual machine id. - * @param host the hostname - * @param name of the Virtual Machine (deployment id), as returned by the - * driver + * @param drv_msg xml data for the mad operation */ void cancel ( const int oid, - const string& host, - const string& name) const; + const string& drv_msg) const; /** - * Sends a checkpoint request to the MAD: "CHECKPOINT ID HOST NAME FILE" + * Sends a checkpoint request to the MAD: "CHECKPOINT ID XML_DRV_MSG" * @param oid the virtual machine id. - * @param host the hostname - * @param name of the Virtual Machine (deployment id), as returned by the - * driver - * @param file the filename to generate the checkpoint file + * @param drv_msg xml data for the mad operation */ void checkpoint ( const int oid, - const string& host, - const string& name, - const string& file) const; + const string& drv_msg) const; /** - * Sends a save request to the MAD: "SAVE ID HOST NAME FILE" + * Sends a save request to the MAD: "SAVE ID XML_DRV_MSG" * @param oid the virtual machine id. - * @param host the hostname - * @param name of the Virtual Machine (deployment id), as returned by the - * driver - * @param file the filename to generate the checkpoint file + * @param drv_msg xml data for the mad operation */ void save ( const int oid, - const string& host, - const string& name, - const string& file) const; + const string& drv_msg) const; /** - * Sends a save request to the MAD: "RESTORE ID HOST FILE -" + * Sends a save request to the MAD: "RESTORE ID XML_DRV_MSG" * @param oid the virtual machine id. - * @param host the hostname - * @param name of the Virtual Machine (deployment id), as returned by the - * driver - * @param file the filename of the checkpoint file to restore the VM - * from + * @param drv_msg xml data for the mad operation */ void restore ( const int oid, - const string& host, - const string& name, - const string& file) const; + const string& drv_msg) const; /** - * Sends a migrate request to the MAD: "MIGRATE ID HOST NAME DEST" + * Sends a migrate request to the MAD: "MIGRATE ID XML_DRV_MSG" * @param oid the virtual machine id. - * @param shost the original host (source) - * @param name of the Virtual Machine (deployment id), as returned by the - * driver - * @param dhost the destination host + * @param drv_msg xml data for the mad operation */ void migrate ( const int oid, - const string& shost, - const string& name, - const string& dhost) const; + const string& drv_msg) const; /** - * Sends a poll request to the MAD: "POLL ID HOST NAME -" + * Sends a poll request to the MAD: "POLL ID XML_DRV_MSG" * @param oid the virtual machine id. - * @param host the hostname - * @param name of the Virtual Machine (deployment id), as returned by the - * driver + * @param drv_msg xml data for the mad operation */ void poll ( const int oid, - const string& host, - const string& name) const; + const string& drv_msg) const; }; /* -------------------------------------------------------------------------- */ diff --git a/src/vmm/VirtualMachineManager.cc b/src/vmm/VirtualMachineManager.cc index fc43d3380f..d7a8720bfc 100644 --- a/src/vmm/VirtualMachineManager.cc +++ b/src/vmm/VirtualMachineManager.cc @@ -245,12 +245,77 @@ void VirtualMachineManager::do_action(const string &action, void * arg) /* Manager Actions */ /* ************************************************************************** */ +string * VirtualMachineManager::format_message( + const string& hostname, + const string& net_drv, + const string& m_hostname, + const string& m_net_drv, + const string& domain, + const string& dfile, + const string& cfile, + const string& tmpl) +{ + ostringstream oss; + + oss << "" + << "" << hostname << "" + << "" << net_drv << ""; + + if (!m_hostname.empty()) + { + oss << "" << m_hostname << "" + << ""<< m_net_drv << ""; + } + else + { + oss << ""; + } + + if (!domain.empty()) + { + oss << "" << domain << ""; + } + else + { + oss << ""; + } + + if (!dfile.empty()) + { + oss << "" << dfile << ""; + } + else + { + oss << ""; + } + + if (!cfile.empty()) + { + oss << "" << cfile << ""; + } + else + { + oss << ""; + } + + oss << "" << tmpl << "" + << ""; + + return SSLTools::base64_encode(oss.str()); +} + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + void VirtualMachineManager::deploy_action(int vid) { - VirtualMachine * vm; - const VirtualMachineManagerDriver * vmd; - int rc; - ostringstream os; + VirtualMachine * vm; + const VirtualMachineManagerDriver * vmd; + int rc; + + ostringstream os; + string vm_tmpl; + string * drv_msg; // Get the VM from the pool vm = vmpool->get(vid,true); @@ -287,7 +352,19 @@ void VirtualMachineManager::deploy_action(int vid) } // Invoke driver method - vmd->deploy(vid,vm->get_hostname(),vm->get_remote_deployment_file()); + drv_msg = format_message( + vm->get_hostname(), + vm->get_vnm_mad(), + "", + "", + "", + vm->get_remote_deployment_file(), + "", + vm->template_to_xml(vm_tmpl)); + + vmd->deploy(vid, *drv_msg); + + delete drv_msg; vm->unlock(); @@ -326,8 +403,11 @@ void VirtualMachineManager::save_action( { VirtualMachine * vm; const VirtualMachineManagerDriver * vmd; - string hostname; - ostringstream os; + + string hostname, vnm_mad; + string vm_tmpl; + string * drv_msg; + ostringstream os; // Get the VM from the pool vm = vmpool->get(vid,true); @@ -359,20 +439,31 @@ void VirtualMachineManager::save_action( } hostname = vm->get_previous_hostname(); + vnm_mad = vm->get_previous_vnm_mad(); } else { - hostname=vm->get_hostname(); + hostname = vm->get_hostname(); + vnm_mad = vm->get_vnm_mad(); } // Invoke driver method - vmd->save( - vid, + drv_msg = format_message( hostname, + vnm_mad, + "", + "", vm->get_deploy_id(), - vm->get_checkpoint_file()); + "", + vm->get_checkpoint_file(), + vm->to_xml(vm_tmpl)); + + vmd->save(vid, *drv_msg); + + delete drv_msg; vm->unlock(); + return; error_history: @@ -406,9 +497,12 @@ error_common: void VirtualMachineManager::shutdown_action( int vid) { - VirtualMachine * vm; - const VirtualMachineManagerDriver * vmd; - ostringstream os; + VirtualMachine * vm; + const VirtualMachineManagerDriver * vmd; + + string vm_tmpl; + string * drv_msg; + ostringstream os; // Get the VM from the pool vm = vmpool->get(vid,true); @@ -432,9 +526,22 @@ void VirtualMachineManager::shutdown_action( } // Invoke driver method - vmd->shutdown(vid,vm->get_hostname(),vm->get_deploy_id()); + drv_msg = format_message( + vm->get_hostname(), + vm->get_vnm_mad(), + "", + "", + vm->get_deploy_id(), + "", + "", + vm->to_xml(vm_tmpl)); + + vmd->shutdown(vid, *drv_msg); + + delete drv_msg; vm->unlock(); + return; error_history: @@ -466,6 +573,9 @@ void VirtualMachineManager::cancel_action( VirtualMachine * vm; ostringstream os; + string vm_tmpl; + string * drv_msg; + const VirtualMachineManagerDriver * vmd; // Get the VM from the pool @@ -490,9 +600,22 @@ void VirtualMachineManager::cancel_action( } // Invoke driver method - vmd->cancel(vid,vm->get_hostname(),vm->get_deploy_id()); + drv_msg = format_message( + vm->get_hostname(), + vm->get_vnm_mad(), + "", + "", + vm->get_deploy_id(), + "", + "", + vm->to_xml(vm_tmpl)); + + vmd->cancel(vid, *drv_msg); + + delete drv_msg; vm->unlock(); + return; error_history: @@ -527,6 +650,9 @@ void VirtualMachineManager::cancel_previous_action( VirtualMachine * vm; ostringstream os; + string vm_tmpl; + string * drv_msg; + const VirtualMachineManagerDriver * vmd; // Get the VM from the pool @@ -551,9 +677,22 @@ void VirtualMachineManager::cancel_previous_action( } // Invoke driver method - vmd->cancel(vid,vm->get_previous_hostname(),vm->get_deploy_id()); + drv_msg = format_message( + vm->get_previous_hostname(), + vm->get_previous_vnm_mad(), + "", + "", + vm->get_deploy_id(), + "", + "", + vm->to_xml(vm_tmpl)); + + vmd->cancel(vid, *drv_msg); + + delete drv_msg; vm->unlock(); + return; error_history: @@ -579,7 +718,10 @@ void VirtualMachineManager::migrate_action( { VirtualMachine * vm; const VirtualMachineManagerDriver * vmd; - ostringstream os; + + ostringstream os; + string vm_tmpl; + string * drv_msg; // Get the VM from the pool vm = vmpool->get(vid,true); @@ -608,10 +750,19 @@ void VirtualMachineManager::migrate_action( } // Invoke driver method - vmd->migrate(vid, - vm->get_previous_hostname(), - vm->get_deploy_id(), - vm->get_hostname()); + drv_msg = format_message( + vm->get_previous_hostname(), + vm->get_previous_vnm_mad(), + vm->get_hostname(), + vm->get_vnm_mad(), + vm->get_deploy_id(), + "", + "", + vm->to_xml(vm_tmpl)); + + vmd->migrate(vid, *drv_msg); + + delete drv_msg; vm->unlock(); @@ -648,9 +799,13 @@ error_common: void VirtualMachineManager::restore_action( int vid) { - VirtualMachine * vm; - const VirtualMachineManagerDriver * vmd; - ostringstream os; + VirtualMachine * vm; + const VirtualMachineManagerDriver * vmd; + + ostringstream os; + + string vm_tmpl; + string * drv_msg; // Get the VM from the pool vm = vmpool->get(vid,true); @@ -674,12 +829,22 @@ void VirtualMachineManager::restore_action( } // Invoke driver method - vmd->restore(vid, - vm->get_hostname(), - vm->get_deploy_id(), - vm->get_checkpoint_file()); + drv_msg = format_message( + vm->get_hostname(), + vm->get_vnm_mad(), + "", + "", + vm->get_deploy_id(), + "", + vm->get_checkpoint_file(), + vm->to_xml(vm_tmpl)); + + vmd->restore(vid, *drv_msg); + + delete drv_msg; vm->unlock(); + return; error_history: @@ -708,9 +873,13 @@ error_common: void VirtualMachineManager::poll_action( int vid) { - VirtualMachine * vm; - const VirtualMachineManagerDriver * vmd; - ostringstream os; + VirtualMachine * vm; + const VirtualMachineManagerDriver * vmd; + + ostringstream os; + + string vm_tmpl; + string * drv_msg; // Get the VM from the pool vm = vmpool->get(vid,true); @@ -734,9 +903,22 @@ void VirtualMachineManager::poll_action( } // Invoke driver method - vmd->poll(vid,vm->get_hostname(),vm->get_deploy_id()); + drv_msg = format_message( + vm->get_hostname(), + vm->get_vnm_mad(), + "", + "", + vm->get_deploy_id(), + "", + "", + vm->to_xml(vm_tmpl)); + + vmd->poll(vid, *drv_msg); + + delete drv_msg; vm->unlock(); + return; error_history: @@ -824,6 +1006,9 @@ void VirtualMachineManager::timer_action() const VirtualMachineManagerDriver * vmd; + string vm_tmpl; + string * drv_msg; + mark = mark + timer_period; if ( mark >= 600 ) @@ -874,7 +1059,19 @@ void VirtualMachineManager::timer_action() continue; } - vmd->poll(*it,vm->get_hostname(),vm->get_deploy_id()); + drv_msg = format_message( + vm->get_hostname(), + vm->get_vnm_mad(), + "", + "", + vm->get_deploy_id(), + "", + "", + vm->to_xml(vm_tmpl)); + + vmd->poll(*it, *drv_msg); + + delete drv_msg; vmpool->update(vm); diff --git a/src/vmm/VirtualMachineManagerDriver.cc b/src/vmm/VirtualMachineManagerDriver.cc index 4b58f06f2f..c186afd927 100644 --- a/src/vmm/VirtualMachineManagerDriver.cc +++ b/src/vmm/VirtualMachineManagerDriver.cc @@ -104,12 +104,11 @@ void VirtualMachineManagerDriver::get_default( void VirtualMachineManagerDriver::deploy ( const int oid, - const string& host, - const string& conf) const + const string& drv_msg) const { ostringstream os; - os << "DEPLOY " << oid << " " << host << " " << conf << " -" << endl; + os << "DEPLOY " << oid << " " << drv_msg << endl; write(os); }; @@ -119,12 +118,11 @@ void VirtualMachineManagerDriver::deploy ( void VirtualMachineManagerDriver::shutdown ( const int oid, - const string& host, - const string& name) const + const string& drv_msg) const { ostringstream os; - os << "SHUTDOWN " << oid << " " << host << " " << name << " -" << endl; + os << "SHUTDOWN " << oid << " " << drv_msg << endl; write(os); }; @@ -134,12 +132,11 @@ void VirtualMachineManagerDriver::shutdown ( void VirtualMachineManagerDriver::cancel ( const int oid, - const string& host, - const string& name) const + const string& drv_msg) const { ostringstream os; - os << "CANCEL " << oid << " " << host << " " << name << " -" << endl; + os << "CANCEL " << oid << " " << drv_msg << endl; write(os); }; @@ -149,13 +146,11 @@ void VirtualMachineManagerDriver::cancel ( void VirtualMachineManagerDriver::checkpoint ( const int oid, - const string& host, - const string& name, - const string& file) const + const string& drv_msg) const { ostringstream os; - os<< "CHECKPOINT " << oid<< " "<< host<< " "<< name<< " "<< file<< endl; + os<< "CHECKPOINT " << oid << " " << drv_msg << endl; write(os); }; @@ -165,13 +160,11 @@ void VirtualMachineManagerDriver::checkpoint ( void VirtualMachineManagerDriver::save ( const int oid, - const string& host, - const string& name, - const string& file) const + const string& drv_msg) const { ostringstream os; - os<< "SAVE " << oid << " " << host << " " << name << " "<< file << endl; + os<< "SAVE " << oid << " " << drv_msg << endl; write(os); }; @@ -181,13 +174,11 @@ void VirtualMachineManagerDriver::save ( void VirtualMachineManagerDriver::restore ( const int oid, - const string& host, - const string& name, - const string& file) const + const string& drv_msg) const { ostringstream os; - os << "RESTORE " << oid << " " << host << " " << name << " " << file<< endl; + os << "RESTORE " << oid << " " << drv_msg << endl; write(os); }; @@ -197,13 +188,11 @@ void VirtualMachineManagerDriver::restore ( void VirtualMachineManagerDriver::migrate ( const int oid, - const string& shost, - const string& name, - const string& dhost) const + const string& drv_msg) const { ostringstream os; - os<< "MIGRATE " << oid << " "<< shost<< " "<< name<< " "<< dhost<< endl; + os<< "MIGRATE " << oid << " " << drv_msg << endl; write(os); }; @@ -213,12 +202,11 @@ void VirtualMachineManagerDriver::migrate ( void VirtualMachineManagerDriver::poll ( const int oid, - const string& host, - const string& name) const + const string& drv_msg) const { ostringstream os; - os << "POLL " << oid << " " << host << " " << name << " -" << endl; + os << "POLL " << oid << " " << drv_msg << endl; write(os); }; diff --git a/src/vmm/XMLDriver.cc b/src/vmm/XMLDriver.cc index 2879211e64..4329b71f30 100644 --- a/src/vmm/XMLDriver.cc +++ b/src/vmm/XMLDriver.cc @@ -35,9 +35,7 @@ int XMLDriver::deployment_description( return -1; } - vm->template_to_xml(xml); - - file << xml ; + file << vm->template_to_xml(xml); file.close(); diff --git a/src/vnm_mad/HostManaged.rb b/src/vnm_mad/remotes/802.1Q/HostManaged.rb similarity index 100% rename from src/vnm_mad/HostManaged.rb rename to src/vnm_mad/remotes/802.1Q/HostManaged.rb diff --git a/src/vnm_mad/hm-vlan b/src/vnm_mad/remotes/802.1Q/hm-vlan similarity index 100% rename from src/vnm_mad/hm-vlan rename to src/vnm_mad/remotes/802.1Q/hm-vlan diff --git a/src/vnm_mad/OpenNebulaNetwork.rb b/src/vnm_mad/remotes/OpenNebulaNetwork.rb similarity index 100% rename from src/vnm_mad/OpenNebulaNetwork.rb rename to src/vnm_mad/remotes/OpenNebulaNetwork.rb diff --git a/src/vnm_mad/OpenNebulaNic.rb b/src/vnm_mad/remotes/OpenNebulaNic.rb similarity index 100% rename from src/vnm_mad/OpenNebulaNic.rb rename to src/vnm_mad/remotes/OpenNebulaNic.rb diff --git a/src/vnm_mad/Ebtables.rb b/src/vnm_mad/remotes/ebtables/Ebtables.rb similarity index 100% rename from src/vnm_mad/Ebtables.rb rename to src/vnm_mad/remotes/ebtables/Ebtables.rb diff --git a/src/vnm_mad/ebtables-vlan b/src/vnm_mad/remotes/ebtables/ebtables-vlan similarity index 100% rename from src/vnm_mad/ebtables-vlan rename to src/vnm_mad/remotes/ebtables/ebtables-vlan diff --git a/src/vnm_mad/Firewall.rb b/src/vnm_mad/remotes/fw/Firewall.rb similarity index 100% rename from src/vnm_mad/Firewall.rb rename to src/vnm_mad/remotes/fw/Firewall.rb diff --git a/src/vnm_mad/firewall b/src/vnm_mad/remotes/fw/firewall similarity index 100% rename from src/vnm_mad/firewall rename to src/vnm_mad/remotes/fw/firewall diff --git a/src/vnm_mad/OpenvSwitch.rb b/src/vnm_mad/remotes/ovswtich/OpenvSwitch.rb similarity index 100% rename from src/vnm_mad/OpenvSwitch.rb rename to src/vnm_mad/remotes/ovswtich/OpenvSwitch.rb diff --git a/src/vnm_mad/openvswitch-vlan b/src/vnm_mad/remotes/ovswtich/openvswitch-vlan similarity index 100% rename from src/vnm_mad/openvswitch-vlan rename to src/vnm_mad/remotes/ovswtich/openvswitch-vlan diff --git a/src/vnm_mad/test/OpenNebulaNetwork_spec.rb b/src/vnm_mad/remotes/test/OpenNebulaNetwork_spec.rb similarity index 100% rename from src/vnm_mad/test/OpenNebulaNetwork_spec.rb rename to src/vnm_mad/remotes/test/OpenNebulaNetwork_spec.rb diff --git a/src/vnm_mad/test/SystemMock.rb b/src/vnm_mad/remotes/test/SystemMock.rb similarity index 100% rename from src/vnm_mad/test/SystemMock.rb rename to src/vnm_mad/remotes/test/SystemMock.rb diff --git a/src/vnm_mad/test/output/brctl_show b/src/vnm_mad/remotes/test/output/brctl_show similarity index 100% rename from src/vnm_mad/test/output/brctl_show rename to src/vnm_mad/remotes/test/output/brctl_show diff --git a/src/vnm_mad/test/output/kvm_lsmod b/src/vnm_mad/remotes/test/output/kvm_lsmod similarity index 100% rename from src/vnm_mad/test/output/kvm_lsmod rename to src/vnm_mad/remotes/test/output/kvm_lsmod diff --git a/src/vnm_mad/test/output/kvm_uname_a b/src/vnm_mad/remotes/test/output/kvm_uname_a similarity index 100% rename from src/vnm_mad/test/output/kvm_uname_a rename to src/vnm_mad/remotes/test/output/kvm_uname_a diff --git a/src/vnm_mad/test/output/onevm_show b/src/vnm_mad/remotes/test/output/onevm_show similarity index 100% rename from src/vnm_mad/test/output/onevm_show rename to src/vnm_mad/remotes/test/output/onevm_show diff --git a/src/vnm_mad/test/output/onevm_show_phydev_kvm b/src/vnm_mad/remotes/test/output/onevm_show_phydev_kvm similarity index 100% rename from src/vnm_mad/test/output/onevm_show_phydev_kvm rename to src/vnm_mad/remotes/test/output/onevm_show_phydev_kvm diff --git a/src/vnm_mad/test/output/onevm_show_vlan_id_kvm b/src/vnm_mad/remotes/test/output/onevm_show_vlan_id_kvm similarity index 100% rename from src/vnm_mad/test/output/onevm_show_vlan_id_kvm rename to src/vnm_mad/remotes/test/output/onevm_show_vlan_id_kvm diff --git a/src/vnm_mad/test/output/onevm_show_xen b/src/vnm_mad/remotes/test/output/onevm_show_xen similarity index 100% rename from src/vnm_mad/test/output/onevm_show_xen rename to src/vnm_mad/remotes/test/output/onevm_show_xen diff --git a/src/vnm_mad/test/output/virsh_dumpxml b/src/vnm_mad/remotes/test/output/virsh_dumpxml similarity index 100% rename from src/vnm_mad/test/output/virsh_dumpxml rename to src/vnm_mad/remotes/test/output/virsh_dumpxml diff --git a/src/vnm_mad/test/output/virsh_dumpxml_phydev b/src/vnm_mad/remotes/test/output/virsh_dumpxml_phydev similarity index 100% rename from src/vnm_mad/test/output/virsh_dumpxml_phydev rename to src/vnm_mad/remotes/test/output/virsh_dumpxml_phydev diff --git a/src/vnm_mad/test/output/virsh_dumpxml_vlan_id b/src/vnm_mad/remotes/test/output/virsh_dumpxml_vlan_id similarity index 100% rename from src/vnm_mad/test/output/virsh_dumpxml_vlan_id rename to src/vnm_mad/remotes/test/output/virsh_dumpxml_vlan_id diff --git a/src/vnm_mad/test/output/xen_lsmod b/src/vnm_mad/remotes/test/output/xen_lsmod similarity index 100% rename from src/vnm_mad/test/output/xen_lsmod rename to src/vnm_mad/remotes/test/output/xen_lsmod diff --git a/src/vnm_mad/test/output/xen_uname_a b/src/vnm_mad/remotes/test/output/xen_uname_a similarity index 100% rename from src/vnm_mad/test/output/xen_uname_a rename to src/vnm_mad/remotes/test/output/xen_uname_a diff --git a/src/vnm_mad/test/output/xm_domid b/src/vnm_mad/remotes/test/output/xm_domid similarity index 100% rename from src/vnm_mad/test/output/xm_domid rename to src/vnm_mad/remotes/test/output/xm_domid diff --git a/src/vnm_mad/test/output/xm_network_list b/src/vnm_mad/remotes/test/output/xm_network_list similarity index 100% rename from src/vnm_mad/test/output/xm_network_list rename to src/vnm_mad/remotes/test/output/xm_network_list From 5571bd81c0373f0a1b0b03737a7aa4b62a8f0a0f Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Thu, 10 Nov 2011 11:20:49 +0100 Subject: [PATCH 002/121] feature #863: Fix comment on for the XML format of the driver message --- include/VirtualMachineManager.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/VirtualMachineManager.h b/include/VirtualMachineManager.h index 1c41918288..8df8df3b1e 100644 --- a/include/VirtualMachineManager.h +++ b/include/VirtualMachineManager.h @@ -185,9 +185,9 @@ private: * domain_id * dfile * cfile - * + * * VM representation in XML - * + * * * * @param hostname of the host to perform the action From 665036efcf67c919fccebf11d5b00a047edac2c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Thu, 10 Nov 2011 17:28:32 +0100 Subject: [PATCH 003/121] Feature #863: Add Virtual Network MAD to hosts --- include/History.h | 2 ++ include/Host.h | 15 +++++++++++++++ include/HostPool.h | 1 + include/RequestManagerVirtualMachine.h | 5 +++-- include/VirtualMachine.h | 9 +++------ src/host/Host.cc | 4 ++++ src/host/HostPool.cc | 13 ++++++++++++- src/rm/RequestManagerAllocate.cc | 6 ++++-- src/rm/RequestManagerVirtualMachine.cc | 17 +++++++++++------ src/vm/History.cc | 5 +++++ src/vm/VirtualMachine.cc | 5 ++++- 11 files changed, 64 insertions(+), 18 deletions(-) diff --git a/include/History.h b/include/History.h index 35e38a3569..0f46fc86f2 100644 --- a/include/History.h +++ b/include/History.h @@ -46,6 +46,7 @@ public: const string& hostname, const string& vm_dir, const string& vmm, + const string& vnm, const string& tm); ~History(){}; @@ -91,6 +92,7 @@ private: int hid; string vmm_mad_name; + string vnm_mad_name; string tm_mad_name; time_t stime; diff --git a/include/Host.h b/include/Host.h index f112532aa0..cb9403cdf4 100644 --- a/include/Host.h +++ b/include/Host.h @@ -130,6 +130,15 @@ public: return vmm_mad_name; }; + /** + * Retrives VNM mad name + * @return string vnm mad name + */ + const string& get_vnm_mad() const + { + return vnm_mad_name; + }; + /** * Retrives TM mad name * @return string tm mad name @@ -311,6 +320,11 @@ private: */ string vmm_mad_name; + /** + * Name of the VN driver used to manage networking in this host + */ + string vnm_mad_name; + /** * Name of the TM driver used to transfer file to and from this host */ @@ -338,6 +352,7 @@ private: const string& hostname="", const string& im_mad_name="", const string& vmm_mad_name="", + const string& vnm_mad_name="", const string& tm_mad_name=""); virtual ~Host(); diff --git a/include/HostPool.h b/include/HostPool.h index 89a516218e..50686a60fe 100644 --- a/include/HostPool.h +++ b/include/HostPool.h @@ -51,6 +51,7 @@ public: const string& hostname, const string& im_mad_name, const string& vmm_mad_name, + const string& vnm_mad_name, const string& tm_mad_name, string& error_str); diff --git a/include/RequestManagerVirtualMachine.h b/include/RequestManagerVirtualMachine.h index ea70ad35f5..0c06b4582b 100644 --- a/include/RequestManagerVirtualMachine.h +++ b/include/RequestManagerVirtualMachine.h @@ -51,13 +51,14 @@ protected: bool vm_authorization(int id, int hid, ImageTemplate *tmpl, RequestAttributes& att); - int get_host_information(int hid, string& name, string& vmm, string& tm, - RequestAttributes& att); + int get_host_information(int hid, string& name, string& vmm, string& vnm, + string& tm, RequestAttributes& att); int add_history(VirtualMachine * vm, int hid, const string& hostname, const string& vmm_mad, + const string& vnm_mad, const string& tm_mad, RequestAttributes& att); diff --git a/include/VirtualMachine.h b/include/VirtualMachine.h index 7d93020fd8..357ccb75a1 100644 --- a/include/VirtualMachine.h +++ b/include/VirtualMachine.h @@ -217,6 +217,7 @@ public: const string& hostname, const string& vm_dir, const string& vmm_mad, + const string& vnm_mad, const string& tm_mad); /** @@ -281,9 +282,7 @@ public: // const string & get_vnm_mad() const string get_vnm_mad() const { - string tmp = "TODO"; - return tmp; - //TODO return history->vnm_mad_name; + return history->vnm_mad_name; }; /** @@ -294,9 +293,7 @@ public: // const string & get_previous_vnm_mad() const string get_previous_vnm_mad() const { - string tmp = "TODO"; - return tmp; - //return previous_history->vnm_mad_name; + return previous_history->vnm_mad_name; }; /** diff --git a/src/host/Host.cc b/src/host/Host.cc index 52361a96ed..484a44953b 100644 --- a/src/host/Host.cc +++ b/src/host/Host.cc @@ -33,11 +33,13 @@ Host::Host( const string& _hostname, const string& _im_mad_name, const string& _vmm_mad_name, + const string& _vnm_mad_name, const string& _tm_mad_name): PoolObjectSQL(id,_hostname,-1,-1,"","",table), state(INIT), im_mad_name(_im_mad_name), vmm_mad_name(_vmm_mad_name), + vnm_mad_name(_vnm_mad_name), tm_mad_name(_tm_mad_name), last_monitored(0) { @@ -200,6 +202,7 @@ string& Host::to_xml(string& xml) const "" << state << "" << "" << im_mad_name << "" << "" << vmm_mad_name << "" << + "" << vnm_mad_name << "" << "" << tm_mad_name << "" << "" << last_monitored << "" << host_share.to_xml(share_xml) << @@ -231,6 +234,7 @@ int Host::from_xml(const string& xml) rc += xpath(im_mad_name, "/HOST/IM_MAD", "not_found"); rc += xpath(vmm_mad_name, "/HOST/VM_MAD", "not_found"); + rc += xpath(vnm_mad_name, "/HOST/VN_MAD", "not_found"); rc += xpath(tm_mad_name, "/HOST/TM_MAD", "not_found"); rc += xpath(last_monitored, "/HOST/LAST_MON_TIME", 0); diff --git a/src/host/HostPool.cc b/src/host/HostPool.cc index d33529cbad..b3d404a1a0 100644 --- a/src/host/HostPool.cc +++ b/src/host/HostPool.cc @@ -139,6 +139,7 @@ int HostPool::allocate ( const string& hostname, const string& im_mad_name, const string& vmm_mad_name, + const string& vnm_mad_name, const string& tm_mad_name, string& error_str) { @@ -165,6 +166,11 @@ int HostPool::allocate ( goto error_vmm; } + if ( vnm_mad_name.empty() ) + { + goto error_vnm; + } + if ( tm_mad_name.empty() ) { goto error_tm; @@ -179,7 +185,8 @@ int HostPool::allocate ( // Build a new Host object - host = new Host(-1, hostname, im_mad_name, vmm_mad_name, tm_mad_name); + host = new Host(-1, hostname, im_mad_name, vmm_mad_name, vnm_mad_name, + tm_mad_name); // Insert the Object in the pool @@ -204,6 +211,10 @@ error_vmm: oss << "VMM_MAD_NAME cannot be empty."; goto error_common; +error_vnm: + oss << "VNM_MAD_NAME cannot be empty."; + goto error_common; + error_tm: oss << "TM_MAD_NAME cannot be empty."; goto error_common; diff --git a/src/rm/RequestManagerAllocate.cc b/src/rm/RequestManagerAllocate.cc index eb60f27e08..6d0eded4cc 100644 --- a/src/rm/RequestManagerAllocate.cc +++ b/src/rm/RequestManagerAllocate.cc @@ -212,11 +212,13 @@ int HostAllocate::pool_allocate(xmlrpc_c::paramList const& paramList, string host = xmlrpc_c::value_string(paramList.getString(1)); string im_mad = xmlrpc_c::value_string(paramList.getString(2)); string vmm_mad = xmlrpc_c::value_string(paramList.getString(3)); - string tm_mad = xmlrpc_c::value_string(paramList.getString(4)); + string vnm_mad = xmlrpc_c::value_string(paramList.getString(4)); + string tm_mad = xmlrpc_c::value_string(paramList.getString(5)); HostPool * hpool = static_cast(pool); - return hpool->allocate(&id, host, im_mad, vmm_mad, tm_mad, error_str); + return hpool->allocate(&id, host, im_mad, vmm_mad, vnm_mad, tm_mad, + error_str); } /* -------------------------------------------------------------------------- */ diff --git a/src/rm/RequestManagerVirtualMachine.cc b/src/rm/RequestManagerVirtualMachine.cc index 17dd537084..ff74188a51 100644 --- a/src/rm/RequestManagerVirtualMachine.cc +++ b/src/rm/RequestManagerVirtualMachine.cc @@ -88,7 +88,8 @@ bool RequestManagerVirtualMachine::vm_authorization(int oid, int RequestManagerVirtualMachine::get_host_information(int hid, string& name, - string& vmm, + string& vmm, + string& vnm, string& tm, RequestAttributes& att) { @@ -110,6 +111,7 @@ int RequestManagerVirtualMachine::get_host_information(int hid, name = host->get_name(); vmm = host->get_vmm_mad(); + vnm = host->get_vnm_mad(); tm = host->get_tm_mad(); host->unlock(); @@ -142,6 +144,7 @@ int RequestManagerVirtualMachine::add_history(VirtualMachine * vm, int hid, const string& hostname, const string& vmm_mad, + const string& vnm_mad, const string& tm_mad, RequestAttributes& att) { @@ -154,7 +157,7 @@ int RequestManagerVirtualMachine::add_history(VirtualMachine * vm, nd.get_configuration_attribute("VM_DIR",vmdir); - vm->add_history(hid,hostname,vmdir,vmm_mad,tm_mad); + vm->add_history(hid,hostname,vmdir,vmm_mad,vnm_mad,tm_mad); rc = vmpool->update_history(vm); @@ -273,6 +276,7 @@ void VirtualMachineDeploy::request_execute(xmlrpc_c::paramList const& paramList, string hostname; string vmm_mad; + string vnm_mad; string tm_mad; int id = xmlrpc_c::value_int(paramList.getInt(1)); @@ -283,7 +287,7 @@ void VirtualMachineDeploy::request_execute(xmlrpc_c::paramList const& paramList, return; } - if (get_host_information(hid,hostname,vmm_mad,tm_mad, att) != 0) + if (get_host_information(hid,hostname,vmm_mad,vnm_mad,tm_mad, att) != 0) { return; } @@ -303,7 +307,7 @@ void VirtualMachineDeploy::request_execute(xmlrpc_c::paramList const& paramList, return; } - if ( add_history(vm,hid,hostname,vmm_mad,tm_mad,att) != 0) + if ( add_history(vm,hid,hostname,vmm_mad,vnm_mad,tm_mad,att) != 0) { vm->unlock(); return; @@ -329,6 +333,7 @@ void VirtualMachineMigrate::request_execute(xmlrpc_c::paramList const& paramList string hostname; string vmm_mad; + string vnm_mad; string tm_mad; int id = xmlrpc_c::value_int(paramList.getInt(1)); @@ -340,7 +345,7 @@ void VirtualMachineMigrate::request_execute(xmlrpc_c::paramList const& paramList return; } - if (get_host_information(hid,hostname,vmm_mad,tm_mad,att) != 0) + if (get_host_information(hid,hostname,vmm_mad,vnm_mad,tm_mad,att) != 0) { return; } @@ -362,7 +367,7 @@ void VirtualMachineMigrate::request_execute(xmlrpc_c::paramList const& paramList return; } - if ( add_history(vm,hid,hostname,vmm_mad,tm_mad,att) != 0) + if ( add_history(vm,hid,hostname,vmm_mad,vnm_mad,tm_mad,att) != 0) { vm->unlock(); return; diff --git a/src/vm/History.cc b/src/vm/History.cc index 3bef2c4eb6..f2a52ccb3c 100644 --- a/src/vm/History.cc +++ b/src/vm/History.cc @@ -43,6 +43,7 @@ History::History( vm_dir(""), hid(-1), vmm_mad_name(""), + vnm_mad_name(""), tm_mad_name(""), stime(0), etime(0), @@ -63,6 +64,7 @@ History::History( const string& _hostname, const string& _vm_dir, const string& _vmm, + const string& _vnm, const string& _tm): oid(_oid), seq(_seq), @@ -70,6 +72,7 @@ History::History( vm_dir(_vm_dir), hid(_hid), vmm_mad_name(_vmm), + vnm_mad_name(_vnm), tm_mad_name(_tm), stime(0), etime(0), @@ -267,6 +270,7 @@ string& History::to_xml(string& xml) const "" << stime << "" << "" << etime << "" << "" << vmm_mad_name << ""<< + "" << vnm_mad_name << ""<< "" << tm_mad_name << "" << "" << prolog_stime << ""<< "" << prolog_etime << ""<< @@ -297,6 +301,7 @@ int History::rebuild_attributes() rc += xpath(stime , "/HISTORY/STIME", 0); rc += xpath(etime , "/HISTORY/ETIME", 0); rc += xpath(vmm_mad_name , "/HISTORY/VMMMAD", "not_found"); + rc += xpath(vnm_mad_name , "/HISTORY/VNMMAD", "not_found"); rc += xpath(tm_mad_name , "/HISTORY/TMMAD", "not_found"); rc += xpath(prolog_stime , "/HISTORY/PSTIME", 0); rc += xpath(prolog_etime , "/HISTORY/PETIME", 0); diff --git a/src/vm/VirtualMachine.cc b/src/vm/VirtualMachine.cc index 349f57b8ba..1ca014f8db 100644 --- a/src/vm/VirtualMachine.cc +++ b/src/vm/VirtualMachine.cc @@ -581,6 +581,7 @@ void VirtualMachine::add_history( const string& hostname, const string& vm_dir, const string& vmm_mad, + const string& vnm_mad, const string& tm_mad) { ostringstream os; @@ -597,7 +598,7 @@ void VirtualMachine::add_history( previous_history = history; } - history = new History(oid,seq,hid,hostname,vm_dir,vmm_mad,tm_mad); + history = new History(oid,seq,hid,hostname,vm_dir,vmm_mad,vnm_mad,tm_mad); history_records.push_back(history); }; @@ -620,6 +621,7 @@ void VirtualMachine::cp_history() history->hostname, history->vm_dir, history->vmm_mad_name, + history->vnm_mad_name, history->tm_mad_name); @@ -647,6 +649,7 @@ void VirtualMachine::cp_previous_history() previous_history->hostname, previous_history->vm_dir, previous_history->vmm_mad_name, + previous_history->vnm_mad_name, previous_history->tm_mad_name); previous_history = history; From fc848e27275da04c9c889c58ecf16787335a2193 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Thu, 10 Nov 2011 09:14:37 -0800 Subject: [PATCH 004/121] Feature #863: Fix tests --- src/host/test/HostHookTest.cc | 8 ++--- src/host/test/HostPoolTest.cc | 51 ++++++++++++++------------- src/lcm/test/LifeCycleManagerTest.cc | 23 ++++++------ src/vm/test/VirtualMachinePoolTest.cc | 12 ++++--- 4 files changed, 49 insertions(+), 45 deletions(-) diff --git a/src/host/test/HostHookTest.cc b/src/host/test/HostHookTest.cc index 406241597e..62361519ef 100644 --- a/src/host/test/HostHookTest.cc +++ b/src/host/test/HostHookTest.cc @@ -96,7 +96,7 @@ public: { string err; - hpool->allocate(&oid, "host_test", "im_mad", "vmm_mad", "tm_mad", err); + hpool->allocate(&oid, "host_test", "im_mad", "vmm_mad", "vnm_mad", "tm_mad", err); CPPUNIT_ASSERT( oid >= 0 ); sleep(1); @@ -114,7 +114,7 @@ public: { string err; - hpool->allocate(&oid, "host_test", "im_mad", "vmm_mad", "tm_mad", err); + hpool->allocate(&oid, "host_test", "im_mad", "vmm_mad", "vnm_mad", "tm_mad", err); CPPUNIT_ASSERT( oid >= 0 ); host = hpool->get(oid, true); @@ -140,7 +140,7 @@ public: { string err; - hpool->allocate(&oid, "host_test", "im_mad", "vmm_mad", "tm_mad", err); + hpool->allocate(&oid, "host_test", "im_mad", "vmm_mad", "vnm_mad", "tm_mad", err); CPPUNIT_ASSERT( oid >= 0 ); host = hpool->get(oid, true); @@ -166,7 +166,7 @@ public: { string err; - hpool->allocate(&oid, "host_test", "im_mad", "vmm_mad", "tm_mad", err); + hpool->allocate(&oid, "host_test", "im_mad", "vmm_mad", "vnm_mad", "tm_mad", err); CPPUNIT_ASSERT( oid >= 0 ); host = hpool->get(oid, true); diff --git a/src/host/test/HostPoolTest.cc b/src/host/test/HostPoolTest.cc index 2b63af6a50..1dab8f08d5 100644 --- a/src/host/test/HostPoolTest.cc +++ b/src/host/test/HostPoolTest.cc @@ -25,6 +25,7 @@ using namespace std; const string im_mad = "im_mad"; const string vmm_mad = "vmm_mad"; +const string vnm_mad = "vnm_mad"; const string tm_mad = "tm_mad"; const string names[] = {"Host one", "Second host"}; @@ -32,7 +33,7 @@ const string names[] = {"Host one", "Second host"}; const string xmls[] = { "0Host one0" - "im_madvmm_madtm_mad" + "im_madvmm_madvnm_madtm_mad" "0" "000" "000" @@ -41,7 +42,7 @@ const string xmls[] = "0", "1Second host0" - "im_madvmm_madtm_mad" + "im_madvmm_madvnm_madtm_mad" "0" "000" "000" @@ -53,34 +54,34 @@ const string xmls[] = // This xml dump result has the LAST_MON_TIMEs modified to 0000000000 const string xml_dump = "0a0im_madvmm_madtm_mad0" + "M_MAD>vmm_madvnm_madtm_mad0" "0000000000000" "1a name0im_madvmm_madtm_mad0vmm_madvnm_madtm_mad000000" "000000002a_name0im_madvmm_madtm_mad0vnm_madtm_mad000000000000003another " "name0im_madvmm_mad" - "tm_mad0vnm_madtm_mad000000000000004host0im_madvmm_madtm_mad" + "ATE>0im_madvmm_madvnm_madtm_mad" "0" "000" "0000" @@ -90,28 +91,28 @@ const string xml_dump = const string xml_dump_like_a = "0a0im_madvmm_madtm_mad0" + "M_MAD>vmm_madvnm_madtm_mad0" "0000000000000" "1a name0im_madvmm_madtm_mad0vmm_madvnm_madtm_mad000000" "000000002a_name0im_madvmm_madtm_mad0vnm_madtm_mad000000000000003another " "name0im_madvmm_mad" - "tm_mad0vnm_madtm_mad00000000000Host one0im_madvmm_madtm_mad00000000000000"; + "0Host one0im_madvmm_madvnm_madtm_mad00000000000000"; const string host_0_cluster = - "0Host one0im_madvmm_madtm_mad0cluster_a0000000000000"; + "0Host one0im_madvmm_madvnm_madtm_mad0cluster_a0000000000000"; /* ************************************************************************* */ /* ************************************************************************* */ @@ -162,7 +163,7 @@ protected: int oid; string err; return ((HostPool*)pool)->allocate(&oid, names[index], im_mad, - vmm_mad, tm_mad, err); + vmm_mad, vnm_mad, tm_mad, err); }; void check(int index, PoolObjectSQL* obj) @@ -184,7 +185,7 @@ protected: if( xml_str != xmls[index] ) { cout << endl << xml_str << endl << "========" - << endl << xmls[index]; + << endl << xmls[index] << endl; } //*/ CPPUNIT_ASSERT( xml_str == xmls[index]); @@ -242,16 +243,16 @@ public: // If we try to allocate two hosts with the same name and drivers, // should fail - rc = hp->allocate(&oid_0, names[0], im_mad, vmm_mad, tm_mad, err); + rc = hp->allocate(&oid_0, names[0], im_mad, vmm_mad, vnm_mad, tm_mad, err); CPPUNIT_ASSERT( oid_0 == 0 ); CPPUNIT_ASSERT( rc == oid_0 ); - rc = hp->allocate(&oid_1, names[0], im_mad, vmm_mad, tm_mad, err); + rc = hp->allocate(&oid_1, names[0], im_mad, vmm_mad, vnm_mad, tm_mad, err); CPPUNIT_ASSERT( oid_1 == -1 ); CPPUNIT_ASSERT( rc == oid_1 ); // the hostname can not be repeated if the drivers change - rc = hp->allocate(&oid_1, names[0], im_mad, vmm_mad, tm_mad_2, err); + rc = hp->allocate(&oid_1, names[0], im_mad, vmm_mad, vnm_mad, tm_mad_2, err); CPPUNIT_ASSERT( oid_1 == -1 ); CPPUNIT_ASSERT( rc == oid_1 ); @@ -272,7 +273,7 @@ public: for(int i=0; i<5; i++) { ((HostPool*)pool)->allocate(&oid, names[i], - im_mad, vmm_mad, tm_mad, err); + im_mad, vmm_mad, vnm_mad, tm_mad, err); } ostringstream oss; @@ -287,7 +288,7 @@ public: if( result != xml_dump ) { cout << endl << result << endl << "========" - << endl << xml_dump; + << endl << xml_dump << endl; } //*/ @@ -305,7 +306,7 @@ public: for(int i=0; i<5; i++) { ((HostPool*)pool)->allocate(&oid, names[i], - im_mad, vmm_mad, tm_mad, err); + im_mad, vmm_mad, vnm_mad, tm_mad, err); } @@ -321,7 +322,7 @@ public: if( result != xml_dump_like_a ) { cout << endl << result << endl << "========" - << endl << xml_dump_like_a; + << endl << xml_dump_like_a << endl; } //*/ @@ -346,7 +347,7 @@ public: { oss << "host" << i; - hp->allocate(&oid, oss.str().c_str(), im_mad, vmm_mad, tm_mad, err); + hp->allocate(&oid, oss.str().c_str(), im_mad, vmm_mad, vnm_mad, tm_mad, err); CPPUNIT_ASSERT(oid == i); if (i >=8 ) @@ -404,7 +405,7 @@ public: { oss << "host" << j; - hp->allocate(&oid, oss.str().c_str(),im_mad,vmm_mad,tm_mad,err); + hp->allocate(&oid, oss.str().c_str(),im_mad,vmm_mad,vnm_mad,tm_mad,err); } the_time2 = time(0) - the_time; @@ -433,7 +434,7 @@ public: for (i=10000,oss.str(""); i<30000 ; i++,oss.str("")) { oss << "host" << i; - hp->allocate(&oid,oss.str().c_str(),im_mad,vmm_mad,tm_mad,err); + hp->allocate(&oid,oss.str().c_str(),im_mad,vmm_mad,vnm_mad,tm_mad,err); host = hp->get(oid, false); diff --git a/src/lcm/test/LifeCycleManagerTest.cc b/src/lcm/test/LifeCycleManagerTest.cc index c2d4386d2e..2f333133d5 100644 --- a/src/lcm/test/LifeCycleManagerTest.cc +++ b/src/lcm/test/LifeCycleManagerTest.cc @@ -47,6 +47,7 @@ const string templates[] = static int hid = 123; static string hostname = "test_hostname"; static string vmm_mad = "vmm_mad"; +static string vnm_mad = "vnm_mad"; static string tm_mad = "tm_mad"; static string vmdir = "vmdir"; @@ -225,7 +226,7 @@ private: vm->lock(); - vm->add_history(hid,hostname,vmdir,vmm_mad,tm_mad); + vm->add_history(hid,hostname,vmdir,vmm_mad,vnm_mad,tm_mad); rc = vmpool->update_history(vm); CPPUNIT_ASSERT( rc == 0 ); @@ -489,7 +490,7 @@ public: { vm = allocate_running(0); - vm->add_history(hid,hostname,vmdir,vmm_mad,tm_mad); + vm->add_history(hid,hostname,vmdir,vmm_mad,vnm_mad,tm_mad); rc = vmpool->update_history(vm); CPPUNIT_ASSERT( rc == 0 ); @@ -573,7 +574,7 @@ public: { vm = allocate_running(0); - vm->add_history(hid,hostname,vmdir,vmm_mad,tm_mad); + vm->add_history(hid,hostname,vmdir,vmm_mad,vnm_mad,tm_mad); rc = vmpool->update_history(vm); CPPUNIT_ASSERT( rc == 0 ); @@ -594,7 +595,7 @@ public: { vm = allocate_running(0); - vm->add_history(hid,hostname,vmdir,vmm_mad,tm_mad); + vm->add_history(hid,hostname,vmdir,vmm_mad,vnm_mad,tm_mad); rc = vmpool->update_history(vm); CPPUNIT_ASSERT( rc == 0 ); @@ -615,7 +616,7 @@ public: { vm = allocate_running(0); - vm->add_history(hid,hostname,vmdir,vmm_mad,tm_mad); + vm->add_history(hid,hostname,vmdir,vmm_mad,vnm_mad,tm_mad); rc = vmpool->update_history(vm); CPPUNIT_ASSERT( rc == 0 ); @@ -637,7 +638,7 @@ public: { vm = allocate_running(0); - vm->add_history(hid,hostname,vmdir,vmm_mad,tm_mad); + vm->add_history(hid,hostname,vmdir,vmm_mad,vnm_mad,tm_mad); rc = vmpool->update_history(vm); CPPUNIT_ASSERT( rc == 0 ); @@ -661,7 +662,7 @@ public: { vm = allocate_running(0); - vm->add_history(hid,hostname,vmdir,vmm_mad,tm_mad); + vm->add_history(hid,hostname,vmdir,vmm_mad,vnm_mad,tm_mad); rc = vmpool->update_history(vm); CPPUNIT_ASSERT( rc == 0 ); @@ -685,7 +686,7 @@ public: { vm = allocate_running(0); - vm->add_history(hid,hostname,vmdir,vmm_mad,tm_mad); + vm->add_history(hid,hostname,vmdir,vmm_mad,vnm_mad,tm_mad); rc = vmpool->update_history(vm); CPPUNIT_ASSERT( rc == 0 ); @@ -749,7 +750,7 @@ public: { vm = allocate_running(0); - vm->add_history(hid,hostname,vmdir,vmm_mad,tm_mad); + vm->add_history(hid,hostname,vmdir,vmm_mad,vnm_mad,tm_mad); rc = vmpool->update_history(vm); CPPUNIT_ASSERT( rc == 0 ); @@ -772,7 +773,7 @@ public: { vm = allocate_running(0); - vm->add_history(hid,hostname,vmdir,vmm_mad,tm_mad); + vm->add_history(hid,hostname,vmdir,vmm_mad,vnm_mad,tm_mad); rc = vmpool->update_history(vm); CPPUNIT_ASSERT( rc == 0 ); @@ -795,7 +796,7 @@ public: { vm = allocate_running(0); - vm->add_history(hid,hostname,vmdir,vmm_mad,tm_mad); + vm->add_history(hid,hostname,vmdir,vmm_mad,vnm_mad,tm_mad); rc = vmpool->update_history(vm); CPPUNIT_ASSERT( rc == 0 ); diff --git a/src/vm/test/VirtualMachinePoolTest.cc b/src/vm/test/VirtualMachinePoolTest.cc index 5bcd6c1e7d..10f87c22ff 100644 --- a/src/vm/test/VirtualMachinePoolTest.cc +++ b/src/vm/test/VirtualMachinePoolTest.cc @@ -302,6 +302,7 @@ public: string hostnames[] = {"A_hostname", "B_hostname", "C_hostname"}; string vm_dirs[] = {"A_vm_dir", "B_vm_dir", "C_vm_dir"}; string vmm_mads[] = {"A_vmm_mad", "B_vmm_mad", "C_vmm_mad"}; + string vnm_mads[] = {"A_vnm_mad", "B_vnm_mad", "C_vnm_mad"}; string tm_mads[] = {"A_tm_mad", "B_tm_mad", "C_tm_mad"}; int oid, rc; @@ -324,7 +325,7 @@ public: CPPUNIT_ASSERT( vm != 0 ); // Add a history item - vm->add_history(0, hostnames[0], vm_dirs[0], vmm_mads[0], tm_mads[0]); + vm->add_history(0, hostnames[0], vm_dirs[0], vmm_mads[0], vnm_mads[0], tm_mads[0]); rc = vmp->update(vm); CPPUNIT_ASSERT( rc == 0 ); @@ -342,7 +343,7 @@ public: CPPUNIT_ASSERT( vm != 0 ); // Add a history item - vm->add_history(1, hostnames[1], vm_dirs[1], vmm_mads[1], tm_mads[1]); + vm->add_history(1, hostnames[1], vm_dirs[1], vmm_mads[1], vnm_mads[1], tm_mads[1]); rc = vmp->update(vm); CPPUNIT_ASSERT( rc == 0 ); @@ -351,7 +352,7 @@ public: CPPUNIT_ASSERT( rc == 0 ); // Add another history item - vm->add_history(2, hostnames[2], vm_dirs[2], vmm_mads[2], tm_mads[2]); + vm->add_history(2, hostnames[2], vm_dirs[2], vmm_mads[2], vnm_mads[2], tm_mads[2]); rc = vmp->update(vm); CPPUNIT_ASSERT( rc == 0 ); @@ -408,6 +409,7 @@ public: string new_hostname = "new_hostname"; string vm_dir = "vm_dir"; string vmm_mad = "vm_mad"; + string vnm_mad = "vn_mad"; string tm_mad = "tm_mad"; // Allocate a VM @@ -418,7 +420,7 @@ public: CPPUNIT_ASSERT( vm != 0 ); // Add a history item - vm->add_history(0, hostname, vm_dir, vmm_mad, tm_mad); + vm->add_history(0, hostname, vm_dir, vmm_mad, vnm_mad, tm_mad); rc = vmp->update(vm); CPPUNIT_ASSERT( rc == 0 ); @@ -426,7 +428,7 @@ public: rc = vmp->update_history(vm); CPPUNIT_ASSERT( rc == 0 ); - vm->add_history(0, new_hostname, vm_dir, vmm_mad, tm_mad); + vm->add_history(0, new_hostname, vm_dir, vmm_mad, vnm_mad, tm_mad); rc = vmp->update(vm); CPPUNIT_ASSERT( rc == 0 ); From 1788425c94663bb55140dc03132b69a7f1acf2a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Thu, 10 Nov 2011 18:27:04 +0100 Subject: [PATCH 005/121] Feature #863: Add new vn_mad to ruby oca and onehost command --- src/cli/one_helper/onehost_helper.rb | 1 + src/cli/onehost | 5 +++-- src/oca/ruby/OpenNebula/Host.rb | 16 ++++++++-------- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/cli/one_helper/onehost_helper.rb b/src/cli/one_helper/onehost_helper.rb index 2a23aab046..d517978664 100644 --- a/src/cli/one_helper/onehost_helper.rb +++ b/src/cli/one_helper/onehost_helper.rb @@ -59,6 +59,7 @@ class OneHostHelper < OpenNebulaHelper::OneHelper puts str % ["STATE", host.state_str] puts str % ["IM_MAD", host['IM_MAD']] puts str % ["VM_MAD", host['VM_MAD']] + puts str % ["VN_MAD", host['VN_MAD']] puts str % ["TM_MAD", host['TM_MAD']] puts diff --git a/src/cli/onehost b/src/cli/onehost index 6f7b5f5c81..adf060ba36 100755 --- a/src/cli/onehost +++ b/src/cli/onehost @@ -60,9 +60,10 @@ cmd=CommandParser::CmdParser.new(ARGV) do Creates a new Host EOT - command :create, create_desc, :hostname, :im_mad, :vmm_mad, :tm_mad do + command :create, create_desc, :hostname, :im_mad, :vmm_mad, :vnm_mad, + :tm_mad do helper.create_resource(options) do |host| - host.allocate(args[0], args[1], args[2], args[3]) + host.allocate(args[0], args[1], args[2], args[3], args[4]) end end diff --git a/src/oca/ruby/OpenNebula/Host.rb b/src/oca/ruby/OpenNebula/Host.rb index 24f205663c..7a66b9ee86 100644 --- a/src/oca/ruby/OpenNebula/Host.rb +++ b/src/oca/ruby/OpenNebula/Host.rb @@ -78,15 +78,15 @@ module OpenNebula # Allocates a new Host in OpenNebula # - # +hostname+ A string containing the name of the new Host. + # @param hostname [String] Name of the new Host. + # @param im [String] Name of the im_driver + # @param vmm [String] Name of the vmm_driver + # @param tm [String] Name of the tm_driver # - # +im+ A string containing the name of the im_driver - # - # +vmm+ A string containing the name of the vmm_driver - # - # +tm+ A string containing the name of the tm_driver - def allocate(hostname,im,vmm,tm) - super(HOST_METHODS[:allocate],hostname,im,vmm,tm) + # @return [Integer, OpenNebula::Error] the new VM ID in case of + # success, error otherwise + def allocate(hostname,im,vmm,vnm,tm) + super(HOST_METHODS[:allocate],hostname,im,vmm,vnm,tm) end # Deletes the Host From 50bb7f3ed410c9397cd62f1befed8e3c2f23a77e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Thu, 10 Nov 2011 18:51:08 +0100 Subject: [PATCH 006/121] Feature #863: Add new vn_mad to java oca --- src/oca/java/src/org/opennebula/client/host/Host.java | 6 +++++- src/oca/java/test/HostTest.java | 6 ++++-- src/oca/java/test/VirtualMachineTest.java | 4 ++-- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/oca/java/src/org/opennebula/client/host/Host.java b/src/oca/java/src/org/opennebula/client/host/Host.java index 20a82df64b..0cc9d646d7 100644 --- a/src/oca/java/src/org/opennebula/client/host/Host.java +++ b/src/oca/java/src/org/opennebula/client/host/Host.java @@ -72,6 +72,9 @@ public class Host extends PoolElement{ * @param vmm The name of the virtual machine manager mad name * (vmm_mad_name), this values are taken from the oned.conf with the * tag name VM_MAD (name) + * @param vnm The name of the virtual network manager mad name + * (vnm_mad_name), this values are taken from the oned.conf with the + * tag name VN_MAD (name) * @param tm The transfer manager mad name to be used with this host * @return If successful the message contains the associated * id generated for this host @@ -80,9 +83,10 @@ public class Host extends PoolElement{ String hostname, String im, String vmm, + String vnm, String tm) { - return client.call(ALLOCATE, hostname, im, vmm, tm); + return client.call(ALLOCATE, hostname, im, vmm, vnm, tm); } /** diff --git a/src/oca/java/test/HostTest.java b/src/oca/java/test/HostTest.java index 81f1878b6a..dfb58022fc 100644 --- a/src/oca/java/test/HostTest.java +++ b/src/oca/java/test/HostTest.java @@ -63,7 +63,8 @@ public class HostTest @Before public void setUp() throws Exception { - res = Host.allocate(client, name, "im_dummy", "vmm_dummy", "tm_dummy"); + res = Host.allocate(client, name, "im_dummy", "vmm_dummy", "vnm_dummy", + "tm_dummy"); int hid = !res.isError() ? Integer.parseInt(res.getMessage()) : -1; host = new Host(hid, client); @@ -83,7 +84,8 @@ public class HostTest { String name = "allocate_test"; - res = Host.allocate(client, name, "im_dummy", "vmm_dummy", "tm_dummy"); + res = Host.allocate(client, name, "im_dummy", "vmm_dummy", "vmm_dummy", + "tm_dummy"); assertTrue( !res.isError() ); // assertTrue( res.getMessage().equals("0") ); diff --git a/src/oca/java/test/VirtualMachineTest.java b/src/oca/java/test/VirtualMachineTest.java index 115042df16..1f2bacd492 100644 --- a/src/oca/java/test/VirtualMachineTest.java +++ b/src/oca/java/test/VirtualMachineTest.java @@ -80,11 +80,11 @@ public class VirtualMachineTest res = Host.allocate(client, "host_A", - "im_dummy", "vmm_dummy", "tm_dummy"); + "im_dummy", "vmm_dummy", "vmm_dummy", "tm_dummy"); hid_A = Integer.parseInt( res.getMessage() ); res = Host.allocate(client, "host_B", - "im_dummy", "vmm_dummy", "tm_dummy"); + "im_dummy", "vmm_dummy", "vmm_dummy", "tm_dummy"); hid_B = Integer.parseInt( res.getMessage() ); } From fbcc340c8ae5a2050ce105a282d9870eb77e1fce Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Thu, 10 Nov 2011 22:53:39 +0100 Subject: [PATCH 007/121] feature #863: change prototype for vnm_mad functions --- include/VirtualMachine.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/include/VirtualMachine.h b/include/VirtualMachine.h index 357ccb75a1..159d7b34e0 100644 --- a/include/VirtualMachine.h +++ b/include/VirtualMachine.h @@ -279,8 +279,7 @@ public: * function MUST be called before this one. * @return the VMM mad name */ - // const string & get_vnm_mad() const - string get_vnm_mad() const + const string & get_vnm_mad() const { return history->vnm_mad_name; }; @@ -290,8 +289,7 @@ public: * function MUST be called before this one. * @return the VMM mad name */ - // const string & get_previous_vnm_mad() const - string get_previous_vnm_mad() const + const string & get_previous_vnm_mad() const { return previous_history->vnm_mad_name; }; From f74108e4ebcc67b6ede41ce02d3c14c9fcdab81e Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Thu, 10 Nov 2011 23:15:04 +0100 Subject: [PATCH 008/121] feature #863: uses VM xml instead of just the template for deploy --- src/vmm/VirtualMachineManager.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vmm/VirtualMachineManager.cc b/src/vmm/VirtualMachineManager.cc index d7a8720bfc..04919e8903 100644 --- a/src/vmm/VirtualMachineManager.cc +++ b/src/vmm/VirtualMachineManager.cc @@ -360,7 +360,7 @@ void VirtualMachineManager::deploy_action(int vid) "", vm->get_remote_deployment_file(), "", - vm->template_to_xml(vm_tmpl)); + vm->to_xml(vm_tmpl)); vmd->deploy(vid, *drv_msg); From a06b5f84d06b98b669b4ba94eb045d719a77d417 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Thu, 10 Nov 2011 23:35:12 +0100 Subject: [PATCH 009/121] Feature: Enable use of user metadata in context --- src/template/template_syntax.cc | 462 ++++++++++++++++------------- src/template/template_syntax.h | 13 +- src/vm/vm_var_syntax.cc | 477 +++++++++++++++++------------- src/vm/vm_var_syntax.h | 15 +- src/vm/vm_var_syntax.y | 17 +- src/xml/expr_arith.cc | 474 ++++++++++++++++-------------- src/xml/expr_arith.h | 13 +- src/xml/expr_bool.cc | 494 ++++++++++++++++++-------------- src/xml/expr_bool.h | 13 +- 9 files changed, 1100 insertions(+), 878 deletions(-) diff --git a/src/template/template_syntax.cc b/src/template/template_syntax.cc index 3aadc30534..3b547760de 100644 --- a/src/template/template_syntax.cc +++ b/src/template/template_syntax.cc @@ -1,9 +1,8 @@ -/* A Bison parser, made by GNU Bison 2.4.2. */ +/* A Bison parser, made by GNU Bison 2.5. */ -/* Skeleton implementation for Bison's Yacc-like parsers in C +/* Bison implementation for Yacc-like parsers in C - Copyright (C) 1984, 1989-1990, 2000-2006, 2009-2010 Free Software - Foundation, Inc. + Copyright (C) 1984, 1989-1990, 2000-2011 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -45,7 +44,7 @@ #define YYBISON 1 /* Bison version. */ -#define YYBISON_VERSION "2.4.2" +#define YYBISON_VERSION "2.5" /* Skeleton name. */ #define YYSKELETON_NAME "yacc.c" @@ -74,7 +73,7 @@ /* Copy the first part of user declarations. */ -/* Line 189 of yacc.c */ +/* Line 268 of yacc.c */ #line 17 "template_syntax.y" #include @@ -127,8 +126,8 @@ extern "C" -/* Line 189 of yacc.c */ -#line 132 "template_syntax.cc" +/* Line 268 of yacc.c */ +#line 131 "template_syntax.cc" /* Enabling traces. */ #ifndef YYDEBUG @@ -171,7 +170,7 @@ extern "C" typedef union YYSTYPE { -/* Line 214 of yacc.c */ +/* Line 293 of yacc.c */ #line 74 "template_syntax.y" char * val_str; @@ -179,8 +178,8 @@ typedef union YYSTYPE -/* Line 214 of yacc.c */ -#line 184 "template_syntax.cc" +/* Line 293 of yacc.c */ +#line 183 "template_syntax.cc" } YYSTYPE; # define YYSTYPE_IS_TRIVIAL 1 # define yystype YYSTYPE /* obsolescent; will be withdrawn */ @@ -204,8 +203,8 @@ typedef struct YYLTYPE /* Copy the second part of user declarations. */ -/* Line 264 of yacc.c */ -#line 209 "template_syntax.cc" +/* Line 343 of yacc.c */ +#line 208 "template_syntax.cc" #ifdef short # undef short @@ -308,11 +307,11 @@ YYID (yyi) # define alloca _alloca # else # define YYSTACK_ALLOC alloca -# if ! defined _ALLOCA_H && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \ +# if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) # include /* INFRINGES ON USER NAME SPACE */ -# ifndef _STDLIB_H -# define _STDLIB_H 1 +# ifndef EXIT_SUCCESS +# define EXIT_SUCCESS 0 # endif # endif # endif @@ -335,24 +334,24 @@ YYID (yyi) # ifndef YYSTACK_ALLOC_MAXIMUM # define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM # endif -# if (defined __cplusplus && ! defined _STDLIB_H \ +# if (defined __cplusplus && ! defined EXIT_SUCCESS \ && ! ((defined YYMALLOC || defined malloc) \ && (defined YYFREE || defined free))) # include /* INFRINGES ON USER NAME SPACE */ -# ifndef _STDLIB_H -# define _STDLIB_H 1 +# ifndef EXIT_SUCCESS +# define EXIT_SUCCESS 0 # endif # endif # ifndef YYMALLOC # define YYMALLOC malloc -# if ! defined malloc && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \ +# if ! defined malloc && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */ # endif # endif # ifndef YYFREE # define YYFREE free -# if ! defined free && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \ +# if ! defined free && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) void free (void *); /* INFRINGES ON USER NAME SPACE */ # endif @@ -383,23 +382,7 @@ union yyalloc ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE) + sizeof (YYLTYPE)) \ + 2 * YYSTACK_GAP_MAXIMUM) -/* Copy COUNT objects from FROM to TO. The source and destination do - not overlap. */ -# ifndef YYCOPY -# if defined __GNUC__ && 1 < __GNUC__ -# define YYCOPY(To, From, Count) \ - __builtin_memcpy (To, From, (Count) * sizeof (*(From))) -# else -# define YYCOPY(To, From, Count) \ - do \ - { \ - YYSIZE_T yyi; \ - for (yyi = 0; yyi < (Count); yyi++) \ - (To)[yyi] = (From)[yyi]; \ - } \ - while (YYID (0)) -# endif -# endif +# define YYCOPY_NEEDED 1 /* Relocate STACK from its old location to the new one. The local variables YYSIZE and YYSTACKSIZE give the old and new number of @@ -419,6 +402,26 @@ union yyalloc #endif +#if defined YYCOPY_NEEDED && YYCOPY_NEEDED +/* Copy COUNT objects from FROM to TO. The source and destination do + not overlap. */ +# ifndef YYCOPY +# if defined __GNUC__ && 1 < __GNUC__ +# define YYCOPY(To, From, Count) \ + __builtin_memcpy (To, From, (Count) * sizeof (*(From))) +# else +# define YYCOPY(To, From, Count) \ + do \ + { \ + YYSIZE_T yyi; \ + for (yyi = 0; yyi < (Count); yyi++) \ + (To)[yyi] = (From)[yyi]; \ + } \ + while (YYID (0)) +# endif +# endif +#endif /* !YYCOPY_NEEDED */ + /* YYFINAL -- State number of the termination state. */ #define YYFINAL 6 /* YYLAST -- Last index in YYTABLE. */ @@ -528,8 +531,8 @@ static const yytype_uint8 yyr2[] = 0, 2, 1, 2, 3, 5, 2, 3, 5 }; -/* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state - STATE-NUM when YYTABLE doesn't specify something else to do. Zero +/* YYDEFACT[STATE-NAME] -- Default reduction number in state STATE-NUM. + Performed when YYTABLE doesn't specify something else to do. Zero means the default is an error. */ static const yytype_uint8 yydefact[] = { @@ -560,8 +563,7 @@ static const yytype_int8 yypgoto[] = /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If positive, shift that token. If negative, reduce the rule which - number is the opposite. If zero, do what YYDEFACT says. - If YYTABLE_NINF, syntax error. */ + number is the opposite. If YYTABLE_NINF, syntax error. */ #define YYTABLE_NINF -1 static const yytype_uint8 yytable[] = { @@ -569,6 +571,12 @@ static const yytype_uint8 yytable[] = 12, 15, 17, 16, 18, 7 }; +#define yypact_value_is_default(yystate) \ + ((yystate) == (-8)) + +#define yytable_value_is_error(yytable_value) \ + YYID (0) + static const yytype_uint8 yycheck[] = { 0, 3, 9, 9, 5, 7, 4, 8, 6, 9, @@ -616,7 +624,6 @@ do \ { \ yychar = (Token); \ yylval = (Value); \ - yytoken = YYTRANSLATE (yychar); \ YYPOPSTACK (1); \ goto yybackup; \ } \ @@ -880,7 +887,6 @@ int yydebug; # define YYMAXDEPTH 10000 #endif - #if YYERROR_VERBOSE @@ -983,115 +989,142 @@ yytnamerr (char *yyres, const char *yystr) } # endif -/* Copy into YYRESULT an error message about the unexpected token - YYCHAR while in state YYSTATE. Return the number of bytes copied, - including the terminating null byte. If YYRESULT is null, do not - copy anything; just return the number of bytes that would be - copied. As a special case, return 0 if an ordinary "syntax error" - message will do. Return YYSIZE_MAXIMUM if overflow occurs during - size calculation. */ -static YYSIZE_T -yysyntax_error (char *yyresult, int yystate, int yychar) +/* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message + about the unexpected token YYTOKEN for the state stack whose top is + YYSSP. + + Return 0 if *YYMSG was successfully written. Return 1 if *YYMSG is + not large enough to hold the message. In that case, also set + *YYMSG_ALLOC to the required number of bytes. Return 2 if the + required number of bytes is too large to store. */ +static int +yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg, + yytype_int16 *yyssp, int yytoken) { - int yyn = yypact[yystate]; + YYSIZE_T yysize0 = yytnamerr (0, yytname[yytoken]); + YYSIZE_T yysize = yysize0; + YYSIZE_T yysize1; + enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 }; + /* Internationalized format string. */ + const char *yyformat = 0; + /* Arguments of yyformat. */ + char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM]; + /* Number of reported tokens (one for the "unexpected", one per + "expected"). */ + int yycount = 0; - if (! (YYPACT_NINF < yyn && yyn <= YYLAST)) - return 0; - else + /* There are many possibilities here to consider: + - Assume YYFAIL is not used. It's too flawed to consider. See + + for details. YYERROR is fine as it does not invoke this + function. + - If this state is a consistent state with a default action, then + the only way this function was invoked is if the default action + is an error action. In that case, don't check for expected + tokens because there are none. + - The only way there can be no lookahead present (in yychar) is if + this state is a consistent state with a default action. Thus, + detecting the absence of a lookahead is sufficient to determine + that there is no unexpected or expected token to report. In that + case, just report a simple "syntax error". + - Don't assume there isn't a lookahead just because this state is a + consistent state with a default action. There might have been a + previous inconsistent state, consistent state with a non-default + action, or user semantic action that manipulated yychar. + - Of course, the expected token list depends on states to have + correct lookahead information, and it depends on the parser not + to perform extra reductions after fetching a lookahead from the + scanner and before detecting a syntax error. Thus, state merging + (from LALR or IELR) and default reductions corrupt the expected + token list. However, the list is correct for canonical LR with + one exception: it will still contain any token that will not be + accepted due to an error action in a later state. + */ + if (yytoken != YYEMPTY) { - int yytype = YYTRANSLATE (yychar); - YYSIZE_T yysize0 = yytnamerr (0, yytname[yytype]); - YYSIZE_T yysize = yysize0; - YYSIZE_T yysize1; - int yysize_overflow = 0; - enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 }; - char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM]; - int yyx; + int yyn = yypact[*yyssp]; + yyarg[yycount++] = yytname[yytoken]; + if (!yypact_value_is_default (yyn)) + { + /* Start YYX at -YYN if negative to avoid negative indexes in + YYCHECK. In other words, skip the first -YYN actions for + this state because they are default actions. */ + int yyxbegin = yyn < 0 ? -yyn : 0; + /* Stay within bounds of both yycheck and yytname. */ + int yychecklim = YYLAST - yyn + 1; + int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; + int yyx; -# if 0 - /* This is so xgettext sees the translatable formats that are - constructed on the fly. */ - YY_("syntax error, unexpected %s"); - YY_("syntax error, unexpected %s, expecting %s"); - YY_("syntax error, unexpected %s, expecting %s or %s"); - YY_("syntax error, unexpected %s, expecting %s or %s or %s"); - YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"); -# endif - char *yyfmt; - char const *yyf; - static char const yyunexpected[] = "syntax error, unexpected %s"; - static char const yyexpecting[] = ", expecting %s"; - static char const yyor[] = " or %s"; - char yyformat[sizeof yyunexpected - + sizeof yyexpecting - 1 - + ((YYERROR_VERBOSE_ARGS_MAXIMUM - 2) - * (sizeof yyor - 1))]; - char const *yyprefix = yyexpecting; - - /* Start YYX at -YYN if negative to avoid negative indexes in - YYCHECK. */ - int yyxbegin = yyn < 0 ? -yyn : 0; - - /* Stay within bounds of both yycheck and yytname. */ - int yychecklim = YYLAST - yyn + 1; - int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; - int yycount = 1; - - yyarg[0] = yytname[yytype]; - yyfmt = yystpcpy (yyformat, yyunexpected); - - for (yyx = yyxbegin; yyx < yyxend; ++yyx) - if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR) - { - if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM) - { - yycount = 1; - yysize = yysize0; - yyformat[sizeof yyunexpected - 1] = '\0'; - break; - } - yyarg[yycount++] = yytname[yyx]; - yysize1 = yysize + yytnamerr (0, yytname[yyx]); - yysize_overflow |= (yysize1 < yysize); - yysize = yysize1; - yyfmt = yystpcpy (yyfmt, yyprefix); - yyprefix = yyor; - } - - yyf = YY_(yyformat); - yysize1 = yysize + yystrlen (yyf); - yysize_overflow |= (yysize1 < yysize); - yysize = yysize1; - - if (yysize_overflow) - return YYSIZE_MAXIMUM; - - if (yyresult) - { - /* Avoid sprintf, as that infringes on the user's name space. - Don't have undefined behavior even if the translation - produced a string with the wrong number of "%s"s. */ - char *yyp = yyresult; - int yyi = 0; - while ((*yyp = *yyf) != '\0') - { - if (*yyp == '%' && yyf[1] == 's' && yyi < yycount) - { - yyp += yytnamerr (yyp, yyarg[yyi++]); - yyf += 2; - } - else - { - yyp++; - yyf++; - } - } - } - return yysize; + for (yyx = yyxbegin; yyx < yyxend; ++yyx) + if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR + && !yytable_value_is_error (yytable[yyx + yyn])) + { + if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM) + { + yycount = 1; + yysize = yysize0; + break; + } + yyarg[yycount++] = yytname[yyx]; + yysize1 = yysize + yytnamerr (0, yytname[yyx]); + if (! (yysize <= yysize1 + && yysize1 <= YYSTACK_ALLOC_MAXIMUM)) + return 2; + yysize = yysize1; + } + } } + + switch (yycount) + { +# define YYCASE_(N, S) \ + case N: \ + yyformat = S; \ + break + YYCASE_(0, YY_("syntax error")); + YYCASE_(1, YY_("syntax error, unexpected %s")); + YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s")); + YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s")); + YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s")); + YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s")); +# undef YYCASE_ + } + + yysize1 = yysize + yystrlen (yyformat); + if (! (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM)) + return 2; + yysize = yysize1; + + if (*yymsg_alloc < yysize) + { + *yymsg_alloc = 2 * yysize; + if (! (yysize <= *yymsg_alloc + && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM)) + *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM; + return 1; + } + + /* Avoid sprintf, as that infringes on the user's name space. + Don't have undefined behavior even if the translation + produced a string with the wrong number of "%s"s. */ + { + char *yyp = *yymsg; + int yyi = 0; + while ((*yyp = *yyformat) != '\0') + if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount) + { + yyp += yytnamerr (yyp, yyarg[yyi++]); + yyformat += 2; + } + else + { + yyp++; + yyformat++; + } + } + return 0; } #endif /* YYERROR_VERBOSE */ - /*-----------------------------------------------. | Release the memory associated to this symbol. | @@ -1132,6 +1165,7 @@ yydestruct (yymsg, yytype, yyvaluep, yylocationp, mc, tmpl, error_msg) } } + /* Prevent warnings from -Wmissing-prototypes. */ #ifdef YYPARSE_PARAM #if defined __STDC__ || defined __cplusplus @@ -1148,12 +1182,9 @@ int yyparse (); #endif /* ! YYPARSE_PARAM */ - - - -/*-------------------------. -| yyparse or yypush_parse. | -`-------------------------*/ +/*----------. +| yyparse. | +`----------*/ #ifdef YYPARSE_PARAM #if (defined __STDC__ || defined __C99__FUNC__ \ @@ -1219,7 +1250,7 @@ YYLTYPE yylloc; YYLTYPE *yylsp; /* The locations where the error started and ended. */ - YYLTYPE yyerror_range[2]; + YYLTYPE yyerror_range[3]; YYSIZE_T yystacksize; @@ -1368,7 +1399,7 @@ yybackup: /* First try to decide what to do without reference to lookahead token. */ yyn = yypact[yystate]; - if (yyn == YYPACT_NINF) + if (yypact_value_is_default (yyn)) goto yydefault; /* Not known => get a lookahead token if don't already have one. */ @@ -1399,8 +1430,8 @@ yybackup: yyn = yytable[yyn]; if (yyn <= 0) { - if (yyn == 0 || yyn == YYTABLE_NINF) - goto yyerrlab; + if (yytable_value_is_error (yyn)) + goto yyerrlab; yyn = -yyn; goto yyreduce; } @@ -1456,7 +1487,7 @@ yyreduce: { case 4: -/* Line 1464 of yacc.c */ +/* Line 1806 of yacc.c */ #line 99 "template_syntax.y" { Attribute * pattr; @@ -1466,12 +1497,12 @@ yyreduce: pattr = new SingleAttribute(name,unescape(value)); tmpl->set(pattr); - ;} + } break; case 5: -/* Line 1464 of yacc.c */ +/* Line 1806 of yacc.c */ #line 109 "template_syntax.y" { Attribute * pattr; @@ -1484,12 +1515,12 @@ yyreduce: tmpl->set(pattr); delete amap; - ;} + } break; case 6: -/* Line 1464 of yacc.c */ +/* Line 1806 of yacc.c */ #line 122 "template_syntax.y" { Attribute * pattr; @@ -1499,12 +1530,12 @@ yyreduce: pattr = new SingleAttribute(name,value); tmpl->set(pattr); - ;} + } break; case 7: -/* Line 1464 of yacc.c */ +/* Line 1806 of yacc.c */ #line 134 "template_syntax.y" { map* vattr; @@ -1517,12 +1548,12 @@ yyreduce: vattr->insert(make_pair(name,unescape(value))); (yyval.val_attr) = static_cast(vattr); - ;} + } break; case 8: -/* Line 1464 of yacc.c */ +/* Line 1806 of yacc.c */ #line 147 "template_syntax.y" { string name((yyvsp[(3) - (5)].val_str)); @@ -1535,15 +1566,26 @@ yyreduce: attrmap->insert(make_pair(name,unescape(value))); (yyval.val_attr) = (yyvsp[(1) - (5)].val_attr); - ;} + } break; -/* Line 1464 of yacc.c */ -#line 1545 "template_syntax.cc" +/* Line 1806 of yacc.c */ +#line 1576 "template_syntax.cc" default: break; } + /* User semantic actions sometimes alter yychar, and that requires + that yytoken be updated with the new translation. We take the + approach of translating immediately before every use of yytoken. + One alternative is translating here after every semantic action, + but that translation would be missed if the semantic action invokes + YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or + if it invokes YYBACKUP. In the case of YYABORT or YYACCEPT, an + incorrect destructor might then be invoked immediately. In the + case of YYERROR or YYBACKUP, subsequent parser actions might lead + to an incorrect destructor call or verbose syntax error message + before the lookahead is translated. */ YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc); YYPOPSTACK (yylen); @@ -1572,6 +1614,10 @@ yyreduce: | yyerrlab -- here on detecting error | `------------------------------------*/ yyerrlab: + /* Make sure we have latest lookahead translation. See comments at + user semantic actions for why this is necessary. */ + yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar); + /* If not already recovering from an error, report this error. */ if (!yyerrstatus) { @@ -1579,41 +1625,40 @@ yyerrlab: #if ! YYERROR_VERBOSE yyerror (&yylloc, mc, tmpl, error_msg, YY_("syntax error")); #else +# define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \ + yyssp, yytoken) { - YYSIZE_T yysize = yysyntax_error (0, yystate, yychar); - if (yymsg_alloc < yysize && yymsg_alloc < YYSTACK_ALLOC_MAXIMUM) - { - YYSIZE_T yyalloc = 2 * yysize; - if (! (yysize <= yyalloc && yyalloc <= YYSTACK_ALLOC_MAXIMUM)) - yyalloc = YYSTACK_ALLOC_MAXIMUM; - if (yymsg != yymsgbuf) - YYSTACK_FREE (yymsg); - yymsg = (char *) YYSTACK_ALLOC (yyalloc); - if (yymsg) - yymsg_alloc = yyalloc; - else - { - yymsg = yymsgbuf; - yymsg_alloc = sizeof yymsgbuf; - } - } - - if (0 < yysize && yysize <= yymsg_alloc) - { - (void) yysyntax_error (yymsg, yystate, yychar); - yyerror (&yylloc, mc, tmpl, error_msg, yymsg); - } - else - { - yyerror (&yylloc, mc, tmpl, error_msg, YY_("syntax error")); - if (yysize != 0) - goto yyexhaustedlab; - } + char const *yymsgp = YY_("syntax error"); + int yysyntax_error_status; + yysyntax_error_status = YYSYNTAX_ERROR; + if (yysyntax_error_status == 0) + yymsgp = yymsg; + else if (yysyntax_error_status == 1) + { + if (yymsg != yymsgbuf) + YYSTACK_FREE (yymsg); + yymsg = (char *) YYSTACK_ALLOC (yymsg_alloc); + if (!yymsg) + { + yymsg = yymsgbuf; + yymsg_alloc = sizeof yymsgbuf; + yysyntax_error_status = 2; + } + else + { + yysyntax_error_status = YYSYNTAX_ERROR; + yymsgp = yymsg; + } + } + yyerror (&yylloc, mc, tmpl, error_msg, yymsgp); + if (yysyntax_error_status == 2) + goto yyexhaustedlab; } +# undef YYSYNTAX_ERROR #endif } - yyerror_range[0] = yylloc; + yyerror_range[1] = yylloc; if (yyerrstatus == 3) { @@ -1650,7 +1695,7 @@ yyerrorlab: if (/*CONSTCOND*/ 0) goto yyerrorlab; - yyerror_range[0] = yylsp[1-yylen]; + yyerror_range[1] = yylsp[1-yylen]; /* Do not reclaim the symbols of the rule which action triggered this YYERROR. */ YYPOPSTACK (yylen); @@ -1669,7 +1714,7 @@ yyerrlab1: for (;;) { yyn = yypact[yystate]; - if (yyn != YYPACT_NINF) + if (!yypact_value_is_default (yyn)) { yyn += YYTERROR; if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR) @@ -1684,7 +1729,7 @@ yyerrlab1: if (yyssp == yyss) YYABORT; - yyerror_range[0] = *yylsp; + yyerror_range[1] = *yylsp; yydestruct ("Error: popping", yystos[yystate], yyvsp, yylsp, mc, tmpl, error_msg); YYPOPSTACK (1); @@ -1694,10 +1739,10 @@ yyerrlab1: *++yyvsp = yylval; - yyerror_range[1] = yylloc; + yyerror_range[2] = yylloc; /* Using YYLLOC is tempting, but would change the location of the lookahead. YYLOC is available though. */ - YYLLOC_DEFAULT (yyloc, (yyerror_range - 1), 2); + YYLLOC_DEFAULT (yyloc, yyerror_range, 2); *++yylsp = yyloc; /* Shift the error token. */ @@ -1733,8 +1778,13 @@ yyexhaustedlab: yyreturn: if (yychar != YYEMPTY) - yydestruct ("Cleanup: discarding lookahead", - yytoken, &yylval, &yylloc, mc, tmpl, error_msg); + { + /* Make sure we have latest lookahead translation. See comments at + user semantic actions for why this is necessary. */ + yytoken = YYTRANSLATE (yychar); + yydestruct ("Cleanup: discarding lookahead", + yytoken, &yylval, &yylloc, mc, tmpl, error_msg); + } /* Do not reclaim the symbols of the rule which action triggered this YYABORT or YYACCEPT. */ YYPOPSTACK (yylen); @@ -1759,7 +1809,7 @@ yyreturn: -/* Line 1684 of yacc.c */ +/* Line 2067 of yacc.c */ #line 160 "template_syntax.y" diff --git a/src/template/template_syntax.h b/src/template/template_syntax.h index dcef6a9d96..aa9ae6b64b 100644 --- a/src/template/template_syntax.h +++ b/src/template/template_syntax.h @@ -1,9 +1,8 @@ -/* A Bison parser, made by GNU Bison 2.4.2. */ +/* A Bison parser, made by GNU Bison 2.5. */ -/* Skeleton interface for Bison's Yacc-like parsers in C +/* Bison interface for Yacc-like parsers in C - Copyright (C) 1984, 1989-1990, 2000-2006, 2009-2010 Free Software - Foundation, Inc. + Copyright (C) 1984, 1989-1990, 2000-2011 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -54,7 +53,7 @@ typedef union YYSTYPE { -/* Line 1685 of yacc.c */ +/* Line 2068 of yacc.c */ #line 74 "template_syntax.y" char * val_str; @@ -62,8 +61,8 @@ typedef union YYSTYPE -/* Line 1685 of yacc.c */ -#line 67 "template_syntax.hh" +/* Line 2068 of yacc.c */ +#line 66 "template_syntax.hh" } YYSTYPE; # define YYSTYPE_IS_TRIVIAL 1 # define yystype YYSTYPE /* obsolescent; will be withdrawn */ diff --git a/src/vm/vm_var_syntax.cc b/src/vm/vm_var_syntax.cc index 30866385ae..6a75d06320 100644 --- a/src/vm/vm_var_syntax.cc +++ b/src/vm/vm_var_syntax.cc @@ -1,9 +1,8 @@ -/* A Bison parser, made by GNU Bison 2.4.3. */ +/* A Bison parser, made by GNU Bison 2.5. */ -/* Skeleton implementation for Bison's Yacc-like parsers in C +/* Bison implementation for Yacc-like parsers in C - Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006, - 2009, 2010 Free Software Foundation, Inc. + Copyright (C) 1984, 1989-1990, 2000-2011 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -45,7 +44,7 @@ #define YYBISON 1 /* Bison version. */ -#define YYBISON_VERSION "2.4.3" +#define YYBISON_VERSION "2.5" /* Skeleton name. */ #define YYSKELETON_NAME "yacc.c" @@ -74,7 +73,7 @@ /* Copy the first part of user declarations. */ -/* Line 189 of yacc.c */ +/* Line 268 of yacc.c */ #line 17 "vm_var_syntax.y" #include @@ -307,7 +306,7 @@ void get_network_attribute(VirtualMachine * vm, /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ -/* + void get_user_attribute(VirtualMachine * vm, const string& attr_name, string& attr_value) @@ -337,7 +336,7 @@ void get_user_attribute(VirtualMachine * vm, user->unlock(); } -*/ + /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ @@ -408,6 +407,19 @@ void insert_vector(VirtualMachine * vm, return; } + else if (name == "USER") + { + string value; + + get_user_attribute(vm, vname, value); + + if (!value.empty()) + { + parsed << value; + } + + return; + } else { if ( ( num = vm->get_template_attribute(name.c_str(),values) ) <= 0 ) @@ -447,8 +459,8 @@ void insert_vector(VirtualMachine * vm, -/* Line 189 of yacc.c */ -#line 452 "vm_var_syntax.cc" +/* Line 268 of yacc.c */ +#line 464 "vm_var_syntax.cc" /* Enabling traces. */ #ifndef YYDEBUG @@ -493,8 +505,8 @@ void insert_vector(VirtualMachine * vm, typedef union YYSTYPE { -/* Line 214 of yacc.c */ -#line 395 "vm_var_syntax.y" +/* Line 293 of yacc.c */ +#line 408 "vm_var_syntax.y" char * val_str; int val_int; @@ -502,8 +514,8 @@ typedef union YYSTYPE -/* Line 214 of yacc.c */ -#line 507 "vm_var_syntax.cc" +/* Line 293 of yacc.c */ +#line 519 "vm_var_syntax.cc" } YYSTYPE; # define YYSTYPE_IS_TRIVIAL 1 # define yystype YYSTYPE /* obsolescent; will be withdrawn */ @@ -527,8 +539,8 @@ typedef struct YYLTYPE /* Copy the second part of user declarations. */ -/* Line 264 of yacc.c */ -#line 532 "vm_var_syntax.cc" +/* Line 343 of yacc.c */ +#line 544 "vm_var_syntax.cc" #ifdef short # undef short @@ -631,11 +643,11 @@ YYID (yyi) # define alloca _alloca # else # define YYSTACK_ALLOC alloca -# if ! defined _ALLOCA_H && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \ +# if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) # include /* INFRINGES ON USER NAME SPACE */ -# ifndef _STDLIB_H -# define _STDLIB_H 1 +# ifndef EXIT_SUCCESS +# define EXIT_SUCCESS 0 # endif # endif # endif @@ -658,24 +670,24 @@ YYID (yyi) # ifndef YYSTACK_ALLOC_MAXIMUM # define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM # endif -# if (defined __cplusplus && ! defined _STDLIB_H \ +# if (defined __cplusplus && ! defined EXIT_SUCCESS \ && ! ((defined YYMALLOC || defined malloc) \ && (defined YYFREE || defined free))) # include /* INFRINGES ON USER NAME SPACE */ -# ifndef _STDLIB_H -# define _STDLIB_H 1 +# ifndef EXIT_SUCCESS +# define EXIT_SUCCESS 0 # endif # endif # ifndef YYMALLOC # define YYMALLOC malloc -# if ! defined malloc && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \ +# if ! defined malloc && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */ # endif # endif # ifndef YYFREE # define YYFREE free -# if ! defined free && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \ +# if ! defined free && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) void free (void *); /* INFRINGES ON USER NAME SPACE */ # endif @@ -706,23 +718,7 @@ union yyalloc ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE) + sizeof (YYLTYPE)) \ + 2 * YYSTACK_GAP_MAXIMUM) -/* Copy COUNT objects from FROM to TO. The source and destination do - not overlap. */ -# ifndef YYCOPY -# if defined __GNUC__ && 1 < __GNUC__ -# define YYCOPY(To, From, Count) \ - __builtin_memcpy (To, From, (Count) * sizeof (*(From))) -# else -# define YYCOPY(To, From, Count) \ - do \ - { \ - YYSIZE_T yyi; \ - for (yyi = 0; yyi < (Count); yyi++) \ - (To)[yyi] = (From)[yyi]; \ - } \ - while (YYID (0)) -# endif -# endif +# define YYCOPY_NEEDED 1 /* Relocate STACK from its old location to the new one. The local variables YYSIZE and YYSTACKSIZE give the old and new number of @@ -742,6 +738,26 @@ union yyalloc #endif +#if defined YYCOPY_NEEDED && YYCOPY_NEEDED +/* Copy COUNT objects from FROM to TO. The source and destination do + not overlap. */ +# ifndef YYCOPY +# if defined __GNUC__ && 1 < __GNUC__ +# define YYCOPY(To, From, Count) \ + __builtin_memcpy (To, From, (Count) * sizeof (*(From))) +# else +# define YYCOPY(To, From, Count) \ + do \ + { \ + YYSIZE_T yyi; \ + for (yyi = 0; yyi < (Count); yyi++) \ + (To)[yyi] = (From)[yyi]; \ + } \ + while (YYID (0)) +# endif +# endif +#endif /* !YYCOPY_NEEDED */ + /* YYFINAL -- State number of the termination state. */ #define YYFINAL 7 /* YYLAST -- Last index in YYTABLE. */ @@ -814,7 +830,7 @@ static const yytype_int8 yyrhs[] = /* YYRLINE[YYN] -- source line where rule number YYN was defined. */ static const yytype_uint16 yyrline[] = { - 0, 419, 419, 420, 423, 427, 440, 455 + 0, 432, 432, 433, 436, 440, 453, 468 }; #endif @@ -851,8 +867,8 @@ static const yytype_uint8 yyr2[] = 0, 2, 1, 2, 1, 2, 5, 9 }; -/* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state - STATE-NUM when YYTABLE doesn't specify something else to do. Zero +/* YYDEFACT[STATE-NAME] -- Default reduction number in state STATE-NUM. + Performed when YYTABLE doesn't specify something else to do. Zero means the default is an error. */ static const yytype_uint8 yydefact[] = { @@ -883,8 +899,7 @@ static const yytype_int8 yypgoto[] = /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If positive, shift that token. If negative, reduce the rule which - number is the opposite. If zero, do what YYDEFACT says. - If YYTABLE_NINF, syntax error. */ + number is the opposite. If YYTABLE_NINF, syntax error. */ #define YYTABLE_NINF -1 static const yytype_uint8 yytable[] = { @@ -892,6 +907,12 @@ static const yytype_uint8 yytable[] = 2, 12, 13, 14, 15, 16, 8, 0, 17 }; +#define yypact_value_is_default(yystate) \ + ((yystate) == (-5)) + +#define yytable_value_is_error(yytable_value) \ + YYID (0) + static const yytype_int8 yycheck[] = { 0, 5, 4, 7, 6, -1, 9, 10, 9, 9, @@ -939,7 +960,6 @@ do \ { \ yychar = (Token); \ yylval = (Value); \ - yytoken = YYTRANSLATE (yychar); \ YYPOPSTACK (1); \ goto yybackup; \ } \ @@ -1207,7 +1227,6 @@ int yydebug; # define YYMAXDEPTH 10000 #endif - #if YYERROR_VERBOSE @@ -1310,115 +1329,142 @@ yytnamerr (char *yyres, const char *yystr) } # endif -/* Copy into YYRESULT an error message about the unexpected token - YYCHAR while in state YYSTATE. Return the number of bytes copied, - including the terminating null byte. If YYRESULT is null, do not - copy anything; just return the number of bytes that would be - copied. As a special case, return 0 if an ordinary "syntax error" - message will do. Return YYSIZE_MAXIMUM if overflow occurs during - size calculation. */ -static YYSIZE_T -yysyntax_error (char *yyresult, int yystate, int yychar) +/* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message + about the unexpected token YYTOKEN for the state stack whose top is + YYSSP. + + Return 0 if *YYMSG was successfully written. Return 1 if *YYMSG is + not large enough to hold the message. In that case, also set + *YYMSG_ALLOC to the required number of bytes. Return 2 if the + required number of bytes is too large to store. */ +static int +yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg, + yytype_int16 *yyssp, int yytoken) { - int yyn = yypact[yystate]; + YYSIZE_T yysize0 = yytnamerr (0, yytname[yytoken]); + YYSIZE_T yysize = yysize0; + YYSIZE_T yysize1; + enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 }; + /* Internationalized format string. */ + const char *yyformat = 0; + /* Arguments of yyformat. */ + char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM]; + /* Number of reported tokens (one for the "unexpected", one per + "expected"). */ + int yycount = 0; - if (! (YYPACT_NINF < yyn && yyn <= YYLAST)) - return 0; - else + /* There are many possibilities here to consider: + - Assume YYFAIL is not used. It's too flawed to consider. See + + for details. YYERROR is fine as it does not invoke this + function. + - If this state is a consistent state with a default action, then + the only way this function was invoked is if the default action + is an error action. In that case, don't check for expected + tokens because there are none. + - The only way there can be no lookahead present (in yychar) is if + this state is a consistent state with a default action. Thus, + detecting the absence of a lookahead is sufficient to determine + that there is no unexpected or expected token to report. In that + case, just report a simple "syntax error". + - Don't assume there isn't a lookahead just because this state is a + consistent state with a default action. There might have been a + previous inconsistent state, consistent state with a non-default + action, or user semantic action that manipulated yychar. + - Of course, the expected token list depends on states to have + correct lookahead information, and it depends on the parser not + to perform extra reductions after fetching a lookahead from the + scanner and before detecting a syntax error. Thus, state merging + (from LALR or IELR) and default reductions corrupt the expected + token list. However, the list is correct for canonical LR with + one exception: it will still contain any token that will not be + accepted due to an error action in a later state. + */ + if (yytoken != YYEMPTY) { - int yytype = YYTRANSLATE (yychar); - YYSIZE_T yysize0 = yytnamerr (0, yytname[yytype]); - YYSIZE_T yysize = yysize0; - YYSIZE_T yysize1; - int yysize_overflow = 0; - enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 }; - char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM]; - int yyx; + int yyn = yypact[*yyssp]; + yyarg[yycount++] = yytname[yytoken]; + if (!yypact_value_is_default (yyn)) + { + /* Start YYX at -YYN if negative to avoid negative indexes in + YYCHECK. In other words, skip the first -YYN actions for + this state because they are default actions. */ + int yyxbegin = yyn < 0 ? -yyn : 0; + /* Stay within bounds of both yycheck and yytname. */ + int yychecklim = YYLAST - yyn + 1; + int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; + int yyx; -# if 0 - /* This is so xgettext sees the translatable formats that are - constructed on the fly. */ - YY_("syntax error, unexpected %s"); - YY_("syntax error, unexpected %s, expecting %s"); - YY_("syntax error, unexpected %s, expecting %s or %s"); - YY_("syntax error, unexpected %s, expecting %s or %s or %s"); - YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"); -# endif - char *yyfmt; - char const *yyf; - static char const yyunexpected[] = "syntax error, unexpected %s"; - static char const yyexpecting[] = ", expecting %s"; - static char const yyor[] = " or %s"; - char yyformat[sizeof yyunexpected - + sizeof yyexpecting - 1 - + ((YYERROR_VERBOSE_ARGS_MAXIMUM - 2) - * (sizeof yyor - 1))]; - char const *yyprefix = yyexpecting; - - /* Start YYX at -YYN if negative to avoid negative indexes in - YYCHECK. */ - int yyxbegin = yyn < 0 ? -yyn : 0; - - /* Stay within bounds of both yycheck and yytname. */ - int yychecklim = YYLAST - yyn + 1; - int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; - int yycount = 1; - - yyarg[0] = yytname[yytype]; - yyfmt = yystpcpy (yyformat, yyunexpected); - - for (yyx = yyxbegin; yyx < yyxend; ++yyx) - if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR) - { - if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM) - { - yycount = 1; - yysize = yysize0; - yyformat[sizeof yyunexpected - 1] = '\0'; - break; - } - yyarg[yycount++] = yytname[yyx]; - yysize1 = yysize + yytnamerr (0, yytname[yyx]); - yysize_overflow |= (yysize1 < yysize); - yysize = yysize1; - yyfmt = yystpcpy (yyfmt, yyprefix); - yyprefix = yyor; - } - - yyf = YY_(yyformat); - yysize1 = yysize + yystrlen (yyf); - yysize_overflow |= (yysize1 < yysize); - yysize = yysize1; - - if (yysize_overflow) - return YYSIZE_MAXIMUM; - - if (yyresult) - { - /* Avoid sprintf, as that infringes on the user's name space. - Don't have undefined behavior even if the translation - produced a string with the wrong number of "%s"s. */ - char *yyp = yyresult; - int yyi = 0; - while ((*yyp = *yyf) != '\0') - { - if (*yyp == '%' && yyf[1] == 's' && yyi < yycount) - { - yyp += yytnamerr (yyp, yyarg[yyi++]); - yyf += 2; - } - else - { - yyp++; - yyf++; - } - } - } - return yysize; + for (yyx = yyxbegin; yyx < yyxend; ++yyx) + if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR + && !yytable_value_is_error (yytable[yyx + yyn])) + { + if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM) + { + yycount = 1; + yysize = yysize0; + break; + } + yyarg[yycount++] = yytname[yyx]; + yysize1 = yysize + yytnamerr (0, yytname[yyx]); + if (! (yysize <= yysize1 + && yysize1 <= YYSTACK_ALLOC_MAXIMUM)) + return 2; + yysize = yysize1; + } + } } + + switch (yycount) + { +# define YYCASE_(N, S) \ + case N: \ + yyformat = S; \ + break + YYCASE_(0, YY_("syntax error")); + YYCASE_(1, YY_("syntax error, unexpected %s")); + YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s")); + YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s")); + YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s")); + YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s")); +# undef YYCASE_ + } + + yysize1 = yysize + yystrlen (yyformat); + if (! (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM)) + return 2; + yysize = yysize1; + + if (*yymsg_alloc < yysize) + { + *yymsg_alloc = 2 * yysize; + if (! (yysize <= *yymsg_alloc + && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM)) + *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM; + return 1; + } + + /* Avoid sprintf, as that infringes on the user's name space. + Don't have undefined behavior even if the translation + produced a string with the wrong number of "%s"s. */ + { + char *yyp = *yymsg; + int yyi = 0; + while ((*yyp = *yyformat) != '\0') + if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount) + { + yyp += yytnamerr (yyp, yyarg[yyi++]); + yyformat += 2; + } + else + { + yyp++; + yyformat++; + } + } + return 0; } #endif /* YYERROR_VERBOSE */ - /*-----------------------------------------------. | Release the memory associated to this symbol. | @@ -1461,6 +1507,7 @@ yydestruct (yymsg, yytype, yyvaluep, yylocationp, mc, vm, parsed, errmsg) } } + /* Prevent warnings from -Wmissing-prototypes. */ #ifdef YYPARSE_PARAM #if defined __STDC__ || defined __cplusplus @@ -1477,12 +1524,9 @@ int yyparse (); #endif /* ! YYPARSE_PARAM */ - - - -/*-------------------------. -| yyparse or yypush_parse. | -`-------------------------*/ +/*----------. +| yyparse. | +`----------*/ #ifdef YYPARSE_PARAM #if (defined __STDC__ || defined __C99__FUNC__ \ @@ -1698,7 +1742,7 @@ yybackup: /* First try to decide what to do without reference to lookahead token. */ yyn = yypact[yystate]; - if (yyn == YYPACT_NINF) + if (yypact_value_is_default (yyn)) goto yydefault; /* Not known => get a lookahead token if don't already have one. */ @@ -1729,8 +1773,8 @@ yybackup: yyn = yytable[yyn]; if (yyn <= 0) { - if (yyn == 0 || yyn == YYTABLE_NINF) - goto yyerrlab; + if (yytable_value_is_error (yyn)) + goto yyerrlab; yyn = -yyn; goto yyreduce; } @@ -1786,17 +1830,17 @@ yyreduce: { case 4: -/* Line 1464 of yacc.c */ -#line 424 "vm_var_syntax.y" +/* Line 1806 of yacc.c */ +#line 437 "vm_var_syntax.y" { (*parsed) << (yyvsp[(1) - (1)].val_str); - ;} + } break; case 5: -/* Line 1464 of yacc.c */ -#line 428 "vm_var_syntax.y" +/* Line 1806 of yacc.c */ +#line 441 "vm_var_syntax.y" { string name((yyvsp[(1) - (2)].val_str)); @@ -1808,13 +1852,13 @@ yyreduce: { (*parsed) << (yyvsp[(2) - (2)].val_char); } - ;} + } break; case 6: -/* Line 1464 of yacc.c */ -#line 441 "vm_var_syntax.y" +/* Line 1806 of yacc.c */ +#line 454 "vm_var_syntax.y" { string name((yyvsp[(1) - (5)].val_str)); string vname((yyvsp[(3) - (5)].val_str)); @@ -1828,13 +1872,13 @@ yyreduce: { (*parsed) << (yyvsp[(5) - (5)].val_char); } - ;} + } break; case 7: -/* Line 1464 of yacc.c */ -#line 456 "vm_var_syntax.y" +/* Line 1806 of yacc.c */ +#line 469 "vm_var_syntax.y" { string name((yyvsp[(1) - (9)].val_str)); string vname((yyvsp[(3) - (9)].val_str)); @@ -1851,15 +1895,26 @@ yyreduce: { (*parsed) << (yyvsp[(9) - (9)].val_char); } - ;} + } break; -/* Line 1464 of yacc.c */ -#line 1861 "vm_var_syntax.cc" +/* Line 1806 of yacc.c */ +#line 1905 "vm_var_syntax.cc" default: break; } + /* User semantic actions sometimes alter yychar, and that requires + that yytoken be updated with the new translation. We take the + approach of translating immediately before every use of yytoken. + One alternative is translating here after every semantic action, + but that translation would be missed if the semantic action invokes + YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or + if it invokes YYBACKUP. In the case of YYABORT or YYACCEPT, an + incorrect destructor might then be invoked immediately. In the + case of YYERROR or YYBACKUP, subsequent parser actions might lead + to an incorrect destructor call or verbose syntax error message + before the lookahead is translated. */ YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc); YYPOPSTACK (yylen); @@ -1888,6 +1943,10 @@ yyreduce: | yyerrlab -- here on detecting error | `------------------------------------*/ yyerrlab: + /* Make sure we have latest lookahead translation. See comments at + user semantic actions for why this is necessary. */ + yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar); + /* If not already recovering from an error, report this error. */ if (!yyerrstatus) { @@ -1895,37 +1954,36 @@ yyerrlab: #if ! YYERROR_VERBOSE yyerror (&yylloc, mc, vm, parsed, errmsg, YY_("syntax error")); #else +# define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \ + yyssp, yytoken) { - YYSIZE_T yysize = yysyntax_error (0, yystate, yychar); - if (yymsg_alloc < yysize && yymsg_alloc < YYSTACK_ALLOC_MAXIMUM) - { - YYSIZE_T yyalloc = 2 * yysize; - if (! (yysize <= yyalloc && yyalloc <= YYSTACK_ALLOC_MAXIMUM)) - yyalloc = YYSTACK_ALLOC_MAXIMUM; - if (yymsg != yymsgbuf) - YYSTACK_FREE (yymsg); - yymsg = (char *) YYSTACK_ALLOC (yyalloc); - if (yymsg) - yymsg_alloc = yyalloc; - else - { - yymsg = yymsgbuf; - yymsg_alloc = sizeof yymsgbuf; - } - } - - if (0 < yysize && yysize <= yymsg_alloc) - { - (void) yysyntax_error (yymsg, yystate, yychar); - yyerror (&yylloc, mc, vm, parsed, errmsg, yymsg); - } - else - { - yyerror (&yylloc, mc, vm, parsed, errmsg, YY_("syntax error")); - if (yysize != 0) - goto yyexhaustedlab; - } + char const *yymsgp = YY_("syntax error"); + int yysyntax_error_status; + yysyntax_error_status = YYSYNTAX_ERROR; + if (yysyntax_error_status == 0) + yymsgp = yymsg; + else if (yysyntax_error_status == 1) + { + if (yymsg != yymsgbuf) + YYSTACK_FREE (yymsg); + yymsg = (char *) YYSTACK_ALLOC (yymsg_alloc); + if (!yymsg) + { + yymsg = yymsgbuf; + yymsg_alloc = sizeof yymsgbuf; + yysyntax_error_status = 2; + } + else + { + yysyntax_error_status = YYSYNTAX_ERROR; + yymsgp = yymsg; + } + } + yyerror (&yylloc, mc, vm, parsed, errmsg, yymsgp); + if (yysyntax_error_status == 2) + goto yyexhaustedlab; } +# undef YYSYNTAX_ERROR #endif } @@ -1985,7 +2043,7 @@ yyerrlab1: for (;;) { yyn = yypact[yystate]; - if (yyn != YYPACT_NINF) + if (!yypact_value_is_default (yyn)) { yyn += YYTERROR; if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR) @@ -2049,8 +2107,13 @@ yyexhaustedlab: yyreturn: if (yychar != YYEMPTY) - yydestruct ("Cleanup: discarding lookahead", - yytoken, &yylval, &yylloc, mc, vm, parsed, errmsg); + { + /* Make sure we have latest lookahead translation. See comments at + user semantic actions for why this is necessary. */ + yytoken = YYTRANSLATE (yychar); + yydestruct ("Cleanup: discarding lookahead", + yytoken, &yylval, &yylloc, mc, vm, parsed, errmsg); + } /* Do not reclaim the symbols of the rule which action triggered this YYABORT or YYACCEPT. */ YYPOPSTACK (yylen); @@ -2075,8 +2138,8 @@ yyreturn: -/* Line 1684 of yacc.c */ -#line 474 "vm_var_syntax.y" +/* Line 2067 of yacc.c */ +#line 487 "vm_var_syntax.y" extern "C" void vm_var__error( diff --git a/src/vm/vm_var_syntax.h b/src/vm/vm_var_syntax.h index 8d099c1d0a..d40f8d1d51 100644 --- a/src/vm/vm_var_syntax.h +++ b/src/vm/vm_var_syntax.h @@ -1,9 +1,8 @@ -/* A Bison parser, made by GNU Bison 2.4.3. */ +/* A Bison parser, made by GNU Bison 2.5. */ -/* Skeleton interface for Bison's Yacc-like parsers in C +/* Bison interface for Yacc-like parsers in C - Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006, - 2009, 2010 Free Software Foundation, Inc. + Copyright (C) 1984, 1989-1990, 2000-2011 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -56,8 +55,8 @@ typedef union YYSTYPE { -/* Line 1685 of yacc.c */ -#line 395 "vm_var_syntax.y" +/* Line 2068 of yacc.c */ +#line 408 "vm_var_syntax.y" char * val_str; int val_int; @@ -65,8 +64,8 @@ typedef union YYSTYPE -/* Line 1685 of yacc.c */ -#line 70 "vm_var_syntax.hh" +/* Line 2068 of yacc.c */ +#line 69 "vm_var_syntax.hh" } YYSTYPE; # define YYSTYPE_IS_TRIVIAL 1 # define yystype YYSTYPE /* obsolescent; will be withdrawn */ diff --git a/src/vm/vm_var_syntax.y b/src/vm/vm_var_syntax.y index ae83471f07..bd75e41a02 100644 --- a/src/vm/vm_var_syntax.y +++ b/src/vm/vm_var_syntax.y @@ -245,7 +245,7 @@ void get_network_attribute(VirtualMachine * vm, /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ -/* + void get_user_attribute(VirtualMachine * vm, const string& attr_name, string& attr_value) @@ -275,7 +275,7 @@ void get_user_attribute(VirtualMachine * vm, user->unlock(); } -*/ + /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ @@ -346,6 +346,19 @@ void insert_vector(VirtualMachine * vm, return; } + else if (name == "USER") + { + string value; + + get_user_attribute(vm, vname, value); + + if (!value.empty()) + { + parsed << value; + } + + return; + } else { if ( ( num = vm->get_template_attribute(name.c_str(),values) ) <= 0 ) diff --git a/src/xml/expr_arith.cc b/src/xml/expr_arith.cc index b8c9394fbf..a27aa8c15b 100644 --- a/src/xml/expr_arith.cc +++ b/src/xml/expr_arith.cc @@ -1,9 +1,8 @@ -/* A Bison parser, made by GNU Bison 2.4.3. */ +/* A Bison parser, made by GNU Bison 2.5. */ -/* Skeleton implementation for Bison's Yacc-like parsers in C +/* Bison implementation for Yacc-like parsers in C - Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006, - 2009, 2010 Free Software Foundation, Inc. + Copyright (C) 1984, 1989-1990, 2000-2011 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -45,7 +44,7 @@ #define YYBISON 1 /* Bison version. */ -#define YYBISON_VERSION "2.4.3" +#define YYBISON_VERSION "2.5" /* Skeleton name. */ #define YYSKELETON_NAME "yacc.c" @@ -74,7 +73,7 @@ /* Copy the first part of user declarations. */ -/* Line 189 of yacc.c */ +/* Line 268 of yacc.c */ #line 17 "expr_arith.y" #include @@ -130,8 +129,8 @@ extern "C" -/* Line 189 of yacc.c */ -#line 135 "expr_arith.cc" +/* Line 268 of yacc.c */ +#line 134 "expr_arith.cc" /* Enabling traces. */ #ifndef YYDEBUG @@ -170,7 +169,7 @@ extern "C" typedef union YYSTYPE { -/* Line 214 of yacc.c */ +/* Line 293 of yacc.c */ #line 78 "expr_arith.y" char * val_str; @@ -179,8 +178,8 @@ typedef union YYSTYPE -/* Line 214 of yacc.c */ -#line 184 "expr_arith.cc" +/* Line 293 of yacc.c */ +#line 183 "expr_arith.cc" } YYSTYPE; # define YYSTYPE_IS_TRIVIAL 1 # define yystype YYSTYPE /* obsolescent; will be withdrawn */ @@ -204,8 +203,8 @@ typedef struct YYLTYPE /* Copy the second part of user declarations. */ -/* Line 264 of yacc.c */ -#line 209 "expr_arith.cc" +/* Line 343 of yacc.c */ +#line 208 "expr_arith.cc" #ifdef short # undef short @@ -308,11 +307,11 @@ YYID (yyi) # define alloca _alloca # else # define YYSTACK_ALLOC alloca -# if ! defined _ALLOCA_H && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \ +# if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) # include /* INFRINGES ON USER NAME SPACE */ -# ifndef _STDLIB_H -# define _STDLIB_H 1 +# ifndef EXIT_SUCCESS +# define EXIT_SUCCESS 0 # endif # endif # endif @@ -335,24 +334,24 @@ YYID (yyi) # ifndef YYSTACK_ALLOC_MAXIMUM # define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM # endif -# if (defined __cplusplus && ! defined _STDLIB_H \ +# if (defined __cplusplus && ! defined EXIT_SUCCESS \ && ! ((defined YYMALLOC || defined malloc) \ && (defined YYFREE || defined free))) # include /* INFRINGES ON USER NAME SPACE */ -# ifndef _STDLIB_H -# define _STDLIB_H 1 +# ifndef EXIT_SUCCESS +# define EXIT_SUCCESS 0 # endif # endif # ifndef YYMALLOC # define YYMALLOC malloc -# if ! defined malloc && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \ +# if ! defined malloc && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */ # endif # endif # ifndef YYFREE # define YYFREE free -# if ! defined free && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \ +# if ! defined free && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) void free (void *); /* INFRINGES ON USER NAME SPACE */ # endif @@ -383,23 +382,7 @@ union yyalloc ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE) + sizeof (YYLTYPE)) \ + 2 * YYSTACK_GAP_MAXIMUM) -/* Copy COUNT objects from FROM to TO. The source and destination do - not overlap. */ -# ifndef YYCOPY -# if defined __GNUC__ && 1 < __GNUC__ -# define YYCOPY(To, From, Count) \ - __builtin_memcpy (To, From, (Count) * sizeof (*(From))) -# else -# define YYCOPY(To, From, Count) \ - do \ - { \ - YYSIZE_T yyi; \ - for (yyi = 0; yyi < (Count); yyi++) \ - (To)[yyi] = (From)[yyi]; \ - } \ - while (YYID (0)) -# endif -# endif +# define YYCOPY_NEEDED 1 /* Relocate STACK from its old location to the new one. The local variables YYSIZE and YYSTACKSIZE give the old and new number of @@ -419,6 +402,26 @@ union yyalloc #endif +#if defined YYCOPY_NEEDED && YYCOPY_NEEDED +/* Copy COUNT objects from FROM to TO. The source and destination do + not overlap. */ +# ifndef YYCOPY +# if defined __GNUC__ && 1 < __GNUC__ +# define YYCOPY(To, From, Count) \ + __builtin_memcpy (To, From, (Count) * sizeof (*(From))) +# else +# define YYCOPY(To, From, Count) \ + do \ + { \ + YYSIZE_T yyi; \ + for (yyi = 0; yyi < (Count); yyi++) \ + (To)[yyi] = (From)[yyi]; \ + } \ + while (YYID (0)) +# endif +# endif +#endif /* !YYCOPY_NEEDED */ + /* YYFINAL -- State number of the termination state. */ #define YYFINAL 10 /* YYLAST -- Last index in YYTABLE. */ @@ -532,8 +535,8 @@ static const yytype_uint8 yyr2[] = 3, 2, 3 }; -/* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state - STATE-NUM when YYTABLE doesn't specify something else to do. Zero +/* YYDEFACT[STATE-NAME] -- Default reduction number in state STATE-NUM. + Performed when YYTABLE doesn't specify something else to do. Zero means the default is an error. */ static const yytype_uint8 yydefact[] = { @@ -564,8 +567,7 @@ static const yytype_int8 yypgoto[] = /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If positive, shift that token. If negative, reduce the rule which - number is the opposite. If zero, do what YYDEFACT says. - If YYTABLE_NINF, syntax error. */ + number is the opposite. If YYTABLE_NINF, syntax error. */ #define YYTABLE_NINF -1 static const yytype_uint8 yytable[] = { @@ -574,6 +576,12 @@ static const yytype_uint8 yytable[] = 4, 5, 11, 12, 13, 14 }; +#define yypact_value_is_default(yystate) \ + ((yystate) == (-5)) + +#define yytable_value_is_error(yytable_value) \ + YYID (0) + static const yytype_int8 yycheck[] = { 1, 5, 6, -1, 5, 0, 3, 4, 5, 6, @@ -622,7 +630,6 @@ do \ { \ yychar = (Token); \ yylval = (Value); \ - yytoken = YYTRANSLATE (yychar); \ YYPOPSTACK (1); \ goto yybackup; \ } \ @@ -890,7 +897,6 @@ int yydebug; # define YYMAXDEPTH 10000 #endif - #if YYERROR_VERBOSE @@ -993,115 +999,142 @@ yytnamerr (char *yyres, const char *yystr) } # endif -/* Copy into YYRESULT an error message about the unexpected token - YYCHAR while in state YYSTATE. Return the number of bytes copied, - including the terminating null byte. If YYRESULT is null, do not - copy anything; just return the number of bytes that would be - copied. As a special case, return 0 if an ordinary "syntax error" - message will do. Return YYSIZE_MAXIMUM if overflow occurs during - size calculation. */ -static YYSIZE_T -yysyntax_error (char *yyresult, int yystate, int yychar) +/* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message + about the unexpected token YYTOKEN for the state stack whose top is + YYSSP. + + Return 0 if *YYMSG was successfully written. Return 1 if *YYMSG is + not large enough to hold the message. In that case, also set + *YYMSG_ALLOC to the required number of bytes. Return 2 if the + required number of bytes is too large to store. */ +static int +yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg, + yytype_int16 *yyssp, int yytoken) { - int yyn = yypact[yystate]; + YYSIZE_T yysize0 = yytnamerr (0, yytname[yytoken]); + YYSIZE_T yysize = yysize0; + YYSIZE_T yysize1; + enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 }; + /* Internationalized format string. */ + const char *yyformat = 0; + /* Arguments of yyformat. */ + char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM]; + /* Number of reported tokens (one for the "unexpected", one per + "expected"). */ + int yycount = 0; - if (! (YYPACT_NINF < yyn && yyn <= YYLAST)) - return 0; - else + /* There are many possibilities here to consider: + - Assume YYFAIL is not used. It's too flawed to consider. See + + for details. YYERROR is fine as it does not invoke this + function. + - If this state is a consistent state with a default action, then + the only way this function was invoked is if the default action + is an error action. In that case, don't check for expected + tokens because there are none. + - The only way there can be no lookahead present (in yychar) is if + this state is a consistent state with a default action. Thus, + detecting the absence of a lookahead is sufficient to determine + that there is no unexpected or expected token to report. In that + case, just report a simple "syntax error". + - Don't assume there isn't a lookahead just because this state is a + consistent state with a default action. There might have been a + previous inconsistent state, consistent state with a non-default + action, or user semantic action that manipulated yychar. + - Of course, the expected token list depends on states to have + correct lookahead information, and it depends on the parser not + to perform extra reductions after fetching a lookahead from the + scanner and before detecting a syntax error. Thus, state merging + (from LALR or IELR) and default reductions corrupt the expected + token list. However, the list is correct for canonical LR with + one exception: it will still contain any token that will not be + accepted due to an error action in a later state. + */ + if (yytoken != YYEMPTY) { - int yytype = YYTRANSLATE (yychar); - YYSIZE_T yysize0 = yytnamerr (0, yytname[yytype]); - YYSIZE_T yysize = yysize0; - YYSIZE_T yysize1; - int yysize_overflow = 0; - enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 }; - char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM]; - int yyx; + int yyn = yypact[*yyssp]; + yyarg[yycount++] = yytname[yytoken]; + if (!yypact_value_is_default (yyn)) + { + /* Start YYX at -YYN if negative to avoid negative indexes in + YYCHECK. In other words, skip the first -YYN actions for + this state because they are default actions. */ + int yyxbegin = yyn < 0 ? -yyn : 0; + /* Stay within bounds of both yycheck and yytname. */ + int yychecklim = YYLAST - yyn + 1; + int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; + int yyx; -# if 0 - /* This is so xgettext sees the translatable formats that are - constructed on the fly. */ - YY_("syntax error, unexpected %s"); - YY_("syntax error, unexpected %s, expecting %s"); - YY_("syntax error, unexpected %s, expecting %s or %s"); - YY_("syntax error, unexpected %s, expecting %s or %s or %s"); - YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"); -# endif - char *yyfmt; - char const *yyf; - static char const yyunexpected[] = "syntax error, unexpected %s"; - static char const yyexpecting[] = ", expecting %s"; - static char const yyor[] = " or %s"; - char yyformat[sizeof yyunexpected - + sizeof yyexpecting - 1 - + ((YYERROR_VERBOSE_ARGS_MAXIMUM - 2) - * (sizeof yyor - 1))]; - char const *yyprefix = yyexpecting; - - /* Start YYX at -YYN if negative to avoid negative indexes in - YYCHECK. */ - int yyxbegin = yyn < 0 ? -yyn : 0; - - /* Stay within bounds of both yycheck and yytname. */ - int yychecklim = YYLAST - yyn + 1; - int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; - int yycount = 1; - - yyarg[0] = yytname[yytype]; - yyfmt = yystpcpy (yyformat, yyunexpected); - - for (yyx = yyxbegin; yyx < yyxend; ++yyx) - if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR) - { - if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM) - { - yycount = 1; - yysize = yysize0; - yyformat[sizeof yyunexpected - 1] = '\0'; - break; - } - yyarg[yycount++] = yytname[yyx]; - yysize1 = yysize + yytnamerr (0, yytname[yyx]); - yysize_overflow |= (yysize1 < yysize); - yysize = yysize1; - yyfmt = yystpcpy (yyfmt, yyprefix); - yyprefix = yyor; - } - - yyf = YY_(yyformat); - yysize1 = yysize + yystrlen (yyf); - yysize_overflow |= (yysize1 < yysize); - yysize = yysize1; - - if (yysize_overflow) - return YYSIZE_MAXIMUM; - - if (yyresult) - { - /* Avoid sprintf, as that infringes on the user's name space. - Don't have undefined behavior even if the translation - produced a string with the wrong number of "%s"s. */ - char *yyp = yyresult; - int yyi = 0; - while ((*yyp = *yyf) != '\0') - { - if (*yyp == '%' && yyf[1] == 's' && yyi < yycount) - { - yyp += yytnamerr (yyp, yyarg[yyi++]); - yyf += 2; - } - else - { - yyp++; - yyf++; - } - } - } - return yysize; + for (yyx = yyxbegin; yyx < yyxend; ++yyx) + if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR + && !yytable_value_is_error (yytable[yyx + yyn])) + { + if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM) + { + yycount = 1; + yysize = yysize0; + break; + } + yyarg[yycount++] = yytname[yyx]; + yysize1 = yysize + yytnamerr (0, yytname[yyx]); + if (! (yysize <= yysize1 + && yysize1 <= YYSTACK_ALLOC_MAXIMUM)) + return 2; + yysize = yysize1; + } + } } + + switch (yycount) + { +# define YYCASE_(N, S) \ + case N: \ + yyformat = S; \ + break + YYCASE_(0, YY_("syntax error")); + YYCASE_(1, YY_("syntax error, unexpected %s")); + YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s")); + YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s")); + YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s")); + YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s")); +# undef YYCASE_ + } + + yysize1 = yysize + yystrlen (yyformat); + if (! (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM)) + return 2; + yysize = yysize1; + + if (*yymsg_alloc < yysize) + { + *yymsg_alloc = 2 * yysize; + if (! (yysize <= *yymsg_alloc + && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM)) + *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM; + return 1; + } + + /* Avoid sprintf, as that infringes on the user's name space. + Don't have undefined behavior even if the translation + produced a string with the wrong number of "%s"s. */ + { + char *yyp = *yymsg; + int yyi = 0; + while ((*yyp = *yyformat) != '\0') + if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount) + { + yyp += yytnamerr (yyp, yyarg[yyi++]); + yyformat += 2; + } + else + { + yyp++; + yyformat++; + } + } + return 0; } #endif /* YYERROR_VERBOSE */ - /*-----------------------------------------------. | Release the memory associated to this symbol. | @@ -1144,6 +1177,7 @@ yydestruct (yymsg, yytype, yyvaluep, yylocationp, mc, oxml, result, error_msg) } } + /* Prevent warnings from -Wmissing-prototypes. */ #ifdef YYPARSE_PARAM #if defined __STDC__ || defined __cplusplus @@ -1160,12 +1194,9 @@ int yyparse (); #endif /* ! YYPARSE_PARAM */ - - - -/*-------------------------. -| yyparse or yypush_parse. | -`-------------------------*/ +/*----------. +| yyparse. | +`----------*/ #ifdef YYPARSE_PARAM #if (defined __STDC__ || defined __C99__FUNC__ \ @@ -1381,7 +1412,7 @@ yybackup: /* First try to decide what to do without reference to lookahead token. */ yyn = yypact[yystate]; - if (yyn == YYPACT_NINF) + if (yypact_value_is_default (yyn)) goto yydefault; /* Not known => get a lookahead token if don't already have one. */ @@ -1412,8 +1443,8 @@ yybackup: yyn = yytable[yyn]; if (yyn <= 0) { - if (yyn == 0 || yyn == YYTABLE_NINF) - goto yyerrlab; + if (yytable_value_is_error (yyn)) + goto yyerrlab; yyn = -yyn; goto yyreduce; } @@ -1469,21 +1500,21 @@ yyreduce: { case 2: -/* Line 1464 of yacc.c */ +/* Line 1806 of yacc.c */ #line 100 "expr_arith.y" - { result = static_cast((yyvsp[(1) - (1)].val_float));;} + { result = static_cast((yyvsp[(1) - (1)].val_float));} break; case 3: -/* Line 1464 of yacc.c */ +/* Line 1806 of yacc.c */ #line 101 "expr_arith.y" - { result = 0; ;} + { result = 0; } break; case 4: -/* Line 1464 of yacc.c */ +/* Line 1806 of yacc.c */ #line 104 "expr_arith.y" { float val = 0.0; @@ -1509,71 +1540,82 @@ yyreduce: } (yyval.val_float) = val; - ;} + } break; case 5: -/* Line 1464 of yacc.c */ +/* Line 1806 of yacc.c */ #line 129 "expr_arith.y" - { (yyval.val_float) = (yyvsp[(1) - (1)].val_float); ;} + { (yyval.val_float) = (yyvsp[(1) - (1)].val_float); } break; case 6: -/* Line 1464 of yacc.c */ +/* Line 1806 of yacc.c */ #line 130 "expr_arith.y" - { (yyval.val_float) = static_cast((yyvsp[(1) - (1)].val_int)); ;} + { (yyval.val_float) = static_cast((yyvsp[(1) - (1)].val_int)); } break; case 7: -/* Line 1464 of yacc.c */ +/* Line 1806 of yacc.c */ #line 131 "expr_arith.y" - { (yyval.val_float) = (yyvsp[(1) - (3)].val_float) + (yyvsp[(3) - (3)].val_float);;} + { (yyval.val_float) = (yyvsp[(1) - (3)].val_float) + (yyvsp[(3) - (3)].val_float);} break; case 8: -/* Line 1464 of yacc.c */ +/* Line 1806 of yacc.c */ #line 132 "expr_arith.y" - { (yyval.val_float) = (yyvsp[(1) - (3)].val_float) - (yyvsp[(3) - (3)].val_float);;} + { (yyval.val_float) = (yyvsp[(1) - (3)].val_float) - (yyvsp[(3) - (3)].val_float);} break; case 9: -/* Line 1464 of yacc.c */ +/* Line 1806 of yacc.c */ #line 133 "expr_arith.y" - { (yyval.val_float) = (yyvsp[(1) - (3)].val_float) * (yyvsp[(3) - (3)].val_float);;} + { (yyval.val_float) = (yyvsp[(1) - (3)].val_float) * (yyvsp[(3) - (3)].val_float);} break; case 10: -/* Line 1464 of yacc.c */ +/* Line 1806 of yacc.c */ #line 134 "expr_arith.y" - { (yyval.val_float) = (yyvsp[(1) - (3)].val_float) / (yyvsp[(3) - (3)].val_float);;} + { (yyval.val_float) = (yyvsp[(1) - (3)].val_float) / (yyvsp[(3) - (3)].val_float);} break; case 11: -/* Line 1464 of yacc.c */ +/* Line 1806 of yacc.c */ #line 135 "expr_arith.y" - { (yyval.val_float) = - (yyvsp[(2) - (2)].val_float);;} + { (yyval.val_float) = - (yyvsp[(2) - (2)].val_float);} break; case 12: -/* Line 1464 of yacc.c */ +/* Line 1806 of yacc.c */ #line 136 "expr_arith.y" - { (yyval.val_float) = (yyvsp[(2) - (3)].val_float);;} + { (yyval.val_float) = (yyvsp[(2) - (3)].val_float);} break; -/* Line 1464 of yacc.c */ -#line 1575 "expr_arith.cc" +/* Line 1806 of yacc.c */ +#line 1606 "expr_arith.cc" default: break; } + /* User semantic actions sometimes alter yychar, and that requires + that yytoken be updated with the new translation. We take the + approach of translating immediately before every use of yytoken. + One alternative is translating here after every semantic action, + but that translation would be missed if the semantic action invokes + YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or + if it invokes YYBACKUP. In the case of YYABORT or YYACCEPT, an + incorrect destructor might then be invoked immediately. In the + case of YYERROR or YYBACKUP, subsequent parser actions might lead + to an incorrect destructor call or verbose syntax error message + before the lookahead is translated. */ YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc); YYPOPSTACK (yylen); @@ -1602,6 +1644,10 @@ yyreduce: | yyerrlab -- here on detecting error | `------------------------------------*/ yyerrlab: + /* Make sure we have latest lookahead translation. See comments at + user semantic actions for why this is necessary. */ + yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar); + /* If not already recovering from an error, report this error. */ if (!yyerrstatus) { @@ -1609,37 +1655,36 @@ yyerrlab: #if ! YYERROR_VERBOSE yyerror (&yylloc, mc, oxml, result, error_msg, YY_("syntax error")); #else +# define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \ + yyssp, yytoken) { - YYSIZE_T yysize = yysyntax_error (0, yystate, yychar); - if (yymsg_alloc < yysize && yymsg_alloc < YYSTACK_ALLOC_MAXIMUM) - { - YYSIZE_T yyalloc = 2 * yysize; - if (! (yysize <= yyalloc && yyalloc <= YYSTACK_ALLOC_MAXIMUM)) - yyalloc = YYSTACK_ALLOC_MAXIMUM; - if (yymsg != yymsgbuf) - YYSTACK_FREE (yymsg); - yymsg = (char *) YYSTACK_ALLOC (yyalloc); - if (yymsg) - yymsg_alloc = yyalloc; - else - { - yymsg = yymsgbuf; - yymsg_alloc = sizeof yymsgbuf; - } - } - - if (0 < yysize && yysize <= yymsg_alloc) - { - (void) yysyntax_error (yymsg, yystate, yychar); - yyerror (&yylloc, mc, oxml, result, error_msg, yymsg); - } - else - { - yyerror (&yylloc, mc, oxml, result, error_msg, YY_("syntax error")); - if (yysize != 0) - goto yyexhaustedlab; - } + char const *yymsgp = YY_("syntax error"); + int yysyntax_error_status; + yysyntax_error_status = YYSYNTAX_ERROR; + if (yysyntax_error_status == 0) + yymsgp = yymsg; + else if (yysyntax_error_status == 1) + { + if (yymsg != yymsgbuf) + YYSTACK_FREE (yymsg); + yymsg = (char *) YYSTACK_ALLOC (yymsg_alloc); + if (!yymsg) + { + yymsg = yymsgbuf; + yymsg_alloc = sizeof yymsgbuf; + yysyntax_error_status = 2; + } + else + { + yysyntax_error_status = YYSYNTAX_ERROR; + yymsgp = yymsg; + } + } + yyerror (&yylloc, mc, oxml, result, error_msg, yymsgp); + if (yysyntax_error_status == 2) + goto yyexhaustedlab; } +# undef YYSYNTAX_ERROR #endif } @@ -1699,7 +1744,7 @@ yyerrlab1: for (;;) { yyn = yypact[yystate]; - if (yyn != YYPACT_NINF) + if (!yypact_value_is_default (yyn)) { yyn += YYTERROR; if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR) @@ -1763,8 +1808,13 @@ yyexhaustedlab: yyreturn: if (yychar != YYEMPTY) - yydestruct ("Cleanup: discarding lookahead", - yytoken, &yylval, &yylloc, mc, oxml, result, error_msg); + { + /* Make sure we have latest lookahead translation. See comments at + user semantic actions for why this is necessary. */ + yytoken = YYTRANSLATE (yychar); + yydestruct ("Cleanup: discarding lookahead", + yytoken, &yylval, &yylloc, mc, oxml, result, error_msg); + } /* Do not reclaim the symbols of the rule which action triggered this YYABORT or YYACCEPT. */ YYPOPSTACK (yylen); @@ -1789,7 +1839,7 @@ yyreturn: -/* Line 1684 of yacc.c */ +/* Line 2067 of yacc.c */ #line 139 "expr_arith.y" diff --git a/src/xml/expr_arith.h b/src/xml/expr_arith.h index 66cd7ebbb4..8dec688916 100644 --- a/src/xml/expr_arith.h +++ b/src/xml/expr_arith.h @@ -1,9 +1,8 @@ -/* A Bison parser, made by GNU Bison 2.4.3. */ +/* A Bison parser, made by GNU Bison 2.5. */ -/* Skeleton interface for Bison's Yacc-like parsers in C +/* Bison interface for Yacc-like parsers in C - Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006, - 2009, 2010 Free Software Foundation, Inc. + Copyright (C) 1984, 1989-1990, 2000-2011 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -50,7 +49,7 @@ typedef union YYSTYPE { -/* Line 1685 of yacc.c */ +/* Line 2068 of yacc.c */ #line 78 "expr_arith.y" char * val_str; @@ -59,8 +58,8 @@ typedef union YYSTYPE -/* Line 1685 of yacc.c */ -#line 64 "expr_arith.hh" +/* Line 2068 of yacc.c */ +#line 63 "expr_arith.hh" } YYSTYPE; # define YYSTYPE_IS_TRIVIAL 1 # define yystype YYSTYPE /* obsolescent; will be withdrawn */ diff --git a/src/xml/expr_bool.cc b/src/xml/expr_bool.cc index 0d9c80598f..be3802607f 100644 --- a/src/xml/expr_bool.cc +++ b/src/xml/expr_bool.cc @@ -1,9 +1,8 @@ -/* A Bison parser, made by GNU Bison 2.4.3. */ +/* A Bison parser, made by GNU Bison 2.5. */ -/* Skeleton implementation for Bison's Yacc-like parsers in C +/* Bison implementation for Yacc-like parsers in C - Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006, - 2009, 2010 Free Software Foundation, Inc. + Copyright (C) 1984, 1989-1990, 2000-2011 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -45,7 +44,7 @@ #define YYBISON 1 /* Bison version. */ -#define YYBISON_VERSION "2.4.3" +#define YYBISON_VERSION "2.5" /* Skeleton name. */ #define YYSKELETON_NAME "yacc.c" @@ -74,7 +73,7 @@ /* Copy the first part of user declarations. */ -/* Line 189 of yacc.c */ +/* Line 268 of yacc.c */ #line 17 "expr_bool.y" #include @@ -135,8 +134,8 @@ void get_xml_attribute(ObjectXML * oxml, const char* attr, string& val); -/* Line 189 of yacc.c */ -#line 140 "expr_bool.cc" +/* Line 268 of yacc.c */ +#line 139 "expr_bool.cc" /* Enabling traces. */ #ifndef YYDEBUG @@ -175,7 +174,7 @@ void get_xml_attribute(ObjectXML * oxml, const char* attr, string& val); typedef union YYSTYPE { -/* Line 214 of yacc.c */ +/* Line 293 of yacc.c */ #line 83 "expr_bool.y" char * val_str; @@ -184,8 +183,8 @@ typedef union YYSTYPE -/* Line 214 of yacc.c */ -#line 189 "expr_bool.cc" +/* Line 293 of yacc.c */ +#line 188 "expr_bool.cc" } YYSTYPE; # define YYSTYPE_IS_TRIVIAL 1 # define yystype YYSTYPE /* obsolescent; will be withdrawn */ @@ -209,8 +208,8 @@ typedef struct YYLTYPE /* Copy the second part of user declarations. */ -/* Line 264 of yacc.c */ -#line 214 "expr_bool.cc" +/* Line 343 of yacc.c */ +#line 213 "expr_bool.cc" #ifdef short # undef short @@ -313,11 +312,11 @@ YYID (yyi) # define alloca _alloca # else # define YYSTACK_ALLOC alloca -# if ! defined _ALLOCA_H && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \ +# if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) # include /* INFRINGES ON USER NAME SPACE */ -# ifndef _STDLIB_H -# define _STDLIB_H 1 +# ifndef EXIT_SUCCESS +# define EXIT_SUCCESS 0 # endif # endif # endif @@ -340,24 +339,24 @@ YYID (yyi) # ifndef YYSTACK_ALLOC_MAXIMUM # define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM # endif -# if (defined __cplusplus && ! defined _STDLIB_H \ +# if (defined __cplusplus && ! defined EXIT_SUCCESS \ && ! ((defined YYMALLOC || defined malloc) \ && (defined YYFREE || defined free))) # include /* INFRINGES ON USER NAME SPACE */ -# ifndef _STDLIB_H -# define _STDLIB_H 1 +# ifndef EXIT_SUCCESS +# define EXIT_SUCCESS 0 # endif # endif # ifndef YYMALLOC # define YYMALLOC malloc -# if ! defined malloc && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \ +# if ! defined malloc && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */ # endif # endif # ifndef YYFREE # define YYFREE free -# if ! defined free && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \ +# if ! defined free && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) void free (void *); /* INFRINGES ON USER NAME SPACE */ # endif @@ -388,23 +387,7 @@ union yyalloc ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE) + sizeof (YYLTYPE)) \ + 2 * YYSTACK_GAP_MAXIMUM) -/* Copy COUNT objects from FROM to TO. The source and destination do - not overlap. */ -# ifndef YYCOPY -# if defined __GNUC__ && 1 < __GNUC__ -# define YYCOPY(To, From, Count) \ - __builtin_memcpy (To, From, (Count) * sizeof (*(From))) -# else -# define YYCOPY(To, From, Count) \ - do \ - { \ - YYSIZE_T yyi; \ - for (yyi = 0; yyi < (Count); yyi++) \ - (To)[yyi] = (From)[yyi]; \ - } \ - while (YYID (0)) -# endif -# endif +# define YYCOPY_NEEDED 1 /* Relocate STACK from its old location to the new one. The local variables YYSIZE and YYSTACKSIZE give the old and new number of @@ -424,6 +407,26 @@ union yyalloc #endif +#if defined YYCOPY_NEEDED && YYCOPY_NEEDED +/* Copy COUNT objects from FROM to TO. The source and destination do + not overlap. */ +# ifndef YYCOPY +# if defined __GNUC__ && 1 < __GNUC__ +# define YYCOPY(To, From, Count) \ + __builtin_memcpy (To, From, (Count) * sizeof (*(From))) +# else +# define YYCOPY(To, From, Count) \ + do \ + { \ + YYSIZE_T yyi; \ + for (yyi = 0; yyi < (Count); yyi++) \ + (To)[yyi] = (From)[yyi]; \ + } \ + while (YYID (0)) +# endif +# endif +#endif /* !YYCOPY_NEEDED */ + /* YYFINAL -- State number of the termination state. */ #define YYFINAL 12 /* YYLAST -- Last index in YYTABLE. */ @@ -540,8 +543,8 @@ static const yytype_uint8 yyr2[] = 3, 3, 3, 4, 3, 3, 2, 3 }; -/* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state - STATE-NUM when YYTABLE doesn't specify something else to do. Zero +/* YYDEFACT[STATE-NAME] -- Default reduction number in state STATE-NUM. + Performed when YYTABLE doesn't specify something else to do. Zero means the default is an error. */ static const yytype_uint8 yydefact[] = { @@ -574,8 +577,7 @@ static const yytype_int8 yypgoto[] = /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If positive, shift that token. If negative, reduce the rule which - number is the opposite. If zero, do what YYDEFACT says. - If YYTABLE_NINF, syntax error. */ + number is the opposite. If YYTABLE_NINF, syntax error. */ #define YYTABLE_NINF -1 static const yytype_uint8 yytable[] = { @@ -584,6 +586,12 @@ static const yytype_uint8 yytable[] = 16, 17, 18, 26, 27, 28, 19, 21, 20, 22 }; +#define yypact_value_is_default(yystate) \ + ((yystate) == (-6)) + +#define yytable_value_is_error(yytable_value) \ + YYID (0) + static const yytype_int8 yycheck[] = { 1, 3, 3, 0, 9, 7, 4, 5, 4, 5, @@ -633,7 +641,6 @@ do \ { \ yychar = (Token); \ yylval = (Value); \ - yytoken = YYTRANSLATE (yychar); \ YYPOPSTACK (1); \ goto yybackup; \ } \ @@ -901,7 +908,6 @@ int yydebug; # define YYMAXDEPTH 10000 #endif - #if YYERROR_VERBOSE @@ -1004,115 +1010,142 @@ yytnamerr (char *yyres, const char *yystr) } # endif -/* Copy into YYRESULT an error message about the unexpected token - YYCHAR while in state YYSTATE. Return the number of bytes copied, - including the terminating null byte. If YYRESULT is null, do not - copy anything; just return the number of bytes that would be - copied. As a special case, return 0 if an ordinary "syntax error" - message will do. Return YYSIZE_MAXIMUM if overflow occurs during - size calculation. */ -static YYSIZE_T -yysyntax_error (char *yyresult, int yystate, int yychar) +/* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message + about the unexpected token YYTOKEN for the state stack whose top is + YYSSP. + + Return 0 if *YYMSG was successfully written. Return 1 if *YYMSG is + not large enough to hold the message. In that case, also set + *YYMSG_ALLOC to the required number of bytes. Return 2 if the + required number of bytes is too large to store. */ +static int +yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg, + yytype_int16 *yyssp, int yytoken) { - int yyn = yypact[yystate]; + YYSIZE_T yysize0 = yytnamerr (0, yytname[yytoken]); + YYSIZE_T yysize = yysize0; + YYSIZE_T yysize1; + enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 }; + /* Internationalized format string. */ + const char *yyformat = 0; + /* Arguments of yyformat. */ + char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM]; + /* Number of reported tokens (one for the "unexpected", one per + "expected"). */ + int yycount = 0; - if (! (YYPACT_NINF < yyn && yyn <= YYLAST)) - return 0; - else + /* There are many possibilities here to consider: + - Assume YYFAIL is not used. It's too flawed to consider. See + + for details. YYERROR is fine as it does not invoke this + function. + - If this state is a consistent state with a default action, then + the only way this function was invoked is if the default action + is an error action. In that case, don't check for expected + tokens because there are none. + - The only way there can be no lookahead present (in yychar) is if + this state is a consistent state with a default action. Thus, + detecting the absence of a lookahead is sufficient to determine + that there is no unexpected or expected token to report. In that + case, just report a simple "syntax error". + - Don't assume there isn't a lookahead just because this state is a + consistent state with a default action. There might have been a + previous inconsistent state, consistent state with a non-default + action, or user semantic action that manipulated yychar. + - Of course, the expected token list depends on states to have + correct lookahead information, and it depends on the parser not + to perform extra reductions after fetching a lookahead from the + scanner and before detecting a syntax error. Thus, state merging + (from LALR or IELR) and default reductions corrupt the expected + token list. However, the list is correct for canonical LR with + one exception: it will still contain any token that will not be + accepted due to an error action in a later state. + */ + if (yytoken != YYEMPTY) { - int yytype = YYTRANSLATE (yychar); - YYSIZE_T yysize0 = yytnamerr (0, yytname[yytype]); - YYSIZE_T yysize = yysize0; - YYSIZE_T yysize1; - int yysize_overflow = 0; - enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 }; - char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM]; - int yyx; + int yyn = yypact[*yyssp]; + yyarg[yycount++] = yytname[yytoken]; + if (!yypact_value_is_default (yyn)) + { + /* Start YYX at -YYN if negative to avoid negative indexes in + YYCHECK. In other words, skip the first -YYN actions for + this state because they are default actions. */ + int yyxbegin = yyn < 0 ? -yyn : 0; + /* Stay within bounds of both yycheck and yytname. */ + int yychecklim = YYLAST - yyn + 1; + int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; + int yyx; -# if 0 - /* This is so xgettext sees the translatable formats that are - constructed on the fly. */ - YY_("syntax error, unexpected %s"); - YY_("syntax error, unexpected %s, expecting %s"); - YY_("syntax error, unexpected %s, expecting %s or %s"); - YY_("syntax error, unexpected %s, expecting %s or %s or %s"); - YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"); -# endif - char *yyfmt; - char const *yyf; - static char const yyunexpected[] = "syntax error, unexpected %s"; - static char const yyexpecting[] = ", expecting %s"; - static char const yyor[] = " or %s"; - char yyformat[sizeof yyunexpected - + sizeof yyexpecting - 1 - + ((YYERROR_VERBOSE_ARGS_MAXIMUM - 2) - * (sizeof yyor - 1))]; - char const *yyprefix = yyexpecting; - - /* Start YYX at -YYN if negative to avoid negative indexes in - YYCHECK. */ - int yyxbegin = yyn < 0 ? -yyn : 0; - - /* Stay within bounds of both yycheck and yytname. */ - int yychecklim = YYLAST - yyn + 1; - int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; - int yycount = 1; - - yyarg[0] = yytname[yytype]; - yyfmt = yystpcpy (yyformat, yyunexpected); - - for (yyx = yyxbegin; yyx < yyxend; ++yyx) - if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR) - { - if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM) - { - yycount = 1; - yysize = yysize0; - yyformat[sizeof yyunexpected - 1] = '\0'; - break; - } - yyarg[yycount++] = yytname[yyx]; - yysize1 = yysize + yytnamerr (0, yytname[yyx]); - yysize_overflow |= (yysize1 < yysize); - yysize = yysize1; - yyfmt = yystpcpy (yyfmt, yyprefix); - yyprefix = yyor; - } - - yyf = YY_(yyformat); - yysize1 = yysize + yystrlen (yyf); - yysize_overflow |= (yysize1 < yysize); - yysize = yysize1; - - if (yysize_overflow) - return YYSIZE_MAXIMUM; - - if (yyresult) - { - /* Avoid sprintf, as that infringes on the user's name space. - Don't have undefined behavior even if the translation - produced a string with the wrong number of "%s"s. */ - char *yyp = yyresult; - int yyi = 0; - while ((*yyp = *yyf) != '\0') - { - if (*yyp == '%' && yyf[1] == 's' && yyi < yycount) - { - yyp += yytnamerr (yyp, yyarg[yyi++]); - yyf += 2; - } - else - { - yyp++; - yyf++; - } - } - } - return yysize; + for (yyx = yyxbegin; yyx < yyxend; ++yyx) + if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR + && !yytable_value_is_error (yytable[yyx + yyn])) + { + if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM) + { + yycount = 1; + yysize = yysize0; + break; + } + yyarg[yycount++] = yytname[yyx]; + yysize1 = yysize + yytnamerr (0, yytname[yyx]); + if (! (yysize <= yysize1 + && yysize1 <= YYSTACK_ALLOC_MAXIMUM)) + return 2; + yysize = yysize1; + } + } } + + switch (yycount) + { +# define YYCASE_(N, S) \ + case N: \ + yyformat = S; \ + break + YYCASE_(0, YY_("syntax error")); + YYCASE_(1, YY_("syntax error, unexpected %s")); + YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s")); + YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s")); + YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s")); + YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s")); +# undef YYCASE_ + } + + yysize1 = yysize + yystrlen (yyformat); + if (! (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM)) + return 2; + yysize = yysize1; + + if (*yymsg_alloc < yysize) + { + *yymsg_alloc = 2 * yysize; + if (! (yysize <= *yymsg_alloc + && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM)) + *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM; + return 1; + } + + /* Avoid sprintf, as that infringes on the user's name space. + Don't have undefined behavior even if the translation + produced a string with the wrong number of "%s"s. */ + { + char *yyp = *yymsg; + int yyi = 0; + while ((*yyp = *yyformat) != '\0') + if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount) + { + yyp += yytnamerr (yyp, yyarg[yyi++]); + yyformat += 2; + } + else + { + yyp++; + yyformat++; + } + } + return 0; } #endif /* YYERROR_VERBOSE */ - /*-----------------------------------------------. | Release the memory associated to this symbol. | @@ -1155,6 +1188,7 @@ yydestruct (yymsg, yytype, yyvaluep, yylocationp, mc, oxml, result, error_msg) } } + /* Prevent warnings from -Wmissing-prototypes. */ #ifdef YYPARSE_PARAM #if defined __STDC__ || defined __cplusplus @@ -1171,12 +1205,9 @@ int yyparse (); #endif /* ! YYPARSE_PARAM */ - - - -/*-------------------------. -| yyparse or yypush_parse. | -`-------------------------*/ +/*----------. +| yyparse. | +`----------*/ #ifdef YYPARSE_PARAM #if (defined __STDC__ || defined __C99__FUNC__ \ @@ -1392,7 +1423,7 @@ yybackup: /* First try to decide what to do without reference to lookahead token. */ yyn = yypact[yystate]; - if (yyn == YYPACT_NINF) + if (yypact_value_is_default (yyn)) goto yydefault; /* Not known => get a lookahead token if don't already have one. */ @@ -1423,8 +1454,8 @@ yybackup: yyn = yytable[yyn]; if (yyn <= 0) { - if (yyn == 0 || yyn == YYTABLE_NINF) - goto yyerrlab; + if (yytable_value_is_error (yyn)) + goto yyerrlab; yyn = -yyn; goto yyreduce; } @@ -1480,152 +1511,163 @@ yyreduce: { case 2: -/* Line 1464 of yacc.c */ +/* Line 1806 of yacc.c */ #line 103 "expr_bool.y" - { result=(yyvsp[(1) - (1)].val_int); ;} + { result=(yyvsp[(1) - (1)].val_int); } break; case 3: -/* Line 1464 of yacc.c */ +/* Line 1806 of yacc.c */ #line 104 "expr_bool.y" - { result=true; ;} + { result=true; } break; case 4: -/* Line 1464 of yacc.c */ +/* Line 1806 of yacc.c */ #line 107 "expr_bool.y" { int val; get_xml_attribute(oxml,(yyvsp[(1) - (3)].val_str),val); - (yyval.val_int) = val == (yyvsp[(3) - (3)].val_int);;} + (yyval.val_int) = val == (yyvsp[(3) - (3)].val_int);} break; case 5: -/* Line 1464 of yacc.c */ +/* Line 1806 of yacc.c */ #line 112 "expr_bool.y" { int val; get_xml_attribute(oxml,(yyvsp[(1) - (4)].val_str),val); - (yyval.val_int) = val != (yyvsp[(4) - (4)].val_int);;} + (yyval.val_int) = val != (yyvsp[(4) - (4)].val_int);} break; case 6: -/* Line 1464 of yacc.c */ +/* Line 1806 of yacc.c */ #line 117 "expr_bool.y" { int val; get_xml_attribute(oxml,(yyvsp[(1) - (3)].val_str),val); - (yyval.val_int) = val > (yyvsp[(3) - (3)].val_int);;} + (yyval.val_int) = val > (yyvsp[(3) - (3)].val_int);} break; case 7: -/* Line 1464 of yacc.c */ +/* Line 1806 of yacc.c */ #line 122 "expr_bool.y" { int val; get_xml_attribute(oxml,(yyvsp[(1) - (3)].val_str),val); - (yyval.val_int) = val < (yyvsp[(3) - (3)].val_int);;} + (yyval.val_int) = val < (yyvsp[(3) - (3)].val_int);} break; case 8: -/* Line 1464 of yacc.c */ +/* Line 1806 of yacc.c */ #line 127 "expr_bool.y" { float val; get_xml_attribute(oxml,(yyvsp[(1) - (3)].val_str),val); - (yyval.val_int) = val == (yyvsp[(3) - (3)].val_float);;} + (yyval.val_int) = val == (yyvsp[(3) - (3)].val_float);} break; case 9: -/* Line 1464 of yacc.c */ +/* Line 1806 of yacc.c */ #line 132 "expr_bool.y" { float val; get_xml_attribute(oxml,(yyvsp[(1) - (4)].val_str),val); - (yyval.val_int) = val != (yyvsp[(4) - (4)].val_float);;} + (yyval.val_int) = val != (yyvsp[(4) - (4)].val_float);} break; case 10: -/* Line 1464 of yacc.c */ +/* Line 1806 of yacc.c */ #line 137 "expr_bool.y" { float val; get_xml_attribute(oxml,(yyvsp[(1) - (3)].val_str),val); - (yyval.val_int) = val > (yyvsp[(3) - (3)].val_float);;} + (yyval.val_int) = val > (yyvsp[(3) - (3)].val_float);} break; case 11: -/* Line 1464 of yacc.c */ +/* Line 1806 of yacc.c */ #line 142 "expr_bool.y" { float val; get_xml_attribute(oxml,(yyvsp[(1) - (3)].val_str),val); - (yyval.val_int) = val < (yyvsp[(3) - (3)].val_float);;} + (yyval.val_int) = val < (yyvsp[(3) - (3)].val_float);} break; case 12: -/* Line 1464 of yacc.c */ +/* Line 1806 of yacc.c */ #line 147 "expr_bool.y" { string val; get_xml_attribute(oxml,(yyvsp[(1) - (3)].val_str),val); - (yyval.val_int) = (val.empty() || (yyvsp[(3) - (3)].val_str)==0) ? false : fnmatch((yyvsp[(3) - (3)].val_str),val.c_str(),0)==0;;} + (yyval.val_int) = (val.empty() || (yyvsp[(3) - (3)].val_str)==0) ? false : fnmatch((yyvsp[(3) - (3)].val_str),val.c_str(),0)==0;} break; case 13: -/* Line 1464 of yacc.c */ +/* Line 1806 of yacc.c */ #line 152 "expr_bool.y" { string val; get_xml_attribute(oxml,(yyvsp[(1) - (4)].val_str),val); - (yyval.val_int) = (val.empty() || (yyvsp[(4) - (4)].val_str)==0) ? false : fnmatch((yyvsp[(4) - (4)].val_str),val.c_str(),0)!=0;;} + (yyval.val_int) = (val.empty() || (yyvsp[(4) - (4)].val_str)==0) ? false : fnmatch((yyvsp[(4) - (4)].val_str),val.c_str(),0)!=0;} break; case 14: -/* Line 1464 of yacc.c */ +/* Line 1806 of yacc.c */ #line 157 "expr_bool.y" - { (yyval.val_int) = (yyvsp[(1) - (3)].val_int) && (yyvsp[(3) - (3)].val_int); ;} + { (yyval.val_int) = (yyvsp[(1) - (3)].val_int) && (yyvsp[(3) - (3)].val_int); } break; case 15: -/* Line 1464 of yacc.c */ +/* Line 1806 of yacc.c */ #line 158 "expr_bool.y" - { (yyval.val_int) = (yyvsp[(1) - (3)].val_int) || (yyvsp[(3) - (3)].val_int); ;} + { (yyval.val_int) = (yyvsp[(1) - (3)].val_int) || (yyvsp[(3) - (3)].val_int); } break; case 16: -/* Line 1464 of yacc.c */ +/* Line 1806 of yacc.c */ #line 159 "expr_bool.y" - { (yyval.val_int) = ! (yyvsp[(2) - (2)].val_int); ;} + { (yyval.val_int) = ! (yyvsp[(2) - (2)].val_int); } break; case 17: -/* Line 1464 of yacc.c */ +/* Line 1806 of yacc.c */ #line 160 "expr_bool.y" - { (yyval.val_int) = (yyvsp[(2) - (3)].val_int); ;} + { (yyval.val_int) = (yyvsp[(2) - (3)].val_int); } break; -/* Line 1464 of yacc.c */ -#line 1627 "expr_bool.cc" +/* Line 1806 of yacc.c */ +#line 1658 "expr_bool.cc" default: break; } + /* User semantic actions sometimes alter yychar, and that requires + that yytoken be updated with the new translation. We take the + approach of translating immediately before every use of yytoken. + One alternative is translating here after every semantic action, + but that translation would be missed if the semantic action invokes + YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or + if it invokes YYBACKUP. In the case of YYABORT or YYACCEPT, an + incorrect destructor might then be invoked immediately. In the + case of YYERROR or YYBACKUP, subsequent parser actions might lead + to an incorrect destructor call or verbose syntax error message + before the lookahead is translated. */ YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc); YYPOPSTACK (yylen); @@ -1654,6 +1696,10 @@ yyreduce: | yyerrlab -- here on detecting error | `------------------------------------*/ yyerrlab: + /* Make sure we have latest lookahead translation. See comments at + user semantic actions for why this is necessary. */ + yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar); + /* If not already recovering from an error, report this error. */ if (!yyerrstatus) { @@ -1661,37 +1707,36 @@ yyerrlab: #if ! YYERROR_VERBOSE yyerror (&yylloc, mc, oxml, result, error_msg, YY_("syntax error")); #else +# define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \ + yyssp, yytoken) { - YYSIZE_T yysize = yysyntax_error (0, yystate, yychar); - if (yymsg_alloc < yysize && yymsg_alloc < YYSTACK_ALLOC_MAXIMUM) - { - YYSIZE_T yyalloc = 2 * yysize; - if (! (yysize <= yyalloc && yyalloc <= YYSTACK_ALLOC_MAXIMUM)) - yyalloc = YYSTACK_ALLOC_MAXIMUM; - if (yymsg != yymsgbuf) - YYSTACK_FREE (yymsg); - yymsg = (char *) YYSTACK_ALLOC (yyalloc); - if (yymsg) - yymsg_alloc = yyalloc; - else - { - yymsg = yymsgbuf; - yymsg_alloc = sizeof yymsgbuf; - } - } - - if (0 < yysize && yysize <= yymsg_alloc) - { - (void) yysyntax_error (yymsg, yystate, yychar); - yyerror (&yylloc, mc, oxml, result, error_msg, yymsg); - } - else - { - yyerror (&yylloc, mc, oxml, result, error_msg, YY_("syntax error")); - if (yysize != 0) - goto yyexhaustedlab; - } + char const *yymsgp = YY_("syntax error"); + int yysyntax_error_status; + yysyntax_error_status = YYSYNTAX_ERROR; + if (yysyntax_error_status == 0) + yymsgp = yymsg; + else if (yysyntax_error_status == 1) + { + if (yymsg != yymsgbuf) + YYSTACK_FREE (yymsg); + yymsg = (char *) YYSTACK_ALLOC (yymsg_alloc); + if (!yymsg) + { + yymsg = yymsgbuf; + yymsg_alloc = sizeof yymsgbuf; + yysyntax_error_status = 2; + } + else + { + yysyntax_error_status = YYSYNTAX_ERROR; + yymsgp = yymsg; + } + } + yyerror (&yylloc, mc, oxml, result, error_msg, yymsgp); + if (yysyntax_error_status == 2) + goto yyexhaustedlab; } +# undef YYSYNTAX_ERROR #endif } @@ -1751,7 +1796,7 @@ yyerrlab1: for (;;) { yyn = yypact[yystate]; - if (yyn != YYPACT_NINF) + if (!yypact_value_is_default (yyn)) { yyn += YYTERROR; if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR) @@ -1815,8 +1860,13 @@ yyexhaustedlab: yyreturn: if (yychar != YYEMPTY) - yydestruct ("Cleanup: discarding lookahead", - yytoken, &yylval, &yylloc, mc, oxml, result, error_msg); + { + /* Make sure we have latest lookahead translation. See comments at + user semantic actions for why this is necessary. */ + yytoken = YYTRANSLATE (yychar); + yydestruct ("Cleanup: discarding lookahead", + yytoken, &yylval, &yylloc, mc, oxml, result, error_msg); + } /* Do not reclaim the symbols of the rule which action triggered this YYABORT or YYACCEPT. */ YYPOPSTACK (yylen); @@ -1841,7 +1891,7 @@ yyreturn: -/* Line 1684 of yacc.c */ +/* Line 2067 of yacc.c */ #line 163 "expr_bool.y" diff --git a/src/xml/expr_bool.h b/src/xml/expr_bool.h index 3e0c95e1f6..0f561150f4 100644 --- a/src/xml/expr_bool.h +++ b/src/xml/expr_bool.h @@ -1,9 +1,8 @@ -/* A Bison parser, made by GNU Bison 2.4.3. */ +/* A Bison parser, made by GNU Bison 2.5. */ -/* Skeleton interface for Bison's Yacc-like parsers in C +/* Bison interface for Yacc-like parsers in C - Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006, - 2009, 2010 Free Software Foundation, Inc. + Copyright (C) 1984, 1989-1990, 2000-2011 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -50,7 +49,7 @@ typedef union YYSTYPE { -/* Line 1685 of yacc.c */ +/* Line 2068 of yacc.c */ #line 83 "expr_bool.y" char * val_str; @@ -59,8 +58,8 @@ typedef union YYSTYPE -/* Line 1685 of yacc.c */ -#line 64 "expr_bool.hh" +/* Line 2068 of yacc.c */ +#line 63 "expr_bool.hh" } YYSTYPE; # define YYSTYPE_IS_TRIVIAL 1 # define yystype YYSTYPE /* obsolescent; will be withdrawn */ From 20f8b684e64fe63656a340b84459d959f2d54878 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Thu, 10 Nov 2011 23:45:20 +0100 Subject: [PATCH 010/121] Bug: Default sunstone server conf file cannot be parsed --- src/sunstone/etc/sunstone-server.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sunstone/etc/sunstone-server.conf b/src/sunstone/etc/sunstone-server.conf index 2311501782..b636b1480d 100644 --- a/src/sunstone/etc/sunstone-server.conf +++ b/src/sunstone/etc/sunstone-server.conf @@ -16,7 +16,7 @@ :core_auth: cipher # Life-time in seconds for token renewal (that used to handle OpenNebula auths) :token_expiration_delta: 1800 - + # VNC Configuration :vnc_proxy_base_port: 29876 :novnc_path: From 3eceea78c2df5f9f7bdec8c90cfc2c997ac3bdde Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Fri, 11 Nov 2011 00:43:46 +0100 Subject: [PATCH 011/121] feature #863: Dummy VM drivers updated --- src/vmm_mad/dummy/one_vmm_dummy.rb | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/src/vmm_mad/dummy/one_vmm_dummy.rb b/src/vmm_mad/dummy/one_vmm_dummy.rb index 1d7b84470b..dad6596de4 100755 --- a/src/vmm_mad/dummy/one_vmm_dummy.rb +++ b/src/vmm_mad/dummy/one_vmm_dummy.rb @@ -30,6 +30,8 @@ $: << RUBY_LIB_LOCATION require "VirtualMachineDriver" require "CommandManager" +require 'base64' +require 'rexml/document' class DummyDriver < VirtualMachineDriver def initialize @@ -39,31 +41,43 @@ class DummyDriver < VirtualMachineDriver ) end - def deploy(id, host, remote_dfile, not_used) - send_message(ACTION[:deploy],RESULT[:success],id,"dummy") + def decode(drv_msg) + message = Base64.decode64(drv_msg) + xml_doc = REXML::Document.new(message) + + xml_doc.root end - def shutdown(id, host, deploy_id, not_used) + def deploy(id, drv_msg) + msg = decode(drv_msg) + + host = msg.elements["HOST"].text + name = msg.elements["VM/NAME"].text + + send_message(ACTION[:deploy],RESULT[:success],id,"#{host}:#{name}:dummy") + end + + def shutdown(id, drv_message) send_message(ACTION[:shutdown],RESULT[:success],id) end - def cancel(id, host, deploy_id, not_used) + def cancel(id, drv_message) send_message(ACTION[:cancel],RESULT[:success],id) end - def save(id, host, deploy_id, file) + def save(id, drv_message) send_message(ACTION[:save],RESULT[:success],id) end - def restore(id, host, deploy_id , file) + def restore(id, drv_message) send_message(ACTION[:restore],RESULT[:success],id) end - def migrate(id, host, deploy_id, dest_host) + def migrate(id, drv_message) send_message(ACTION[:migrate],RESULT[:success],id) end - def poll(id, host, deploy_id, not_used) + def poll(id, drv_message) # monitor_info: string in the form "VAR=VAL VAR=VAL ... VAR=VAL" # known VAR are in POLL_ATTRIBUTES. VM states VM_STATES monitor_info = "#{POLL_ATTRIBUTE[:state]}=#{VM_STATE[:active]} " \ From 504f0f557d0c3cdc49abbabb2e983f96bb5907ca Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Fri, 11 Nov 2011 00:45:08 +0100 Subject: [PATCH 012/121] feature #863: Update VirtualMachine Driver base class to new protocol --- src/mad/ruby/VirtualMachineDriver.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/mad/ruby/VirtualMachineDriver.rb b/src/mad/ruby/VirtualMachineDriver.rb index 06240a8ac1..fa3249824d 100644 --- a/src/mad/ruby/VirtualMachineDriver.rb +++ b/src/mad/ruby/VirtualMachineDriver.rb @@ -118,37 +118,37 @@ class VirtualMachineDriver < OpenNebulaDriver end # Virtual Machine Manager Protocol Actions (generic implementation) - def deploy(id, host, remote_dfile, not_used) + def deploy(id, drv_message) error = "Action not implemented by driver #{self.class}" send_message(ACTION[:deploy],RESULT[:failure],id,error) end - def shutdown(id, host, deploy_id, not_used) + def shutdown(id, drv_message) error = "Action not implemented by driver #{self.class}" send_message(ACTION[:shutdown],RESULT[:failure],id,error) end - def cancel(id, host, deploy_id, not_used) + def cancel(id, drv_message) error = "Action not implemented by driver #{self.class}" send_message(ACTION[:cancel],RESULT[:failure],id,error) end - def save(id, host, deploy_id, file) + def save(id, drv_message) error = "Action not implemented by driver #{self.class}" send_message(ACTION[:save],RESULT[:failure],id,error) end - def restore(id, host, deploy_id, file) + def restore(id, drv_message) error = "Action not implemented by driver #{self.class}" send_message(ACTION[:restore],RESULT[:failure],id,error) end - def migrate(id, host, deploy_id, dest_host) + def migrate(id, drv_message) error = "Action not implemented by driver #{self.class}" send_message(ACTION[:migrate],RESULT[:failure],id,error) end - def poll(id, host, deploy_id, not_used) + def poll(id, drv_message) error = "Action not implemented by driver #{self.class}" send_message(ACTION[:poll],RESULT[:failure],id,error) end From 744ab1faca2eea87fa41014d145b2e06f57c905b Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Fri, 11 Nov 2011 00:45:33 +0100 Subject: [PATCH 013/121] feature #863: Fix XML for the driver message --- include/VirtualMachineManager.h | 4 ++-- src/vmm/VirtualMachineManager.cc | 10 +++++----- src/vmm/VirtualMachineManagerDriver.cc | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/include/VirtualMachineManager.h b/include/VirtualMachineManager.h index 8df8df3b1e..1c41918288 100644 --- a/include/VirtualMachineManager.h +++ b/include/VirtualMachineManager.h @@ -185,9 +185,9 @@ private: * domain_id * dfile * cfile - * + * * VM representation in XML - * + * * * * @param hostname of the host to perform the action diff --git a/src/vmm/VirtualMachineManager.cc b/src/vmm/VirtualMachineManager.cc index 04919e8903..37539374a7 100644 --- a/src/vmm/VirtualMachineManager.cc +++ b/src/vmm/VirtualMachineManager.cc @@ -268,7 +268,7 @@ string * VirtualMachineManager::format_message( } else { - oss << ""; + oss << ""; } if (!domain.empty()) @@ -277,7 +277,7 @@ string * VirtualMachineManager::format_message( } else { - oss << ""; + oss << ""; } if (!dfile.empty()) @@ -286,7 +286,7 @@ string * VirtualMachineManager::format_message( } else { - oss << ""; + oss << ""; } if (!cfile.empty()) @@ -295,10 +295,10 @@ string * VirtualMachineManager::format_message( } else { - oss << ""; + oss << ""; } - oss << "" << tmpl << "" + oss << tmpl << ""; return SSLTools::base64_encode(oss.str()); diff --git a/src/vmm/VirtualMachineManagerDriver.cc b/src/vmm/VirtualMachineManagerDriver.cc index c186afd927..d20db0f5e0 100644 --- a/src/vmm/VirtualMachineManagerDriver.cc +++ b/src/vmm/VirtualMachineManagerDriver.cc @@ -109,7 +109,7 @@ void VirtualMachineManagerDriver::deploy ( ostringstream os; os << "DEPLOY " << oid << " " << drv_msg << endl; - + write(os); }; From 7efcb0e140c3fd6b1df878a9001c65003e3d8efb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Fri, 11 Nov 2011 14:55:18 +0100 Subject: [PATCH 014/121] Feature #863: Small comment fix --- include/VirtualMachine.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/VirtualMachine.h b/include/VirtualMachine.h index 159d7b34e0..a375b97242 100644 --- a/include/VirtualMachine.h +++ b/include/VirtualMachine.h @@ -277,7 +277,7 @@ public: /** * Returns the VNM driver name for the current host. The hasHistory() * function MUST be called before this one. - * @return the VMM mad name + * @return the VNM mad name */ const string & get_vnm_mad() const { @@ -287,7 +287,7 @@ public: /** * Returns the VNM driver name for the previous host. The hasPreviousHistory() * function MUST be called before this one. - * @return the VMM mad name + * @return the VNM mad name */ const string & get_previous_vnm_mad() const { From bea7da7475f7c6ab9ecb0395d805526ba99fdd86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Fri, 11 Nov 2011 17:09:26 +0100 Subject: [PATCH 015/121] Feature #863: Change old net hooks to act as mad scripts --- src/vnm_mad/remotes/802.1Q/HostManaged.rb | 16 ++++++------ src/vnm_mad/remotes/802.1Q/clean | 19 ++++++++++++++ src/vnm_mad/remotes/802.1Q/post | 19 ++++++++++++++ src/vnm_mad/remotes/802.1Q/pre | 25 +++++++++++++++++++ src/vnm_mad/remotes/OpenNebulaNetwork.rb | 6 +++++ src/vnm_mad/remotes/dummy/clean | 19 ++++++++++++++ src/vnm_mad/remotes/dummy/post | 19 ++++++++++++++ src/vnm_mad/remotes/dummy/pre | 19 ++++++++++++++ src/vnm_mad/remotes/ebtables/Ebtables.rb | 12 +++++++-- .../{802.1Q/hm-vlan => ebtables/clean} | 11 ++++---- .../remotes/ebtables/{ebtables-vlan => post} | 18 +++---------- src/vnm_mad/remotes/ebtables/pre | 19 ++++++++++++++ src/vnm_mad/remotes/ovswtich/OpenvSwitch.rb | 6 ++++- src/vnm_mad/remotes/ovswtich/clean | 19 ++++++++++++++ .../ovswtich/{openvswitch-vlan => post} | 8 ++---- src/vnm_mad/remotes/ovswtich/pre | 19 ++++++++++++++ 16 files changed, 216 insertions(+), 38 deletions(-) create mode 100755 src/vnm_mad/remotes/802.1Q/clean create mode 100755 src/vnm_mad/remotes/802.1Q/post create mode 100755 src/vnm_mad/remotes/802.1Q/pre create mode 100755 src/vnm_mad/remotes/dummy/clean create mode 100755 src/vnm_mad/remotes/dummy/post create mode 100755 src/vnm_mad/remotes/dummy/pre rename src/vnm_mad/remotes/{802.1Q/hm-vlan => ebtables/clean} (89%) rename src/vnm_mad/remotes/ebtables/{ebtables-vlan => post} (80%) create mode 100755 src/vnm_mad/remotes/ebtables/pre create mode 100755 src/vnm_mad/remotes/ovswtich/clean rename src/vnm_mad/remotes/ovswtich/{openvswitch-vlan => post} (90%) create mode 100755 src/vnm_mad/remotes/ovswtich/pre diff --git a/src/vnm_mad/remotes/802.1Q/HostManaged.rb b/src/vnm_mad/remotes/802.1Q/HostManaged.rb index bda6286ef1..631d4ec2dc 100644 --- a/src/vnm_mad/remotes/802.1Q/HostManaged.rb +++ b/src/vnm_mad/remotes/802.1Q/HostManaged.rb @@ -14,6 +14,8 @@ # limitations under the License. # #--------------------------------------------------------------------------- # +require 'OpenNebulaNetwork' + class OpenNebulaHM < OpenNebulaNetwork def initialize(vm, hypervisor = nil) super(vm,hypervisor) @@ -48,12 +50,8 @@ class OpenNebulaHM < OpenNebulaNetwork end end end - end - def deactivate - vm_id = @vm['ID'] - process do |nic| - end + return 0 end def bridge_exists?(bridge) @@ -61,7 +59,7 @@ class OpenNebulaHM < OpenNebulaNetwork end def create_bridge(bridge) - system("#{COMMANDS[:brctl]} addbr #{bridge}") + exec_and_log("#{COMMANDS[:brctl]} addbr #{bridge}") end def device_exists?(dev, vlan=nil) @@ -70,7 +68,7 @@ class OpenNebulaHM < OpenNebulaNetwork end def create_dev_vlan(dev, vlan) - system("#{COMMANDS[:vconfig]} add #{dev} #{vlan}") + exec_and_log("#{COMMANDS[:vconfig]} add #{dev} #{vlan}") end def attached_bridge_dev?(bridge, dev, vlan=nil) @@ -81,11 +79,11 @@ class OpenNebulaHM < OpenNebulaNetwork def attach_brigde_dev(bridge, dev, vlan=nil) dev = "#{dev}.#{vlan}" if vlan - system("#{COMMANDS[:brctl]} addif #{bridge} #{dev}") + exec_and_log("#{COMMANDS[:brctl]} addif #{bridge} #{dev}") end def ifup(dev, vlan=nil) dev = "#{dev}.#{vlan}" if vlan - system("#{COMMANDS[:ip]} link set #{dev} up") + exec_and_log("#{COMMANDS[:ip]} link set #{dev} up") end end diff --git a/src/vnm_mad/remotes/802.1Q/clean b/src/vnm_mad/remotes/802.1Q/clean new file mode 100755 index 0000000000..44337c50d2 --- /dev/null +++ b/src/vnm_mad/remotes/802.1Q/clean @@ -0,0 +1,19 @@ +#!/bin/bash + +# -------------------------------------------------------------------------- # +# 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. # +#--------------------------------------------------------------------------- # + +exit 0 \ No newline at end of file diff --git a/src/vnm_mad/remotes/802.1Q/post b/src/vnm_mad/remotes/802.1Q/post new file mode 100755 index 0000000000..44337c50d2 --- /dev/null +++ b/src/vnm_mad/remotes/802.1Q/post @@ -0,0 +1,19 @@ +#!/bin/bash + +# -------------------------------------------------------------------------- # +# 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. # +#--------------------------------------------------------------------------- # + +exit 0 \ No newline at end of file diff --git a/src/vnm_mad/remotes/802.1Q/pre b/src/vnm_mad/remotes/802.1Q/pre new file mode 100755 index 0000000000..c7ce885d28 --- /dev/null +++ b/src/vnm_mad/remotes/802.1Q/pre @@ -0,0 +1,25 @@ +#!/usr/bin/env ruby + +# -------------------------------------------------------------------------- # +# 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. # +#--------------------------------------------------------------------------- # + +$: << File.dirname(__FILE__) +$: << File.join(File.dirname(__FILE__), "..") + +require 'HostManaged' + +hm = OpenNebulaHM.from_base64(ARGV[0]) +exit hm.activate diff --git a/src/vnm_mad/remotes/OpenNebulaNetwork.rb b/src/vnm_mad/remotes/OpenNebulaNetwork.rb index c837e88214..fc49236d73 100644 --- a/src/vnm_mad/remotes/OpenNebulaNetwork.rb +++ b/src/vnm_mad/remotes/OpenNebulaNetwork.rb @@ -20,6 +20,7 @@ $: << File.dirname(__FILE__) require 'rexml/document' require 'OpenNebulaNic' +require 'base64' CONF = { :start_vlan => 2 @@ -98,6 +99,11 @@ end class OpenNebulaNetwork attr_reader :hypervisor, :vm + def self.from_base64(vm_64, hypervisor=nil) + vm_xml = Base64::decode64(vm_64) + self.new(vm_xml, hypervisor) + end + def initialize(vm_tpl, hypervisor=nil) if !hypervisor @hypervisor = detect_hypervisor diff --git a/src/vnm_mad/remotes/dummy/clean b/src/vnm_mad/remotes/dummy/clean new file mode 100755 index 0000000000..44337c50d2 --- /dev/null +++ b/src/vnm_mad/remotes/dummy/clean @@ -0,0 +1,19 @@ +#!/bin/bash + +# -------------------------------------------------------------------------- # +# 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. # +#--------------------------------------------------------------------------- # + +exit 0 \ No newline at end of file diff --git a/src/vnm_mad/remotes/dummy/post b/src/vnm_mad/remotes/dummy/post new file mode 100755 index 0000000000..44337c50d2 --- /dev/null +++ b/src/vnm_mad/remotes/dummy/post @@ -0,0 +1,19 @@ +#!/bin/bash + +# -------------------------------------------------------------------------- # +# 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. # +#--------------------------------------------------------------------------- # + +exit 0 \ No newline at end of file diff --git a/src/vnm_mad/remotes/dummy/pre b/src/vnm_mad/remotes/dummy/pre new file mode 100755 index 0000000000..44337c50d2 --- /dev/null +++ b/src/vnm_mad/remotes/dummy/pre @@ -0,0 +1,19 @@ +#!/bin/bash + +# -------------------------------------------------------------------------- # +# 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. # +#--------------------------------------------------------------------------- # + +exit 0 \ No newline at end of file diff --git a/src/vnm_mad/remotes/ebtables/Ebtables.rb b/src/vnm_mad/remotes/ebtables/Ebtables.rb index 71f9bb1e8e..860a56fb0a 100644 --- a/src/vnm_mad/remotes/ebtables/Ebtables.rb +++ b/src/vnm_mad/remotes/ebtables/Ebtables.rb @@ -14,15 +14,19 @@ # limitations under the License. # #--------------------------------------------------------------------------- # +require 'OpenNebulaNetwork' + class EbtablesVLAN < OpenNebulaNetwork def initialize(vm, hypervisor = nil) super(vm,hypervisor) end def ebtables(rule) - system("#{COMMANDS[:ebtables]} -A #{rule}") + exec_and_log("#{COMMANDS[:ebtables]} -A #{rule}") end + # Activates ebtables rules + # def activate process do |nic| tap = nic[:tap] @@ -42,6 +46,8 @@ class EbtablesVLAN < OpenNebulaNetwork ebtables(out_rule) end end + + return 0 end def deactivate @@ -59,6 +65,8 @@ class EbtablesVLAN < OpenNebulaNetwork end remove_rules(tap) end + + return 0 end def rules @@ -74,6 +82,6 @@ class EbtablesVLAN < OpenNebulaNetwork end def remove_rule(rule) - system("#{COMMANDS[:ebtables]} -D FORWARD #{rule}") + exec_and_log("#{COMMANDS[:ebtables]} -D FORWARD #{rule}") end end diff --git a/src/vnm_mad/remotes/802.1Q/hm-vlan b/src/vnm_mad/remotes/ebtables/clean similarity index 89% rename from src/vnm_mad/remotes/802.1Q/hm-vlan rename to src/vnm_mad/remotes/ebtables/clean index 63f1dc53e1..0aaefc7e02 100755 --- a/src/vnm_mad/remotes/802.1Q/hm-vlan +++ b/src/vnm_mad/remotes/ebtables/clean @@ -17,13 +17,12 @@ #--------------------------------------------------------------------------- # $: << File.dirname(__FILE__) +$: << File.join(File.dirname(__FILE__), "..") -require 'base64' -require 'OpenNebulaNetwork' -require 'HostManaged' +require 'Ebtables' template = ARGV[0] -vm_xml = Base64::decode64(template) -hm = OpenNebulaHM.new(vm_xml) -hm.activate +onevlan = EbtablesVLAN.from_base64(template) + +exit onevlan.deactivate diff --git a/src/vnm_mad/remotes/ebtables/ebtables-vlan b/src/vnm_mad/remotes/ebtables/post similarity index 80% rename from src/vnm_mad/remotes/ebtables/ebtables-vlan rename to src/vnm_mad/remotes/ebtables/post index d4e72abe34..e69f291c26 100755 --- a/src/vnm_mad/remotes/ebtables/ebtables-vlan +++ b/src/vnm_mad/remotes/ebtables/post @@ -17,24 +17,14 @@ #--------------------------------------------------------------------------- # $: << File.dirname(__FILE__) +$: << File.join(File.dirname(__FILE__), "..") -require 'base64' -require 'OpenNebulaNetwork' require 'Ebtables' -action = ARGV[0] -template = ARGV[1] - # Uncomment to act only on the listed bridges. #FILTERED_BRIDGES = ['br0'] -vm_xml = Base64::decode64(template) -onevlan = EbtablesVLAN.new(vm_xml) +onevlan = EbtablesVLAN.from_base64(ARGV[0]) -case action -when "on" - onevlan.filter(:bridge => FILTERED_BRIDGES) if defined? FILTERED_BRIDGES - onevlan.activate -when "off" - onevlan.deactivate -end +onevlan.filter(:bridge => FILTERED_BRIDGES) if defined? FILTERED_BRIDGES +exit onevlan.activate diff --git a/src/vnm_mad/remotes/ebtables/pre b/src/vnm_mad/remotes/ebtables/pre new file mode 100755 index 0000000000..44337c50d2 --- /dev/null +++ b/src/vnm_mad/remotes/ebtables/pre @@ -0,0 +1,19 @@ +#!/bin/bash + +# -------------------------------------------------------------------------- # +# 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. # +#--------------------------------------------------------------------------- # + +exit 0 \ No newline at end of file diff --git a/src/vnm_mad/remotes/ovswtich/OpenvSwitch.rb b/src/vnm_mad/remotes/ovswtich/OpenvSwitch.rb index 2ba84ca1ea..fdbf91c21e 100644 --- a/src/vnm_mad/remotes/ovswtich/OpenvSwitch.rb +++ b/src/vnm_mad/remotes/ovswtich/OpenvSwitch.rb @@ -14,6 +14,8 @@ # limitations under the License. # #--------------------------------------------------------------------------- # +require 'OpenNebulaNetwork' + class OpenvSwitchVLAN < OpenNebulaNetwork def initialize(vm, hypervisor = nil) super(vm,hypervisor) @@ -30,7 +32,9 @@ class OpenvSwitchVLAN < OpenNebulaNetwork cmd = "#{COMMANDS[:ovs_vsctl]} set Port #{nic[:tap]} " cmd << "tag=#{vlan}" - system(cmd) + exec_and_log(cmd) end + + return 0 end end diff --git a/src/vnm_mad/remotes/ovswtich/clean b/src/vnm_mad/remotes/ovswtich/clean new file mode 100755 index 0000000000..44337c50d2 --- /dev/null +++ b/src/vnm_mad/remotes/ovswtich/clean @@ -0,0 +1,19 @@ +#!/bin/bash + +# -------------------------------------------------------------------------- # +# 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. # +#--------------------------------------------------------------------------- # + +exit 0 \ No newline at end of file diff --git a/src/vnm_mad/remotes/ovswtich/openvswitch-vlan b/src/vnm_mad/remotes/ovswtich/post similarity index 90% rename from src/vnm_mad/remotes/ovswtich/openvswitch-vlan rename to src/vnm_mad/remotes/ovswtich/post index 1cd64fcf1b..5a1bb54a76 100755 --- a/src/vnm_mad/remotes/ovswtich/openvswitch-vlan +++ b/src/vnm_mad/remotes/ovswtich/post @@ -18,12 +18,8 @@ $: << File.dirname(__FILE__) -require 'base64' require 'OpenNebulaNetwork' require 'OpenvSwitch' -template = ARGV[0] -vm_xml = Base64::decode64(template) - -onevlan = OpenvSwitchVLAN.new(vm_xml) -onevlan.activate +onevlan = OpenvSwitchVLAN.from_base64(ARGV[0]) +exit onevlan.activate() diff --git a/src/vnm_mad/remotes/ovswtich/pre b/src/vnm_mad/remotes/ovswtich/pre new file mode 100755 index 0000000000..44337c50d2 --- /dev/null +++ b/src/vnm_mad/remotes/ovswtich/pre @@ -0,0 +1,19 @@ +#!/bin/bash + +# -------------------------------------------------------------------------- # +# 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. # +#--------------------------------------------------------------------------- # + +exit 0 \ No newline at end of file From 0401048bea9677ca033fa529c910908da41a3bc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Fri, 11 Nov 2011 08:52:27 -0800 Subject: [PATCH 016/121] Feature #863: Small fix in vnm mad ruby requirement --- src/vnm_mad/remotes/ovswtich/post | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vnm_mad/remotes/ovswtich/post b/src/vnm_mad/remotes/ovswtich/post index 5a1bb54a76..e59bd2ead6 100755 --- a/src/vnm_mad/remotes/ovswtich/post +++ b/src/vnm_mad/remotes/ovswtich/post @@ -17,8 +17,8 @@ #--------------------------------------------------------------------------- # $: << File.dirname(__FILE__) +$: << File.join(File.dirname(__FILE__), "..") -require 'OpenNebulaNetwork' require 'OpenvSwitch' onevlan = OpenvSwitchVLAN.from_base64(ARGV[0]) From 87f099390488dff4bc5c00b6fce824cc1bf4c04e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Tue, 15 Nov 2011 12:44:50 +0100 Subject: [PATCH 017/121] Feaure #863 - #975: Update install.sh, and rename ovswitch drivers --- install.sh | 58 ++++++++++++++----- .../{ovswtich => ovswitch}/OpenvSwitch.rb | 0 .../remotes/{ovswtich => ovswitch}/clean | 0 .../remotes/{ovswtich => ovswitch}/post | 0 .../remotes/{ovswtich => ovswitch}/pre | 0 5 files changed, 43 insertions(+), 15 deletions(-) rename src/vnm_mad/remotes/{ovswtich => ovswitch}/OpenvSwitch.rb (100%) rename src/vnm_mad/remotes/{ovswtich => ovswitch}/clean (100%) rename src/vnm_mad/remotes/{ovswtich => ovswitch}/post (100%) rename src/vnm_mad/remotes/{ovswtich => ovswitch}/pre (100%) diff --git a/install.sh b/install.sh index e68a8ca288..310a15af65 100755 --- a/install.sh +++ b/install.sh @@ -223,8 +223,13 @@ VAR_DIRS="$VAR_LOCATION/remotes \ $VAR_LOCATION/remotes/im/ganglia.d \ $VAR_LOCATION/remotes/vmm/xen \ $VAR_LOCATION/remotes/vmm/kvm \ + $VAR_LOCATION/remotes/vnm \ + $VAR_LOCATION/remotes/vnm/802.1Q \ + $VAR_LOCATION/remotes/vnm/dummy \ + $VAR_LOCATION/remotes/vnm/ebtables \ + $VAR_LOCATION/remotes/vnm/fw \ + $VAR_LOCATION/remotes/vnm/ovswitch \ $VAR_LOCATION/remotes/hooks \ - $VAR_LOCATION/remotes/hooks/vnm \ $VAR_LOCATION/remotes/hooks/ft \ $VAR_LOCATION/remotes/image \ $VAR_LOCATION/remotes/image/fs \ @@ -342,13 +347,17 @@ INSTALL_FILES=( DUMMY_TM_COMMANDS_LIB_FILES:$LIB_LOCATION/tm_commands/dummy LVM_TM_COMMANDS_LIB_FILES:$LIB_LOCATION/tm_commands/lvm IMAGE_DRIVER_FS_SCRIPTS:$VAR_LOCATION/remotes/image/fs - NETWORK_HOOK_SCRIPTS:$VAR_LOCATION/remotes/vnm + NETWORK_FILES:$VAR_LOCATION/remotes/vnm + NETWORK_8021Q_FILES:$VAR_LOCATION/remotes/vnm/802.1Q + NETWORK_DUMMY_FILES:$VAR_LOCATION/remotes/vnm/dummy + NETWORK_EBTABLES_FILES:$VAR_LOCATION/remotes/vnm/ebtables + NETWORK_FW_FILES:$VAR_LOCATION/remotes/vnm/fw + NETWORK_OVSWITCH_FILES:$VAR_LOCATION/remotes/vnm/ovswitch EXAMPLE_SHARE_FILES:$SHARE_LOCATION/examples INSTALL_NOVNC_SHARE_FILE:$SHARE_LOCATION INSTALL_GEMS_SHARE_FILE:$SHARE_LOCATION TM_EXAMPLE_SHARE_FILES:$SHARE_LOCATION/examples/tm HOOK_FT_FILES:$VAR_LOCATION/remotes/hooks/ft - HOOK_NETWORK_FILES:$VAR_LOCATION/remotes/hooks/vnm COMMON_CLOUD_LIB_FILES:$LIB_LOCATION/ruby/cloud CLOUD_AUTH_LIB_FILES:$LIB_LOCATION/ruby/cloud/CloudAuth ECO_LIB_FILES:$LIB_LOCATION/ruby/cloud/econe @@ -611,6 +620,36 @@ AUTH_PLAIN_FILES="src/authm_mad/remotes/plain/authenticate" AUTH_QUOTA_FILES="src/authm_mad/remotes/quota/authorize" +#------------------------------------------------------------------------------- +# Virtual Network Manager drivers to be installed under $REMOTES_LOCATION/vnm +#------------------------------------------------------------------------------- + +NETWORK_FILES="src/vnm_mad/remotes/OpenNebulaNetwork.rb \ + src/vnm_mad/remotes/OpenNebulaNic.rb" + +NETWORK_8021Q_FILES="src/vnm_mad/remotes/802.1Q/clean \ + src/vnm_mad/remotes/802.1Q/post \ + src/vnm_mad/remotes/802.1Q/pre \ + src/vnm_mad/remotes/802.1Q/HostManaged.rb" + +NETWORK_DUMMY_FILES="src/vnm_mad/remotes/dummy/clean \ + src/vnm_mad/remotes/dummy/post \ + src/vnm_mad/remotes/dummy/pre" + +NETWORK_EBTABLES_FILES="src/vnm_mad/remotes/ebtables/clean \ + src/vnm_mad/remotes/ebtables/post \ + src/vnm_mad/remotes/ebtables/pre \ + src/vnm_mad/remotes/ebtables/Ebtables.rb" + +NETWORK_FW_FILES="src/vnm_mad/remotes/fw/firewall \ + src/vnm_mad/remotes/fw/Firewall.rb" + +NETWORK_OVSWITCH_FILES="src/vnm_mad/remotes/ovswitch/clean \ + src/vnm_mad/remotes/ovswitch/post \ + src/vnm_mad/remotes/ovswitch/pre \ + src/vnm_mad/remotes/ovswitch/OpenvSwitch.rb" + + #------------------------------------------------------------------------------- # Transfer Manager commands, to be installed under $LIB_LOCATION/tm_commands # - SHARED TM, $LIB_LOCATION/tm_commands/shared @@ -756,20 +795,9 @@ TM_EXAMPLE_SHARE_FILES="share/examples/tm/tm_clone.sh \ HOOK_FT_FILES="share/hooks/host_error.rb" #------------------------------------------------------------------------------- -# Network Hook scripts, to be installed under $VAR_LOCATION/remotes/hooks +# Installation scripts, to be installed under $SHARE_LOCATION #------------------------------------------------------------------------------- -HOOK_NETWORK_FILES="src/vnm_mad/hm-vlan \ - src/vnm_mad/ebtables-vlan \ - src/vnm_mad/firewall \ - src/vnm_mad/HostManaged.rb \ - src/vnm_mad/OpenNebulaNetwork.rb \ - src/vnm_mad/OpenNebulaNic.rb \ - src/vnm_mad/OpenvSwitch.rb \ - src/vnm_mad/openvswitch-vlan \ - src/vnm_mad/Firewall.rb \ - src/vnm_mad/Ebtables.rb" - INSTALL_NOVNC_SHARE_FILE="share/install_novnc.sh" INSTALL_GEMS_SHARE_FILE="share/install_gems/install_gems" diff --git a/src/vnm_mad/remotes/ovswtich/OpenvSwitch.rb b/src/vnm_mad/remotes/ovswitch/OpenvSwitch.rb similarity index 100% rename from src/vnm_mad/remotes/ovswtich/OpenvSwitch.rb rename to src/vnm_mad/remotes/ovswitch/OpenvSwitch.rb diff --git a/src/vnm_mad/remotes/ovswtich/clean b/src/vnm_mad/remotes/ovswitch/clean similarity index 100% rename from src/vnm_mad/remotes/ovswtich/clean rename to src/vnm_mad/remotes/ovswitch/clean diff --git a/src/vnm_mad/remotes/ovswtich/post b/src/vnm_mad/remotes/ovswitch/post similarity index 100% rename from src/vnm_mad/remotes/ovswtich/post rename to src/vnm_mad/remotes/ovswitch/post diff --git a/src/vnm_mad/remotes/ovswtich/pre b/src/vnm_mad/remotes/ovswitch/pre similarity index 100% rename from src/vnm_mad/remotes/ovswtich/pre rename to src/vnm_mad/remotes/ovswitch/pre From 9d50b437c65df2b07e8e722ed3b785732b728ceb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Tue, 15 Nov 2011 07:30:53 -0800 Subject: [PATCH 018/121] Feature #863: Remove networking hooks from oned.conf --- share/etc/oned.conf | 130 -------------------------------------------- 1 file changed, 130 deletions(-) diff --git a/share/etc/oned.conf b/share/etc/oned.conf index 630303e906..3c4f9f629f 100644 --- a/share/etc/oned.conf +++ b/share/etc/oned.conf @@ -405,136 +405,6 @@ HM_MAD = [ # arguments = "$VMID" ] #------------------------------------------------------------------------------- -#******************************************************************************* -# Networking Hooks -#******************************************************************************* -# The following network hooks can be activated in order to manage network -# isolation and firewalls. -#******************************************************************************* -#------------------------------------------------------------------------------- -# Firewall -#------------------------------------------------------------------------------- -# -# Firewalling rules activated in the physical host executing the VM. Can be used -# to filter TCP and UDP ports, and to define a policy for ICMP connections. To -# use it specify under the NIC section of the VM one or more of the following -# attributes: -# -# - WHITE_PORTS_TCP = iptables_range -# Permits access to the VM only through the specified ports in the TCP -# protocol. Supersedes BLACK_PORTS_TCP if defined. -# -# - BLACK_PORTS_TCP = iptables_range -# Doesn't permit access to the VM through the specified ports in the TCP -# protocol. Superseded by WHITE_PORTS_TCP if defined. -# -# - WHITE_PORTS_UDP = iptables_range -# Permits access to the VM only through the specified ports in the UDP -# protocol. Supersedes BLACK_PORTS_UDP if defined. -# -# - BLACK_PORTS_UDP = iptables_range -# Doesn't permit access to the VM through the specified ports in the UDP -# protocol. Superseded by WHITE_PORTS_UDP if defined. -# -# - ICMP = no | drop -# Blocks ICMP connections to the VM. By default it's enabled. -# -# This hook requires the sudoers file to be configured so oneadmin can execute -# iptables without a password. -# -#------------------------------------------------------------------------------- -# -# VM_HOOK = [ -# name = "firewall-on", -# on = "RUNNING", -# command = "vnm/firewall", -# arguments = "on $TEMPLATE", -# remote = "yes" ] -# -# VM_HOOK = [ -# name = "firewall-off", -# on = "DONE", -# command = "vnm/firewall", -# arguments = "off $TEMPLATE", -# remote = "yes" ] -#------------------------------------------------------------------------------- -# Host-managed VLANs -#------------------------------------------------------------------------------- -# -# Network isolation provided through host-managed vlans. This hook will create a -# bridge for each OpenNebula virtual network and attach a tagged network -# interface to the bridge. -# -# For this hook to be effective you need to specify the attribute PHYDEV in your -# VNET template, which should contain the name of the physical network interface -# each VM should be attached to. If BRIDGE is not defined it will be -# automatically generated. -# -# In order to use this hook you need to: -# - load module 8021q -# - install vconfig -# - configure passwordless sudo in the worker nodes for oneadmin for these -# commands: brctl, ip, vconfig. -# -#------------------------------------------------------------------------------- -# -# VM_HOOK = [ -# name = "hm-vlan", -# on = "PROLOG", -# command = "vnm/hm-vlan", -# arguments = "$TEMPLATE", -# remote = "yes" ] -# -#------------------------------------------------------------------------------- -# Ebtables Network Isolation -#------------------------------------------------------------------------------- -# -# Network isolation provided through ebtables rules applied on the bridges. This -# method will only permit isolation with a mask of 255.255.255.0. -# -# This hook requires the sudoers file to be configured so oneadmin can execute -# ebtables without a password, and the ebtables package to be installed. -# -#------------------------------------------------------------------------------- -# -# VM_HOOK = [ -# name = "ebtables-vlan-on", -# on = "RUNNING", -# command = "vnm/ebtables-vlan", -# arguments = "on $TEMPLATE", -# remote = "yes" ] -# -# VM_HOOK = [ -# name = "ebtables-vlan-off", -# on = "DONE", -# command = "vnm/ebtables-vlan", -# arguments = "off $TEMPLATE", -# remote = "yes" ] -# -#------------------------------------------------------------------------------- -# Open vSwitch Network Isolation -#------------------------------------------------------------------------------- -# -# Network isolation provided through Open vSwitch. Each virtual network -# interface will receive an VLAN tag enabling network isolation. -# -# This hook requires Open vSwitch to be installed along with the Open vSwitch -# compatibility layer for Linux bridging, on each worker node. -# See http://openvswitch.org/ for more information. -# -# Passwordless sudo permissions for oneadmin to execute ovs_vsctl. -# -#------------------------------------------------------------------------------- -# -# VM_HOOK = [ -# name = "openvswitch-vlan", -# on = "RUNNING", -# command = "vnm/openvswitch-vlan", -# arguments = "$TEMPLATE", -# remote = "yes" ] -# -#------------------------------------------------------------------------------- - #******************************************************************************* # Auth Manager Configuration #******************************************************************************* From 85a676e9594644f72e863724e28a71e94da5a4dc Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Wed, 16 Nov 2011 18:11:43 +0100 Subject: [PATCH 019/121] now vmm deploy gets local and remote deployment paths --- include/VirtualMachineManager.h | 3 ++- src/vmm/VirtualMachineManager.cc | 20 ++++++++++++++++---- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/include/VirtualMachineManager.h b/include/VirtualMachineManager.h index 1c41918288..cab1799800 100644 --- a/include/VirtualMachineManager.h +++ b/include/VirtualMachineManager.h @@ -205,7 +205,8 @@ private: const string& m_hostname, const string& m_net_drv, const string& domain, - const string& dfile, + const string& ldfile, + const string& rdfile, const string& cfile, const string& tmpl); diff --git a/src/vmm/VirtualMachineManager.cc b/src/vmm/VirtualMachineManager.cc index 37539374a7..31edfe92a4 100644 --- a/src/vmm/VirtualMachineManager.cc +++ b/src/vmm/VirtualMachineManager.cc @@ -251,7 +251,8 @@ string * VirtualMachineManager::format_message( const string& m_hostname, const string& m_net_drv, const string& domain, - const string& dfile, + const string& ldfile, + const string& rdfile, const string& cfile, const string& tmpl) { @@ -280,13 +281,15 @@ string * VirtualMachineManager::format_message( oss << ""; } - if (!dfile.empty()) + if (!ldfile.empty()) { - oss << "" << dfile << ""; + oss << "" << ldfile << ""; + oss << "" << rdfile << ""; } else { - oss << ""; + oss << ""; + oss << ""; } if (!cfile.empty()) @@ -358,6 +361,7 @@ void VirtualMachineManager::deploy_action(int vid) "", "", "", + vm->get_deployment_file(), vm->get_remote_deployment_file(), "", vm->to_xml(vm_tmpl)); @@ -455,6 +459,7 @@ void VirtualMachineManager::save_action( "", vm->get_deploy_id(), "", + "", vm->get_checkpoint_file(), vm->to_xml(vm_tmpl)); @@ -534,6 +539,7 @@ void VirtualMachineManager::shutdown_action( vm->get_deploy_id(), "", "", + "", vm->to_xml(vm_tmpl)); vmd->shutdown(vid, *drv_msg); @@ -608,6 +614,7 @@ void VirtualMachineManager::cancel_action( vm->get_deploy_id(), "", "", + "", vm->to_xml(vm_tmpl)); vmd->cancel(vid, *drv_msg); @@ -685,6 +692,7 @@ void VirtualMachineManager::cancel_previous_action( vm->get_deploy_id(), "", "", + "", vm->to_xml(vm_tmpl)); vmd->cancel(vid, *drv_msg); @@ -758,6 +766,7 @@ void VirtualMachineManager::migrate_action( vm->get_deploy_id(), "", "", + "", vm->to_xml(vm_tmpl)); vmd->migrate(vid, *drv_msg); @@ -836,6 +845,7 @@ void VirtualMachineManager::restore_action( "", vm->get_deploy_id(), "", + "", vm->get_checkpoint_file(), vm->to_xml(vm_tmpl)); @@ -911,6 +921,7 @@ void VirtualMachineManager::poll_action( vm->get_deploy_id(), "", "", + "", vm->to_xml(vm_tmpl)); vmd->poll(vid, *drv_msg); @@ -1067,6 +1078,7 @@ void VirtualMachineManager::timer_action() vm->get_deploy_id(), "", "", + "", vm->to_xml(vm_tmpl)); vmd->poll(*it, *drv_msg); From b7fda37436219cffefc761a34336fa2347567037 Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Wed, 16 Nov 2011 19:05:16 +0100 Subject: [PATCH 020/121] changed domain by deploy_id in the vmm driver xml --- src/vmm/VirtualMachineManager.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/vmm/VirtualMachineManager.cc b/src/vmm/VirtualMachineManager.cc index 31edfe92a4..94706f35f8 100644 --- a/src/vmm/VirtualMachineManager.cc +++ b/src/vmm/VirtualMachineManager.cc @@ -274,11 +274,11 @@ string * VirtualMachineManager::format_message( if (!domain.empty()) { - oss << "" << domain << ""; + oss << "" << domain << ""; } else { - oss << ""; + oss << ""; } if (!ldfile.empty()) From 048364353c1b4ed2622f1a7180b16b0686e1c2a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Wed, 16 Nov 2011 19:05:09 +0100 Subject: [PATCH 021/121] Feature #863 - #974: Update ec2 hybrid driver for the new protocol --- src/mad/ruby/VirtualMachineDriver.rb | 29 ++++++++++------------------ src/vmm_mad/dummy/one_vmm_dummy.rb | 13 ++----------- src/vmm_mad/ec2/one_vmm_ec2.rb | 27 +++++++++++++++++++++----- 3 files changed, 34 insertions(+), 35 deletions(-) diff --git a/src/mad/ruby/VirtualMachineDriver.rb b/src/mad/ruby/VirtualMachineDriver.rb index fa3249824d..f9f5fc1c21 100644 --- a/src/mad/ruby/VirtualMachineDriver.rb +++ b/src/mad/ruby/VirtualMachineDriver.rb @@ -15,6 +15,8 @@ #--------------------------------------------------------------------------- # require "OpenNebulaDriver" require "CommandManager" +require 'base64' +require 'rexml/document' # Author:: dsa-research.org # Copyright:: (c) 2011 Universidad Computense de Madrid @@ -85,26 +87,15 @@ class VirtualMachineDriver < OpenNebulaDriver register_action(ACTION[:poll].to_sym, method("poll")) end - # Converts a deployment file from its remote path to the local (front-end) - # path - def get_local_deployment_file(rfile) - lfile = nil + # Decodes the encoded XML driver message received from the core + # + # @param [String] drv_message the driver message + # @return [REXML::Element] the root element of the decoded XML message + def decode(drv_message) + message = Base64.decode64(drv_message) + xml_doc = REXML::Document.new(message) - one_location = ENV["ONE_LOCATION"] - - if one_location == nil - var_location = "/var/lib/one/" - else - var_location = one_location + "/var/" - end - - m = rfile.match(/.*?\/(\d+)\/images\/(deployment.\d+)$/) - - lfile = "#{var_location}#{m[1]}/#{m[2]}" if m - - lfile = nil if lfile and !File.exists?(lfile) - - return lfile + xml_doc.root end # Execute a command associated to an action and id in a remote host. diff --git a/src/vmm_mad/dummy/one_vmm_dummy.rb b/src/vmm_mad/dummy/one_vmm_dummy.rb index dad6596de4..f424a12c13 100755 --- a/src/vmm_mad/dummy/one_vmm_dummy.rb +++ b/src/vmm_mad/dummy/one_vmm_dummy.rb @@ -30,8 +30,6 @@ $: << RUBY_LIB_LOCATION require "VirtualMachineDriver" require "CommandManager" -require 'base64' -require 'rexml/document' class DummyDriver < VirtualMachineDriver def initialize @@ -41,15 +39,8 @@ class DummyDriver < VirtualMachineDriver ) end - def decode(drv_msg) - message = Base64.decode64(drv_msg) - xml_doc = REXML::Document.new(message) - - xml_doc.root - end - - def deploy(id, drv_msg) - msg = decode(drv_msg) + def deploy(id, drv_message) + msg = decode(drv_message) host = msg.elements["HOST"].text name = msg.elements["VM/NAME"].text diff --git a/src/vmm_mad/ec2/one_vmm_ec2.rb b/src/vmm_mad/ec2/one_vmm_ec2.rb index 10441c1115..f5346e58f9 100755 --- a/src/vmm_mad/ec2/one_vmm_ec2.rb +++ b/src/vmm_mad/ec2/one_vmm_ec2.rb @@ -89,9 +89,12 @@ class EC2Driver < VirtualMachineDriver end # DEPLOY action, also sets ports and ip if needed - def deploy(id, host, remote_dfile, not_used) + def deploy(id, drv_message) + msg = decode(drv_message) - local_dfile = get_local_deployment_file(remote_dfile) + host = msg.elements["HOST"].text + + local_dfile = msg.elements["LOCAL_DEPLOYMENT_FILE"].text if !local_dfile send_message(ACTION[:deploy],RESULT[:failure],id, @@ -175,17 +178,31 @@ class EC2Driver < VirtualMachineDriver end # Shutdown a EC2 instance - def shutdown(id, host, deploy_id, not_used) + def shutdown(id, drv_message) + msg = decode(drv_message) + + host = msg.elements["HOST"].text + deploy_id = msg.elements["DEPLOY_ID"].text + ec2_terminate(ACTION[:shutdown], id, deploy_id) end # Cancel a EC2 instance - def cancel(id, host, deploy_id, not_used) + def cancel(id, drv_message) + msg = decode(drv_message) + + host = msg.elements["HOST"].text + deploy_id = msg.elements["DEPLOY_ID"].text + ec2_terminate(ACTION[:cancel], id, deploy_id) end # Get info (IP, and state) for a EC2 instance - def poll(id, host, deploy_id, not_used) + def poll(id, drv_message) + msg = decode(drv_message) + + host = msg.elements["HOST"].text + deploy_id = msg.elements["DEPLOY_ID"].text info = "#{POLL_ATTRIBUTE[:usedmemory]}=0 " \ "#{POLL_ATTRIBUTE[:usedcpu]}=0 " \ From 84f912866bcba863f601be8c562b4ea16e7f506e Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Thu, 17 Nov 2011 12:13:51 +0100 Subject: [PATCH 022/121] decode vmm_exec parameters --- src/vmm_mad/exec/one_vmm_exec.rb | 44 ++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 8 deletions(-) diff --git a/src/vmm_mad/exec/one_vmm_exec.rb b/src/vmm_mad/exec/one_vmm_exec.rb index fff1872265..7b5e0c0e4d 100755 --- a/src/vmm_mad/exec/one_vmm_exec.rb +++ b/src/vmm_mad/exec/one_vmm_exec.rb @@ -49,8 +49,11 @@ class ExecDriver < VirtualMachineDriver end # DEPLOY action, sends the deployment file to remote host - def deploy(id, host, remote_dfile, not_used) - local_dfile = get_local_deployment_file(remote_dfile) + def deploy(id, drv_message) + data = decode(drv_message) + + local_dfile = data['LOCAL_DEPLOYMENT_DATA'] + host= data['HOST'] if !local_dfile || File.zero?(local_dfile) send_message(ACTION[:deploy],RESULT[:failure],id, @@ -74,27 +77,52 @@ class ExecDriver < VirtualMachineDriver # Basic Domain Management Operations - def shutdown(id, host, deploy_id, not_used) + def shutdown(id, drv_message) + data = decode(drv_message) + host = data['HOST'] + deploy_id = data['DEPLOY_ID'] + do_action("#{deploy_id} #{host}", id, host, :shutdown) end - def cancel(id, host, deploy_id, not_used) + def cancel(id, drv_message) + data = decode(drv_message) + host = data['HOST'] + deploy_id = data['DEPLOY_ID'] + do_action("#{deploy_id} #{host}", id, host, :cancel) end - def save(id, host, deploy_id, file) + def save(id, drv_message) + data = decode(drv_message) + host = data['HOST'] + deploy_id = data['DEPLOY_ID'] + file = data['CHECKPOINT_FILE'] + do_action("#{deploy_id} #{file} #{host}", id, host, :save) end - def restore(id, host, deploy_id, file) + def restore(id, drv_message) + data = decode(drv_message) + host = data['HOST'] + file = data['CHECKPOINT_FILE'] + do_action("#{file} #{host}", id, host, :restore) end - def migrate(id, host, deploy_id, dest_host) + def migrate(id, drv_message) + data = decode(drv_message) + host = data['HOST'] + deploy_id = data['DEPLOY_ID'] + do_action("#{deploy_id} #{dest_host} #{host}", id, host, :migrate) end - def poll(id, host, deploy_id, not_used) + def poll(id, drv_message) + data = decode(drv_message) + host = data['HOST'] + deploy_id = data['DEPLOY_ID'] + do_action("#{deploy_id} #{host}", id, host, :poll) end end From 8a68b8eef256dfd7866ab82ddf2a203359eab68f Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Fri, 18 Nov 2011 17:31:18 +0100 Subject: [PATCH 023/121] added ssh_stream --- src/mad/ruby/ssh_stream.rb | 175 +++++++++++++++++++++++++++++++++++++ 1 file changed, 175 insertions(+) create mode 100644 src/mad/ruby/ssh_stream.rb diff --git a/src/mad/ruby/ssh_stream.rb b/src/mad/ruby/ssh_stream.rb new file mode 100644 index 0000000000..38da9241dc --- /dev/null +++ b/src/mad/ruby/ssh_stream.rb @@ -0,0 +1,175 @@ + +require 'CommandManager' +require 'open3' + +class SshStream + attr_reader :stream_out, :stream_err, :stdin + attr_reader :out, :err + + # + # + EOF_ERR = "EOF_ERR" + EOF_OUT = "EOF_OUT" + RC_STR = "ExitCode: " + + EOF_CMD = "echo \"#{RC_STR}$?#{EOF_ERR}\" 1>&2; echo \"#{EOF_OUT}\"" + SSH_CMD = "ssh" + # + # + # + def initialize(host) + @host = host + end + + def opened? + defined?(@stdin) + end + + def open + @stdin, @stdout, @stderr=Open3::popen3("#{SSH_CMD} #{@host} bash -s") + + @stream_out = "" + @stream_err = "" + + @out = "" + @err = "" + end + + def close + @stdin.puts "\nexit" + + @stdin.close if not @stdin.closed? + @stdout.close if not @stdout.closed? + @stderr.close if not @stderr.closed? + end + + def exec(command) + @out = "" + @err = "" + + begin + @stdin.write "(#{command}); #{EOF_CMD}\n" + @stdin.flush + rescue + + end + end + + def wait_for_command + done_out = false + done_err = false + + code = -1 + + while not (done_out and done_err) + rc, rw, = IO.select([@stdout, @stderr],[],[]) + + rc.each { |fd| + c = fd.read_nonblock(1) + + if !c + done = true + break + end + + if fd == @stdout + @out << c + done_out = true if @out.slice!("#{EOF_OUT}\n") + else + @err << c + + tmp = @err.scan(/^#{RC_STR}(\d*)#{EOF_ERR}\n/) + + if tmp[0] + code = tmp[0][0].to_i + done_err = true + + @err.slice!("#{EOF_ERR}\n") + end + end + } + end + + @stream_out << @out + @stream_err << @err + + return code + end + + def exec_and_wait(command) + exec(command) + wait_for_command + end +end + + +class SshStreamCommand < GenericCommand + def initialize(host, logger=nil, stdin=nil) + @host=host + super('true', logger, stdin) + + @stream=SshStream.new(host) + @stream.open + end + + def run(command, stdin=nil) + @stream.open unless @stream.opened? + + @stream.exec(command) + @stream.stdin.write(stdin) if stdin + + code=@stream.wait_for_command + + @stdout=@stream.out + @stderr=@stream.err + + if code!=0 + log("Command execution fail: #{command}") + end + + log(@stderr) + + return code + end +end + + +if $0 == __FILE__ + + ssh=SshStream.new('localhost') + + ssh.open + + ssh.exec("date | tee /tmp/test.javi") + code=ssh.wait_for_command + + puts "Code: #{code}" + puts "output: #{ssh.out}" + + ssh.exec "cat << EOT | cat" + ssh.stdin.puts "blah blah\nmas blah\nrequeteblah" + ssh.stdin.puts "EOT" + + code=ssh.wait_for_command + + puts "Code: #{code}" + puts "output: #{ssh.out}" + + code=ssh.exec_and_wait("whoami") + + puts "Code: #{code}" + puts "output: #{ssh.out}" + + code=ssh.exec_and_wait("touch /etc/pepe.txt") + + puts "Code: #{code}" + puts "output: #{ssh.out}" + puts "output err: #{ssh.err}" + + + ssh.close + +end + + + From 80efad700b070da00ded6372354ee37f63e4fd5a Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Fri, 18 Nov 2011 17:32:17 +0100 Subject: [PATCH 024/121] feature #863: added execute_network_script to one_vmm_exec --- src/vmm_mad/exec/one_vmm_exec.rb | 72 ++++++++++++++++++++++++++++++-- 1 file changed, 68 insertions(+), 4 deletions(-) diff --git a/src/vmm_mad/exec/one_vmm_exec.rb b/src/vmm_mad/exec/one_vmm_exec.rb index 7b5e0c0e4d..49b34124e9 100755 --- a/src/vmm_mad/exec/one_vmm_exec.rb +++ b/src/vmm_mad/exec/one_vmm_exec.rb @@ -1,5 +1,6 @@ #!/usr/bin/env ruby + # -------------------------------------------------------------------------- # # Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org) # # # @@ -34,6 +35,9 @@ $: << RUBY_LIB_LOCATION require "VirtualMachineDriver" require 'getoptlong' +require 'ssh_stream' +require 'pp' + # The main class for the Sh driver class ExecDriver < VirtualMachineDriver @@ -48,12 +52,60 @@ class ExecDriver < VirtualMachineDriver @hypervisor = hypervisor end + # network script actions + + def execute_network_script(action, connection, message) + driver=message.elements['NET_DRV'].text + id=message.elements['VM/ID'].text + + vm_encoded=Base64.encode64(message.elements['VM'].to_s).delete("\n") + + result=[false, ''] + + if(action_is_local?(action.to_s)) + script_path=File.join( + @local_scripts_base_path, + 'vnm', + driver, + action.to_s) + + command="#{script_path} #{vm_encoded}" + + command_exe = LocalCommand.run(command, log_method(id)) + + code=(command_exe.code==0) + + result=[code, command_exe] + else + script_path=File.join( + @remote_scripts_base_path, + 'vnm', + driver, + action.to_s) + + command="#{script_path} #{vm_encoded}" + + pp command + + error_code=connection.run(command) + + pp error_code + pp connection.stderr + + code=(error_code==0) + + result=[code, connection] + end + end + + # DEPLOY action, sends the deployment file to remote host def deploy(id, drv_message) data = decode(drv_message) - local_dfile = data['LOCAL_DEPLOYMENT_DATA'] - host= data['HOST'] + local_dfile = data.elements['LOCAL_DEPLOYMENT_FILE'].text + remote_dfile = data.elements['REMOTE_DEPLOYMENT_FILE'].text + host= data.elements['HOST'].text if !local_dfile || File.zero?(local_dfile) send_message(ACTION[:deploy],RESULT[:failure],id, @@ -71,8 +123,20 @@ class ExecDriver < VirtualMachineDriver dfile=remote_dfile end - do_action("#{dfile} #{host}", id, host, :deploy, - :stdin => domain) + ssh=SshStreamCommand.new(host, log_method(id)) + + execute_network_script(:pre, ssh, data) + + pp ssh.run("cat << EOT | #{remote_scripts_path}/deploy #{dfile} #{host}", + domain+"\nEOT\n") + + execute_network_script(:post, ssh, data) + + pp ssh.stdout + pp ssh.stderr + + #do_action("#{dfile} #{host}", id, host, :deploy, + # :stdin => domain) end # Basic Domain Management Operations From d4508e54a7a4d84cece84a2828ebee82aed9a437 Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Mon, 21 Nov 2011 16:43:08 +0100 Subject: [PATCH 025/121] feature #863: refactored do_action --- src/authm_mad/one_auth_mad.rb | 6 ++-- src/image_mad/one_image.rb | 12 ++++--- src/mad/ruby/OpenNebulaDriver.rb | 55 ++++++++++++++++---------------- 3 files changed, 39 insertions(+), 34 deletions(-) diff --git a/src/authm_mad/one_auth_mad.rb b/src/authm_mad/one_auth_mad.rb index 81ea494ecf..7a244519e9 100755 --- a/src/authm_mad/one_auth_mad.rb +++ b/src/authm_mad/one_auth_mad.rb @@ -111,7 +111,8 @@ class AuthDriver < OpenNebulaDriver command = File.join(authN_path,ACTION[:authN].downcase) command << ' ' << user << ' ' << password << ' ' << secret - local_action(command, request_id, ACTION[:authN]) + do_action(command, request_id, nil, ACTION[:authN], + :local => true) end # Authenticate a user based in a string of the form user:secret when using the @@ -141,7 +142,8 @@ class AuthDriver < OpenNebulaDriver command = @authZ_cmd.clone command << ' ' << user_id << ' ' << requests.join(' ') - local_action(command, request_id, ACTION[:authZ]) + do_action(command, request_id, nil, ACTION[:authZ], + :local => true) end end end diff --git a/src/image_mad/one_image.rb b/src/image_mad/one_image.rb index 72bb6fbbbe..358972a879 100755 --- a/src/image_mad/one_image.rb +++ b/src/image_mad/one_image.rb @@ -69,19 +69,23 @@ class ImageDriver < OpenNebulaDriver # Image Manager Protocol Actions (generic implementation def mv(id, src, dst) - local_action("#{@actions_path}/mv #{src} #{dst} #{id}",id,ACTION[:mv]) + do_action("#{@actions_path}/mv #{src} #{dst} #{id}", id, nil, + ACTION[:mv], :local => true) end def cp(id, src) - local_action("#{@actions_path}/cp #{src} #{id}",id,ACTION[:cp]) + do_action("#{@actions_path}/cp #{src} #{id}", id, nil, ACTION[:cp], + :local => true) end def rm(id, dst) - local_action("#{@actions_path}/rm #{dst} #{id}",id,ACTION[:rm]) + do_action("#{@actions_path}/rm #{dst} #{id}", id, nil, ACTION[:rm], + :local => true) end def mkfs(id, fs, size) - local_action("#{@actions_path}/mkfs #{fs} #{size} #{id}",id,ACTION[:mkfs]) + do_action("#{@actions_path}/mkfs #{fs} #{size} #{id}", id, nil, + ACTION[:mkfs], :local => true) end end diff --git a/src/mad/ruby/OpenNebulaDriver.rb b/src/mad/ruby/OpenNebulaDriver.rb index 6129795d3a..d69d616456 100644 --- a/src/mad/ruby/OpenNebulaDriver.rb +++ b/src/mad/ruby/OpenNebulaDriver.rb @@ -141,21 +141,43 @@ class OpenNebulaDriver < ActionManager def do_action(parameters, id, host, aname, ops={}) options={ :stdin => nil, - :script_name => nil + :script_name => nil, + :respond => true }.merge(ops) params=parameters+" #{id} #{host}" command=action_command_line(aname, params, options[:script_name]) - if action_is_local? aname - local_action(command, id, aname) + if ops[:local] || action_is_local? aname + execution=local_action(command, id, aname) else - remotes_action(command, id, host, aname, @remote_scripts_base_path, - options[:stdin]) + execution=remotes_action(command, id, host, aname, + @remote_scripts_base_path, options[:stdin]) + end + + if ops[:respond] + send_message_from_execution(aname, id, execution) + else + execution end end + def send_message_from_execution(aname, id, command_exe) + if command_exe.code == 0 + result = RESULT[:success] + info = command_exe.stdout + else + result = RESULT[:failure] + info = command_exe.get_error_message + end + + info = "-" if info == nil || info.empty? + + send_message(aname,result,id,info) + end + + # Given the action name and the parameter returns full path of the script # and appends its parameters. It uses @local_actions hash to know if the # actions is remote or local. If the local actions has defined an special @@ -213,17 +235,6 @@ class OpenNebulaDriver < ActionManager log_method(id), std_in, @retries) - if command_exe.code == 0 - result = RESULT[:success] - info = command_exe.stdout - else - result = RESULT[:failure] - info = command_exe.get_error_message - end - - info = "-" if info == nil || info.empty? - - send_message(aname,result,id,info) end # Execute a command associated to an action and id on localhost @@ -233,18 +244,6 @@ class OpenNebulaDriver < ActionManager # @param [String, Symbol] aname name of the action def local_action(command, id, aname) command_exe = LocalCommand.run(command, log_method(id)) - - if command_exe.code == 0 - result = RESULT[:success] - info = command_exe.stdout - else - result = RESULT[:failure] - info = command_exe.get_error_message - end - - info = "-" if info == nil || info.empty? - - send_message(aname,result,id,info) end # Sends a log message to ONE. The +message+ can be multiline, it will From 24ad9bf49e5dd532ec32b92694f8fdd5f0d7967f Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Mon, 21 Nov 2011 18:14:04 +0100 Subject: [PATCH 026/121] feature #863: Work on driver design --- src/mad/ruby/OpenNebulaDriver.rb | 220 +++++++------------------------ src/mad/ruby/ssh_stream.rb | 12 +- src/vmm_mad/exec/one_vmm_exec.rb | 7 +- 3 files changed, 61 insertions(+), 178 deletions(-) diff --git a/src/mad/ruby/OpenNebulaDriver.rb b/src/mad/ruby/OpenNebulaDriver.rb index d69d616456..4833d7bdd4 100644 --- a/src/mad/ruby/OpenNebulaDriver.rb +++ b/src/mad/ruby/OpenNebulaDriver.rb @@ -30,44 +30,13 @@ require "CommandManager" # for each action it wants to receive. The method must be associated # with the action name through the register_action function class OpenNebulaDriver < ActionManager + include DriverExecHelper + # @return [String] Base path for scripts attr_reader :local_scripts_base_path, :remote_scripts_base_path # @return [String] Path for scripts attr_reader :local_scripts_path, :remote_scripts_path - # This function parses a string with this form: - # - # 'deploy,shutdown,poll=poll_ganglia, cancel ' - # - # and returns a hash: - # - # {"POLL"=>"poll_ganglia", "DEPLOY"=>nil, "SHUTDOWN"=>nil, - # "CANCEL"=>nil} - # - # @param [String] str imput string to parse - # @return [Hash] parsed actions - def self.parse_actions_list(str) - actions=Hash.new - str_splitted=str.split(/\s*,\s*/).map {|s| s.strip } - - str_splitted.each do |a| - m=a.match(/([^=]+)(=(.*))?/) - next if !m - - action=m[1].upcase - - if m[2] - script=m[3] - script.strip! if script - else - script=nil - end - - actions[action]=script - end - - actions - end # Action result strings for messages RESULT = { @@ -98,23 +67,11 @@ class OpenNebulaDriver < ActionManager super(@options[:concurrency], @options[:threaded]) @retries = @options[:retries] - @local_actions = @options[:local_actions] @send_mutex = Mutex.new - - # set default values - @config = read_configuration - @remote_scripts_base_path = @config['SCRIPTS_REMOTE_DIR'] - - if ENV['ONE_LOCATION'] == nil - @local_scripts_base_path = "/var/lib/one/remotes" - else - @local_scripts_base_path = "#{ENV['ONE_LOCATION']}/var/remotes" - end - - # dummy paths - @remote_scripts_path = File.join(@remote_scripts_base_path, directory) - @local_scripts_path = File.join(@local_scripts_base_path, directory) + + #Set default values + initialize_helper(directory, @options) register_action(:INIT, method("init")) end @@ -150,100 +107,23 @@ class OpenNebulaDriver < ActionManager command=action_command_line(aname, params, options[:script_name]) if ops[:local] || action_is_local? aname - execution=local_action(command, id, aname) + execution = LocalCommand.run(command, log_method(id)) else - execution=remotes_action(command, id, host, aname, - @remote_scripts_base_path, options[:stdin]) + execution = RemotesCommand.run(command, + host, + @remote_scripts_base_path, + log_method(id), + options[:stdin], + @retries) end + result, info = get_info_from_execution(command_exe) + if ops[:respond] - send_message_from_execution(aname, id, execution) - else - execution - end - end - - def send_message_from_execution(aname, id, command_exe) - if command_exe.code == 0 - result = RESULT[:success] - info = command_exe.stdout - else - result = RESULT[:failure] - info = command_exe.get_error_message + send_message(aname,result,id,info) end - info = "-" if info == nil || info.empty? - - send_message(aname,result,id,info) - end - - - # Given the action name and the parameter returns full path of the script - # and appends its parameters. It uses @local_actions hash to know if the - # actions is remote or local. If the local actions has defined an special - # script name this is used, otherwise the action name in downcase is - # used as the script name. - # - # @param [String, Symbol] action name of the action - # @param [String] parameters arguments for the script - # @param [String, nil] default_name alternative name for the script - # @return [String] command line needed to execute the action - def action_command_line(action, parameters, default_name=nil) - if action_is_local? action - script_path=@local_scripts_path - else - script_path=@remote_scripts_path - end - - File.join(script_path, action_script_name(action, default_name))+ - " "+parameters - end - - # True if the action is meant to be executed locally - # - # @param [String, Symbol] action name of the action - def action_is_local?(action) - @local_actions.include? action.to_s.upcase - end - - # Name of the script file for the given action - # - # @param [String, Symbol] action name of the action - # @param [String, nil] default_name alternative name for the script - def action_script_name(action, default_name=nil) - name=@local_actions[action.to_s.upcase] - - if name - name - else - default_name || action.to_s.downcase - end - end - - # Execute a command associated to an action and id in a remote host. - # - # @param [String] command command line to execute the script - # @param [Number, String] id action identifier - # @param [String] host hostname where the action is going to be executed - # @param [String, Symbol] aname name of the action - # @param [String] remote_dir path where the remotes reside - # @param [String, nil] std_in input of the string from the STDIN - def remotes_action(command, id, host, aname, remote_dir, std_in=nil) - command_exe = RemotesCommand.run(command, - host, - remote_dir, - log_method(id), - std_in, - @retries) - end - - # Execute a command associated to an action and id on localhost - # - # @param [String] command command line to execute the script - # @param [Number, String] id action identifier - # @param [String, Symbol] aname name of the action - def local_action(command, id, aname) - command_exe = LocalCommand.run(command, log_method(id)) + [result, info] end # Sends a log message to ONE. The +message+ can be multiline, it will @@ -300,6 +180,40 @@ class OpenNebulaDriver < ActionManager loop_thread.kill end + # This function parses a string with this form: + # + # 'deploy,shutdown,poll=poll_ganglia, cancel ' + # + # and returns a hash: + # + # {"POLL"=>"poll_ganglia", "DEPLOY"=>nil, "SHUTDOWN"=>nil, + # "CANCEL"=>nil} + # + # @param [String] str imput string to parse + # @return [Hash] parsed actions + def self.parse_actions_list(str) + actions=Hash.new + str_splitted=str.split(/\s*,\s*/).map {|s| s.strip } + + str_splitted.each do |a| + m=a.match(/([^=]+)(=(.*))?/) + next if !m + + action=m[1].upcase + + if m[2] + script=m[3] + script.strip! if script + else + script=nil + end + + actions[action]=script + end + + actions + end + private def init @@ -332,40 +246,6 @@ private end end end - - def read_configuration - one_config=nil - - if ENV['ONE_LOCATION'] - one_config=ENV['ONE_LOCATION']+'/var/config' - else - one_config='/var/lib/one/config' - end - - config=Hash.new - cfg='' - - begin - open(one_config) do |file| - cfg=file.read - end - - cfg.split(/\n/).each do |line| - m=line.match(/^([^=]+)=(.*)$/) - - if m - name=m[1].strip.upcase - value=m[2].strip - config[name]=value - end - end - rescue Exception => e - STDERR.puts "Error reading config: #{e.inspect}" - STDERR.flush - end - - config - end end ################################################################ diff --git a/src/mad/ruby/ssh_stream.rb b/src/mad/ruby/ssh_stream.rb index 38da9241dc..2ae9167471 100644 --- a/src/mad/ruby/ssh_stream.rb +++ b/src/mad/ruby/ssh_stream.rb @@ -108,7 +108,7 @@ class SshStreamCommand < GenericCommand @host=host super('true', logger, stdin) - @stream=SshStream.new(host) + @stream = SshStream.new(host) @stream.open end @@ -118,18 +118,18 @@ class SshStreamCommand < GenericCommand @stream.exec(command) @stream.stdin.write(stdin) if stdin - code=@stream.wait_for_command + @code = @stream.wait_for_command - @stdout=@stream.out - @stderr=@stream.err + @stdout = @stream.out + @stderr = @stream.err - if code!=0 + if @code != 0 log("Command execution fail: #{command}") end log(@stderr) - return code + return @code end end diff --git a/src/vmm_mad/exec/one_vmm_exec.rb b/src/vmm_mad/exec/one_vmm_exec.rb index 49b34124e9..7a42b35af7 100755 --- a/src/vmm_mad/exec/one_vmm_exec.rb +++ b/src/vmm_mad/exec/one_vmm_exec.rb @@ -123,9 +123,12 @@ class ExecDriver < VirtualMachineDriver dfile=remote_dfile end - ssh=SshStreamCommand.new(host, log_method(id)) - execute_network_script(:pre, ssh, data) + ssh=SshStreamCommand.new(host, log_method(id)) + vnm=crea nuevo driver(:ssh_stream => ssh) + + #execute_network_script(:pre, ssh, data) + vnm.action_pre(data) pp ssh.run("cat << EOT | #{remote_scripts_path}/deploy #{dfile} #{host}", domain+"\nEOT\n") From aee7cf809403154f44d634a75800d647a0cdd76a Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Mon, 21 Nov 2011 19:09:04 +0100 Subject: [PATCH 027/121] feature #863: Added files --- src/mad/ruby/DriverExecHelper.rb | 129 +++++++++++++++++++++++++++++++ src/mad/ruby/StreamDriver.rb | 46 +++++++++++ 2 files changed, 175 insertions(+) create mode 100644 src/mad/ruby/DriverExecHelper.rb create mode 100644 src/mad/ruby/StreamDriver.rb diff --git a/src/mad/ruby/DriverExecHelper.rb b/src/mad/ruby/DriverExecHelper.rb new file mode 100644 index 0000000000..ff43bdbfcd --- /dev/null +++ b/src/mad/ruby/DriverExecHelper.rb @@ -0,0 +1,129 @@ +# -------------------------------------------------------------------------- # +# 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. # +#--------------------------------------------------------------------------- # + + +# This module provides an abstraction to generate an execution context for +# OpenNebula Drivers +module DriverExecHelper + #Initialize module variables + def initialize_helper(directory, options) + @config = read_configuration + @remote_scripts_base_path = @config['SCRIPTS_REMOTE_DIR'] + + @local_actions = options[:local_actions] + + if ENV['ONE_LOCATION'] == nil + @local_scripts_base_path = "/var/lib/one/remotes" + else + @local_scripts_base_path = "#{ENV['ONE_LOCATION']}/var/remotes" + end + + # dummy paths + @remote_scripts_path = File.join(@remote_scripts_base_path, directory) + @local_scripts_path = File.join(@local_scripts_base_path, directory) + end + + # Given the action name and the parameter returns full path of the script + # and appends its parameters. It uses @local_actions hash to know if the + # actions is remote or local. If the local actions has defined an special + # script name this is used, otherwise the action name in downcase is + # used as the script name. + # + # @param [String, Symbol] action name of the action + # @param [String] parameters arguments for the script + # @param [String, nil] default_name alternative name for the script + # @return [String] command line needed to execute the action + def action_command_line(action, parameters, default_name=nil) + if action_is_local? action + script_path=@local_scripts_path + else + script_path=@remote_scripts_path + end + + File.join(script_path, action_script_name(action, default_name))+ + " "+parameters + end + + # True if the action is meant to be executed locally + # + # @param [String, Symbol] action name of the action + def action_is_local?(action) + @local_actions.include? action.to_s.upcase + end + + # Name of the script file for the given action + # + # @param [String, Symbol] action name of the action + # @param [String, nil] default_name alternative name for the script + def action_script_name(action, default_name=nil) + name=@local_actions[action.to_s.upcase] + + if name + name + else + default_name || action.to_s.downcase + end + end + + def get_info_from_execution(command_exe) + if command_exe.code == 0 + result = RESULT[:success] + info = command_exe.stdout + else + result = RESULT[:failure] + info = command_exe.get_error_message + end + + info = "-" if info == nil || info.empty? + + [result, info] + end + + # Simple parser for the config file generated by OpenNebula + def read_configuration + one_config=nil + + if ENV['ONE_LOCATION'] + one_config=ENV['ONE_LOCATION']+'/var/config' + else + one_config='/var/lib/one/config' + end + + config=Hash.new + cfg='' + + begin + open(one_config) do |file| + cfg=file.read + end + + cfg.split(/\n/).each do |line| + m=line.match(/^([^=]+)=(.*)$/) + + if m + name=m[1].strip.upcase + value=m[2].strip + config[name]=value + end + end + rescue Exception => e + STDERR.puts "Error reading config: #{e.inspect}" + STDERR.flush + end + + config + end +end \ No newline at end of file diff --git a/src/mad/ruby/StreamDriver.rb b/src/mad/ruby/StreamDriver.rb new file mode 100644 index 0000000000..e07b8ef428 --- /dev/null +++ b/src/mad/ruby/StreamDriver.rb @@ -0,0 +1,46 @@ +# -------------------------------------------------------------------------- # +# 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. # +#--------------------------------------------------------------------------- # + + +# This module provides an abstraction to generate an execution context for +# OpenNebula Drivers + +class VirtualNetworkDriver + include DriverExecHelper + + def initialize(directory, options={}) + + @options = options + @ssh_stream = options[:ssh_stream] + + + initialize_helper("vnet/#{directory}", options) + end + + def do_action(parameters, aname) + vm_encoded = Base64.encode64(message.elements['VM'].to_s).delete("\n") + + command = action_command_line(aname, @vm_encoded, options[:script_name]) + + if action_is_local? aname + execution = LocalCommand.run(command, log_method(id)) + else + execution = @ssh_stream.run(command) + end + + result, info = get_info_from_execution(command_exe) + end +end From c061648b62e1bc8f70afde5c6c6231057ba4a620 Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Mon, 21 Nov 2011 19:29:21 +0100 Subject: [PATCH 028/121] feature #863: changed StreamSriver to one_vnm --- src/{mad/ruby/StreamDriver.rb => vnm_mad/one_vnm.rb} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/{mad/ruby/StreamDriver.rb => vnm_mad/one_vnm.rb} (100%) diff --git a/src/mad/ruby/StreamDriver.rb b/src/vnm_mad/one_vnm.rb similarity index 100% rename from src/mad/ruby/StreamDriver.rb rename to src/vnm_mad/one_vnm.rb From 9624dd4b034c9a859583d4e1ddf5b8fe241c4864 Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Tue, 22 Nov 2011 11:01:18 +0100 Subject: [PATCH 029/121] changes to vnm_driver --- src/mad/ruby/DriverExecHelper.rb | 6 +++--- src/vnm_mad/one_vnm.rb | 23 ++++++++++++----------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/mad/ruby/DriverExecHelper.rb b/src/mad/ruby/DriverExecHelper.rb index ff43bdbfcd..d857dec8ab 100644 --- a/src/mad/ruby/DriverExecHelper.rb +++ b/src/mad/ruby/DriverExecHelper.rb @@ -78,7 +78,7 @@ module DriverExecHelper end end - def get_info_from_execution(command_exe) + def get_info_from_execution(command_exe) if command_exe.code == 0 result = RESULT[:success] info = command_exe.stdout @@ -90,7 +90,7 @@ module DriverExecHelper info = "-" if info == nil || info.empty? [result, info] - end + end # Simple parser for the config file generated by OpenNebula def read_configuration @@ -126,4 +126,4 @@ module DriverExecHelper config end -end \ No newline at end of file +end diff --git a/src/vnm_mad/one_vnm.rb b/src/vnm_mad/one_vnm.rb index e07b8ef428..586f24c7eb 100644 --- a/src/vnm_mad/one_vnm.rb +++ b/src/vnm_mad/one_vnm.rb @@ -19,21 +19,21 @@ # OpenNebula Drivers class VirtualNetworkDriver - include DriverExecHelper + include DriverExecHelper - def initialize(directory, options={}) + def initialize(directory, options={}) - @options = options - @ssh_stream = options[:ssh_stream] + @options = options + @ssh_stream = options[:ssh_stream] + @message = options[:message] + @vm_encoded = Base64.encode64(@message.elements['VM'].to_s).delete("\n") - initialize_helper("vnet/#{directory}", options) - end + initialize_helper("vnet/#{directory}", options) + end - def do_action(parameters, aname) - vm_encoded = Base64.encode64(message.elements['VM'].to_s).delete("\n") - - command = action_command_line(aname, @vm_encoded, options[:script_name]) + def do_action(parameters, aname) + command = action_command_line(aname, @vm_encoded, options[:script_name]) if action_is_local? aname execution = LocalCommand.run(command, log_method(id)) @@ -42,5 +42,6 @@ class VirtualNetworkDriver end result, info = get_info_from_execution(command_exe) - end + end end + From 122bd19678d538f7de20d722ac7a6b0ed518ab8d Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Tue, 22 Nov 2011 12:08:56 +0100 Subject: [PATCH 030/121] feature #863: Increased buffer read to 80, in ssh streamer --- src/mad/ruby/ssh_stream.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mad/ruby/ssh_stream.rb b/src/mad/ruby/ssh_stream.rb index 2ae9167471..b2e9595a4a 100644 --- a/src/mad/ruby/ssh_stream.rb +++ b/src/mad/ruby/ssh_stream.rb @@ -65,7 +65,7 @@ class SshStream rc, rw, = IO.select([@stdout, @stderr],[],[]) rc.each { |fd| - c = fd.read_nonblock(1) + c = fd.read_nonblock(80) if !c done = true From 7d89b719a59a5f563674e5d75681331cbcee2da6 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Tue, 22 Nov 2011 12:09:41 +0100 Subject: [PATCH 031/121] feature #863: Moved RESULT constants to base module for get_info_from_execution --- src/mad/ruby/DriverExecHelper.rb | 14 +++++++++++--- src/mad/ruby/OpenNebulaDriver.rb | 7 ------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/mad/ruby/DriverExecHelper.rb b/src/mad/ruby/DriverExecHelper.rb index d857dec8ab..9ea245f8c6 100644 --- a/src/mad/ruby/DriverExecHelper.rb +++ b/src/mad/ruby/DriverExecHelper.rb @@ -16,8 +16,15 @@ # This module provides an abstraction to generate an execution context for -# OpenNebula Drivers +# OpenNebula Drivers. The module has been designed to be included as part +# of a driver and not to be used standalone. module DriverExecHelper + # Action result strings for messages + RESULT = { + :success => "SUCCESS", + :failure => "FAILURE" + } + #Initialize module variables def initialize_helper(directory, options) @config = read_configuration @@ -78,6 +85,7 @@ module DriverExecHelper end end + #This method returns the result in terms def get_info_from_execution(command_exe) if command_exe.code == 0 result = RESULT[:success] @@ -97,9 +105,9 @@ module DriverExecHelper one_config=nil if ENV['ONE_LOCATION'] - one_config=ENV['ONE_LOCATION']+'/var/config' + one_config = ENV['ONE_LOCATION']+'/var/config' else - one_config='/var/lib/one/config' + one_config = '/var/lib/one/config' end config=Hash.new diff --git a/src/mad/ruby/OpenNebulaDriver.rb b/src/mad/ruby/OpenNebulaDriver.rb index 4833d7bdd4..174e65a9db 100644 --- a/src/mad/ruby/OpenNebulaDriver.rb +++ b/src/mad/ruby/OpenNebulaDriver.rb @@ -37,13 +37,6 @@ class OpenNebulaDriver < ActionManager # @return [String] Path for scripts attr_reader :local_scripts_path, :remote_scripts_path - - # Action result strings for messages - RESULT = { - :success => "SUCCESS", - :failure => "FAILURE" - } - # Initialize OpenNebulaDriver object # # @param [String] directory path inside the remotes directory where the From 0143a6d5204081e7a1f032e8d7afe28fc98e0ae7 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Tue, 22 Nov 2011 12:19:26 +0100 Subject: [PATCH 032/121] feature #863: Moved Log methods to base driver module --- src/mad/ruby/DriverExecHelper.rb | 56 +++++++++++++++++++++++++++++++- src/mad/ruby/OpenNebulaDriver.rb | 51 ++--------------------------- 2 files changed, 58 insertions(+), 49 deletions(-) diff --git a/src/mad/ruby/DriverExecHelper.rb b/src/mad/ruby/DriverExecHelper.rb index 9ea245f8c6..d3d440b7d3 100644 --- a/src/mad/ruby/DriverExecHelper.rb +++ b/src/mad/ruby/DriverExecHelper.rb @@ -42,7 +42,10 @@ module DriverExecHelper @remote_scripts_path = File.join(@remote_scripts_base_path, directory) @local_scripts_path = File.join(@local_scripts_base_path, directory) end - + + # + # METHODS FOR COMMAND LINE & ACTION PATHS + # # Given the action name and the parameter returns full path of the script # and appends its parameters. It uses @local_actions hash to know if the # actions is remote or local. If the local actions has defined an special @@ -85,6 +88,55 @@ module DriverExecHelper end end + # + # METHODS FOR LOGS & COMMAND OUTPUT + # + # Sends a log message to ONE. The +message+ can be multiline, it will + # be automatically splitted by lines. + def log(number, message) + in_error_message=false + msg=message.strip + msg.each_line {|line| + severity='I' + + l=line.strip + + if l=='ERROR MESSAGE --8<------' + in_error_message=true + next + elsif l=='ERROR MESSAGE ------>8--' + in_error_message=false + next + else + if in_error_message + severity='E' + elsif line.match(/^(ERROR|DEBUG|INFO):(.*)$/) + line=$2 + case $1 + when 'ERROR' + severity='E' + when 'DEBUG' + severity='D' + when 'INFO' + severity='I' + else + severity='I' + end + end + end + + send_message("LOG", severity, number, line.strip) + } + end + + # Generates a proc with that calls log with a hardcoded number. It will + # be used to add loging to command actions + def log_method(num) + lambda {|message| + log(num, message) + } + end + #This method returns the result in terms def get_info_from_execution(command_exe) if command_exe.code == 0 @@ -100,6 +152,8 @@ module DriverExecHelper [result, info] end + # + # # Simple parser for the config file generated by OpenNebula def read_configuration one_config=nil diff --git a/src/mad/ruby/OpenNebulaDriver.rb b/src/mad/ruby/OpenNebulaDriver.rb index 174e65a9db..117706ae89 100644 --- a/src/mad/ruby/OpenNebulaDriver.rb +++ b/src/mad/ruby/OpenNebulaDriver.rb @@ -88,6 +88,7 @@ class OpenNebulaDriver < ActionManager # @option ops [String] :stdin text to be writen to stdin # @option ops [String] :script_name default script name for the action, # action name is used by defaults + # @option ops [String] :respond if defined will send result to ONE core def do_action(parameters, id, host, aname, ops={}) options={ :stdin => nil, @@ -95,9 +96,9 @@ class OpenNebulaDriver < ActionManager :respond => true }.merge(ops) - params=parameters+" #{id} #{host}" + params = parameters+" #{id} #{host}" - command=action_command_line(aname, params, options[:script_name]) + command = action_command_line(aname, params, options[:script_name]) if ops[:local] || action_is_local? aname execution = LocalCommand.run(command, log_method(id)) @@ -119,52 +120,6 @@ class OpenNebulaDriver < ActionManager [result, info] end - # Sends a log message to ONE. The +message+ can be multiline, it will - # be automatically splitted by lines. - def log(number, message) - in_error_message=false - msg=message.strip - msg.each_line {|line| - severity='I' - - l=line.strip - - if l=='ERROR MESSAGE --8<------' - in_error_message=true - next - elsif l=='ERROR MESSAGE ------>8--' - in_error_message=false - next - else - if in_error_message - severity='E' - elsif line.match(/^(ERROR|DEBUG|INFO):(.*)$/) - line=$2 - case $1 - when 'ERROR' - severity='E' - when 'DEBUG' - severity='D' - when 'INFO' - severity='I' - else - severity='I' - end - end - end - - send_message("LOG", severity, number, line.strip) - } - end - - # Generates a proc with that calls log with a hardcoded number. It will - # be used to add loging to command actions - def log_method(num) - lambda {|message| - log(num, message) - } - end - # Start the driver. Reads from STDIN and executes methods associated with # the messages def start_driver From 594f49505038458f5307fb168cdad5a90448ff9f Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Tue, 22 Nov 2011 12:44:37 +0100 Subject: [PATCH 033/121] feature #863: Fixes var name --- src/mad/ruby/OpenNebulaDriver.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/mad/ruby/OpenNebulaDriver.rb b/src/mad/ruby/OpenNebulaDriver.rb index 117706ae89..bf2ebcede2 100644 --- a/src/mad/ruby/OpenNebulaDriver.rb +++ b/src/mad/ruby/OpenNebulaDriver.rb @@ -89,6 +89,7 @@ class OpenNebulaDriver < ActionManager # @option ops [String] :script_name default script name for the action, # action name is used by defaults # @option ops [String] :respond if defined will send result to ONE core + # @option ops [String] :local if defined will execute the action locally def do_action(parameters, id, host, aname, ops={}) options={ :stdin => nil, @@ -111,7 +112,7 @@ class OpenNebulaDriver < ActionManager @retries) end - result, info = get_info_from_execution(command_exe) + result, info = get_info_from_execution(execution) if ops[:respond] send_message(aname,result,id,info) From e4cae17f92cc3ca583ea43a3c0b4bfcd8ee628fe Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Tue, 22 Nov 2011 12:44:51 +0100 Subject: [PATCH 034/121] feature #863: Add support to stdin to the VirtualNetwork driver --- src/vnm_mad/one_vnm.rb | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/src/vnm_mad/one_vnm.rb b/src/vnm_mad/one_vnm.rb index 586f24c7eb..a48a374e20 100644 --- a/src/vnm_mad/one_vnm.rb +++ b/src/vnm_mad/one_vnm.rb @@ -21,6 +21,10 @@ class VirtualNetworkDriver include DriverExecHelper + # Inits the VNET Driver + # @param [String] name of the vnet driver to use, as listed in remotes/vnet + # @option ops [String] :ssh_stream to be used for command execution + # @option ops [String] :message from ONE def initialize(directory, options={}) @options = options @@ -32,16 +36,33 @@ class VirtualNetworkDriver initialize_helper("vnet/#{directory}", options) end - def do_action(parameters, aname) - command = action_command_line(aname, @vm_encoded, options[:script_name]) + # Calls remotes or local action checking the action name and + # @local_actions. Optional arguments can be specified as a hash + # + # @param [Number, String] id action identifier + # @param [String, Symbol] aname name of the action + # @param [Hash] ops extra options for the command + # @option ops [String] :stdin text to be writen to stdin + def do_action(id, aname, ops = {}) + options={ + :stdin => nil, + }.merge(ops) + + command = action_command_line(aname, @vm_encoded) if action_is_local? aname execution = LocalCommand.run(command, log_method(id)) else - execution = @ssh_stream.run(command) + if options[:stdin] + command = "cat << EOT | #{command}" + stdin = "#{options[:stdin]\nEOT\n}" + else + stdin = nil + end + + execution = @ssh_stream.run(command,stdin) end - result, info = get_info_from_execution(command_exe) + result, info = get_info_from_execution(execution) end -end - +end \ No newline at end of file From 300f2a6633ca3dde5ccbccf8b303983b77a8f8db Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Tue, 22 Nov 2011 12:52:33 +0100 Subject: [PATCH 035/121] feature #863: Adds support for ssh_streams to OpenNebulaDriver --- src/mad/ruby/OpenNebulaDriver.rb | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/mad/ruby/OpenNebulaDriver.rb b/src/mad/ruby/OpenNebulaDriver.rb index bf2ebcede2..549a91614e 100644 --- a/src/mad/ruby/OpenNebulaDriver.rb +++ b/src/mad/ruby/OpenNebulaDriver.rb @@ -92,17 +92,27 @@ class OpenNebulaDriver < ActionManager # @option ops [String] :local if defined will execute the action locally def do_action(parameters, id, host, aname, ops={}) options={ - :stdin => nil, + :stdin => nil, :script_name => nil, - :respond => true + :respond => true, + :ssh_stream => nil }.merge(ops) params = parameters+" #{id} #{host}" - command = action_command_line(aname, params, options[:script_name]) - if ops[:local] || action_is_local? aname + if options[:local] || action_is_local? aname execution = LocalCommand.run(command, log_method(id)) + elsif options[:ssh_stream] + if options[:stdin] + command = "cat << EOT | #{command}" + stdin = "#{options[:stdin]\nEOT\n}" + else + stdin = nil + end + + execution = options[:ssh_stream].run(command,stdin) + else execution = RemotesCommand.run(command, host, @@ -114,13 +124,14 @@ class OpenNebulaDriver < ActionManager result, info = get_info_from_execution(execution) - if ops[:respond] + if options[:respond] send_message(aname,result,id,info) end [result, info] end + # Start the driver. Reads from STDIN and executes methods associated with # the messages def start_driver From fa0cdade1dc871c706a162f19777efa34c771d6a Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Tue, 22 Nov 2011 13:15:09 +0100 Subject: [PATCH 036/121] feature #863: Use new VirtualNetworkDriver & VM Driver --- src/mad/ruby/DriverExecHelper.rb | 4 ++ src/vmm_mad/exec/one_vmm_exec.rb | 98 +++++++++++--------------------- 2 files changed, 37 insertions(+), 65 deletions(-) diff --git a/src/mad/ruby/DriverExecHelper.rb b/src/mad/ruby/DriverExecHelper.rb index d3d440b7d3..478ab49260 100644 --- a/src/mad/ruby/DriverExecHelper.rb +++ b/src/mad/ruby/DriverExecHelper.rb @@ -25,6 +25,10 @@ module DriverExecHelper :failure => "FAILURE" } + def failed?(rc_str) + return rc_str == RESULT[:failure] + end + #Initialize module variables def initialize_helper(directory, options) @config = read_configuration diff --git a/src/vmm_mad/exec/one_vmm_exec.rb b/src/vmm_mad/exec/one_vmm_exec.rb index 7a42b35af7..42be7534cc 100755 --- a/src/vmm_mad/exec/one_vmm_exec.rb +++ b/src/vmm_mad/exec/one_vmm_exec.rb @@ -52,60 +52,14 @@ class ExecDriver < VirtualMachineDriver @hypervisor = hypervisor end - # network script actions - - def execute_network_script(action, connection, message) - driver=message.elements['NET_DRV'].text - id=message.elements['VM/ID'].text - - vm_encoded=Base64.encode64(message.elements['VM'].to_s).delete("\n") - - result=[false, ''] - - if(action_is_local?(action.to_s)) - script_path=File.join( - @local_scripts_base_path, - 'vnm', - driver, - action.to_s) - - command="#{script_path} #{vm_encoded}" - - command_exe = LocalCommand.run(command, log_method(id)) - - code=(command_exe.code==0) - - result=[code, command_exe] - else - script_path=File.join( - @remote_scripts_base_path, - 'vnm', - driver, - action.to_s) - - command="#{script_path} #{vm_encoded}" - - pp command - - error_code=connection.run(command) - - pp error_code - pp connection.stderr - - code=(error_code==0) - - result=[code, connection] - end - end - - # DEPLOY action, sends the deployment file to remote host def deploy(id, drv_message) data = decode(drv_message) - local_dfile = data.elements['LOCAL_DEPLOYMENT_FILE'].text + local_dfile = data.elements['LOCAL_DEPLOYMENT_FILE'].text remote_dfile = data.elements['REMOTE_DEPLOYMENT_FILE'].text - host= data.elements['HOST'].text + + host = data.elements['HOST'].text if !local_dfile || File.zero?(local_dfile) send_message(ACTION[:deploy],RESULT[:failure],id, @@ -113,33 +67,47 @@ class ExecDriver < VirtualMachineDriver return end - tmp = File.new(local_dfile) - domain = tmp.read - tmp.close() + domain = File.read(local_dfile) if action_is_local?(:deploy) - dfile=local_dfile + dfile = local_dfile else - dfile=remote_dfile + dfile = remote_dfile end + ssh = SshStreamCommand.new(host, log_method(id)) + vnm = VirtualNetworkDriver.new(data.elements['NET_DRV'].text, + :local_actions => @options[:local_actions], + :message => data, + :ssh_stream => ssh) + + result, info = vnm.do_action(id, :pre) - ssh=SshStreamCommand.new(host, log_method(id)) - vnm=crea nuevo driver(:ssh_stream => ssh) + if failed?(result) + send_message(:deploy,result,id,info) + return + end - #execute_network_script(:pre, ssh, data) - vnm.action_pre(data) + result, info = do_action("#{dfile} #{host}", id, host, :deploy, + :stdin => domain, + :ssh_stream => ssh, + :respond => false) - pp ssh.run("cat << EOT | #{remote_scripts_path}/deploy #{dfile} #{host}", - domain+"\nEOT\n") + if failed?(result) + send_message(:deploy,result,id,info) + return + end - execute_network_script(:post, ssh, data) + domain_id = info - pp ssh.stdout - pp ssh.stderr + result, info = vnm.do_action(id, :post) - #do_action("#{dfile} #{host}", id, host, :deploy, - # :stdin => domain) + if failed?(result) + send_message(:deploy,result,id,info) + return + end + + send_message(:deploy,RESULT[:success],id,domain_id) end # Basic Domain Management Operations From 041e58bbf4e2b908ced67225463874364d312c93 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Tue, 22 Nov 2011 13:35:46 +0100 Subject: [PATCH 037/121] feature #863: Use action names in messages --- src/vmm_mad/exec/one_vmm_exec.rb | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/vmm_mad/exec/one_vmm_exec.rb b/src/vmm_mad/exec/one_vmm_exec.rb index 42be7534cc..a9e012f0fb 100755 --- a/src/vmm_mad/exec/one_vmm_exec.rb +++ b/src/vmm_mad/exec/one_vmm_exec.rb @@ -84,30 +84,28 @@ class ExecDriver < VirtualMachineDriver result, info = vnm.do_action(id, :pre) if failed?(result) - send_message(:deploy,result,id,info) + send_message(ACTION[:deploy],result,id,info) return end - result, info = do_action("#{dfile} #{host}", id, host, :deploy, - :stdin => domain, - :ssh_stream => ssh, - :respond => false) - + result, domain_id = do_action("#{dfile} #{host}", id, host, :deploy, + :stdin => domain, + :ssh_stream => ssh, + :respond => false) if failed?(result) - send_message(:deploy,result,id,info) + send_message(ACTION[:deploy],result,id,info) return end - domain_id = info - result, info = vnm.do_action(id, :post) + #TODO: Need to rollback (VM is running) or send success and log error if failed?(result) - send_message(:deploy,result,id,info) + send_message(ACTION[:deploy],result,id,info) return end - send_message(:deploy,RESULT[:success],id,domain_id) + send_message(ACTION[:deploy],RESULT[:success],id,domain_id) end # Basic Domain Management Operations From 36127a584a21678363f4436dd6674af123efa5f0 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Tue, 22 Nov 2011 13:49:41 +0100 Subject: [PATCH 038/121] feature #863: Fix syntax errors --- install.sh | 3 +++ src/mad/ruby/DriverExecHelper.rb | 1 - src/mad/ruby/OpenNebulaDriver.rb | 6 ++++-- src/mad/ruby/ssh_stream.rb | 15 +++++++++++++++ src/vmm_mad/exec/one_vmm_exec.rb | 4 +--- src/vnm_mad/one_vnm.rb | 5 +++-- 6 files changed, 26 insertions(+), 8 deletions(-) diff --git a/install.sh b/install.sh index 310a15af65..151e6fcd5e 100755 --- a/install.sh +++ b/install.sh @@ -507,6 +507,9 @@ RUBY_LIB_FILES="src/mad/ruby/ActionManager.rb \ src/mad/ruby/CommandManager.rb \ src/mad/ruby/OpenNebulaDriver.rb \ src/mad/ruby/VirtualMachineDriver.rb \ + src/mad/ruby/DriverExecHelper.rb \ + src/mad/ruby/ssh_stream.rb \ + src/vnm_mad/one_vnm.rb \ src/mad/ruby/Ganglia.rb \ src/oca/ruby/OpenNebula.rb \ src/tm_mad/TMScript.rb \ diff --git a/src/mad/ruby/DriverExecHelper.rb b/src/mad/ruby/DriverExecHelper.rb index 478ab49260..37581568fd 100644 --- a/src/mad/ruby/DriverExecHelper.rb +++ b/src/mad/ruby/DriverExecHelper.rb @@ -14,7 +14,6 @@ # limitations under the License. # #--------------------------------------------------------------------------- # - # This module provides an abstraction to generate an execution context for # OpenNebula Drivers. The module has been designed to be included as part # of a driver and not to be used standalone. diff --git a/src/mad/ruby/OpenNebulaDriver.rb b/src/mad/ruby/OpenNebulaDriver.rb index 549a91614e..5e8f6126a3 100644 --- a/src/mad/ruby/OpenNebulaDriver.rb +++ b/src/mad/ruby/OpenNebulaDriver.rb @@ -17,6 +17,8 @@ require "ActionManager" require "CommandManager" +require "DriverExecHelper" + # Author:: dsa-research.org # Copyright:: (c) OpenNebula Project Leads (OpenNebula.org) # License:: Apache License @@ -101,12 +103,12 @@ class OpenNebulaDriver < ActionManager params = parameters+" #{id} #{host}" command = action_command_line(aname, params, options[:script_name]) - if options[:local] || action_is_local? aname + if options[:local] || action_is_local?(aname) execution = LocalCommand.run(command, log_method(id)) elsif options[:ssh_stream] if options[:stdin] command = "cat << EOT | #{command}" - stdin = "#{options[:stdin]\nEOT\n}" + stdin = "#{options[:stdin]}\nEOT\n" else stdin = nil end diff --git a/src/mad/ruby/ssh_stream.rb b/src/mad/ruby/ssh_stream.rb index b2e9595a4a..c67988b5d9 100644 --- a/src/mad/ruby/ssh_stream.rb +++ b/src/mad/ruby/ssh_stream.rb @@ -1,3 +1,18 @@ +# -------------------------------------------------------------------------- # +# 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 'CommandManager' require 'open3' diff --git a/src/vmm_mad/exec/one_vmm_exec.rb b/src/vmm_mad/exec/one_vmm_exec.rb index a9e012f0fb..4203210a24 100755 --- a/src/vmm_mad/exec/one_vmm_exec.rb +++ b/src/vmm_mad/exec/one_vmm_exec.rb @@ -1,6 +1,5 @@ #!/usr/bin/env ruby - # -------------------------------------------------------------------------- # # Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org) # # # @@ -17,7 +16,6 @@ # limitations under the License. # #--------------------------------------------------------------------------- # - # Set up the environment for the driver ONE_LOCATION = ENV["ONE_LOCATION"] @@ -33,9 +31,9 @@ end $: << RUBY_LIB_LOCATION require "VirtualMachineDriver" +require 'one_vnm' require 'getoptlong' -require 'ssh_stream' require 'pp' # The main class for the Sh driver diff --git a/src/vnm_mad/one_vnm.rb b/src/vnm_mad/one_vnm.rb index a48a374e20..4847c4deea 100644 --- a/src/vnm_mad/one_vnm.rb +++ b/src/vnm_mad/one_vnm.rb @@ -14,6 +14,7 @@ # limitations under the License. # #--------------------------------------------------------------------------- # +require "DriverExecHelper" # This module provides an abstraction to generate an execution context for # OpenNebula Drivers @@ -50,12 +51,12 @@ class VirtualNetworkDriver command = action_command_line(aname, @vm_encoded) - if action_is_local? aname + if action_is_local?(aname) execution = LocalCommand.run(command, log_method(id)) else if options[:stdin] command = "cat << EOT | #{command}" - stdin = "#{options[:stdin]\nEOT\n}" + stdin = "#{options[:stdin]}\nEOT\n" else stdin = nil end From 82a78bb9a60e2130139a1608f415296981207a05 Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Thu, 24 Nov 2011 18:31:07 +0100 Subject: [PATCH 039/121] feature #863: write 100 byte blocks to ssh so the pipe is not filled --- src/mad/ruby/ssh_stream.rb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/mad/ruby/ssh_stream.rb b/src/mad/ruby/ssh_stream.rb index c67988b5d9..d055c33c9d 100644 --- a/src/mad/ruby/ssh_stream.rb +++ b/src/mad/ruby/ssh_stream.rb @@ -63,7 +63,16 @@ class SshStream @err = "" begin - @stdin.write "(#{command}); #{EOF_CMD}\n" + cmd="(#{command}); #{EOF_CMD}\n" + + sliced=cmd.scan(/.{1,100}/) + + sliced.each do |slice| + @stdin.write slice + @stdin.flush + end + + @stdin.puts @stdin.flush rescue From c04e4da220fb39f8c13b3709366281dbf1735f00 Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Thu, 24 Nov 2011 18:32:25 +0100 Subject: [PATCH 040/121] feature #863: bug fixes and cosmetic changes --- src/mad/ruby/ssh_stream.rb | 10 +++++++--- src/vmm_mad/exec/one_vmm_exec.rb | 1 + src/vnm_mad/one_vnm.rb | 6 +++--- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/mad/ruby/ssh_stream.rb b/src/mad/ruby/ssh_stream.rb index d055c33c9d..6feb379752 100644 --- a/src/mad/ruby/ssh_stream.rb +++ b/src/mad/ruby/ssh_stream.rb @@ -86,10 +86,14 @@ class SshStream code = -1 while not (done_out and done_err) - rc, rw, = IO.select([@stdout, @stderr],[],[]) + rc, rw, re= IO.select([@stdout, @stderr],[],[]) rc.each { |fd| - c = fd.read_nonblock(80) + begin + c = fd.read_nonblock(50) + rescue EOFError => e + next + end if !c done = true @@ -153,7 +157,7 @@ class SshStreamCommand < GenericCommand log(@stderr) - return @code + return self end end diff --git a/src/vmm_mad/exec/one_vmm_exec.rb b/src/vmm_mad/exec/one_vmm_exec.rb index 4203210a24..83043836d1 100755 --- a/src/vmm_mad/exec/one_vmm_exec.rb +++ b/src/vmm_mad/exec/one_vmm_exec.rb @@ -33,6 +33,7 @@ $: << RUBY_LIB_LOCATION require "VirtualMachineDriver" require 'one_vnm' require 'getoptlong' +require 'ssh_stream' require 'pp' diff --git a/src/vnm_mad/one_vnm.rb b/src/vnm_mad/one_vnm.rb index 4847c4deea..a5f069b1c5 100644 --- a/src/vnm_mad/one_vnm.rb +++ b/src/vnm_mad/one_vnm.rb @@ -34,7 +34,7 @@ class VirtualNetworkDriver @vm_encoded = Base64.encode64(@message.elements['VM'].to_s).delete("\n") - initialize_helper("vnet/#{directory}", options) + initialize_helper("vnm/#{directory}", options) end # Calls remotes or local action checking the action name and @@ -61,9 +61,9 @@ class VirtualNetworkDriver stdin = nil end - execution = @ssh_stream.run(command,stdin) + execution = @ssh_stream.run(command, stdin) end result, info = get_info_from_execution(execution) end -end \ No newline at end of file +end From 93fbaab0c956077b5be916a51d9af8436ee75d6d Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Thu, 24 Nov 2011 18:33:52 +0100 Subject: [PATCH 041/121] feature #863: detect ssh errors --- src/mad/ruby/ssh_stream.rb | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/mad/ruby/ssh_stream.rb b/src/mad/ruby/ssh_stream.rb index 6feb379752..7679f7e757 100644 --- a/src/mad/ruby/ssh_stream.rb +++ b/src/mad/ruby/ssh_stream.rb @@ -26,6 +26,7 @@ class SshStream EOF_ERR = "EOF_ERR" EOF_OUT = "EOF_OUT" RC_STR = "ExitCode: " + SSH_RC_STR = "ExitSSHCode: " EOF_CMD = "echo \"#{RC_STR}$?#{EOF_ERR}\" 1>&2; echo \"#{EOF_OUT}\"" SSH_CMD = "ssh" @@ -41,7 +42,7 @@ class SshStream end def open - @stdin, @stdout, @stderr=Open3::popen3("#{SSH_CMD} #{@host} bash -s") + @stdin, @stdout, @stderr=Open3::popen3("#{SSH_CMD} #{@host} bash -s ; echo #{SSH_RC_STR} $? 1>&2") @stream_out = "" @stream_err = "" @@ -106,13 +107,23 @@ class SshStream else @err << c - tmp = @err.scan(/^#{RC_STR}(\d*)#{EOF_ERR}\n/) + tmp = @err.scan(/^#{SSH_RC_STR}(\d+)$/) + + if tmp[0] + @err << "\n" + @err << "ERROR MESSAGE --8<------\n" + @err << "Error connecting to #{@host}\n" + @err << "ERROR MESSAGE ------>8--\n" + return tmp[0][0].to_i + end + + tmp = @err.scan(/^#{RC_STR}(\d*) #{EOF_ERR}\n/) if tmp[0] code = tmp[0][0].to_i done_err = true - @err.slice!("#{EOF_ERR}\n") + @err.slice!(" #{EOF_ERR}\n") end end } From 1a1529390387635e4cb25d16d6d9ab4fd7053a32 Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Thu, 24 Nov 2011 18:35:30 +0100 Subject: [PATCH 042/121] feature #863: make end of stderr tag more readable --- src/mad/ruby/ssh_stream.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/mad/ruby/ssh_stream.rb b/src/mad/ruby/ssh_stream.rb index 7679f7e757..664a469b20 100644 --- a/src/mad/ruby/ssh_stream.rb +++ b/src/mad/ruby/ssh_stream.rb @@ -17,6 +17,7 @@ require 'CommandManager' require 'open3' + class SshStream attr_reader :stream_out, :stream_err, :stdin attr_reader :out, :err @@ -28,7 +29,7 @@ class SshStream RC_STR = "ExitCode: " SSH_RC_STR = "ExitSSHCode: " - EOF_CMD = "echo \"#{RC_STR}$?#{EOF_ERR}\" 1>&2; echo \"#{EOF_OUT}\"" + EOF_CMD = "echo \"#{RC_STR}$? #{EOF_ERR}\" 1>&2; echo \"#{EOF_OUT}\"" SSH_CMD = "ssh" # # From 800ee164cf913ca6ca8ac212782dc3ee8946f6eb Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Fri, 25 Nov 2011 00:30:58 +0100 Subject: [PATCH 043/121] feature #863: uses scripts_common for error_messages, added more rescue if ssh command fails. --- src/mad/ruby/scripts_common.rb | 13 +++++++++--- src/mad/ruby/ssh_stream.rb | 38 +++++++++++++++++----------------- 2 files changed, 29 insertions(+), 22 deletions(-) diff --git a/src/mad/ruby/scripts_common.rb b/src/mad/ruby/scripts_common.rb index ba24205e20..8251ae48ff 100644 --- a/src/mad/ruby/scripts_common.rb +++ b/src/mad/ruby/scripts_common.rb @@ -43,11 +43,18 @@ module OpenNebula # This function is used to pass error message to the mad def self.error_message(message) - STDERR.puts "ERROR MESSAGE --8<------" - STDERR.puts message - STDERR.puts "ERROR MESSAGE ------>8--" + STDERR.puts format_error_message(message) end + #This function formats an error message for OpenNebula Copyright e + def self.format_error_message(message) + error_str = "ERROR MESSAGE --8<------\n" + error_str << message + error_str << "\nERROR MESSAGE ------>8--" + + return error_str + end + # Executes a command, if it fails returns error message and exits # If a second parameter is present it is used as the error message when # the command fails diff --git a/src/mad/ruby/ssh_stream.rb b/src/mad/ruby/ssh_stream.rb index 664a469b20..b0de36b72f 100644 --- a/src/mad/ruby/ssh_stream.rb +++ b/src/mad/ruby/ssh_stream.rb @@ -16,7 +16,7 @@ require 'CommandManager' require 'open3' - +require 'scripts_common' class SshStream attr_reader :stream_out, :stream_err, :stdin @@ -53,7 +53,10 @@ class SshStream end def close - @stdin.puts "\nexit" + begin + @stdin.puts "\nexit" + rescue #rescue from EPIPE if ssh command exited already + end @stdin.close if not @stdin.closed? @stdout.close if not @stdout.closed? @@ -93,15 +96,11 @@ class SshStream rc.each { |fd| begin c = fd.read_nonblock(50) - rescue EOFError => e + next if !c + rescue #rescue from EOF if ssh command finishes and closes fds next end - - if !c - done = true - break - end - + if fd == @stdout @out << c done_out = true if @out.slice!("#{EOF_OUT}\n") @@ -111,11 +110,14 @@ class SshStream tmp = @err.scan(/^#{SSH_RC_STR}(\d+)$/) if tmp[0] - @err << "\n" - @err << "ERROR MESSAGE --8<------\n" - @err << "Error connecting to #{@host}\n" - @err << "ERROR MESSAGE ------>8--\n" - return tmp[0][0].to_i + message = "Error connecting to #{@host}" + code = tmp[0][0].to_i + + @err << OpenNebula.format_error_message(message) + + done_out = true + done_err = true + break end tmp = @err.scan(/^#{RC_STR}(\d*) #{EOF_ERR}\n/) @@ -182,7 +184,7 @@ if $0 == __FILE__ ssh.exec("date | tee /tmp/test.javi") code=ssh.wait_for_command - + puts "Code: #{code}" puts "output: #{ssh.out}" @@ -206,10 +208,8 @@ if $0 == __FILE__ puts "output: #{ssh.out}" puts "output err: #{ssh.err}" - ssh.close + cssh = SshStreamCommand.new('no_host',lambda { |e| STDOUT.puts "error: #{e}" }, nil) + cssh.run('whoami') end - - - From 053efd8854737371620223d1fc074fe9eb05fdc5 Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Fri, 25 Nov 2011 17:03:31 +0100 Subject: [PATCH 044/121] feature #863: get xml values in all vmm actions --- src/vmm_mad/exec/one_vmm_exec.rb | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/vmm_mad/exec/one_vmm_exec.rb b/src/vmm_mad/exec/one_vmm_exec.rb index 83043836d1..659c37767c 100755 --- a/src/vmm_mad/exec/one_vmm_exec.rb +++ b/src/vmm_mad/exec/one_vmm_exec.rb @@ -111,49 +111,49 @@ class ExecDriver < VirtualMachineDriver def shutdown(id, drv_message) data = decode(drv_message) - host = data['HOST'] - deploy_id = data['DEPLOY_ID'] + host = data.elements['HOST'].text + deploy_id = data.elements['DEPLOY_ID'].text do_action("#{deploy_id} #{host}", id, host, :shutdown) end def cancel(id, drv_message) data = decode(drv_message) - host = data['HOST'] - deploy_id = data['DEPLOY_ID'] + host = data.elements['HOST'].text + deploy_id = data.elements['DEPLOY_ID'].text do_action("#{deploy_id} #{host}", id, host, :cancel) end def save(id, drv_message) data = decode(drv_message) - host = data['HOST'] - deploy_id = data['DEPLOY_ID'] - file = data['CHECKPOINT_FILE'] + host = data.elements['HOST'].text + deploy_id = data.elements['DEPLOY_ID'].text + file = data.elements['CHECKPOINT_FILE'].text do_action("#{deploy_id} #{file} #{host}", id, host, :save) end def restore(id, drv_message) data = decode(drv_message) - host = data['HOST'] - file = data['CHECKPOINT_FILE'] + host = data.elements['HOST'].text + file = data.elements['CHECKPOINT_FILE'].text do_action("#{file} #{host}", id, host, :restore) end def migrate(id, drv_message) data = decode(drv_message) - host = data['HOST'] - deploy_id = data['DEPLOY_ID'] + host = data.elements['HOST'].text + deploy_id = data.elements['DEPLOY_ID'].text do_action("#{deploy_id} #{dest_host} #{host}", id, host, :migrate) end def poll(id, drv_message) data = decode(drv_message) - host = data['HOST'] - deploy_id = data['DEPLOY_ID'] + host = data.elements['HOST'].text + deploy_id = data.elements['DEPLOY_ID'].text do_action("#{deploy_id} #{host}", id, host, :poll) end From 83e82830c8fa6951e21f5f2d7fd8270d8dc55e59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Fri, 25 Nov 2011 10:02:17 -0800 Subject: [PATCH 045/121] Feature #602: Refactor Ranged VNets to store first and last IP of the range --- include/FixedLeases.h | 8 +--- include/Leases.h | 25 ++++++----- include/RangedLeases.h | 14 ++---- include/VirtualNetwork.h | 3 ++ src/vnm/FixedLeases.cc | 2 +- src/vnm/RangedLeases.cc | 29 ++++-------- src/vnm/VirtualNetwork.cc | 92 ++++++++++++++++++++++----------------- 7 files changed, 83 insertions(+), 90 deletions(-) diff --git a/include/FixedLeases.h b/include/FixedLeases.h index 399afb02d7..d194a8130c 100644 --- a/include/FixedLeases.h +++ b/include/FixedLeases.h @@ -44,8 +44,7 @@ public: FixedLeases(SqlDB * db, int _oid, unsigned int _mac_prefix): - Leases(db,_oid,0), - mac_prefix(_mac_prefix), + Leases(db,_oid,0,_mac_prefix), current(leases.begin()){}; ~FixedLeases(){}; @@ -112,11 +111,6 @@ public: private: - /** - * The default MAC prefix for the Leases - */ - unsigned int mac_prefix; - /** * Current lease pointer */ diff --git a/include/Leases.h b/include/Leases.h index ef38c2c13b..5927f36f14 100644 --- a/include/Leases.h +++ b/include/Leases.h @@ -40,7 +40,7 @@ public: * @param _oid the virtual network unique identifier * @param _size the max number of leases */ - Leases(SqlDB * _db, int _oid, unsigned long _size): + Leases(SqlDB * _db, int _oid, unsigned long _size, unsigned int _mac_prefix): ObjectSQL(), oid(_oid), size(_size), n_used(0), db(_db){}; @@ -230,13 +230,13 @@ protected: // Leases fields // ------------------------------------------------------------------------- /** - * Leases indentifier. Connects it to a Virtual Network - */ + * Leases identifier. Connects it to a Virtual Network + */ int oid; /** - * Number of possible leases (free + asigned) - */ + * Number of possible leases (free + assigned) + */ unsigned int size; /** @@ -249,6 +249,11 @@ protected: */ int n_used; + /** + * The default MAC prefix for the Leases + */ + unsigned int mac_prefix; + // ------------------------------------------------------------------------- // DataBase implementation variables // ------------------------------------------------------------------------- @@ -286,11 +291,11 @@ protected: friend ostream& operator<<(ostream& os, Lease& _lease); /** - * Function to print the Leases object into a string in - * XML format - * @param xml the resulting XML string - * @return a reference to the generated string - */ + * Function to print the Leases object into a string in + * XML format + * @param xml the resulting XML string + * @return a reference to the generated string + */ string& to_xml(string& xml) const; private: diff --git a/include/RangedLeases.h b/include/RangedLeases.h index 946db6f349..4f97acb821 100644 --- a/include/RangedLeases.h +++ b/include/RangedLeases.h @@ -30,9 +30,9 @@ public: // ************************************************************************* RangedLeases(SqlDB * db, int _oid, - unsigned long _size, unsigned int _mac_prefix, - const string& _network_address); + unsigned int _ip_start, + unsigned int _ip_end); ~RangedLeases(){}; @@ -105,15 +105,9 @@ public: } private: - /** - * The default MAC prefix for the Leases - */ - unsigned int mac_prefix; - /** - * The Network address to generate leases - */ - unsigned int network_address; + unsigned int ip_start; + unsigned int ip_end; unsigned int current; diff --git a/include/VirtualNetwork.h b/include/VirtualNetwork.h index be02e86954..9146d69f97 100644 --- a/include/VirtualNetwork.h +++ b/include/VirtualNetwork.h @@ -222,6 +222,9 @@ private: */ Leases * leases; + unsigned int ip_start; + unsigned int ip_end; + // ************************************************************************* // DataBase implementation (Private) // ************************************************************************* diff --git a/src/vnm/FixedLeases.cc b/src/vnm/FixedLeases.cc index 83180c2a92..fc14480c74 100644 --- a/src/vnm/FixedLeases.cc +++ b/src/vnm/FixedLeases.cc @@ -25,7 +25,7 @@ FixedLeases::FixedLeases( int _oid, unsigned int _mac_prefix, vector& vector_leases): - Leases(db,_oid,0),mac_prefix(_mac_prefix),current(leases.begin()) + Leases(db,_oid,0,_mac_prefix),current(leases.begin()) { const VectorAttribute * single_attr_lease; string _mac; diff --git a/src/vnm/RangedLeases.cc b/src/vnm/RangedLeases.cc index d74f599e17..c94d59118b 100644 --- a/src/vnm/RangedLeases.cc +++ b/src/vnm/RangedLeases.cc @@ -17,7 +17,6 @@ #include "RangedLeases.h" #include "Nebula.h" -#include /* ************************************************************************** */ /* Ranged Leases class */ @@ -26,21 +25,13 @@ RangedLeases::RangedLeases( SqlDB * db, int _oid, - unsigned long _size, unsigned int _mac_prefix, - const string& _network_address): - Leases(db,_oid,_size),mac_prefix(_mac_prefix),current(0) + unsigned int _ip_start, + unsigned int _ip_end): + Leases(db,_oid,0,_mac_prefix), + ip_start(_ip_start),ip_end(_ip_end),current(0) { - unsigned int net_addr; - - Leases::Lease::ip_to_number(_network_address,net_addr); - - //size is the number of hosts in the network - size = _size + 2; - - network_address = 0xFFFFFFFF << (int) ceil(log(size)/log(2)); - - network_address &= net_addr; + size = ip_end - ip_start + 1; } /* ************************************************************************** */ @@ -52,9 +43,9 @@ int RangedLeases::get(int vid, string& ip, string& mac) unsigned int num_ip; int rc = -1; - for (unsigned int i=0; i + /* ************************************************************************** */ /* Virtual Network :: Constructor/Destructor */ /* ************************************************************************** */ @@ -119,49 +121,16 @@ int VirtualNetwork::select_leases(SqlDB * db) string network_address; - unsigned int default_size = VirtualNetworkPool::default_size(); unsigned int mac_prefix = VirtualNetworkPool::mac_prefix(); //Get the leases if (type == RANGED) { - string nclass = ""; - int size = 0; - - // retrieve specific information from the template - get_template_attribute("NETWORK_ADDRESS",network_address); - - if (network_address.empty()) - { - goto error_addr; - } - - get_template_attribute("NETWORK_SIZE",nclass); - - if ( nclass == "B" || nclass == "b" ) - { - size = 65534; - } - else if ( nclass == "C" || nclass == "c" ) - { - size = 254; - } - else if (!nclass.empty()) //Assume it's a number - { - istringstream iss(nclass); - iss >> size; - } - - if (size == 0) - { - size = default_size; - } - leases = new RangedLeases(db, oid, - size, mac_prefix, - network_address); + ip_start, + ip_end); } else if(type == FIXED) { @@ -190,9 +159,6 @@ error_type: ose << "Wrong type of Virtual Network: " << type; goto error_common; -error_addr: - ose << "Network address is not defined nid: " << oid; - error_common: NebulaLog::log("VNM", Log::ERROR, ose); return -1; @@ -292,6 +258,7 @@ int VirtualNetwork::insert(SqlDB * db, string& error_str) string nclass = ""; string naddr = ""; int size = 0; + unsigned int net_addr; // retrieve specific information from template get_template_attribute("NETWORK_ADDRESS",naddr); @@ -311,7 +278,7 @@ int VirtualNetwork::insert(SqlDB * db, string& error_str) { size = 254; } - else if (!nclass.empty())//Assume its a number + else if (!nclass.empty())//Assume it's a number { istringstream iss(nclass); @@ -323,11 +290,26 @@ int VirtualNetwork::insert(SqlDB * db, string& error_str) size = default_size; } + Leases::Lease::ip_to_number(naddr,net_addr); + + int shift; + shift = (int) ceil(log(size+2)/log(2)); + size = (1 << shift) - 2; + unsigned int network_mask = 0xFFFFFFFF << shift; + + if (net_addr != (network_mask & net_addr) ) + { + // TODO: net_addr is not a valid network address, should end with 0s + } + + ip_start = net_addr + 1; + ip_end = ip_start + size -1; + leases = new RangedLeases(db, oid, - size, mac_prefix, - naddr); + ip_start, + ip_end); } else // VirtualNetwork::FIXED { @@ -527,6 +509,21 @@ string& VirtualNetwork::to_xml_extended(string& xml, bool extended) const os << "" << vlan_id << ""; } + if ( type == RANGED ) + { + string st_ip_start; + string st_ip_end; + + Leases::Lease::ip_to_string(ip_start, st_ip_start); + Leases::Lease::ip_to_string(ip_end, st_ip_end); + + os << + "" << + "" << st_ip_start << "" << + "" << st_ip_end << "" << + ""; + } + os << "" << public_obj << "" << ""<< total_leases << ""<< obj_template->to_xml(template_xml); @@ -585,6 +582,19 @@ int VirtualNetwork::from_xml(const string &xml_str) ObjectXML::free_nodes(content); + // Ranged Leases + if (type == RANGED) + { + string st_ip_start; + string st_ip_end; + + rc += xpath(st_ip_start, "/VNET/RANGE/IP_START", "0"); + rc += xpath(st_ip_end, "/VNET/RANGE/IP_END", "0"); + + Leases::Lease::ip_to_number(st_ip_start, ip_start); + Leases::Lease::ip_to_number(st_ip_end, ip_end); + } + if (rc != 0) { return -1; From 23e33e32003ea08cda38c66bc3df1be112c23afc Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Sat, 26 Nov 2011 01:12:24 +0100 Subject: [PATCH 046/121] feature #863: Update remotes in sshtream. Checks if the stream is alive before using it --- src/mad/ruby/ssh_stream.rb | 53 +++++++++++++++++++++++--------- src/vmm_mad/exec/one_vmm_exec.rb | 5 ++- src/vnm_mad/one_vnm.rb | 15 ++++----- 3 files changed, 50 insertions(+), 23 deletions(-) diff --git a/src/mad/ruby/ssh_stream.rb b/src/mad/ruby/ssh_stream.rb index b0de36b72f..067227beeb 100644 --- a/src/mad/ruby/ssh_stream.rb +++ b/src/mad/ruby/ssh_stream.rb @@ -42,6 +42,10 @@ class SshStream defined?(@stdin) end + def alive? + @alive == true + end + def open @stdin, @stdout, @stderr=Open3::popen3("#{SSH_CMD} #{@host} bash -s ; echo #{SSH_RC_STR} $? 1>&2") @@ -50,6 +54,8 @@ class SshStream @out = "" @err = "" + + @alive = true end def close @@ -61,14 +67,18 @@ class SshStream @stdin.close if not @stdin.closed? @stdout.close if not @stdout.closed? @stderr.close if not @stderr.closed? + + @alive = false end def exec(command) + return if ! @alive + @out = "" @err = "" begin - cmd="(#{command}); #{EOF_CMD}\n" + cmd="(#{command}); #{EOF_CMD}" sliced=cmd.scan(/.{1,100}/) @@ -77,7 +87,7 @@ class SshStream @stdin.flush end - @stdin.puts + @stdin.write "\n" @stdin.flush rescue @@ -90,12 +100,12 @@ class SshStream code = -1 - while not (done_out and done_err) + while not (done_out and done_err ) and @alive rc, rw, re= IO.select([@stdout, @stderr],[],[]) rc.each { |fd| begin - c = fd.read_nonblock(50) + c = fd.read_nonblock(100) next if !c rescue #rescue from EOF if ssh command finishes and closes fds next @@ -115,8 +125,7 @@ class SshStream @err << OpenNebula.format_error_message(message) - done_out = true - done_err = true + @alive = false break end @@ -145,18 +154,29 @@ class SshStream end -class SshStreamCommand < GenericCommand - def initialize(host, logger=nil, stdin=nil) - @host=host - super('true', logger, stdin) +class SshStreamCommand < RemotesCommand + def initialize(host, remote_dir, logger=nil, stdin=nil) + super('true', host, logger, stdin) + + @remote_dir = remote_dir + @stream = SshStream.new(host) - @stream = SshStream.new(host) @stream.open end - def run(command, stdin=nil) + def run(command, stdin=nil, base_cmd = nil) @stream.open unless @stream.opened? + if base_cmd #Check if base command is on remote host + chk_cmd = "if [ ! -x \"#{base_cmd.match(/\S*/)[0]}\" ]; \ + then exit #{MAGIC_RC} 1>&2; \ + fi" + + if @stream.exec_and_wait(chk_cmd) == MAGIC_RC + RemotesCommand.update_remotes(@host, @remote_dir, @logger) + end + end + @stream.exec(command) @stream.stdin.write(stdin) if stdin @@ -184,7 +204,7 @@ if $0 == __FILE__ ssh.exec("date | tee /tmp/test.javi") code=ssh.wait_for_command - + puts "Code: #{code}" puts "output: #{ssh.out}" @@ -210,6 +230,9 @@ if $0 == __FILE__ ssh.close - cssh = SshStreamCommand.new('no_host',lambda { |e| STDOUT.puts "error: #{e}" }, nil) + cssh = SshStreamCommand.new('no_host', + '/tmp', + lambda { |e| STDOUT.puts "error: #{e}" }, + nil) cssh.run('whoami') -end +end \ No newline at end of file diff --git a/src/vmm_mad/exec/one_vmm_exec.rb b/src/vmm_mad/exec/one_vmm_exec.rb index 659c37767c..c79d789410 100755 --- a/src/vmm_mad/exec/one_vmm_exec.rb +++ b/src/vmm_mad/exec/one_vmm_exec.rb @@ -74,7 +74,10 @@ class ExecDriver < VirtualMachineDriver dfile = remote_dfile end - ssh = SshStreamCommand.new(host, log_method(id)) + ssh = SshStreamCommand.new(host, + @remote_scripts_base_path, + log_method(id)) + vnm = VirtualNetworkDriver.new(data.elements['NET_DRV'].text, :local_actions => @options[:local_actions], :message => data, diff --git a/src/vnm_mad/one_vnm.rb b/src/vnm_mad/one_vnm.rb index a5f069b1c5..aba0339611 100644 --- a/src/vnm_mad/one_vnm.rb +++ b/src/vnm_mad/one_vnm.rb @@ -49,21 +49,22 @@ class VirtualNetworkDriver :stdin => nil, }.merge(ops) - command = action_command_line(aname, @vm_encoded) + cmd = action_command_line(aname, @vm_encoded) if action_is_local?(aname) - execution = LocalCommand.run(command, log_method(id)) + execution = LocalCommand.run(cmd, log_method(id)) else if options[:stdin] - command = "cat << EOT | #{command}" - stdin = "#{options[:stdin]}\nEOT\n" + cmdin = "cat << EOT | #{cmd}" + stdin = "#{options[:stdin]}\nEOT\n" else - stdin = nil + cmdin = cmd + stdin = nil end - execution = @ssh_stream.run(command, stdin) + execution = @ssh_stream.run(cmdin, stdin, cmd) end result, info = get_info_from_execution(execution) end -end +end \ No newline at end of file From 0a191e113b48cd3bc7be59e7dc75ea2a7f4501f7 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Sat, 26 Nov 2011 01:41:02 +0100 Subject: [PATCH 047/121] feature #863: update remotes in OpenNebula driver when re-using a ssh stream --- src/mad/ruby/OpenNebulaDriver.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/mad/ruby/OpenNebulaDriver.rb b/src/mad/ruby/OpenNebulaDriver.rb index 5e8f6126a3..3ecbdd23bb 100644 --- a/src/mad/ruby/OpenNebulaDriver.rb +++ b/src/mad/ruby/OpenNebulaDriver.rb @@ -107,13 +107,14 @@ class OpenNebulaDriver < ActionManager execution = LocalCommand.run(command, log_method(id)) elsif options[:ssh_stream] if options[:stdin] - command = "cat << EOT | #{command}" - stdin = "#{options[:stdin]}\nEOT\n" + cmdin = "cat << EOT | #{command}" + stdin = "#{options[:stdin]}\nEOT\n" else - stdin = nil + cmdin = command + stdin = nil end - execution = options[:ssh_stream].run(command,stdin) + execution = options[:ssh_stream].run(cmdin, stdin, command) else execution = RemotesCommand.run(command, From 476fb23c5c66211b2566b82f4a8c88bed37ff877 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Sat, 26 Nov 2011 01:41:56 +0100 Subject: [PATCH 048/121] feature #863: Log deploy operations, rollback deployment if post-boot fails --- src/vmm_mad/exec/one_vmm_exec.rb | 39 ++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/src/vmm_mad/exec/one_vmm_exec.rb b/src/vmm_mad/exec/one_vmm_exec.rb index c79d789410..5c6100dd71 100755 --- a/src/vmm_mad/exec/one_vmm_exec.rb +++ b/src/vmm_mad/exec/one_vmm_exec.rb @@ -53,12 +53,17 @@ class ExecDriver < VirtualMachineDriver # DEPLOY action, sends the deployment file to remote host def deploy(id, drv_message) + # ---------------------------------------------------------------------- + # Initialization of deployment data + # ---------------------------------------------------------------------- + data = decode(drv_message) local_dfile = data.elements['LOCAL_DEPLOYMENT_FILE'].text remote_dfile = data.elements['REMOTE_DEPLOYMENT_FILE'].text - host = data.elements['HOST'].text + host = data.elements['HOST'].text + net_drv = data.elements['NET_DRV'].text if !local_dfile || File.zero?(local_dfile) send_message(ACTION[:deploy],RESULT[:failure],id, @@ -78,11 +83,15 @@ class ExecDriver < VirtualMachineDriver @remote_scripts_base_path, log_method(id)) - vnm = VirtualNetworkDriver.new(data.elements['NET_DRV'].text, + vnm = VirtualNetworkDriver.new(net_drv, :local_actions => @options[:local_actions], - :message => data, - :ssh_stream => ssh) + :message => data, + :ssh_stream => ssh) + # ---------------------------------------------------------------------- + # Execute pre-boot action of the network driver + # ---------------------------------------------------------------------- + result, info = vnm.do_action(id, :pre) if failed?(result) @@ -90,6 +99,12 @@ class ExecDriver < VirtualMachineDriver return end + log(id, "Successfully executed network driver #{net_drv} (pre-boot)") + + # ---------------------------------------------------------------------- + # Boot the VM + # ---------------------------------------------------------------------- + result, domain_id = do_action("#{dfile} #{host}", id, host, :deploy, :stdin => domain, :ssh_stream => ssh, @@ -99,14 +114,28 @@ class ExecDriver < VirtualMachineDriver return end + log(id, "Successfully booted VM with id: #{domain_id}") + + # ---------------------------------------------------------------------- + # Execute post-boot action of the network driver + # ---------------------------------------------------------------------- + result, info = vnm.do_action(id, :post) - #TODO: Need to rollback (VM is running) or send success and log error if failed?(result) + log(id, "Failed to executed network driver #{net_drv} (post-boot)") + log(id, "Cancelling VM with id: #{domain_id}") + + do_action("#{domain_id} #{host}", id, host, :cancel, + :ssh_stream => ssh, + :respond => false) + send_message(ACTION[:deploy],result,id,info) return end + log(id, "Successfully executed network driver #{net_drv} (post-boot)") + send_message(ACTION[:deploy],RESULT[:success],id,domain_id) end From e894fb5d373508c789866075a9b697e9c2ae7600 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Mon, 28 Nov 2011 16:30:08 +0100 Subject: [PATCH 049/121] Feature #602: Make Network size definition more flexible. The netmask is generated from the given size The Network size can be defined as: * NETWORK_ADDRESS attribute: 19.2168.30.0/24 * SIZE: Letter (a,b,c) or number of hosts * NETWORK_MASK: 255.255.255.0 creates a network of 254 hosts --- src/vnm/VirtualNetwork.cc | 115 +++++++++++++++++++++++++++++--------- 1 file changed, 88 insertions(+), 27 deletions(-) diff --git a/src/vnm/VirtualNetwork.cc b/src/vnm/VirtualNetwork.cc index c3c125cbbb..899154538d 100644 --- a/src/vnm/VirtualNetwork.cc +++ b/src/vnm/VirtualNetwork.cc @@ -255,53 +255,114 @@ int VirtualNetwork::insert(SqlDB * db, string& error_str) //-------------------------------------------------------------------------- if (type == VirtualNetwork::RANGED) { - string nclass = ""; - string naddr = ""; - int size = 0; + string st_size = ""; + string st_addr = ""; + string st_mask = ""; + + unsigned int size = default_size; + unsigned int host_bits; + unsigned int network_bits; + unsigned int net_addr; + unsigned int net_mask; + size_t pos; // retrieve specific information from template - get_template_attribute("NETWORK_ADDRESS",naddr); - if (naddr.empty()) + erase_template_attribute("NETWORK_ADDRESS",st_addr); + + if (st_addr.empty()) { goto error_addr; } - get_template_attribute("NETWORK_SIZE",nclass); + // Check if the IP has a network prefix + pos = st_addr.find("/"); - if ( nclass == "B" || nclass == "b" ) + if ( pos != string::npos ) { - size = 65534; - } - else if ( nclass == "C" || nclass == "c" ) - { - size = 254; - } - else if (!nclass.empty())//Assume it's a number - { - istringstream iss(nclass); + string st_network_bits; - iss >> size; + st_network_bits = st_addr.substr(pos+1); + st_addr = st_addr.substr(0,pos); + + istringstream iss(st_network_bits); + iss >> network_bits; + + if ( network_bits > 32 ) + { + // TODO wrong prefix + } + + host_bits = 32 - network_bits; + } + else + { + erase_template_attribute("NETWORK_MASK", st_mask); + + if ( !st_mask.empty() ) + { + // st_mask is in decimal format, e.g. 255.255.0.0 + // The number of trailing 0s is needed + + Leases::Lease::ip_to_number(st_mask, net_mask); + + host_bits = 0; + + while ( host_bits < 32 && + ((net_mask >> host_bits) & 1) != 1 ) + { + host_bits++; + } + } + else + { + erase_template_attribute("NETWORK_SIZE",st_size); + + if ( st_size == "C" || st_size == "c" ) + { + host_bits = 8; + } + else if ( st_size == "B" || st_size == "b" ) + { + host_bits = 16; + } + else if ( st_size == "A" || st_size == "a" ) + { + host_bits = 24; + } + else + { + size = default_size; + + if (!st_size.empty())//Assume it's a number + { + istringstream iss(st_size); + + iss >> size; + } + + host_bits = (int) ceil(log(size+2)/log(2)); + } + } } - if (size == 0) - { - size = default_size; - } + remove_template_attribute("NETWORK_SIZE"); - Leases::Lease::ip_to_number(naddr,net_addr); + // Set the network mask + net_mask = ( 0xFFFFFFFF << host_bits ) & 0xFFFFFFFF; + Leases::Lease::ip_to_string(net_mask, st_mask); + replace_template_attribute("NETWORK_MASK", st_mask); - int shift; - shift = (int) ceil(log(size+2)/log(2)); - size = (1 << shift) - 2; - unsigned int network_mask = 0xFFFFFFFF << shift; + Leases::Lease::ip_to_number(st_addr,net_addr); - if (net_addr != (network_mask & net_addr) ) + if (net_addr != (net_mask & net_addr) ) { // TODO: net_addr is not a valid network address, should end with 0s } + size = (1 << host_bits) - 2; + ip_start = net_addr + 1; ip_end = ip_start + size -1; From 4fcf406c0c8b51e05007f04ddb5bb95ffa8a06d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Mon, 28 Nov 2011 16:47:11 +0100 Subject: [PATCH 050/121] Feature #602: Show RANGE/IP_START and RANGE/IP_END in 'onevnet show' --- src/cli/one_helper/onevnet_helper.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/cli/one_helper/onevnet_helper.rb b/src/cli/one_helper/onevnet_helper.rb index 3d72e196af..71ead0d55f 100644 --- a/src/cli/one_helper/onevnet_helper.rb +++ b/src/cli/one_helper/onevnet_helper.rb @@ -66,6 +66,13 @@ class OneVNetHelper < OpenNebulaHelper::OneHelper puts vn.template_str(false) + if vn.type_str == "RANGED" + puts + CLIHelper.print_header(str_h1 % ["RANGE"], false) + puts str % ["IP_START", vn['RANGE/IP_START']] + puts str % ["IP_END", vn['RANGE/IP_END']] + end + leases_str = vn.template_like_str('/VNET/LEASES', false) if !leases_str.empty? From 37debbf02ff5a2f2bbed162e013abab4111485e9 Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Mon, 28 Nov 2011 17:07:28 +0100 Subject: [PATCH 051/121] feature #863: added calls to network actions in vmm --- src/vmm_mad/exec/one_vmm_exec.rb | 259 +++++++++++++++++++++++++++++-- 1 file changed, 242 insertions(+), 17 deletions(-) diff --git a/src/vmm_mad/exec/one_vmm_exec.rb b/src/vmm_mad/exec/one_vmm_exec.rb index 5c6100dd71..1ce1bc9c79 100755 --- a/src/vmm_mad/exec/one_vmm_exec.rb +++ b/src/vmm_mad/exec/one_vmm_exec.rb @@ -79,15 +79,15 @@ class ExecDriver < VirtualMachineDriver dfile = remote_dfile end - ssh = SshStreamCommand.new(host, - @remote_scripts_base_path, - log_method(id)) + ssh = SshStreamCommand.new(host, + @remote_scripts_base_path, + log_method(id)) vnm = VirtualNetworkDriver.new(net_drv, :local_actions => @options[:local_actions], :message => data, :ssh_stream => ssh) - + # ---------------------------------------------------------------------- # Execute pre-boot action of the network driver # ---------------------------------------------------------------------- @@ -95,7 +95,7 @@ class ExecDriver < VirtualMachineDriver result, info = vnm.do_action(id, :pre) if failed?(result) - send_message(ACTION[:deploy],result,id,info) + send_message(ACTION[:deploy], result, id,info) return end @@ -105,16 +105,18 @@ class ExecDriver < VirtualMachineDriver # Boot the VM # ---------------------------------------------------------------------- - result, domain_id = do_action("#{dfile} #{host}", id, host, :deploy, + result, info = do_action("#{dfile} #{host}", id, host, :deploy, :stdin => domain, :ssh_stream => ssh, :respond => false) if failed?(result) - send_message(ACTION[:deploy],result,id,info) + send_message(ACTION[:deploy], result, id, info) return end - log(id, "Successfully booted VM with id: #{domain_id}") + deploy_id = info + + log(id, "Successfully booted VM with id: #{deploy_id}") # ---------------------------------------------------------------------- # Execute post-boot action of the network driver @@ -124,19 +126,19 @@ class ExecDriver < VirtualMachineDriver if failed?(result) log(id, "Failed to executed network driver #{net_drv} (post-boot)") - log(id, "Cancelling VM with id: #{domain_id}") + log(id, "Canceling VM with id: #{deploy_id}") - do_action("#{domain_id} #{host}", id, host, :cancel, + do_action("#{deploy_id} #{host}", id, host, :cancel, :ssh_stream => ssh, :respond => false) - send_message(ACTION[:deploy],result,id,info) + send_message(ACTION[:deploy], result, id, info) return end log(id, "Successfully executed network driver #{net_drv} (post-boot)") - send_message(ACTION[:deploy],RESULT[:success],id,domain_id) + send_message(ACTION[:deploy], RESULT[:success], id, deploy_id) end # Basic Domain Management Operations @@ -144,26 +146,130 @@ class ExecDriver < VirtualMachineDriver def shutdown(id, drv_message) data = decode(drv_message) host = data.elements['HOST'].text + net_drv = data.elements['NET_DRV'].text deploy_id = data.elements['DEPLOY_ID'].text - do_action("#{deploy_id} #{host}", id, host, :shutdown) + ssh = SshStreamCommand.new(host, + @remote_scripts_base_path, + log_method(id)) + + vnm = VirtualNetworkDriver.new(net_drv, + :local_actions => @options[:local_actions], + :message => data, + :ssh_stream => ssh) + + result, info = do_action("#{deploy_id} #{host}", id, host, :shutdown, + :ssh_stream => ssh, + :respond => false) + + if failed?(result) + send_message(ACTION[:shutdown], result, id,info) + return + end + + log(id, "Successfully shut down VM with id: #{deploy_id}") + + # ---------------------------------------------------------------------- + # Execute clean action of the network driver + # ---------------------------------------------------------------------- + + result, info = vnm.do_action(id, :clean) + + if failed?(result) + send_message(ACTION[:shutdown], result, id,info) + return + end + + log(id, "Successfully executed network driver #{net_drv}" << + " (clean-shutdown)") end def cancel(id, drv_message) data = decode(drv_message) host = data.elements['HOST'].text + net_drv = data.elements['NET_DRV'].text deploy_id = data.elements['DEPLOY_ID'].text - do_action("#{deploy_id} #{host}", id, host, :cancel) + ssh = SshStreamCommand.new(host, + @remote_scripts_base_path, + log_method(id)) + + vnm = VirtualNetworkDriver.new(net_drv, + :local_actions => @options[:local_actions], + :message => data, + :ssh_stream => ssh) + + result, info = do_action("#{deploy_id} #{host}", id, host, :cancel, + :ssh_stream => ssh, + :respond => false) + + if failed?(result) + send_message(ACTION[:cancel], result, id,info) + return + end + + log(id, "Successfully canceled VM with id: #{deploy_id}") + + # ---------------------------------------------------------------------- + # Execute clean action of the network driver + # ---------------------------------------------------------------------- + + result, info = vnm.do_action(id, :clean) + + if failed?(result) + send_message(ACTION[:cancel], result, id,info) + return + end + + log(id, "Successfully executed network driver #{net_drv}" << + " (clean-cancel)") + + send_message(ACTION[:shutdown], RESULT[:success], id, domain_id) end def save(id, drv_message) data = decode(drv_message) host = data.elements['HOST'].text + net_drv = data.elements['NET_DRV'].text deploy_id = data.elements['DEPLOY_ID'].text file = data.elements['CHECKPOINT_FILE'].text - do_action("#{deploy_id} #{file} #{host}", id, host, :save) + ssh = SshStreamCommand.new(host, + @remote_scripts_base_path, + log_method(id)) + + vnm = VirtualNetworkDriver.new(net_drv, + :local_actions => @options[:local_actions], + :message => data, + :ssh_stream => ssh) + + result, info = do_action("#{deploy_id} #{file} #{host}", id, host, + :save, + :ssh_stream => ssh, + :respond => false) + + if failed?(result) + send_message(ACTION[:save], result, id,info) + return + end + + log(id, "Successfully saved VM with id: #{deploy_id}") + + # ---------------------------------------------------------------------- + # Execute clean action of the network driver + # ---------------------------------------------------------------------- + + result, info = vnm.do_action(id, :clean) + + if failed?(result) + send_message(ACTION[:save], result, id,info) + return + end + + log(id, "Successfully executed network driver #{net_drv}" << + " (clean-save)") + + send_message(ACTION[:save], RESULT[:success], id, domain_id) end def restore(id, drv_message) @@ -171,15 +277,134 @@ class ExecDriver < VirtualMachineDriver host = data.elements['HOST'].text file = data.elements['CHECKPOINT_FILE'].text - do_action("#{file} #{host}", id, host, :restore) + ssh = SshStreamCommand.new(host, + @remote_scripts_base_path, + log_method(id)) + + vnm = VirtualNetworkDriver.new(net_drv, + :local_actions => @options[:local_actions], + :message => data, + :ssh_stream => ssh) + + # ---------------------------------------------------------------------- + # Execute pre-boot action of the network driver + # ---------------------------------------------------------------------- + + result, info = vnm.do_action(id, :pre) + + if failed?(result) + send_message(ACTION[:restore], result, id,info) + return + end + + log(id, "Successfully executed network driver #{net_drv} (pre-restore)") + + result, info = do_action("#{file} #{host}", id, host, :restore, + :save, + :ssh_stream => ssh, + :respond => false) + if failed?(result) + send_message(ACTION[:restore], result, id, info) + return + end + + log(id, "Successfully restored VM with id: #{info}") + + # ---------------------------------------------------------------------- + # Execute post-restore action of the network driver + # ---------------------------------------------------------------------- + + result, info = vnm.do_action(id, :post) + + if failed?(result) + log(id, "Failed to executed network driver #{net_drv} (post-restore)") + log(id, "Canceling VM with id: #{domain_id}") + + do_action("#{domain_id} #{host}", id, host, :cancel, + :ssh_stream => ssh, + :respond => false) + + send_message(ACTION[:restore], result, id, info) + return + end + + log(id, "Successfully executed network driver #{net_drv} (post-restore)") + + send_message(ACTION[:restore], RESULT[:success], id, domain_id) end def migrate(id, drv_message) data = decode(drv_message) + net_drv = data.elements['NET_DRV'].text host = data.elements['HOST'].text deploy_id = data.elements['DEPLOY_ID'].text + dest_host = data.elements['MIGR_HOST'].text + dest_driver = data.elements['MIGR_NET_DRV'].text - do_action("#{deploy_id} #{dest_host} #{host}", id, host, :migrate) + ssh_src = SshStreamCommand.new(host, + @remote_scripts_base_path, + log_method(id)) + + ssh_dst = SshStreamCommand.new(dest_host, + @remote_scripts_base_path, + log_method(id)) + + vnm_src = VirtualNetworkDriver.new(net_drv, + :local_actions => @options[:local_actions], + :message => data, + :ssh_stream => ssh_src) + + vnm_dst = VirtualNetworkDriver.new(dest_driver, + :local_actions => @options[:local_actions], + :message => data, + :ssh_stream => ssh_dst) + + # ---------------------------------------------------------------------- + # Execute pre-boot action of the network driver + # ---------------------------------------------------------------------- + + result, info = vnm_dst.do_action(id, :pre) + + if failed?(result) + send_message(ACTION[:migrate], result, id,info) + return + end + + log(id, "Successfully executed network driver #{net_drv} (pre-migrate)") + + result, info = do_action("#{deploy_id} #{dest_host} #{host}", id, host, + :migrate, + :save, + :ssh_stream => ssh_src, + :respond => false) + if failed?(result) + send_message(ACTION[:migrate], result, id, info) + return + end + + log(id, "Successfully migrated VM with id: #{deploy_id}") + + # ---------------------------------------------------------------------- + # Execute post-migrate action of the network driver + # ---------------------------------------------------------------------- + + result, info = vnm_dst.do_action(id, :post) + + if failed?(result) + log(id, "Failed to executed network driver #{dest_driver} (post-migrate)") + log(id, "Canceling VM with id: #{deploy_id}") + + do_action("#{deploy_id} #{host}", id, dest_host, :cancel, + :ssh_stream => ssh_dst, + :respond => false) + + send_message(ACTION[:restore], result, id, info) + return + end + + log(id, "Successfully executed network driver #{net_drv} (post-restore)") + + send_message(ACTION[:restore], RESULT[:success], id, deploy_id) end def poll(id, drv_message) From effb4a57126b862b247916675ee71fa326fbd233 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Mon, 28 Nov 2011 17:24:46 +0100 Subject: [PATCH 052/121] Feature #602: Refactorin of the Range creation code. New method RangedLeases::process_template --- include/RangedLeases.h | 12 ++++ src/vnm/RangedLeases.cc | 132 ++++++++++++++++++++++++++++++++++++++ src/vnm/VirtualNetwork.cc | 118 +++------------------------------- 3 files changed, 152 insertions(+), 110 deletions(-) diff --git a/include/RangedLeases.h b/include/RangedLeases.h index 4f97acb821..a8a81d9968 100644 --- a/include/RangedLeases.h +++ b/include/RangedLeases.h @@ -18,6 +18,7 @@ #define RANGED_LEASES_H_ #include "Leases.h" +#include "VirtualNetwork.h" using namespace std; @@ -36,6 +37,17 @@ public: ~RangedLeases(){}; + /** + * Reads (and clears) the necessary attributes to define a Ranged VNet + * @param vn Virtual Network + * @param ip_start First IP of the range + * @param ip_end Last IP of the range + * @param error_str Error reason, if any + * @return 0 on success, -1 otherwise + */ + static int process_template(VirtualNetwork * vn, + unsigned int& ip_start, unsigned int& ip_end, string& error_str); + /** * Returns an unused lease, which becomes used * @param vid identifier of the VM getting this lease diff --git a/src/vnm/RangedLeases.cc b/src/vnm/RangedLeases.cc index c94d59118b..26fb6940dd 100644 --- a/src/vnm/RangedLeases.cc +++ b/src/vnm/RangedLeases.cc @@ -18,6 +18,8 @@ #include "RangedLeases.h" #include "Nebula.h" +#include + /* ************************************************************************** */ /* Ranged Leases class */ /* ************************************************************************** */ @@ -37,6 +39,136 @@ RangedLeases::RangedLeases( /* ************************************************************************** */ /* Ranged Leases :: Methods */ /* ************************************************************************** */ +int RangedLeases::process_template(VirtualNetwork* vn, + unsigned int& ip_start, unsigned int& ip_end, string& error_str) +{ + ostringstream oss; + + string st_size = ""; + string st_addr = ""; + string st_mask = ""; + + int default_size = VirtualNetworkPool::default_size(); + unsigned int size = default_size; + unsigned int host_bits; + unsigned int network_bits; + + unsigned int net_addr; + unsigned int net_mask; + size_t pos; + + // retrieve specific information from template + + vn->erase_template_attribute("NETWORK_ADDRESS",st_addr); + + if (st_addr.empty()) + { + goto error_addr; + } + + // Check if the IP has a network prefix + pos = st_addr.find("/"); + + if ( pos != string::npos ) + { + string st_network_bits; + + st_network_bits = st_addr.substr(pos+1); + st_addr = st_addr.substr(0,pos); + + istringstream iss(st_network_bits); + iss >> network_bits; + + if ( network_bits > 32 ) + { + // TODO wrong prefix + } + + host_bits = 32 - network_bits; + } + else + { + vn->erase_template_attribute("NETWORK_MASK", st_mask); + + if ( !st_mask.empty() ) + { + // st_mask is in decimal format, e.g. 255.255.0.0 + // The number of trailing 0s is needed + + Leases::Lease::ip_to_number(st_mask, net_mask); + + host_bits = 0; + + while ( host_bits < 32 && + ((net_mask >> host_bits) & 1) != 1 ) + { + host_bits++; + } + } + else + { + vn->erase_template_attribute("NETWORK_SIZE",st_size); + + if ( st_size == "C" || st_size == "c" ) + { + host_bits = 8; + } + else if ( st_size == "B" || st_size == "b" ) + { + host_bits = 16; + } + else if ( st_size == "A" || st_size == "a" ) + { + host_bits = 24; + } + else + { + size = default_size; + + if (!st_size.empty())//Assume it's a number + { + istringstream iss(st_size); + + iss >> size; + } + + host_bits = (int) ceil(log(size+2)/log(2)); + } + } + } + + vn->remove_template_attribute("NETWORK_SIZE"); + + // Set the network mask + net_mask = ( 0xFFFFFFFF << host_bits ) & 0xFFFFFFFF; + Lease::ip_to_string(net_mask, st_mask); + vn->replace_template_attribute("NETWORK_MASK", st_mask); + + Leases::Lease::ip_to_number(st_addr,net_addr); + + if (net_addr != (net_mask & net_addr) ) + { + // TODO: net_addr is not a valid network address, should end with 0s + } + + size = (1 << host_bits) - 2; + + ip_start = net_addr + 1; + ip_end = ip_start + size -1; + + return 0; + +error_addr: + oss << "No NETWORK_ADDRESS in template for Virtual Network."; + goto error_common; + +error_common: + error_str = oss.str(); + return -1; +} + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ int RangedLeases::get(int vid, string& ip, string& mac) { diff --git a/src/vnm/VirtualNetwork.cc b/src/vnm/VirtualNetwork.cc index 899154538d..72a833d407 100644 --- a/src/vnm/VirtualNetwork.cc +++ b/src/vnm/VirtualNetwork.cc @@ -25,8 +25,6 @@ #include "AuthManager.h" -#include - /* ************************************************************************** */ /* Virtual Network :: Constructor/Destructor */ /* ************************************************************************** */ @@ -174,8 +172,8 @@ int VirtualNetwork::insert(SqlDB * db, string& error_str) string pub; string s_type; + string ranged_error_str; - unsigned int default_size = VirtualNetworkPool::default_size(); unsigned int mac_prefix = VirtualNetworkPool::mac_prefix(); //-------------------------------------------------------------------------- @@ -255,117 +253,17 @@ int VirtualNetwork::insert(SqlDB * db, string& error_str) //-------------------------------------------------------------------------- if (type == VirtualNetwork::RANGED) { - string st_size = ""; - string st_addr = ""; - string st_mask = ""; - unsigned int size = default_size; - unsigned int host_bits; - unsigned int network_bits; + int rc; - unsigned int net_addr; - unsigned int net_mask; - size_t pos; + rc = RangedLeases::process_template(this, ip_start, ip_end, + ranged_error_str); - // retrieve specific information from template - - erase_template_attribute("NETWORK_ADDRESS",st_addr); - - if (st_addr.empty()) + if ( rc != 0 ) { - goto error_addr; + goto error_ranged; } - // Check if the IP has a network prefix - pos = st_addr.find("/"); - - if ( pos != string::npos ) - { - string st_network_bits; - - st_network_bits = st_addr.substr(pos+1); - st_addr = st_addr.substr(0,pos); - - istringstream iss(st_network_bits); - iss >> network_bits; - - if ( network_bits > 32 ) - { - // TODO wrong prefix - } - - host_bits = 32 - network_bits; - } - else - { - erase_template_attribute("NETWORK_MASK", st_mask); - - if ( !st_mask.empty() ) - { - // st_mask is in decimal format, e.g. 255.255.0.0 - // The number of trailing 0s is needed - - Leases::Lease::ip_to_number(st_mask, net_mask); - - host_bits = 0; - - while ( host_bits < 32 && - ((net_mask >> host_bits) & 1) != 1 ) - { - host_bits++; - } - } - else - { - erase_template_attribute("NETWORK_SIZE",st_size); - - if ( st_size == "C" || st_size == "c" ) - { - host_bits = 8; - } - else if ( st_size == "B" || st_size == "b" ) - { - host_bits = 16; - } - else if ( st_size == "A" || st_size == "a" ) - { - host_bits = 24; - } - else - { - size = default_size; - - if (!st_size.empty())//Assume it's a number - { - istringstream iss(st_size); - - iss >> size; - } - - host_bits = (int) ceil(log(size+2)/log(2)); - } - } - } - - remove_template_attribute("NETWORK_SIZE"); - - // Set the network mask - net_mask = ( 0xFFFFFFFF << host_bits ) & 0xFFFFFFFF; - Leases::Lease::ip_to_string(net_mask, st_mask); - replace_template_attribute("NETWORK_MASK", st_mask); - - Leases::Lease::ip_to_number(st_addr,net_addr); - - if (net_addr != (net_mask & net_addr) ) - { - // TODO: net_addr is not a valid network address, should end with 0s - } - - size = (1 << host_bits) - 2; - - ip_start = net_addr + 1; - ip_end = ip_start + size -1; - leases = new RangedLeases(db, oid, mac_prefix, @@ -423,8 +321,8 @@ error_update: ose << "Can not update Virtual Network."; goto error_common; -error_addr: - ose << "No NETWORK_ADDRESS in template for Virtual Network."; +error_ranged: + ose << ranged_error_str; goto error_common; error_null_leases: From 9791ece838364d7992911b98bac0d03c240d3194 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Mon, 28 Nov 2011 18:10:00 +0100 Subject: [PATCH 053/121] Feature #602: Add support for IP_START and IP_END redefinition in Ranged networks --- src/vnm/Leases.cc | 5 ++++ src/vnm/RangedLeases.cc | 64 +++++++++++++++++++++++++++++++++++------ 2 files changed, 60 insertions(+), 9 deletions(-) diff --git a/src/vnm/Leases.cc b/src/vnm/Leases.cc index 17dc998d07..fa0eedabb1 100644 --- a/src/vnm/Leases.cc +++ b/src/vnm/Leases.cc @@ -66,6 +66,11 @@ int Leases::Lease::ip_to_number(const string& _ip, unsigned int& i_ip) { iss >> dec >> tmp >> ws; + if ( tmp > 255 ) + { + return -1; + } + i_ip <<= 8; i_ip += tmp; } diff --git a/src/vnm/RangedLeases.cc b/src/vnm/RangedLeases.cc index 26fb6940dd..ce860d673b 100644 --- a/src/vnm/RangedLeases.cc +++ b/src/vnm/RangedLeases.cc @@ -48,8 +48,10 @@ int RangedLeases::process_template(VirtualNetwork* vn, string st_addr = ""; string st_mask = ""; - int default_size = VirtualNetworkPool::default_size(); - unsigned int size = default_size; + string st_ip_start = ""; + string st_ip_end = ""; + + unsigned int size = VirtualNetworkPool::default_size(); unsigned int host_bits; unsigned int network_bits; @@ -57,13 +59,41 @@ int RangedLeases::process_template(VirtualNetwork* vn, unsigned int net_mask; size_t pos; - // retrieve specific information from template + ip_start = 0; + ip_end = 0; - vn->erase_template_attribute("NETWORK_ADDRESS",st_addr); + // retrieve specific information from template + vn->erase_template_attribute("IP_START", st_ip_start); + vn->erase_template_attribute("IP_END", st_ip_end); + + if ( !st_ip_start.empty() ) + { + if ( Leases::Lease::ip_to_number(st_ip_start, ip_start) != 0 ) + { + goto error_ip_start; + } + } + + if ( !st_ip_end.empty() ) + { + if ( Leases::Lease::ip_to_number(st_ip_end, ip_end) != 0 ) + { + goto error_ip_end; + } + } + + vn->erase_template_attribute("NETWORK_ADDRESS", st_addr); if (st_addr.empty()) { - goto error_addr; + if ( ip_start != 0 && ip_end != 0 ) + { + return 0; + } + else + { + goto error_addr; + } } // Check if the IP has a network prefix @@ -123,8 +153,6 @@ int RangedLeases::process_template(VirtualNetwork* vn, } else { - size = default_size; - if (!st_size.empty())//Assume it's a number { istringstream iss(st_size); @@ -153,11 +181,29 @@ int RangedLeases::process_template(VirtualNetwork* vn, size = (1 << host_bits) - 2; - ip_start = net_addr + 1; - ip_end = ip_start + size -1; + // TODO: check that start < end; ip_start & ip_end are part of the network + + if ( ip_start == 0 ) + { + ip_start = net_addr + 1; + } + + if ( ip_end == 0 ) + { + ip_end = net_addr + size; + } return 0; + +error_ip_start: + oss << "IP_START is not a valid IP."; + goto error_common; + +error_ip_end: + oss << "IP_END is not a valid IP."; + goto error_common; + error_addr: oss << "No NETWORK_ADDRESS in template for Virtual Network."; goto error_common; From 07bc7d01549178defbef55205f22b4ce3e44ad6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Mon, 28 Nov 2011 19:07:44 +0100 Subject: [PATCH 054/121] Feature #602: Add error checks in Ranged network creation --- src/vnm/RangedLeases.cc | 78 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 70 insertions(+), 8 deletions(-) diff --git a/src/vnm/RangedLeases.cc b/src/vnm/RangedLeases.cc index ce860d673b..84c1bddaf0 100644 --- a/src/vnm/RangedLeases.cc +++ b/src/vnm/RangedLeases.cc @@ -88,6 +88,11 @@ int RangedLeases::process_template(VirtualNetwork* vn, { if ( ip_start != 0 && ip_end != 0 ) { + if ( ip_end < ip_start ) + { + goto error_greater; + } + return 0; } else @@ -111,7 +116,7 @@ int RangedLeases::process_template(VirtualNetwork* vn, if ( network_bits > 32 ) { - // TODO wrong prefix + goto error_prefix; } host_bits = 32 - network_bits; @@ -125,7 +130,10 @@ int RangedLeases::process_template(VirtualNetwork* vn, // st_mask is in decimal format, e.g. 255.255.0.0 // The number of trailing 0s is needed - Leases::Lease::ip_to_number(st_mask, net_mask); + if ( Leases::Lease::ip_to_number(st_mask, net_mask) != 0 ) + { + goto error_netmask; + } host_bits = 0; @@ -172,17 +180,19 @@ int RangedLeases::process_template(VirtualNetwork* vn, Lease::ip_to_string(net_mask, st_mask); vn->replace_template_attribute("NETWORK_MASK", st_mask); - Leases::Lease::ip_to_number(st_addr,net_addr); + if ( Leases::Lease::ip_to_number(st_addr,net_addr) != 0 ) + { + goto error_net_addr; + } if (net_addr != (net_mask & net_addr) ) { - // TODO: net_addr is not a valid network address, should end with 0s + goto error_not_base_addr; } size = (1 << host_bits) - 2; - // TODO: check that start < end; ip_start & ip_end are part of the network - + // Set IP start/end if ( ip_start == 0 ) { ip_start = net_addr + 1; @@ -193,21 +203,73 @@ int RangedLeases::process_template(VirtualNetwork* vn, ip_end = net_addr + size; } + // Check range restrictions + if ( (ip_start & net_mask) != net_addr ) + { + goto error_range_ip_start; + } + + if ( (ip_end & net_mask) != net_addr ) + { + goto error_range_ip_end; + } + + if ( ip_end < ip_start ) + { + goto error_greater; + } + return 0; error_ip_start: - oss << "IP_START is not a valid IP."; + oss << "IP_START " << st_ip_start << " is not a valid IP."; goto error_common; error_ip_end: - oss << "IP_END is not a valid IP."; + oss << "IP_END " << st_ip_end << " is not a valid IP."; + goto error_common; + +error_not_base_addr: + oss << "NETWORK_ADDRESS " << st_addr + << " is not a base address for the network mask " << st_mask << "."; + goto error_common; + +error_net_addr: + oss << "NETWORK_ADDRESS " << st_addr << " is not a valid IP."; + goto error_common; + +error_netmask: + oss << "NETWORK_MASK " << st_mask << " is not a valid network mask."; + goto error_common; + +error_prefix: + oss << "A CIDR prefix of " << network_bits << " bits is not valid."; goto error_common; error_addr: oss << "No NETWORK_ADDRESS in template for Virtual Network."; goto error_common; +error_range_ip_start: + oss << "IP_START " << st_ip_start << " is not part of the network " + << st_addr << "/" << 32-host_bits << "."; + goto error_common; + +error_range_ip_end: + oss << "IP_END " << st_ip_end << " is not part of the network " + << st_addr << "/" << 32-host_bits << "."; + goto error_common; + +error_greater: + Leases::Lease::ip_to_string(ip_start, st_ip_start); + Leases::Lease::ip_to_string(ip_end, st_ip_end); + + oss << "IP_START " << st_ip_start << " cannot be greater than the IP_END " + << st_ip_end << "."; + goto error_common; + + error_common: error_str = oss.str(); return -1; From c472c6c9f570add9a1032516ff321868f448551e Mon Sep 17 00:00:00 2001 From: Hector Sanjuan Date: Wed, 16 Nov 2011 16:36:35 +0100 Subject: [PATCH 055/121] Task #972: Add VNM driver to Sunstone. Updated server, host info and host creation dialog. (cherry picked from commit bccc091d8ed5bd9f44aa6cf6f0f8447ee63bf6e5) --- src/sunstone/models/OpenNebulaJSON/HostJSON.rb | 7 ++++--- src/sunstone/public/js/plugins/hosts-tab.js | 16 +++++++++++++++- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/sunstone/models/OpenNebulaJSON/HostJSON.rb b/src/sunstone/models/OpenNebulaJSON/HostJSON.rb index d4395231bb..cf24bb1ee9 100644 --- a/src/sunstone/models/OpenNebulaJSON/HostJSON.rb +++ b/src/sunstone/models/OpenNebulaJSON/HostJSON.rb @@ -27,9 +27,10 @@ module OpenNebulaJSON end self.allocate(host_hash['name'], - host_hash['im_mad'], - host_hash['vm_mad'], - host_hash['tm_mad']) + host_hash['im_mad'], + host_hash['vm_mad'], + host_hash['vnm_mad'], + host_hash['tm_mad']) end def delete diff --git a/src/sunstone/public/js/plugins/hosts-tab.js b/src/sunstone/public/js/plugins/hosts-tab.js index c54d9a78d9..cfbf85d2f7 100644 --- a/src/sunstone/public/js/plugins/hosts-tab.js +++ b/src/sunstone/public/js/plugins/hosts-tab.js @@ -80,10 +80,19 @@ var create_host_tmpl = \ \ \ +
\ + \ + \ +
\
\ \ \ @@ -443,6 +452,10 @@ function updateHostInfo(request,host){ VM MAD\ '+host_info.VM_MAD+'\ \ + \ + VN MAD\ + '+host_info.VN_MAD+'\ + \ \ TM MAD\ '+host_info.TM_MAD+'\ @@ -537,6 +550,7 @@ function setupCreateHostDialog(){ "name": $('#name',this).val(), "tm_mad": $('#tm_mad :selected',this).val(), "vm_mad": $('#vmm_mad :selected',this).val(), + "vnm_mad": $('#vnm_mad :selected',this).val(), "im_mad": $('#im_mad :selected',this).val() } } From 4904cc964beb37122f169eaaaf935f3ed24be160 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Tue, 29 Nov 2011 16:12:00 +0100 Subject: [PATCH 056/121] Feature #965: New one.vn.hold and one.vn.release methods to mark IPs as used, without an associated VM. Includes Ruby OCA and CLI --- include/Leases.h | 20 +++++ include/RequestManagerVirtualNetwork.h | 38 ++++++++ include/VirtualNetwork.h | 23 ++++- src/cli/onevnet | 23 ++++- src/oca/ruby/OpenNebula/VirtualNetwork.rb | 30 ++++++- src/rm/RequestManager.cc | 4 + src/rm/RequestManagerVirtualNetwork.cc | 2 +- src/vnm/Leases.cc | 103 +++++++++++++++++++--- src/vnm/VirtualNetwork.cc | 26 ++++++ 9 files changed, 250 insertions(+), 19 deletions(-) diff --git a/include/Leases.h b/include/Leases.h index 5927f36f14..bb8453e53b 100644 --- a/include/Leases.h +++ b/include/Leases.h @@ -102,6 +102,26 @@ public: virtual int remove_leases(vector& vector_leases, string& error_msg) = 0; + /** + * Holds a Lease, marking it as used + * @param vector_leases vector of VectorAttribute objects. For the + * moment, the vector can only contain one LEASE. + * @param error_msg If the action fails, this message contains + * the reason. + * @return 0 on success + */ + int hold_leases(vector& vector_leases, string& error_msg); + + /** + * Releases a Lease on hold + * @param vector_leases vector of VectorAttribute objects. For the + * moment, the vector can only contain one LEASE. + * @param error_msg If the action fails, this message contains + * the reason. + * @return 0 on success + */ + int free_leases(vector& vector_leases, string& error_msg); + // ------------------------------------------------------------------------- // ------------------------------------------------------------------------- diff --git a/include/RequestManagerVirtualNetwork.h b/include/RequestManagerVirtualNetwork.h index f402499ac2..4a6245754b 100644 --- a/include/RequestManagerVirtualNetwork.h +++ b/include/RequestManagerVirtualNetwork.h @@ -93,6 +93,44 @@ public: } }; +/* ------------------------------------------------------------------------- */ +/* ------------------------------------------------------------------------- */ + +class VirtualNetworkHold : public RequestManagerVirtualNetwork +{ +public: + VirtualNetworkHold(): + RequestManagerVirtualNetwork("VirtualNetworkHold", + "Holds a virtual network Lease as used"){}; + ~VirtualNetworkHold(){}; + + int leases_action(VirtualNetwork * vn, + VirtualNetworkTemplate * tmpl, + string& error_str) + { + return vn->hold_leases(tmpl, error_str); + } +}; + +/* ------------------------------------------------------------------------- */ +/* ------------------------------------------------------------------------- */ + +class VirtualNetworkRelease : public RequestManagerVirtualNetwork +{ +public: + VirtualNetworkRelease(): + RequestManagerVirtualNetwork("VirtualNetworkRelease", + "Releases a virtual network Lease on hold"){}; + ~VirtualNetworkRelease(){}; + + int leases_action(VirtualNetwork * vn, + VirtualNetworkTemplate * tmpl, + string& error_str) + { + return vn->free_leases(tmpl, error_str); + } +}; + /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ diff --git a/include/VirtualNetwork.h b/include/VirtualNetwork.h index 9146d69f97..6625c260b4 100644 --- a/include/VirtualNetwork.h +++ b/include/VirtualNetwork.h @@ -85,7 +85,7 @@ public: /** * Adds Leases to the virtual network (Only implemented for FIXED networks) - * @param leases_template template in the form LEASES = [IP=XX, MAC=XX]. + * @param leases template in the form LEASES = [IP=XX, MAC=XX]. * MAC is optional. The template can only contain one LEASE * definition. * @param error_msg If the action fails, this message contains the reason. @@ -96,7 +96,7 @@ public: /** * Removes Leases from the virtual network; if they are not used.(Only * implemented for FIXED networks) - * @param leases_template template in the form LEASES = [IP=XX]. + * @param leases template in the form LEASES = [IP=XX]. * The template can only contain one LEASE definition. * @param error_msg If the action fails, this message contains * the reason. @@ -104,6 +104,25 @@ public: */ int remove_leases(VirtualNetworkTemplate* leases, string& error_msg); + /** + * Holds a Lease, marking it as used + * @param leases template in the form LEASES = [IP=XX]. + * The template can only contain one LEASE definition. + * @param error_msg If the action fails, this message contains the reason. + * @return 0 on success + */ + int hold_leases(VirtualNetworkTemplate * leases, string& error_msg); + + /** + * Releases a Lease on hold + * @param leases template in the form LEASES = [IP=XX]. + * The template can only contain one LEASE definition. + * @param error_msg If the action fails, this message contains + * the reason. + * @return 0 on success + */ + int free_leases(VirtualNetworkTemplate* leases, string& error_msg); + /** * Gets a new lease for a specific VM * @param vid VM identifier diff --git a/src/cli/onevnet b/src/cli/onevnet index 72ab53716a..b2ba672371 100755 --- a/src/cli/onevnet +++ b/src/cli/onevnet @@ -93,8 +93,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do Adds a lease to the Virtual Network EOT - command :addleases, 'Adds a lease to the Virtual Network', :vnetid, :ip, - [:mac, nil] do + command :addleases, addleases_desc, :vnetid, :ip, [:mac, nil] do helper.perform_action(args[0],options,"lease added") do |vn| vn.addleases(args[1], args[2]) end @@ -110,6 +109,26 @@ cmd=CommandParser::CmdParser.new(ARGV) do end end + hold_desc = <<-EOT.unindent + Holds a Virtual Network lease, marking it as used + EOT + + command :hold, hold_desc, :vnetid, :ip do + helper.perform_action(args[0],options,"lease on hold") do |vn| + vn.hold(args[1]) + end + end + + release_desc = <<-EOT.unindent + Releases a Virtual Network lease on hold + EOT + + command :release, release_desc, :vnetid, :ip do + helper.perform_action(args[0],options,"lease released") do |vn| + vn.release(args[1]) + end + end + publish_desc = <<-EOT.unindent Publishes the given Virtual Network. A public Virtual Network can be seen and used by other Users in the Virtual Network's group diff --git a/src/oca/ruby/OpenNebula/VirtualNetwork.rb b/src/oca/ruby/OpenNebula/VirtualNetwork.rb index 7020bac0fc..b932d7cbe8 100644 --- a/src/oca/ruby/OpenNebula/VirtualNetwork.rb +++ b/src/oca/ruby/OpenNebula/VirtualNetwork.rb @@ -32,7 +32,9 @@ module OpenNebula :addleases => "vn.addleases", :rmleases => "vn.rmleases", :chown => "vn.chown", - :update => "vn.update" + :update => "vn.update", + :hold => "vn.hold", + :release => "vn.release" } VN_TYPES=%w{RANGED FIXED} @@ -128,6 +130,32 @@ module OpenNebula return rc end + # Holds a virtual network Lease as used + # @param ip [String] IP to hold + def hold(ip) + return Error.new('ID not defined') if !@pe_id + + lease_template = "LEASES = [ IP = #{ip} ]" + + rc = @client.call(VN_METHODS[:hold], @pe_id, lease_template) + rc = nil if !OpenNebula.is_error?(rc) + + return rc + end + + # Releases a virtual network Lease on hold + # @param ip [String] IP to release + def release(ip) + return Error.new('ID not defined') if !@pe_id + + lease_template = "LEASES = [ IP = #{ip} ]" + + rc = @client.call(VN_METHODS[:release], @pe_id, lease_template) + rc = nil if !OpenNebula.is_error?(rc) + + return rc + end + # Changes the owner/group # uid:: _Integer_ the new owner id. Set to -1 to leave the current one # gid:: _Integer_ the new group id. Set to -1 to leave the current one diff --git a/src/rm/RequestManager.cc b/src/rm/RequestManager.cc index 6c3ca96d3e..08dd938794 100644 --- a/src/rm/RequestManager.cc +++ b/src/rm/RequestManager.cc @@ -246,6 +246,8 @@ void RequestManager::register_xml_methods() // VirtualNetwork Methods xmlrpc_c::methodPtr vn_addleases(new VirtualNetworkAddLeases()); xmlrpc_c::methodPtr vn_rmleases(new VirtualNetworkRemoveLeases()); + xmlrpc_c::methodPtr vn_hold(new VirtualNetworkHold()); + xmlrpc_c::methodPtr vn_release(new VirtualNetworkRelease()); // Update Template Methods xmlrpc_c::methodPtr image_update(new ImageUpdateTemplate()); @@ -357,6 +359,8 @@ void RequestManager::register_xml_methods() /* Network related methods*/ RequestManagerRegistry.addMethod("one.vn.addleases", vn_addleases); RequestManagerRegistry.addMethod("one.vn.rmleases", vn_rmleases); + RequestManagerRegistry.addMethod("one.vn.hold", vn_hold); + RequestManagerRegistry.addMethod("one.vn.release", vn_release); RequestManagerRegistry.addMethod("one.vn.allocate", vn_allocate); RequestManagerRegistry.addMethod("one.vn.publish", vn_publish); RequestManagerRegistry.addMethod("one.vn.update", vn_update); diff --git a/src/rm/RequestManagerVirtualNetwork.cc b/src/rm/RequestManagerVirtualNetwork.cc index af410a025f..b3bb5ed0b8 100644 --- a/src/rm/RequestManagerVirtualNetwork.cc +++ b/src/rm/RequestManagerVirtualNetwork.cc @@ -80,7 +80,7 @@ void RequestManagerVirtualNetwork:: if ( rc < 0 ) { failure_response(INTERNAL, - request_error("Error modifiying network leases",error_str), + request_error("Error modifying network leases",error_str), att); vn->unlock(); diff --git a/src/vnm/Leases.cc b/src/vnm/Leases.cc index fa0eedabb1..c159294625 100644 --- a/src/vnm/Leases.cc +++ b/src/vnm/Leases.cc @@ -386,23 +386,11 @@ int Leases::update(SqlDB * db) bool Leases::check(const string& ip) { - map::iterator it; - unsigned int _ip; Leases::Lease::ip_to_number(ip,_ip); - - it=leases.find(_ip); - - if (it!=leases.end()) - { - return it->second->used; - } - else - { - return false; - } + return check(_ip); } /* -------------------------------------------------------------------------- */ @@ -424,6 +412,95 @@ bool Leases::check(unsigned int ip) } } +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + +int Leases::hold_leases(vector& vector_leases, + string& error_msg) +{ + const VectorAttribute * single_attr_lease = 0; + + int rc; + string ip; + string mac; + + if ( vector_leases.size() > 0 ) + { + single_attr_lease = + dynamic_cast(vector_leases[0]); + } + + if ( single_attr_lease == 0 ) + { + error_msg = "Empty lease description."; + return -1; + } + + ip = single_attr_lease->vector_value("IP"); + + if ( check(ip) ) + { + error_msg = "Lease is in use."; + return -1; + } + + rc = set(-1, ip, mac); + + if ( rc != 0 ) + { + error_msg = "Lease is not part of the NET."; + return -1; + } + + return 0; +} + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + +int Leases::free_leases(vector& vector_leases, + string& error_msg) +{ + const VectorAttribute * single_attr_lease = 0; + map::iterator it; + + unsigned int i_ip; + string st_ip; + string mac; + + if ( vector_leases.size() > 0 ) + { + single_attr_lease = + dynamic_cast(vector_leases[0]); + } + + if ( single_attr_lease == 0 ) + { + error_msg = "Empty lease description."; + return -1; + } + + st_ip = single_attr_lease->vector_value("IP"); + + if ( Leases::Lease::ip_to_number(st_ip,i_ip) != 0 ) + { + error_msg = "Wrong Lease format."; + return -1; + } + + it = leases.find(i_ip); + + if ( it == leases.end() || (it->second->used && it->second->vid != -1) ) + { + error_msg = "Lease is not on hold."; + return -1; + } + + release(st_ip); + + return 0; +} + /* ************************************************************************** */ /* Leases :: Misc */ /* ************************************************************************** */ diff --git a/src/vnm/VirtualNetwork.cc b/src/vnm/VirtualNetwork.cc index 72a833d407..5fa53f2115 100644 --- a/src/vnm/VirtualNetwork.cc +++ b/src/vnm/VirtualNetwork.cc @@ -646,3 +646,29 @@ int VirtualNetwork::remove_leases(VirtualNetworkTemplate * leases_template, /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ + +int VirtualNetwork::hold_leases(VirtualNetworkTemplate * leases_template, + string& error_msg) +{ + vector vector_leases; + + leases_template->get("LEASES", vector_leases); + + return leases->hold_leases(vector_leases, error_msg); +} + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + +int VirtualNetwork::free_leases(VirtualNetworkTemplate * leases_template, + string& error_msg) +{ + vector vector_leases; + + leases_template->get("LEASES", vector_leases); + + return leases->free_leases(vector_leases, error_msg); +} + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ From 05e40b5b6f41c3691e0e0b7a8ea6d99ad80056d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Tue, 29 Nov 2011 18:09:19 +0100 Subject: [PATCH 057/121] Feature #602: Small bugfixes --- include/Leases.h | 2 +- src/vnm/RangedLeases.cc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/Leases.h b/include/Leases.h index bb8453e53b..74a04d7928 100644 --- a/include/Leases.h +++ b/include/Leases.h @@ -42,7 +42,7 @@ public: */ Leases(SqlDB * _db, int _oid, unsigned long _size, unsigned int _mac_prefix): ObjectSQL(), - oid(_oid), size(_size), n_used(0), db(_db){}; + oid(_oid), size(_size), n_used(0), mac_prefix(_mac_prefix), db(_db){}; virtual ~Leases() { diff --git a/src/vnm/RangedLeases.cc b/src/vnm/RangedLeases.cc index 84c1bddaf0..d992ad29c0 100644 --- a/src/vnm/RangedLeases.cc +++ b/src/vnm/RangedLeases.cc @@ -176,7 +176,7 @@ int RangedLeases::process_template(VirtualNetwork* vn, vn->remove_template_attribute("NETWORK_SIZE"); // Set the network mask - net_mask = ( 0xFFFFFFFF << host_bits ) & 0xFFFFFFFF; + net_mask = 0xFFFFFFFF << host_bits; Lease::ip_to_string(net_mask, st_mask); vn->replace_template_attribute("NETWORK_MASK", st_mask); From 8ef3c966a4ea28c265ffe74e7dc183187c809587 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Tue, 29 Nov 2011 18:10:05 +0100 Subject: [PATCH 058/121] Feature #602: Fix tests --- src/vnm/test/VirtualNetworkPoolTest.cc | 36 +++++++++++++++++++------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/src/vnm/test/VirtualNetworkPoolTest.cc b/src/vnm/test/VirtualNetworkPoolTest.cc index 2d5801309c..556f6884a6 100644 --- a/src/vnm/test/VirtualNetworkPoolTest.cc +++ b/src/vnm/test/VirtualNetworkPoolTest.cc @@ -73,16 +73,16 @@ const string xmls[] = { "01230the_useroneadminNet number one1br100130.10.0.150:20:20:20:20:200-1", - "12610the_useroneadminA virtual network0br010", + "12610the_useroneadminA virtual network0br0192.168.0.1192.168.0.25410", "01330the_useroneadminNet number two1br100130.10.2.150:20:20:20:20:200-1", }; const string xml_dump = - "010the_useroneadminNet number one1br100120the_useroneadminA virtual network0br010"; + "010the_useroneadminNet number one1br100120the_useroneadminA virtual network0br0192.168.0.1192.168.0.25410"; const string xml_dump_where = - "120the_useroneadminA virtual network0br010"; + "120the_useroneadminA virtual network0br0192.168.0.1192.168.0.25410"; /* ************************************************************************* */ /* ************************************************************************* */ @@ -411,16 +411,16 @@ public: "TYPE = RANGED\n" "BRIDGE = br0\n" "NETWORK_SIZE = B\n" - "NETWORK_ADDRESS = 192.168.1.0\n", + "NETWORK_ADDRESS = 192.168.0.0\n", - // Size "X", defaults to 128 + // Size 126 "NAME = \"Net D\"\n" "TYPE = RANGED\n" "BRIDGE = br0\n" - "NETWORK_SIZE = X\n" + "NETWORK_SIZE = 126\n" "NETWORK_ADDRESS = 192.168.1.0\n", - // Size 32 + // Size 30 "NAME = \"Net E\"\n" "TYPE = RANGED\n" "BRIDGE = br0\n" @@ -428,7 +428,7 @@ public: "NETWORK_ADDRESS = 192.168.1.0\n" }; - unsigned int sizes[7]={1,3,256,256,65536,128,32}; + unsigned int sizes[7]={1,3,254,254,65534,126,30}; int oid[7]; for (int i = 0 ; i < 7 ; i++) @@ -695,7 +695,7 @@ public: CPPUNIT_ASSERT( rc != 0 ); - // Ask for two more IPs + // Ask for the rest of IPs vn->lock(); rc = vn->get_lease(123, ip, mac, bridge); vn->unlock(); @@ -708,12 +708,28 @@ public: CPPUNIT_ASSERT( rc == 0 ); + vn->lock(); + rc = vn->get_lease(457, ip, mac, bridge); + vn->unlock(); + + CPPUNIT_ASSERT( rc == 0 ); + + vn->lock(); + rc = vn->get_lease(458, ip, mac, bridge); + vn->unlock(); + + CPPUNIT_ASSERT( rc == 0 ); + + vn->lock(); + rc = vn->get_lease(459, ip, mac, bridge); + vn->unlock(); + + CPPUNIT_ASSERT( rc == 0 ); // All IPs are now used vn->lock(); rc = vn->get_lease(789, ip, mac, bridge); vn->unlock(); - CPPUNIT_ASSERT( rc != 0 ); // Release one of the 3 IPs From 09fe832399d175dcb12884d4f817788ad3b03fd9 Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Tue, 29 Nov 2011 11:51:27 +0100 Subject: [PATCH 059/121] feature #863: fix some bugs introduced with library changes --- src/image_mad/one_image.rb | 26 ++++++++++++++------------ src/vmm_mad/exec/one_vmm_exec.rb | 2 +- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/image_mad/one_image.rb b/src/image_mad/one_image.rb index 358972a879..2cde2db22b 100755 --- a/src/image_mad/one_image.rb +++ b/src/image_mad/one_image.rb @@ -54,12 +54,16 @@ class ImageDriver < OpenNebulaDriver @options={ :concurrency => 10, :threaded => true, - :retries => 0 + :retries => 0, + :local_actions => { + 'MV' => nil, + 'CP' => nil, + 'RM' => nil, + 'MKFS' => nil + } }.merge!(options) - super('', @options) - - @actions_path = "#{VAR_LOCATION}/remotes/image/#{fs_type}" + super("image/#{fs_type}", @options) register_action(ACTION[:mv].to_sym, method("mv")) register_action(ACTION[:cp].to_sym, method("cp")) @@ -69,23 +73,21 @@ class ImageDriver < OpenNebulaDriver # Image Manager Protocol Actions (generic implementation def mv(id, src, dst) - do_action("#{@actions_path}/mv #{src} #{dst} #{id}", id, nil, - ACTION[:mv], :local => true) + do_action("#{src} #{dst} #{id}", id, nil, + ACTION[:mv]) end def cp(id, src) - do_action("#{@actions_path}/cp #{src} #{id}", id, nil, ACTION[:cp], - :local => true) + do_action("#{src} #{id}", id, nil, ACTION[:cp]) end def rm(id, dst) - do_action("#{@actions_path}/rm #{dst} #{id}", id, nil, ACTION[:rm], - :local => true) + do_action("#{dst} #{id}", id, nil, ACTION[:rm]) end def mkfs(id, fs, size) - do_action("#{@actions_path}/mkfs #{fs} #{size} #{id}", id, nil, - ACTION[:mkfs], :local => true) + do_action("#{fs} #{size} #{id}", id, nil, + ACTION[:mkfs]) end end diff --git a/src/vmm_mad/exec/one_vmm_exec.rb b/src/vmm_mad/exec/one_vmm_exec.rb index 1ce1bc9c79..6e73a14d09 100755 --- a/src/vmm_mad/exec/one_vmm_exec.rb +++ b/src/vmm_mad/exec/one_vmm_exec.rb @@ -224,7 +224,7 @@ class ExecDriver < VirtualMachineDriver log(id, "Successfully executed network driver #{net_drv}" << " (clean-cancel)") - send_message(ACTION[:shutdown], RESULT[:success], id, domain_id) + send_message(ACTION[:shutdown], RESULT[:success], id, deploy_id) end def save(id, drv_message) From ab10f16d507f5d0e1db22c5c999a90851768e6c6 Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Tue, 29 Nov 2011 19:43:13 +0100 Subject: [PATCH 060/121] feature #863: added a configurable action system and changed some actions to use it --- src/vmm_mad/exec/one_vmm_exec.rb | 501 ++++++++++++++++--------------- 1 file changed, 264 insertions(+), 237 deletions(-) diff --git a/src/vmm_mad/exec/one_vmm_exec.rb b/src/vmm_mad/exec/one_vmm_exec.rb index 6e73a14d09..6a6b021e73 100755 --- a/src/vmm_mad/exec/one_vmm_exec.rb +++ b/src/vmm_mad/exec/one_vmm_exec.rb @@ -37,8 +37,148 @@ require 'ssh_stream' require 'pp' +class VmmAction + attr_reader :data + + def initialize(driver, id, action, xml_data) + @vmm=driver + @id=id + @main_action=action + @xml_data=@vmm.decode(xml_data) + + @data=Hash.new + + get_data(:host) + get_data(:net_drv) + get_data(:deploy_id) + get_data(:checkpoint_file) + + get_data(:local_dfile, :LOCAL_DEPLOYMENT_FILE) + get_data(:remote_dfile, :REMOTE_DEPLOYMENT_FILE) + + # For migration + get_data(:dest_host, :MIGR_HOST) + get_data(:dest_driver, :MIGR_NET_DRV) + + # Initialize streams and vnm + @ssh_src = @vmm.get_ssh_stream(@data[:host], @id) + @vnm_src = VirtualNetworkDriver.new(@data[:net_drv], + :local_actions => @vmm.options[:local_actions], + :message => @xml_data, + :ssh_stream => @ssh_src) + + if @data[:dest_host] and !@data[:dest_host].empty? + @ssh_dst = @vmm.get_ssh_stream(@data[:dest_host], @id) + @vnm_dst = VirtualNetworkDriver.new(@data[:dest_driver], + :local_actions => @vmm.options[:local_actions], + :message => @xml_data, + :ssh_stream => @ssh_dst) + end + end + + def get_data(name, xml_path=nil) + if xml_path + path=xml_path.to_s + else + path=name.to_s.upcase + end + + @data[name]=@xml_data.elements[path].text + end + +=begin + { + :driver => :vmm, + :action => :deploy, + :parameters => [:host, :deploy_id], + :destination => false + :save_info => :deploy_id, + :fail_actions => [], + :pre_log => "", + :post_log => "", + :stdin => nil + } +=end + + def execute_steps(steps) + result=false + info='Action #{step[:action]} not found' + + steps.each do |step| + + driver=step[:driver] || :vmm + + @vmm.log(@id, @data[:pre_log]) if @data[:pre_log] + + case driver + when :vmm + if step[:destination] + host = @data[:dest_host] + ssh = @ssh_dst + else + host = @data[:host] + ssh = @ssh_src + end + + result, info=@vmm.do_action(get_parameters(step), @id, host, + step[:action], + :ssh_stream => ssh, + :respond => false, + :stdin => step[:stdin]) + + when :vnm + if step[:destination] + vnm=@vnm_dst + else + vnm=@vnm_src + end + + result, info=vnm.do_action(@id, step[:action]) + else + end + + # Save the info variable if asked for + if @data[:save_info] + @data[@data[:save_info]]=info + end + + if @vmm.failed?(result) + if @data[:fail_actions] + execute_steps(@data[:fail_actions]) + end + + break + end + + @vmm.log(@id, @data[:post_log]) if @data[:post_log] + end + + return result, info + end + + def run(steps) + result, info=execute_steps(steps) + + @vmm.send_message(VirtualMachineDriver::ACTION[@main_action], + result, @id, info) + end + + def get_parameters(step) + parameters=step[:parameters] || [] + parameters.map do |param| + if Symbol===param + @data[param].to_s + else + param + end + end.join(' ') + end +end + + # The main class for the Sh driver class ExecDriver < VirtualMachineDriver + attr_reader :options # SshDriver constructor def initialize(hypervisor, options={}) @@ -51,19 +191,21 @@ class ExecDriver < VirtualMachineDriver @hypervisor = hypervisor end + def get_ssh_stream(host, id) + SshStreamCommand.new(host, + @remote_scripts_base_path, + log_method(id)) + end + # DEPLOY action, sends the deployment file to remote host def deploy(id, drv_message) # ---------------------------------------------------------------------- # Initialization of deployment data # ---------------------------------------------------------------------- - data = decode(drv_message) + action=VmmAction.new(self, id, :deploy, drv_message) - local_dfile = data.elements['LOCAL_DEPLOYMENT_FILE'].text - remote_dfile = data.elements['REMOTE_DEPLOYMENT_FILE'].text - - host = data.elements['HOST'].text - net_drv = data.elements['NET_DRV'].text + local_dfile=action.data[:local_dfile] if !local_dfile || File.zero?(local_dfile) send_message(ACTION[:deploy],RESULT[:failure],id, @@ -74,263 +216,146 @@ class ExecDriver < VirtualMachineDriver domain = File.read(local_dfile) if action_is_local?(:deploy) - dfile = local_dfile + dfile = action.data[:local_dfile] else - dfile = remote_dfile + dfile = action.data[:remote_dfile] end - ssh = SshStreamCommand.new(host, - @remote_scripts_base_path, - log_method(id)) + steps=[ + { + :driver => :vnm, + :action => :pre, + :post_log => "Successfully executed network driver " << + "#{action.data[:net_drv]} (pre-boot)" + }, + { + :driver => :vmm, + :action => :deploy, + :parameters => [dfile, :host], + :stdin => domain, + :save_info => :deploy_id + }, + { + :driver => :vnm, + :action => :post, + :fail_actions => [ + { + :driver => :vmm, + :action => :cancel, + :parameters => [:deploy_id, :host] + } + ] + } + ] - vnm = VirtualNetworkDriver.new(net_drv, - :local_actions => @options[:local_actions], - :message => data, - :ssh_stream => ssh) - - # ---------------------------------------------------------------------- - # Execute pre-boot action of the network driver - # ---------------------------------------------------------------------- - - result, info = vnm.do_action(id, :pre) - - if failed?(result) - send_message(ACTION[:deploy], result, id,info) - return - end - - log(id, "Successfully executed network driver #{net_drv} (pre-boot)") - - # ---------------------------------------------------------------------- - # Boot the VM - # ---------------------------------------------------------------------- - - result, info = do_action("#{dfile} #{host}", id, host, :deploy, - :stdin => domain, - :ssh_stream => ssh, - :respond => false) - if failed?(result) - send_message(ACTION[:deploy], result, id, info) - return - end - - deploy_id = info - - log(id, "Successfully booted VM with id: #{deploy_id}") - - # ---------------------------------------------------------------------- - # Execute post-boot action of the network driver - # ---------------------------------------------------------------------- - - result, info = vnm.do_action(id, :post) - - if failed?(result) - log(id, "Failed to executed network driver #{net_drv} (post-boot)") - log(id, "Canceling VM with id: #{deploy_id}") - - do_action("#{deploy_id} #{host}", id, host, :cancel, - :ssh_stream => ssh, - :respond => false) - - send_message(ACTION[:deploy], result, id, info) - return - end - - log(id, "Successfully executed network driver #{net_drv} (post-boot)") - - send_message(ACTION[:deploy], RESULT[:success], id, deploy_id) + action.run(steps) end # Basic Domain Management Operations def shutdown(id, drv_message) - data = decode(drv_message) - host = data.elements['HOST'].text - net_drv = data.elements['NET_DRV'].text - deploy_id = data.elements['DEPLOY_ID'].text + action=VmmAction.new(self, id, :shutdown, drv_message) - ssh = SshStreamCommand.new(host, - @remote_scripts_base_path, - log_method(id)) + steps=[ + { + :driver => :vmm, + :action => :shutdown, + :parameters => [:deploy_id, :host], + :post_log => "Successfully shut down VM with id: " << + action.data[:deploy_id] + }, + { + :driver => :vnm, + :action => :clean, + :post_log => "Successfully executed network driver " << + "#{action.data[:net_drv]} (clean-shutdown)" + } + } - vnm = VirtualNetworkDriver.new(net_drv, - :local_actions => @options[:local_actions], - :message => data, - :ssh_stream => ssh) - - result, info = do_action("#{deploy_id} #{host}", id, host, :shutdown, - :ssh_stream => ssh, - :respond => false) - - if failed?(result) - send_message(ACTION[:shutdown], result, id,info) - return - end - - log(id, "Successfully shut down VM with id: #{deploy_id}") - - # ---------------------------------------------------------------------- - # Execute clean action of the network driver - # ---------------------------------------------------------------------- - - result, info = vnm.do_action(id, :clean) - - if failed?(result) - send_message(ACTION[:shutdown], result, id,info) - return - end - - log(id, "Successfully executed network driver #{net_drv}" << - " (clean-shutdown)") + action.run(steps) end def cancel(id, drv_message) - data = decode(drv_message) - host = data.elements['HOST'].text - net_drv = data.elements['NET_DRV'].text - deploy_id = data.elements['DEPLOY_ID'].text + action=VmmAction.new(self, id, :cancel, drv_message) - ssh = SshStreamCommand.new(host, - @remote_scripts_base_path, - log_method(id)) + steps=[ + { + :driver => :vmm, + :action => :cancel, + :parameters => [:deploy_id, :host], + :post_log => "Successfully canceled VM with id: " << + action.data[:deploy_id] + }, + { + :driver => :vnm, + :action => :clean, + :post_log => "Successfully executed network driver " << + "#{action.data[:net_drv]} (clean-cancel)" + } + ] - vnm = VirtualNetworkDriver.new(net_drv, - :local_actions => @options[:local_actions], - :message => data, - :ssh_stream => ssh) - - result, info = do_action("#{deploy_id} #{host}", id, host, :cancel, - :ssh_stream => ssh, - :respond => false) - - if failed?(result) - send_message(ACTION[:cancel], result, id,info) - return - end - - log(id, "Successfully canceled VM with id: #{deploy_id}") - - # ---------------------------------------------------------------------- - # Execute clean action of the network driver - # ---------------------------------------------------------------------- - - result, info = vnm.do_action(id, :clean) - - if failed?(result) - send_message(ACTION[:cancel], result, id,info) - return - end - - log(id, "Successfully executed network driver #{net_drv}" << - " (clean-cancel)") - - send_message(ACTION[:shutdown], RESULT[:success], id, deploy_id) + action.run(steps) end def save(id, drv_message) - data = decode(drv_message) - host = data.elements['HOST'].text - net_drv = data.elements['NET_DRV'].text - deploy_id = data.elements['DEPLOY_ID'].text - file = data.elements['CHECKPOINT_FILE'].text + action=VmmAction.new(self, id, :save, drv_message) - ssh = SshStreamCommand.new(host, - @remote_scripts_base_path, - log_method(id)) + steps=[ + { + :driver => :vmm, + :action => :save, + :parameters => [:deploy_id, :checkpoint_file, :host], + :post_log => "Successfully saved VM with id: " << + action.data[:deploy_id] + }, + { + :driver => :vnm, + :action => :clean, + :post_log => "Successfully executed network driver " << + "#{action.data[:net_drv]} (clean-save)" + } + ] - vnm = VirtualNetworkDriver.new(net_drv, - :local_actions => @options[:local_actions], - :message => data, - :ssh_stream => ssh) - - result, info = do_action("#{deploy_id} #{file} #{host}", id, host, - :save, - :ssh_stream => ssh, - :respond => false) - - if failed?(result) - send_message(ACTION[:save], result, id,info) - return - end - - log(id, "Successfully saved VM with id: #{deploy_id}") - - # ---------------------------------------------------------------------- - # Execute clean action of the network driver - # ---------------------------------------------------------------------- - - result, info = vnm.do_action(id, :clean) - - if failed?(result) - send_message(ACTION[:save], result, id,info) - return - end - - log(id, "Successfully executed network driver #{net_drv}" << - " (clean-save)") - - send_message(ACTION[:save], RESULT[:success], id, domain_id) + action.run(steps) end def restore(id, drv_message) - data = decode(drv_message) - host = data.elements['HOST'].text - file = data.elements['CHECKPOINT_FILE'].text + action=VmmAction.new(self, id, :restore, drv_message) - ssh = SshStreamCommand.new(host, - @remote_scripts_base_path, - log_method(id)) + steps=[ + { + :driver => :vnm, + :action => :pre, + :post_log => "Successfully executed network driver " << + "#{action.data[:net_drv]} (pre-restore)" + }, + { + :driver => :vmm, + :action => :restore, + :parameters => [:checkpoint_file, :host], + :save_info => :deploy_id, + :post_log => "Successfully restored VM with id: " << + action.data[:deploy_id] + }, + { + :driver => :vnm, + :action => :post, + :fail_actions => [ + { + :pre_log => "Failed to execute network driver" << + "#{action.data[:net_drv]} (post-restore). " << + "Cancelling VM with id: #{action.data[:deploy_id]}" + :driver => :vmm, + :action => :cancel, + :parameters => [:deploy_id, :host] + } + ], + :post_log => "Successfully executed network driver " << + "#{action.data[:net_drv]} (post-restore)" + } + ] - vnm = VirtualNetworkDriver.new(net_drv, - :local_actions => @options[:local_actions], - :message => data, - :ssh_stream => ssh) - - # ---------------------------------------------------------------------- - # Execute pre-boot action of the network driver - # ---------------------------------------------------------------------- - - result, info = vnm.do_action(id, :pre) - - if failed?(result) - send_message(ACTION[:restore], result, id,info) - return - end - - log(id, "Successfully executed network driver #{net_drv} (pre-restore)") - - result, info = do_action("#{file} #{host}", id, host, :restore, - :save, - :ssh_stream => ssh, - :respond => false) - if failed?(result) - send_message(ACTION[:restore], result, id, info) - return - end - - log(id, "Successfully restored VM with id: #{info}") - - # ---------------------------------------------------------------------- - # Execute post-restore action of the network driver - # ---------------------------------------------------------------------- - - result, info = vnm.do_action(id, :post) - - if failed?(result) - log(id, "Failed to executed network driver #{net_drv} (post-restore)") - log(id, "Canceling VM with id: #{domain_id}") - - do_action("#{domain_id} #{host}", id, host, :cancel, - :ssh_stream => ssh, - :respond => false) - - send_message(ACTION[:restore], result, id, info) - return - end - - log(id, "Successfully executed network driver #{net_drv} (post-restore)") - - send_message(ACTION[:restore], RESULT[:success], id, domain_id) + action.run(steps) end def migrate(id, drv_message) @@ -455,3 +480,5 @@ exec_driver = ExecDriver.new(hypervisor, :local_actions => local_actions) exec_driver.start_driver + + From ee6888567a754a57b76837042b11094c748f41bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Wed, 30 Nov 2011 11:41:41 +0100 Subject: [PATCH 061/121] Feature #602: Add tests for range definition --- src/vnm/test/VirtualNetworkPoolTest.cc | 130 +++++++++++++++++++++++++ 1 file changed, 130 insertions(+) diff --git a/src/vnm/test/VirtualNetworkPoolTest.cc b/src/vnm/test/VirtualNetworkPoolTest.cc index 556f6884a6..2a26cbef48 100644 --- a/src/vnm/test/VirtualNetworkPoolTest.cc +++ b/src/vnm/test/VirtualNetworkPoolTest.cc @@ -180,6 +180,8 @@ class VirtualNetworkPoolTest : public PoolTest CPPUNIT_TEST (del_lease_nonexistent_ip); CPPUNIT_TEST (del_lease_used_ip); + CPPUNIT_TEST (range_definition); + CPPUNIT_TEST_SUITE_END (); protected: @@ -1642,6 +1644,134 @@ public: CPPUNIT_ASSERT( rc != 0 ); CPPUNIT_ASSERT( error_str != "" ); } + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + + void range_definition() + { + VirtualNetworkPoolFriend * vnpool = + static_cast(pool); + + int rc; + VirtualNetwork* vnet; + + int oid; + string xml_str; + string xpath; + string err; + + // All these templates should create the same range + string templ[] = { + "NAME = R\n" + "TYPE = RANGED\n" + "BRIDGE = vbr0\n" + "NETWORK_ADDRESS = 10.10.10.0\n" + "NETWORK_SIZE = C\n", + + "NAME = R\n" + "TYPE = RANGED\n" + "BRIDGE = vbr0\n" + "NETWORK_ADDRESS = 10.10.10.0\n" + "NETWORK_SIZE = 254\n", + + "NAME = R\n" + "TYPE = RANGED\n" + "BRIDGE = vbr0\n" + "NETWORK_ADDRESS = 10.10.10.0/24\n", + + "NAME = R\n" + "TYPE = RANGED\n" + "BRIDGE = vbr0\n" + "NETWORK_ADDRESS = 10.10.10.0\n" + "NETWORK_MASK = 255.255.255.0\n", + + + + "NAME = R\n" + "TYPE = RANGED\n" + "BRIDGE = vbr0\n" + "NETWORK_ADDRESS = 10.10.10.0/24\n" + "IP_START = 10.10.10.17\n", + + "NAME = R\n" + "TYPE = RANGED\n" + "BRIDGE = vbr0\n" + "NETWORK_ADDRESS = 10.10.10.0/24\n" + "IP_END = 10.10.10.41\n", + + "NAME = R\n" + "TYPE = RANGED\n" + "BRIDGE = vbr0\n" + "NETWORK_ADDRESS = 10.10.10.0/24\n" + "IP_START = 10.10.10.17\n" + "IP_END = 10.10.10.41\n", + + + + "NAME = R\n" + "TYPE = RANGED\n" + "BRIDGE = vbr0\n" + "IP_START = 10.10.10.17\n" + "IP_END = 10.10.10.41\n", + + "NAME = R\n" + "TYPE = RANGED\n" + "BRIDGE = vbr0\n" + "NETWORK_ADDRESS = 10.10.10.0\n", + }; + + string ip_start[] = { + "10.10.10.1", + "10.10.10.1", + "10.10.10.1", + "10.10.10.1", + + "10.10.10.17", + "10.10.10.1", + "10.10.10.17", + + "10.10.10.17", + + "10.10.10.1", + }; + + string ip_end[] = { + "10.10.10.254", + "10.10.10.254", + "10.10.10.254", + "10.10.10.254", + + "10.10.10.254", + "10.10.10.41", + "10.10.10.41", + + "10.10.10.41", + + "10.10.10.126", + }; + + + for (int i = 0 ; i < 9 ; i++) + { + rc = vnpool->allocate(uids[0], templ[i], &oid); + + CPPUNIT_ASSERT( rc >= 0 ); + + vnet = vnpool->get(oid, false); + CPPUNIT_ASSERT( vnet != 0 ); + + vnet->to_xml_extended(xml_str); + + ObjectXML::xpath_value(xpath, xml_str.c_str(), "/VNET/RANGE/IP_START" ); + CPPUNIT_ASSERT( xpath == ip_start[i] ); + + ObjectXML::xpath_value(xpath, xml_str.c_str(), "/VNET/RANGE/IP_END" ); + CPPUNIT_ASSERT( xpath == ip_end[i] ); + + vnpool->drop(vnet, err); + } + } }; /* ************************************************************************* */ From a173e7bd754abc0b372aae76fb6267d4f5883ea5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Wed, 30 Nov 2011 12:43:36 +0100 Subject: [PATCH 062/121] Feature #602: onevnet release returns error if a Lease is not used, this achieves the same behaviour for fixed and ranged networks --- src/vnm/Leases.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vnm/Leases.cc b/src/vnm/Leases.cc index c159294625..98cf0e38dc 100644 --- a/src/vnm/Leases.cc +++ b/src/vnm/Leases.cc @@ -490,7 +490,7 @@ int Leases::free_leases(vector& vector_leases, it = leases.find(i_ip); - if ( it == leases.end() || (it->second->used && it->second->vid != -1) ) + if ( it == leases.end() || !it->second->used || it->second->vid != -1 ) { error_msg = "Lease is not on hold."; return -1; From f0efbf09b6b36bfc7c1b9dd57e737fc908b02878 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Wed, 30 Nov 2011 13:19:15 +0100 Subject: [PATCH 063/121] Feature #602: Add VNet hold and release methods in Java OCA --- .../client/vnet/VirtualNetwork.java | 53 ++++++++++++++++++- src/oca/java/test/VirtualNetworkTest.java | 48 +++++++++++++++++ 2 files changed, 100 insertions(+), 1 deletion(-) diff --git a/src/oca/java/src/org/opennebula/client/vnet/VirtualNetwork.java b/src/oca/java/src/org/opennebula/client/vnet/VirtualNetwork.java index ac58d7a316..9bd60df8d3 100644 --- a/src/oca/java/src/org/opennebula/client/vnet/VirtualNetwork.java +++ b/src/oca/java/src/org/opennebula/client/vnet/VirtualNetwork.java @@ -36,7 +36,8 @@ public class VirtualNetwork extends PoolElement{ private static final String RMLEASES = METHOD_PREFIX + "rmleases"; private static final String CHOWN = METHOD_PREFIX + "chown"; private static final String UPDATE = METHOD_PREFIX + "update"; - + private static final String HOLD = METHOD_PREFIX + "hold"; + private static final String RELEASE = METHOD_PREFIX + "release"; /** * Creates a new virtual network representation. @@ -140,6 +141,32 @@ public class VirtualNetwork extends PoolElement{ return client.call(RMLEASES, id, template); } + /** + * Holds a VirtualNetwork lease, marking it as used + * + * @param client XML-RPC Client. + * @param id The virtual network id (nid) of the target network. + * @param template IP to hold, e.g. "LEASES = [ IP = 192.168.0.5 ]" + * @return A encapsulated response. + */ + public static OneResponse hold(Client client, int id, String template) + { + return client.call(HOLD, id, template); + } + + /** + * Releases a VirtualNetwork lease on hold + * + * @param client XML-RPC Client. + * @param id The virtual network id (nid) of the target network. + * @param template IP to release, e.g. "LEASES = [ IP = 192.168.0.5 ]" + * @return A encapsulated response. + */ + public static OneResponse release(Client client, int id, String template) + { + return client.call(RELEASE, id, template); + } + /** * Changes the owner/group * @@ -271,6 +298,30 @@ public class VirtualNetwork extends PoolElement{ return rmLeases(client, id, lease_template); } + /** + * Holds a VirtualNetwork lease, marking it as used + * + * @param ip IP to hold, e.g. "192.168.0.5" + * @return A encapsulated response. + */ + public OneResponse hold(String ip) + { + String lease_template = "LEASES = [ IP = " + ip + " ]"; + return hold(client, id, lease_template); + } + + /** + * Releases a VirtualNetwork lease on hold + * + * @param ip IP to release, e.g. "192.168.0.5" + * @return A encapsulated response. + */ + public OneResponse release(String ip) + { + String lease_template = "LEASES = [ IP = " + ip + " ]"; + return release(client, id, lease_template); + } + /** * Changes the owner/group * diff --git a/src/oca/java/test/VirtualNetworkTest.java b/src/oca/java/test/VirtualNetworkTest.java index dcea0775e6..6a0c86537b 100644 --- a/src/oca/java/test/VirtualNetworkTest.java +++ b/src/oca/java/test/VirtualNetworkTest.java @@ -209,6 +209,54 @@ public class VirtualNetworkTest fixed_vnet.delete(); } + @Test + public void holdFixed() + { + res = VirtualNetwork.allocate(client, fixed_template); + assertTrue( !res.isError() ); + + VirtualNetwork fixed_vnet = + new VirtualNetwork(Integer.parseInt(res.getMessage()), client); + + res = fixed_vnet.hold("130.10.0.1"); + assertTrue( !res.isError() ); + + res = fixed_vnet.hold("130.10.0.5"); + assertTrue( res.isError() ); + + res = fixed_vnet.release("130.10.0.1"); + assertTrue( !res.isError() ); + + res = fixed_vnet.release("130.10.0.1"); + assertTrue( res.isError() ); + + res = fixed_vnet.release("130.10.0.5"); + assertTrue( res.isError() ); + + fixed_vnet.delete(); + } + + @Test + public void holdRanged() + { + res = vnet.hold("192.168.0.10"); + assertTrue( !res.isError() ); + + res = vnet.hold("192.168.100.1"); + assertTrue( res.isError() ); + + res = vnet.release("192.168.0.10"); + assertTrue( !res.isError() ); + + res = vnet.release("192.168.0.10"); + assertTrue( res.isError() ); + + res = vnet.release("192.168.100.1"); + assertTrue( res.isError() ); + + vnet.delete(); + } + @Test public void update() { From b2c04d65cdd9ddfd60862aad5f47e41346c0fd52 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Wed, 30 Nov 2011 22:56:30 +0100 Subject: [PATCH 064/121] feature #863: Removed uneeded copyright comments --- src/mad/ruby/ActionManager.rb | 1 - src/mad/ruby/OpenNebulaDriver.rb | 4 ---- 2 files changed, 5 deletions(-) diff --git a/src/mad/ruby/ActionManager.rb b/src/mad/ruby/ActionManager.rb index abc66bab48..dfdea8aa8c 100644 --- a/src/mad/ruby/ActionManager.rb +++ b/src/mad/ruby/ActionManager.rb @@ -16,7 +16,6 @@ require 'thread' =begin rdoc -Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org) This class provides support to handle actions. Class methods, or actions, can be registered in the action manager. The manager will wait for actions to be diff --git a/src/mad/ruby/OpenNebulaDriver.rb b/src/mad/ruby/OpenNebulaDriver.rb index 3ecbdd23bb..316ca92af2 100644 --- a/src/mad/ruby/OpenNebulaDriver.rb +++ b/src/mad/ruby/OpenNebulaDriver.rb @@ -19,10 +19,6 @@ require "CommandManager" require "DriverExecHelper" -# Author:: dsa-research.org -# Copyright:: (c) OpenNebula Project Leads (OpenNebula.org) -# License:: Apache License - # This class provides basic messaging and logging functionality # to implement OpenNebula Drivers. A driver is a program that # specialize the OpenNebula behavior by interfacing with specific From 5414c030288627e8e8a80741425ae29aeb803ffa Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Wed, 30 Nov 2011 22:56:52 +0100 Subject: [PATCH 065/121] feature #863: added comments, simpler log messages. Now the main action info is the one returned to OpenNebula core --- src/mad/ruby/DriverExecHelper.rb | 2 +- src/vmm_mad/exec/one_vmm_exec.rb | 452 ++++++++++++++++--------------- 2 files changed, 231 insertions(+), 223 deletions(-) diff --git a/src/mad/ruby/DriverExecHelper.rb b/src/mad/ruby/DriverExecHelper.rb index 37581568fd..d6b632b7e0 100644 --- a/src/mad/ruby/DriverExecHelper.rb +++ b/src/mad/ruby/DriverExecHelper.rb @@ -24,7 +24,7 @@ module DriverExecHelper :failure => "FAILURE" } - def failed?(rc_str) + def self.failed?(rc_str) return rc_str == RESULT[:failure] end diff --git a/src/vmm_mad/exec/one_vmm_exec.rb b/src/vmm_mad/exec/one_vmm_exec.rb index 6a6b021e73..6d1c9130ca 100755 --- a/src/vmm_mad/exec/one_vmm_exec.rb +++ b/src/vmm_mad/exec/one_vmm_exec.rb @@ -40,13 +40,20 @@ require 'pp' class VmmAction attr_reader :data + # Initialize a VmmAction object + # @param[OpenNebula::ExecDriver] Driver to be used for the actions + # @param[String] Id of the VM + # @param[String] name of the actions as described in the VMM protocol + # @param[xml_data] data sent from OpenNebula core def initialize(driver, id, action, xml_data) - @vmm=driver - @id=id - @main_action=action - @xml_data=@vmm.decode(xml_data) + # Initialize object with xml data + @vmm = driver + @id = id - @data=Hash.new + @main_action = action + @xml_data = @vmm.decode(xml_data) + + @data = Hash.new get_data(:host) get_data(:net_drv) @@ -76,6 +83,115 @@ class VmmAction end end + #Execute a set of steps defined with + # - :driver :vmm or :vnm to execute the step + # - :action for the step + # - :parameters command line paremeters for the action + # - :destination use next host + # - :fail_action steps to be executed if steps fail + # - :stdin for the action + # @param [Array] of steps + def run(steps, info_on_success = nil) + result = execute_steps(steps) + + #Prepare the info for the OpenNebula core + if DriverExecHelper.failed?(result) + info = @data[:failed_info] + else + info = @data["#{@main_action.to_s}_info".to_sym] + end + + @vmm.send_message(VirtualMachineDriver::ACTION[@main_action], + result, @id, info) + end + + private + + DRIVER_NAMES = { + :vmm => "virtualization driver" + :vnm => "network driver" + } + + # Executes a set of steps. If one step fails any recover action is performed + # and the step execution breaks. + # @param [Array] array of steps to be executed + # @return [String, Hash] "SUCCESS/FAILURE" for the step set, and + # information associated to each step (by :_info). In case of + # failure information is also in [:failed_info] + def execute_steps(steps) + steps.each do |step| + # Execute Step + case step[:driver] + when :vmm + if step[:destination] + host = @data[:dest_host] + ssh = @ssh_dst + else + host = @data[:host] + ssh = @ssh_src + end + + result, info = @vmm.do_action(get_parameters(step[:parameters]), + @id, + host, + step[:action], + :ssh_stream => ssh, + :respond => false, + :stdin => step[:stdin]) + when :vnm + if step[:destination] + vnm = @vnm_dst + else + vnm = @vnm_src + end + + result, info = vnm.do_action(@id, step[:action]) + else + result = DriverExecHelper.RESULT[:failure] + info = "No driver in #{step[:action]}"} + end + + # Save the step info + @data["#{step[:action]}_info".to_sym] = info + + # Roll back steps, store failed info and break steps + if DriverExecHelper.failed?(result) + execute_steps(@data[:fail_actions]) if @data[:fail_actions] + @data[:failed_info] = info + + @vmm.log(@id, + "Failed to execute #{DRIVER_NAMES[step[:driver]]} " \ + "operation: #{step[:action]}.") + break + else + @vmm.log(@id, + "Sussecfully execute #{DRIVER_NAMES[step[:driver]]} " \ + "operation: #{step[:action]}.") + end + end + + return result + end + + # Prepare the parameters for the action step generating a blanck separated + # list of command arguments + # @param [Hash] an action step + def get_parameters(step_params) + parameters = step_params || [] + + parameters.map do |param| + if Symbol===param + @data[param].to_s + else + param + end + end.join(' ') + end + + # Extracts data from the XML argument of the VMM action + # @param [Symbol] corresponding to a XML element + # @param [String] an xpath for the XML element + # @return [String] the element value def get_data(name, xml_path=nil) if xml_path path=xml_path.to_s @@ -85,94 +201,6 @@ class VmmAction @data[name]=@xml_data.elements[path].text end - -=begin - { - :driver => :vmm, - :action => :deploy, - :parameters => [:host, :deploy_id], - :destination => false - :save_info => :deploy_id, - :fail_actions => [], - :pre_log => "", - :post_log => "", - :stdin => nil - } -=end - - def execute_steps(steps) - result=false - info='Action #{step[:action]} not found' - - steps.each do |step| - - driver=step[:driver] || :vmm - - @vmm.log(@id, @data[:pre_log]) if @data[:pre_log] - - case driver - when :vmm - if step[:destination] - host = @data[:dest_host] - ssh = @ssh_dst - else - host = @data[:host] - ssh = @ssh_src - end - - result, info=@vmm.do_action(get_parameters(step), @id, host, - step[:action], - :ssh_stream => ssh, - :respond => false, - :stdin => step[:stdin]) - - when :vnm - if step[:destination] - vnm=@vnm_dst - else - vnm=@vnm_src - end - - result, info=vnm.do_action(@id, step[:action]) - else - end - - # Save the info variable if asked for - if @data[:save_info] - @data[@data[:save_info]]=info - end - - if @vmm.failed?(result) - if @data[:fail_actions] - execute_steps(@data[:fail_actions]) - end - - break - end - - @vmm.log(@id, @data[:post_log]) if @data[:post_log] - end - - return result, info - end - - def run(steps) - result, info=execute_steps(steps) - - @vmm.send_message(VirtualMachineDriver::ACTION[@main_action], - result, @id, info) - end - - def get_parameters(step) - parameters=step[:parameters] || [] - parameters.map do |param| - if Symbol===param - @data[param].to_s - else - param - end - end.join(' ') - end end @@ -180,7 +208,9 @@ end class ExecDriver < VirtualMachineDriver attr_reader :options - # SshDriver constructor + # Initializes the VMM driver + # @param [String] hypervisor name identifies the plugin + # @param [OpenNebulaDriver::options] def initialize(hypervisor, options={}) @options={ :threaded => true @@ -191,20 +221,26 @@ class ExecDriver < VirtualMachineDriver @hypervisor = hypervisor end + # Creates an SshStream to execute commands on the target host + # @param[String] the hostname of the host + # @param[String] id of the VM to log messages + # @return [SshStreamCommand] def get_ssh_stream(host, id) SshStreamCommand.new(host, @remote_scripts_base_path, log_method(id)) end + #--------------------------------------------------------------------------- + # Virtual Machine Manager Protocol Actions + #--------------------------------------------------------------------------- + # # DEPLOY action, sends the deployment file to remote host + # def deploy(id, drv_message) # ---------------------------------------------------------------------- # Initialization of deployment data # ---------------------------------------------------------------------- - - action=VmmAction.new(self, id, :deploy, drv_message) - local_dfile=action.data[:local_dfile] if !local_dfile || File.zero?(local_dfile) @@ -221,28 +257,33 @@ class ExecDriver < VirtualMachineDriver dfile = action.data[:remote_dfile] end + # ---------------------------------------------------------------------- + # Deployment Steps + # ---------------------------------------------------------------------- + action = VmmAction.new(self, id, :deploy, drv_message) + steps=[ + # Execute pre-boot networking setup { - :driver => :vnm, - :action => :pre, - :post_log => "Successfully executed network driver " << - "#{action.data[:net_drv]} (pre-boot)" + :driver => :vnm, + :action => :pre }, + # Boot the Virtual Machine { - :driver => :vmm, - :action => :deploy, - :parameters => [dfile, :host], - :stdin => domain, - :save_info => :deploy_id - }, + :driver => :vmm, + :action => :deploy, + :parameters => [dfile, :host], + :stdin => domain + }, + # Execute post-boot networking setup { - :driver => :vnm, - :action => :post, - :fail_actions => [ + :driver => :vnm, + :action => :post, + :fail_actions => [ { :driver => :vmm, :action => :cancel, - :parameters => [:deploy_id, :host] + :parameters => [:deploy_info, :host] } ] } @@ -251,187 +292,149 @@ class ExecDriver < VirtualMachineDriver action.run(steps) end - # Basic Domain Management Operations - + # + # SHUTDOWN action, graceful shutdown and network clean up + # def shutdown(id, drv_message) - action=VmmAction.new(self, id, :shutdown, drv_message) + action = VmmAction.new(self, id, :shutdown, drv_message) steps=[ + # Shutdown the Virtual Machine { :driver => :vmm, :action => :shutdown, - :parameters => [:deploy_id, :host], - :post_log => "Successfully shut down VM with id: " << - action.data[:deploy_id] + :parameters => [:deploy_id, :host] }, + # Execute networking clean up operations { - :driver => :vnm, - :action => :clean, - :post_log => "Successfully executed network driver " << - "#{action.data[:net_drv]} (clean-shutdown)" + :driver => :vnm, + :action => :clean } } action.run(steps) end + # + # CANCEL action, destroys a VM and network clean up + # def cancel(id, drv_message) - action=VmmAction.new(self, id, :cancel, drv_message) + action = VmmAction.new(self, id, :cancel, drv_message) steps=[ + # Cancel the Virtual Machine { :driver => :vmm, :action => :cancel, - :parameters => [:deploy_id, :host], - :post_log => "Successfully canceled VM with id: " << - action.data[:deploy_id] + :parameters => [:deploy_id, :host] }, + # Execute networking clean up operations { - :driver => :vnm, - :action => :clean, - :post_log => "Successfully executed network driver " << - "#{action.data[:net_drv]} (clean-cancel)" + :driver => :vnm, + :action => :clean } ] action.run(steps) end + # + # SAVE action, stops the VM and saves its state, network is cleaned up + # def save(id, drv_message) - action=VmmAction.new(self, id, :save, drv_message) + action = VmmAction.new(self, id, :save, drv_message) steps=[ + # Save the Virtual Machine state { :driver => :vmm, :action => :save, - :parameters => [:deploy_id, :checkpoint_file, :host], - :post_log => "Successfully saved VM with id: " << - action.data[:deploy_id] + :parameters => [:deploy_id, :checkpoint_file, :host] }, + # Execute networking clean up operations { - :driver => :vnm, - :action => :clean, - :post_log => "Successfully executed network driver " << - "#{action.data[:net_drv]} (clean-save)" + :driver => :vnm, + :action => :clean } ] action.run(steps) end + # + # RESTORE action, restore a VM from a previous state, and restores network + # def restore(id, drv_message) action=VmmAction.new(self, id, :restore, drv_message) steps=[ + # Execute pre-boot networking setup { :driver => :vnm, - :action => :pre, - :post_log => "Successfully executed network driver " << - "#{action.data[:net_drv]} (pre-restore)" + :action => :pre }, + # Restore the Virtual Machine from checkpoint { :driver => :vmm, :action => :restore, - :parameters => [:checkpoint_file, :host], - :save_info => :deploy_id, - :post_log => "Successfully restored VM with id: " << - action.data[:deploy_id] + :parameters => [:checkpoint_file, :host] }, + # Execute post-boot networking setup { - :driver => :vnm, - :action => :post, - :fail_actions => [ + :driver => :vnm, + :action => :post, + :fail_actions => [ { - :pre_log => "Failed to execute network driver" << - "#{action.data[:net_drv]} (post-restore). " << - "Cancelling VM with id: #{action.data[:deploy_id]}" :driver => :vmm, :action => :cancel, :parameters => [:deploy_id, :host] } ], - :post_log => "Successfully executed network driver " << - "#{action.data[:net_drv]} (post-restore)" } ] action.run(steps) end + # + # MIGRATE (live) action, migrates a VM to another host creating network + # def migrate(id, drv_message) - data = decode(drv_message) - net_drv = data.elements['NET_DRV'].text - host = data.elements['HOST'].text - deploy_id = data.elements['DEPLOY_ID'].text - dest_host = data.elements['MIGR_HOST'].text - dest_driver = data.elements['MIGR_NET_DRV'].text + action=VmmAction.new(self, id, :migrate, drv_message) - ssh_src = SshStreamCommand.new(host, - @remote_scripts_base_path, - log_method(id)) + steps=[ + # Execute pre-boot networking setup on migrating host + { + :driver => :vnm, + :action => :pre, + :destination => true + }, + # Migrate the Virtual Machine + { + :driver => :vmm, + :action => :migrate, + :parameters => [:deploy_id, :migr_host, :host] + }, + # Execute networking clean up operations + { + :driver => :vnm, + :action => :clean + }, + # Execute post-boot networking setup on migrating host + { + :driver => :vnm, + :action => :post, + :destination => :true + #TODO :fail_action what to do here? cancel VM? + }, + ] - ssh_dst = SshStreamCommand.new(dest_host, - @remote_scripts_base_path, - log_method(id)) - - vnm_src = VirtualNetworkDriver.new(net_drv, - :local_actions => @options[:local_actions], - :message => data, - :ssh_stream => ssh_src) - - vnm_dst = VirtualNetworkDriver.new(dest_driver, - :local_actions => @options[:local_actions], - :message => data, - :ssh_stream => ssh_dst) - - # ---------------------------------------------------------------------- - # Execute pre-boot action of the network driver - # ---------------------------------------------------------------------- - - result, info = vnm_dst.do_action(id, :pre) - - if failed?(result) - send_message(ACTION[:migrate], result, id,info) - return - end - - log(id, "Successfully executed network driver #{net_drv} (pre-migrate)") - - result, info = do_action("#{deploy_id} #{dest_host} #{host}", id, host, - :migrate, - :save, - :ssh_stream => ssh_src, - :respond => false) - if failed?(result) - send_message(ACTION[:migrate], result, id, info) - return - end - - log(id, "Successfully migrated VM with id: #{deploy_id}") - - # ---------------------------------------------------------------------- - # Execute post-migrate action of the network driver - # ---------------------------------------------------------------------- - - result, info = vnm_dst.do_action(id, :post) - - if failed?(result) - log(id, "Failed to executed network driver #{dest_driver} (post-migrate)") - log(id, "Canceling VM with id: #{deploy_id}") - - do_action("#{deploy_id} #{host}", id, dest_host, :cancel, - :ssh_stream => ssh_dst, - :respond => false) - - send_message(ACTION[:restore], result, id, info) - return - end - - log(id, "Successfully executed network driver #{net_drv} (post-restore)") - - send_message(ACTION[:restore], RESULT[:success], id, deploy_id) + action.run(steps) end + # + # POLL action, gets information of a VM + # def poll(id, drv_message) data = decode(drv_message) host = data.elements['HOST'].text @@ -441,7 +444,12 @@ class ExecDriver < VirtualMachineDriver end end -# SshDriver Main program +################################################################################ +# +# Virtual Machine Manager Execution Driver - Main Program +# +################################################################################ + opts = GetoptLong.new( [ '--retries', '-r', GetoptLong::OPTIONAL_ARGUMENT ], [ '--threads', '-t', GetoptLong::OPTIONAL_ARGUMENT ], From 536d69b5ab017f2a04facc865d810b5c6561e485 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Thu, 1 Dec 2011 07:50:37 -0800 Subject: [PATCH 066/121] Feature #602: Change onevnet show format to separate used, free and 'on hold' leases --- src/cli/one_helper/onevnet_helper.rb | 18 ++++++++++++------ src/oca/ruby/OpenNebula/XMLUtils.rb | 4 ++-- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/cli/one_helper/onevnet_helper.rb b/src/cli/one_helper/onevnet_helper.rb index 71ead0d55f..3a59dac76a 100644 --- a/src/cli/one_helper/onevnet_helper.rb +++ b/src/cli/one_helper/onevnet_helper.rb @@ -73,13 +73,19 @@ class OneVNetHelper < OpenNebulaHelper::OneHelper puts str % ["IP_END", vn['RANGE/IP_END']] end - leases_str = vn.template_like_str('/VNET/LEASES', false) + lease_types = [ ["LEASES ON HOLD", 'LEASE[USED=1 and VID=-1]'], + ["USED LEASES", 'LEASE[USED=1 and VID>-1]'], + ["FREE LEASES", 'LEASE[USED=0]'] ] - if !leases_str.empty? - puts - CLIHelper.print_header(str_h1 % ["LEASES INFORMATION"], false) - puts leases_str - end + lease_types.each { |pair| + leases_str = vn.template_like_str('/VNET/LEASES', false, pair[1]) + + if !leases_str.empty? + puts + CLIHelper.print_header(str_h1 % [pair[0]], false) + puts leases_str + end + } end def format_pool(options) diff --git a/src/oca/ruby/OpenNebula/XMLUtils.rb b/src/oca/ruby/OpenNebula/XMLUtils.rb index 1dfa884532..3505fb9cc6 100644 --- a/src/oca/ruby/OpenNebula/XMLUtils.rb +++ b/src/oca/ruby/OpenNebula/XMLUtils.rb @@ -201,7 +201,7 @@ module OpenNebula template_like_str('TEMPLATE', indent) end - def template_like_str(root_element, indent=true) + def template_like_str(root_element, indent=true, xpath_exp=nil) if NOKOGIRI xml_template=@xml.xpath(root_element).to_s rexml=REXML::Document.new(xml_template).root @@ -217,7 +217,7 @@ module OpenNebula ind_tab=' ' end - str=rexml.collect {|n| + str=rexml.elements.collect(xpath_exp) {|n| if n.class==REXML::Element str_line="" if n.has_elements? From 1467190510a9014b0abf3413794f3f8b4e16b2a7 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Thu, 1 Dec 2011 19:29:46 +0100 Subject: [PATCH 067/121] feature #863: Solves minor bugs --- src/vmm_mad/exec/one_vmm_exec.rb | 14 +++++++++----- src/vnm_mad/remotes/802.1Q/HostManaged.rb | 8 ++++---- src/vnm_mad/remotes/OpenNebulaNetwork.rb | 6 +++++- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/vmm_mad/exec/one_vmm_exec.rb b/src/vmm_mad/exec/one_vmm_exec.rb index 6d1c9130ca..8deca53439 100755 --- a/src/vmm_mad/exec/one_vmm_exec.rb +++ b/src/vmm_mad/exec/one_vmm_exec.rb @@ -108,7 +108,7 @@ class VmmAction private DRIVER_NAMES = { - :vmm => "virtualization driver" + :vmm => "virtualization driver", :vnm => "network driver" } @@ -119,6 +119,8 @@ class VmmAction # information associated to each step (by :_info). In case of # failure information is also in [:failed_info] def execute_steps(steps) + result = DriverExecHelper.const_get(:RESULT)[:failure] + steps.each do |step| # Execute Step case step[:driver] @@ -147,8 +149,8 @@ class VmmAction result, info = vnm.do_action(@id, step[:action]) else - result = DriverExecHelper.RESULT[:failure] - info = "No driver in #{step[:action]}"} + result = DriverExecHelper.const_get(:RESULT)[:failure] + info = "No driver in #{step[:action]}" end # Save the step info @@ -238,6 +240,8 @@ class ExecDriver < VirtualMachineDriver # DEPLOY action, sends the deployment file to remote host # def deploy(id, drv_message) + action = VmmAction.new(self, id, :deploy, drv_message) + # ---------------------------------------------------------------------- # Initialization of deployment data # ---------------------------------------------------------------------- @@ -260,7 +264,6 @@ class ExecDriver < VirtualMachineDriver # ---------------------------------------------------------------------- # Deployment Steps # ---------------------------------------------------------------------- - action = VmmAction.new(self, id, :deploy, drv_message) steps=[ # Execute pre-boot networking setup @@ -296,6 +299,7 @@ class ExecDriver < VirtualMachineDriver # SHUTDOWN action, graceful shutdown and network clean up # def shutdown(id, drv_message) + action = VmmAction.new(self, id, :shutdown, drv_message) steps=[ @@ -310,7 +314,7 @@ class ExecDriver < VirtualMachineDriver :driver => :vnm, :action => :clean } - } + ] action.run(steps) end diff --git a/src/vnm_mad/remotes/802.1Q/HostManaged.rb b/src/vnm_mad/remotes/802.1Q/HostManaged.rb index 631d4ec2dc..8d5194b869 100644 --- a/src/vnm_mad/remotes/802.1Q/HostManaged.rb +++ b/src/vnm_mad/remotes/802.1Q/HostManaged.rb @@ -59,7 +59,7 @@ class OpenNebulaHM < OpenNebulaNetwork end def create_bridge(bridge) - exec_and_log("#{COMMANDS[:brctl]} addbr #{bridge}") + OpenNebula.exec_and_log("#{COMMANDS[:brctl]} addbr #{bridge}") end def device_exists?(dev, vlan=nil) @@ -68,7 +68,7 @@ class OpenNebulaHM < OpenNebulaNetwork end def create_dev_vlan(dev, vlan) - exec_and_log("#{COMMANDS[:vconfig]} add #{dev} #{vlan}") + OpenNebula.exec_and_log("#{COMMANDS[:vconfig]} add #{dev} #{vlan}") end def attached_bridge_dev?(bridge, dev, vlan=nil) @@ -79,11 +79,11 @@ class OpenNebulaHM < OpenNebulaNetwork def attach_brigde_dev(bridge, dev, vlan=nil) dev = "#{dev}.#{vlan}" if vlan - exec_and_log("#{COMMANDS[:brctl]} addif #{bridge} #{dev}") + OpenNebula.exec_and_log("#{COMMANDS[:brctl]} addif #{bridge} #{dev}") end def ifup(dev, vlan=nil) dev = "#{dev}.#{vlan}" if vlan - exec_and_log("#{COMMANDS[:ip]} link set #{dev} up") + OpenNebula.exec_and_log("#{COMMANDS[:ip]} link set #{dev} up") end end diff --git a/src/vnm_mad/remotes/OpenNebulaNetwork.rb b/src/vnm_mad/remotes/OpenNebulaNetwork.rb index fc49236d73..25cf31d8be 100644 --- a/src/vnm_mad/remotes/OpenNebulaNetwork.rb +++ b/src/vnm_mad/remotes/OpenNebulaNetwork.rb @@ -17,11 +17,15 @@ #--------------------------------------------------------------------------- # $: << File.dirname(__FILE__) +$: << File.join(File.dirname(__FILE__), '..') require 'rexml/document' require 'OpenNebulaNic' require 'base64' +require 'scripts_common' +include OpenNebula + CONF = { :start_vlan => 2 } @@ -29,7 +33,7 @@ CONF = { COMMANDS = { :ebtables => "sudo /sbin/ebtables", :iptables => "sudo /sbin/iptables", - :brctl => "sudo /usr/sbin/brctl", + :brctl => "sudo /sbin/brctl", :ip => "sudo /sbin/ip", :vconfig => "sudo /sbin/vconfig", :virsh => "virsh -c qemu:///system", From cb5837ec8e9dd80d9e455f3e049a86b96416d8e7 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Thu, 1 Dec 2011 20:10:02 +0100 Subject: [PATCH 068/121] feature #863: Fix dest_host bug --- src/vmm_mad/exec/one_vmm_exec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vmm_mad/exec/one_vmm_exec.rb b/src/vmm_mad/exec/one_vmm_exec.rb index 8deca53439..b16867ee56 100755 --- a/src/vmm_mad/exec/one_vmm_exec.rb +++ b/src/vmm_mad/exec/one_vmm_exec.rb @@ -417,7 +417,7 @@ class ExecDriver < VirtualMachineDriver { :driver => :vmm, :action => :migrate, - :parameters => [:deploy_id, :migr_host, :host] + :parameters => [:deploy_id, :dest_host, :host] }, # Execute networking clean up operations { From 8117ca4b77cf7e52b2c6155ee8d2e7f66772ce55 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Thu, 1 Dec 2011 21:58:29 +0100 Subject: [PATCH 069/121] Bug: Fixed wrong method name for VM migrate --- include/RequestManagerVirtualMachine.h | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/include/RequestManagerVirtualMachine.h b/include/RequestManagerVirtualMachine.h index 0c06b4582b..8c2dcccf32 100644 --- a/include/RequestManagerVirtualMachine.h +++ b/include/RequestManagerVirtualMachine.h @@ -108,12 +108,9 @@ class VirtualMachineMigrate : public RequestManagerVirtualMachine { public: VirtualMachineMigrate(): - RequestManagerVirtualMachine("VirtualMachineDeploy", + RequestManagerVirtualMachine("VirtualMachineMigrate", "Migrates a virtual machine", - "A:siib") - { - auth_op = AuthRequest::DEPLOY; - }; + "A:siib"){}; ~VirtualMachineMigrate(){}; From 22899b7139e6a784408c117c9607054f6b5f5f0a Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Fri, 2 Dec 2011 00:07:16 +0100 Subject: [PATCH 070/121] feature #863: Moved fw driver to standard pre-post-clean plugins. --- src/vnm_mad/remotes/{fw => }/Firewall.rb | 0 src/vnm_mad/remotes/fw/{firewall => clean} | 16 +++---------- src/vnm_mad/remotes/fw/post | 27 ++++++++++++++++++++++ src/vnm_mad/remotes/fw/pre | 19 +++++++++++++++ 4 files changed, 49 insertions(+), 13 deletions(-) rename src/vnm_mad/remotes/{fw => }/Firewall.rb (100%) rename src/vnm_mad/remotes/fw/{firewall => clean} (86%) create mode 100755 src/vnm_mad/remotes/fw/post create mode 100755 src/vnm_mad/remotes/fw/pre diff --git a/src/vnm_mad/remotes/fw/Firewall.rb b/src/vnm_mad/remotes/Firewall.rb similarity index 100% rename from src/vnm_mad/remotes/fw/Firewall.rb rename to src/vnm_mad/remotes/Firewall.rb diff --git a/src/vnm_mad/remotes/fw/firewall b/src/vnm_mad/remotes/fw/clean similarity index 86% rename from src/vnm_mad/remotes/fw/firewall rename to src/vnm_mad/remotes/fw/clean index ca5507d7f9..95c11359c4 100755 --- a/src/vnm_mad/remotes/fw/firewall +++ b/src/vnm_mad/remotes/fw/clean @@ -17,21 +17,11 @@ #--------------------------------------------------------------------------- # $: << File.dirname(__FILE__) +$: << File.join(File.dirname(__FILE__), "..") -require 'base64' require 'OpenNebulaNetwork' require 'Firewall' -action = ARGV[0] -template = ARGV[1] +fw = OpenNebulaFirewall.from_base64(ARGV[0]) -vm_xml = Base64::decode64(template) - -fw = OpenNebulaFirewall.new(vm_xml) - -case action -when "on" - fw.activate -when "off" - fw.deactivate -end +fw.deactivate diff --git a/src/vnm_mad/remotes/fw/post b/src/vnm_mad/remotes/fw/post new file mode 100755 index 0000000000..6458772e86 --- /dev/null +++ b/src/vnm_mad/remotes/fw/post @@ -0,0 +1,27 @@ +#!/usr/bin/env ruby + +# -------------------------------------------------------------------------- # +# 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. # +#--------------------------------------------------------------------------- # + +$: << File.dirname(__FILE__) +$: << File.join(File.dirname(__FILE__), "..") + +require 'OpenNebulaNetwork' +require 'Firewall' + +fw = OpenNebulaFirewall.from_base64(ARGV[0]) + +fw.activate diff --git a/src/vnm_mad/remotes/fw/pre b/src/vnm_mad/remotes/fw/pre new file mode 100755 index 0000000000..44337c50d2 --- /dev/null +++ b/src/vnm_mad/remotes/fw/pre @@ -0,0 +1,19 @@ +#!/bin/bash + +# -------------------------------------------------------------------------- # +# 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. # +#--------------------------------------------------------------------------- # + +exit 0 \ No newline at end of file From a4e880d93252351639043ca1386355d1d942c8d9 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Fri, 2 Dec 2011 00:07:53 +0100 Subject: [PATCH 071/121] feature #863: Fixes use od scripts_common for exec_and_log --- src/vnm_mad/remotes/ebtables/Ebtables.rb | 4 ++-- src/vnm_mad/remotes/ovswitch/OpenvSwitch.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/vnm_mad/remotes/ebtables/Ebtables.rb b/src/vnm_mad/remotes/ebtables/Ebtables.rb index 860a56fb0a..c22ad69340 100644 --- a/src/vnm_mad/remotes/ebtables/Ebtables.rb +++ b/src/vnm_mad/remotes/ebtables/Ebtables.rb @@ -22,7 +22,7 @@ class EbtablesVLAN < OpenNebulaNetwork end def ebtables(rule) - exec_and_log("#{COMMANDS[:ebtables]} -A #{rule}") + OpenNebula.exec_and_log("#{COMMANDS[:ebtables]} -A #{rule}") end # Activates ebtables rules @@ -82,6 +82,6 @@ class EbtablesVLAN < OpenNebulaNetwork end def remove_rule(rule) - exec_and_log("#{COMMANDS[:ebtables]} -D FORWARD #{rule}") + OpenNebula.exec_and_log("#{COMMANDS[:ebtables]} -D FORWARD #{rule}") end end diff --git a/src/vnm_mad/remotes/ovswitch/OpenvSwitch.rb b/src/vnm_mad/remotes/ovswitch/OpenvSwitch.rb index fdbf91c21e..9716d99f8a 100644 --- a/src/vnm_mad/remotes/ovswitch/OpenvSwitch.rb +++ b/src/vnm_mad/remotes/ovswitch/OpenvSwitch.rb @@ -32,7 +32,7 @@ class OpenvSwitchVLAN < OpenNebulaNetwork cmd = "#{COMMANDS[:ovs_vsctl]} set Port #{nic[:tap]} " cmd << "tag=#{vlan}" - exec_and_log(cmd) + OpenNebula.exec_and_log(cmd) end return 0 From bae7cc9b9cd2e28a588d3e762f509a7beee63114 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Fri, 2 Dec 2011 00:19:09 +0100 Subject: [PATCH 072/121] feature #863: Get unit tests for VNET drivers run again. (Still needs fix) --- src/vnm_mad/remotes/test/OpenNebulaNetwork_spec.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/vnm_mad/remotes/test/OpenNebulaNetwork_spec.rb b/src/vnm_mad/remotes/test/OpenNebulaNetwork_spec.rb index c8e7c14ccd..88fdee820e 100644 --- a/src/vnm_mad/remotes/test/OpenNebulaNetwork_spec.rb +++ b/src/vnm_mad/remotes/test/OpenNebulaNetwork_spec.rb @@ -1,7 +1,11 @@ #!/usr/bin/env ruby -$: << File.dirname(__FILE__) + '/..' \ - << './' +$: << File.dirname(__FILE__) + '/..' +$: << File.dirname(__FILE__) + '/../ebtables' +$: << File.dirname(__FILE__) + '/../802.1Q' +$: << File.dirname(__FILE__) + '/../ovswitch' +$: << File.dirname(__FILE__) + '/../../../mad/ruby' +$: << './' require 'rubygems' require 'rspec' From cdf1231f819814b3e98b5c5747dd34b78203846d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Fri, 2 Dec 2011 12:23:21 +0100 Subject: [PATCH 073/121] Feature #602 #863: Add VLAN tag to vnets and VM NIC attribute --- include/VirtualNetwork.h | 5 +++++ src/cli/one_helper/onevnet_helper.rb | 1 + src/vnm/VirtualNetwork.cc | 29 ++++++++++++++++++++++---- src/vnm/test/VirtualNetworkPoolTest.cc | 14 ++++++------- 4 files changed, 38 insertions(+), 11 deletions(-) diff --git a/include/VirtualNetwork.h b/include/VirtualNetwork.h index 6625c260b4..cca301be12 100644 --- a/include/VirtualNetwork.h +++ b/include/VirtualNetwork.h @@ -227,6 +227,11 @@ private: */ string vlan_id; + /** + * Whether or not to isolate this network with the vnm driver + */ + int vlan; + // ------------------------------------------------------------------------- // Virtual Network Description // ------------------------------------------------------------------------- diff --git a/src/cli/one_helper/onevnet_helper.rb b/src/cli/one_helper/onevnet_helper.rb index acaf71d0bb..561f49d97a 100644 --- a/src/cli/one_helper/onevnet_helper.rb +++ b/src/cli/one_helper/onevnet_helper.rb @@ -59,6 +59,7 @@ class OneVNetHelper < OpenNebulaHelper::OneHelper puts str % ["PUBLIC", OpenNebulaHelper.boolean_to_str(vn['PUBLIC'])] puts str % ["TYPE", vn.type_str] puts str % ["BRIDGE", vn["BRIDGE"]] + puts str % ["VLAN", OpenNebulaHelper.boolean_to_str(vn['VLAN'])] puts str % ["PHYSICAL DEVICE", vn["PHYDEV"]] if vn["PHYDEV"] puts str % ["VLAN ID", vn["VLAN_ID"]] if vn["VLAN_ID"] puts str % ["USED LEASES", vn['TOTAL_LEASES']] diff --git a/src/vnm/VirtualNetwork.cc b/src/vnm/VirtualNetwork.cc index 5fa53f2115..0579f4d270 100644 --- a/src/vnm/VirtualNetwork.cc +++ b/src/vnm/VirtualNetwork.cc @@ -25,6 +25,8 @@ #include "AuthManager.h" +#define TO_UPPER(S) transform(S.begin(),S.end(),S.begin(),(int(*)(int))toupper) + /* ************************************************************************** */ /* Virtual Network :: Constructor/Destructor */ /* ************************************************************************** */ @@ -171,6 +173,7 @@ int VirtualNetwork::insert(SqlDB * db, string& error_str) int rc; string pub; + string vlan_attr; string s_type; string ranged_error_str; @@ -183,7 +186,7 @@ int VirtualNetwork::insert(SqlDB * db, string& error_str) // ------------ TYPE ---------------------- erase_template_attribute("TYPE",s_type); - transform(s_type.begin(),s_type.end(),s_type.begin(),(int(*)(int))toupper); + TO_UPPER(s_type); if (s_type == "RANGED") { @@ -219,6 +222,14 @@ int VirtualNetwork::insert(SqlDB * db, string& error_str) erase_template_attribute("VLAN_ID",vlan_id); + // ------------ VLAN ---------------------- + + erase_template_attribute("VLAN", vlan_attr); + + TO_UPPER(vlan_attr); + + vlan = (vlan_attr == "YES"); + // ------------ BRIDGE -------------------- erase_template_attribute("BRIDGE",bridge); @@ -236,7 +247,6 @@ int VirtualNetwork::insert(SqlDB * db, string& error_str) oss << "onebr" << oid; bridge = oss.str(); - replace_template_attribute("BRIDGE",bridge); } } @@ -244,7 +254,7 @@ int VirtualNetwork::insert(SqlDB * db, string& error_str) erase_template_attribute("PUBLIC", pub); - transform (pub.begin(), pub.end(), pub.begin(), (int(*)(int))toupper); + TO_UPPER(pub); public_obj = (pub == "YES"); @@ -456,7 +466,8 @@ string& VirtualNetwork::to_xml_extended(string& xml, bool extended) const "" << gname << "" << "" << name << "" << "" << type << "" << - "" << bridge << ""; + "" << bridge << ""<< + "" << vlan << ""; if (!phydev.empty()) { @@ -522,6 +533,7 @@ int VirtualNetwork::from_xml(const string &xml_str) rc += xpath(int_type, "/VNET/TYPE", -1); rc += xpath(bridge, "/VNET/BRIDGE", "not_found"); rc += xpath(public_obj, "/VNET/PUBLIC", 0); + rc += xpath(vlan, "/VNET/VLAN", 0); xpath(phydev, "/VNET/PHYDEV", ""); xpath(vlan_id, "/VNET/VLAN_ID",""); @@ -605,6 +617,15 @@ int VirtualNetwork::nic_attribute(VectorAttribute *nic, int vid) nic->replace("MAC" ,mac); nic->replace("IP" ,ip); + if ( vlan == 1 ) + { + nic->replace("VLAN", "YES"); + } + else + { + nic->replace("VLAN", "NO"); + } + if (!phydev.empty()) { nic->replace("PHYDEV", phydev); diff --git a/src/vnm/test/VirtualNetworkPoolTest.cc b/src/vnm/test/VirtualNetworkPoolTest.cc index 2a26cbef48..d1744b2876 100644 --- a/src/vnm/test/VirtualNetworkPoolTest.cc +++ b/src/vnm/test/VirtualNetworkPoolTest.cc @@ -71,18 +71,18 @@ const string templates[] = const string xmls[] = { - "01230the_useroneadminNet number one1br100130.10.0.150:20:20:20:20:200-1", + "01230the_useroneadminNet number one1br1000130.10.0.150:20:20:20:20:200-1", - "12610the_useroneadminA virtual network0br0192.168.0.1192.168.0.25410", + "12610the_useroneadminA virtual network0br00192.168.0.1192.168.0.25410", - "01330the_useroneadminNet number two1br100130.10.2.150:20:20:20:20:200-1", + "01330the_useroneadminNet number two1br1000130.10.2.150:20:20:20:20:200-1", }; const string xml_dump = - "010the_useroneadminNet number one1br100120the_useroneadminA virtual network0br0192.168.0.1192.168.0.25410"; + "010the_useroneadminNet number one1br1000120the_useroneadminA virtual network0br00192.168.0.1192.168.0.25410"; const string xml_dump_where = - "120the_useroneadminA virtual network0br0192.168.0.1192.168.0.25410"; + "120the_useroneadminA virtual network0br00192.168.0.1192.168.0.25410"; /* ************************************************************************* */ /* ************************************************************************* */ @@ -312,8 +312,8 @@ public: }; string phydev_xml[] = { - "000the_useroneadminBRIDGE and PHYDEV1br0eth000130.10.0.150:20:20:20:20:200-1", - "100the_useroneadminNo BRIDGE only PHYDEV1onebr1eth000130.10.0.150:20:20:20:20:200-1" + "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" }; // test vm with bridge and phydev From 7a11688738b9b02f7b7c1e2e8724b048dfdaff95 Mon Sep 17 00:00:00 2001 From: Jaime Melis Date: Fri, 2 Dec 2011 12:35:55 +0100 Subject: [PATCH 074/121] feature #863: Remove the filtering functionality, just rely on the VLAN=yes option. --- src/vnm_mad/remotes/OpenNebulaNetwork.rb | 32 +++------------- src/vnm_mad/remotes/OpenNebulaNic.rb | 48 ------------------------ src/vnm_mad/remotes/ebtables/post | 5 --- 3 files changed, 5 insertions(+), 80 deletions(-) diff --git a/src/vnm_mad/remotes/OpenNebulaNetwork.rb b/src/vnm_mad/remotes/OpenNebulaNetwork.rb index 25cf31d8be..79c8e14fa4 100644 --- a/src/vnm_mad/remotes/OpenNebulaNetwork.rb +++ b/src/vnm_mad/remotes/OpenNebulaNetwork.rb @@ -42,11 +42,8 @@ COMMANDS = { :lsmod => "/sbin/lsmod" } -# -# -# class VM - attr_accessor :nics, :filtered_nics, :vm_info + attr_accessor :nics, :vm_info def initialize(vm_root, hypervisor) @vm_root = vm_root @@ -55,7 +52,7 @@ class VM nics = Nics.new(@hypervisor) - @vm_root.elements.each("TEMPLATE/NIC") do |nic_element| + @vm_root.elements.each("TEMPLATE/NIC[VLAN=yes]") do |nic_element| nic = nics.new_nic nic_element.elements.each('*') do |nic_attribute| @@ -69,21 +66,12 @@ class VM nics << nic end - @nics = nics - @filtered_nics = nics - end - - def filter(*filter) - @filtered_nics = @nics.get(*filter) - end - - def unfilter - @filtered_nics = @nics + @nics = nics end def each_nic(block) - if @filtered_nics != nil - @filtered_nics.each do |the_nic| + if @nics != nil + @nics.each do |the_nic| block.call(the_nic) end end @@ -118,16 +106,6 @@ class OpenNebulaNetwork @vm = VM.new(REXML::Document.new(vm_tpl).root, @hypervisor) end - def filter(*filter) - @vm.filter(*filter) - self - end - - def unfilter - @vm.unfilter - self - end - def process(&block) @vm.each_nic(block) end diff --git a/src/vnm_mad/remotes/OpenNebulaNic.rb b/src/vnm_mad/remotes/OpenNebulaNic.rb index d2916a91bd..2872de52ee 100644 --- a/src/vnm_mad/remotes/OpenNebulaNic.rb +++ b/src/vnm_mad/remotes/OpenNebulaNic.rb @@ -28,54 +28,6 @@ class Nics < Array def new_nic @nicClass.new end - - # finds nics that match 'args' - # 'args' can be a Hash, or an array - # args example: - # {:mac => "02:00:C0:A8:01:01", :bridge => "br0"} - # :mac, "02:00:C0:A8:01:01" - # key values may also be an array: - # {:mac => "02:00:C0:A8:01:01", :bridge => ["br0","br1"]} - def get(*args) - if args.length == 2 - dict = Hash.new - dict[args[0]] = args[1] - elsif args.length == 1 - dict = args[0] - else - return nil - end - - matching = Array.new - self.each do |e| - e_filter = Hash.new - dict.each_key{|k| e_filter[k] = e[k]} - if compare(e_filter,dict) - matching << e - end - end - - if matching.empty? - nil - else - matching - end - end - - def compare(hash1, hash2) - #hash1 has a single value per key - #hash2 may contain an array of values - hash1.each do |k,v| - return false if !hash2[k] - v2 = hash2[k] - if hash2[k].kind_of?(Array) - return false if !v2.include? v - else - return false if v != v2 - end - end - true - end end diff --git a/src/vnm_mad/remotes/ebtables/post b/src/vnm_mad/remotes/ebtables/post index e69f291c26..c142e41a2f 100755 --- a/src/vnm_mad/remotes/ebtables/post +++ b/src/vnm_mad/remotes/ebtables/post @@ -21,10 +21,5 @@ $: << File.join(File.dirname(__FILE__), "..") require 'Ebtables' -# Uncomment to act only on the listed bridges. -#FILTERED_BRIDGES = ['br0'] - onevlan = EbtablesVLAN.from_base64(ARGV[0]) - -onevlan.filter(:bridge => FILTERED_BRIDGES) if defined? FILTERED_BRIDGES exit onevlan.activate From 5f7cea8083675c1285eec0d3247c39cb2526e396 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Fri, 2 Dec 2011 12:23:21 +0100 Subject: [PATCH 075/121] Feature #602 #863: Add VLAN tag to vnets and VM NIC attribute (cherry picked from commit cdf1231f819814b3e98b5c5747dd34b78203846d) Conflicts: src/cli/one_helper/onevnet_helper.rb src/vnm/test/VirtualNetworkPoolTest.cc --- include/VirtualNetwork.h | 5 +++++ src/cli/one_helper/onevnet_helper.rb | 5 +++++ src/vnm/VirtualNetwork.cc | 29 ++++++++++++++++++++++---- src/vnm/test/VirtualNetworkPoolTest.cc | 14 ++++++------- 4 files changed, 42 insertions(+), 11 deletions(-) diff --git a/include/VirtualNetwork.h b/include/VirtualNetwork.h index be02e86954..b398b8aee2 100644 --- a/include/VirtualNetwork.h +++ b/include/VirtualNetwork.h @@ -208,6 +208,11 @@ private: */ string vlan_id; + /** + * Whether or not to isolate this network with the vnm driver + */ + int vlan; + // ------------------------------------------------------------------------- // Virtual Network Description // ------------------------------------------------------------------------- diff --git a/src/cli/one_helper/onevnet_helper.rb b/src/cli/one_helper/onevnet_helper.rb index 07a4dab8e9..6abd1a60dd 100644 --- a/src/cli/one_helper/onevnet_helper.rb +++ b/src/cli/one_helper/onevnet_helper.rb @@ -56,6 +56,11 @@ class OneVNetHelper < OpenNebulaHelper::OneHelper puts str % ["USER", vn['UNAME']] puts str % ["GROUP", vn['GNAME']] puts str % ["PUBLIC", OpenNebulaHelper.boolean_to_str(vn['PUBLIC'])] + puts str % ["TYPE", vn.type_str] + puts str % ["BRIDGE", vn["BRIDGE"]] + puts str % ["VLAN", OpenNebulaHelper.boolean_to_str(vn['VLAN'])] + puts str % ["PHYSICAL DEVICE", vn["PHYDEV"]] if vn["PHYDEV"] + puts str % ["VLAN ID", vn["VLAN_ID"]] if vn["VLAN_ID"] puts str % ["USED LEASES", vn['TOTAL_LEASES']] puts diff --git a/src/vnm/VirtualNetwork.cc b/src/vnm/VirtualNetwork.cc index 520ba533b5..77762d0830 100644 --- a/src/vnm/VirtualNetwork.cc +++ b/src/vnm/VirtualNetwork.cc @@ -25,6 +25,8 @@ #include "AuthManager.h" +#define TO_UPPER(S) transform(S.begin(),S.end(),S.begin(),(int(*)(int))toupper) + /* ************************************************************************** */ /* Virtual Network :: Constructor/Destructor */ /* ************************************************************************** */ @@ -207,6 +209,7 @@ int VirtualNetwork::insert(SqlDB * db, string& error_str) int rc; string pub; + string vlan_attr; string s_type; unsigned int default_size = VirtualNetworkPool::default_size(); @@ -219,7 +222,7 @@ int VirtualNetwork::insert(SqlDB * db, string& error_str) // ------------ TYPE ---------------------- erase_template_attribute("TYPE",s_type); - transform(s_type.begin(),s_type.end(),s_type.begin(),(int(*)(int))toupper); + TO_UPPER(s_type); if (s_type == "RANGED") { @@ -255,6 +258,14 @@ int VirtualNetwork::insert(SqlDB * db, string& error_str) erase_template_attribute("VLAN_ID",vlan_id); + // ------------ VLAN ---------------------- + + erase_template_attribute("VLAN", vlan_attr); + + TO_UPPER(vlan_attr); + + vlan = (vlan_attr == "YES"); + // ------------ BRIDGE -------------------- erase_template_attribute("BRIDGE",bridge); @@ -272,7 +283,6 @@ int VirtualNetwork::insert(SqlDB * db, string& error_str) oss << "onebr" << oid; bridge = oss.str(); - replace_template_attribute("BRIDGE",bridge); } } @@ -280,7 +290,7 @@ int VirtualNetwork::insert(SqlDB * db, string& error_str) erase_template_attribute("PUBLIC", pub); - transform (pub.begin(), pub.end(), pub.begin(), (int(*)(int))toupper); + TO_UPPER(pub); public_obj = (pub == "YES"); @@ -515,7 +525,8 @@ string& VirtualNetwork::to_xml_extended(string& xml, bool extended) const "" << gname << "" << "" << name << "" << "" << type << "" << - "" << bridge << ""; + "" << bridge << ""<< + "" << vlan << ""; if (!phydev.empty()) { @@ -566,6 +577,7 @@ int VirtualNetwork::from_xml(const string &xml_str) rc += xpath(int_type, "/VNET/TYPE", -1); rc += xpath(bridge, "/VNET/BRIDGE", "not_found"); rc += xpath(public_obj, "/VNET/PUBLIC", 0); + rc += xpath(vlan, "/VNET/VLAN", 0); xpath(phydev, "/VNET/PHYDEV", ""); xpath(vlan_id, "/VNET/VLAN_ID",""); @@ -636,6 +648,15 @@ int VirtualNetwork::nic_attribute(VectorAttribute *nic, int vid) nic->replace("MAC" ,mac); nic->replace("IP" ,ip); + if ( vlan == 1 ) + { + nic->replace("VLAN", "YES"); + } + else + { + nic->replace("VLAN", "NO"); + } + if (!phydev.empty()) { nic->replace("PHYDEV", phydev); diff --git a/src/vnm/test/VirtualNetworkPoolTest.cc b/src/vnm/test/VirtualNetworkPoolTest.cc index e7854565e1..033a188943 100644 --- a/src/vnm/test/VirtualNetworkPoolTest.cc +++ b/src/vnm/test/VirtualNetworkPoolTest.cc @@ -71,18 +71,18 @@ const string templates[] = const string xmls[] = { - "01230the_useroneadminNet number one1br100130.10.0.150:20:20:20:20:200-1", + "01230the_useroneadminNet number one1br1000130.10.0.150:20:20:20:20:200-1", - "12610the_useroneadminA virtual network0br010", + "12610the_useroneadminA virtual network0br0010", - "01330the_useroneadminNet number two1br100130.10.2.150:20:20:20:20:200-1", + "01330the_useroneadminNet number two1br1000130.10.2.150:20:20:20:20:200-1", }; const string xml_dump = - "010the_useroneadminNet number one1br100120the_useroneadminA virtual network0br010"; + "010the_useroneadminNet number one1br1000120the_useroneadminA virtual network0br0010"; const string xml_dump_where = - "120the_useroneadminA virtual network0br010"; + "120the_useroneadminA virtual network0br0010"; /* ************************************************************************* */ /* ************************************************************************* */ @@ -310,8 +310,8 @@ public: }; string phydev_xml[] = { - "000the_useroneadminBRIDGE and PHYDEV1br0eth000130.10.0.150:20:20:20:20:200-1", - "100the_useroneadminNo BRIDGE only PHYDEV1onebr1eth000130.10.0.150:20:20:20:20:200-1" + "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" }; // test vm with bridge and phydev From 6a9ac5ae0d59e717d4b751013b7ee952631fe769 Mon Sep 17 00:00:00 2001 From: Tino Vazquez Date: Fri, 2 Dec 2011 12:44:11 +0100 Subject: [PATCH 076/121] =?UTF-8?q?feature-#863:=20=C3Change=20arguments?= =?UTF-8?q?=20for=20onehost=20create=20to=20ensure=20compatiblity?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/cli/onehost | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cli/onehost b/src/cli/onehost index adf060ba36..c002900274 100755 --- a/src/cli/onehost +++ b/src/cli/onehost @@ -60,10 +60,10 @@ cmd=CommandParser::CmdParser.new(ARGV) do Creates a new Host EOT - command :create, create_desc, :hostname, :im_mad, :vmm_mad, :vnm_mad, - :tm_mad do + command :create, create_desc, :hostname, :im_mad, :vmm_mad, + :tm_mad, :vnm_mad do helper.create_resource(options) do |host| - host.allocate(args[0], args[1], args[2], args[3], args[4]) + host.allocate(args[0], args[1], args[2], args[4], args[3]) end end From cb1c13c4b7089f119f5bc65a8a2bea8fb1c94968 Mon Sep 17 00:00:00 2001 From: Jaime Melis Date: Fri, 2 Dec 2011 16:59:51 +0100 Subject: [PATCH 077/121] feature #863: fix tests --- src/vnm_mad/remotes/802.1Q/HostManaged.rb | 2 +- src/vnm_mad/remotes/Firewall.rb | 2 +- src/vnm_mad/remotes/OpenNebulaNetwork.rb | 4 +- src/vnm_mad/remotes/OpenNebulaNic.rb | 8 +- .../remotes/test/OpenNebulaNetwork_spec.rb | 76 ++++++++++--------- src/vnm_mad/remotes/test/SystemMock.rb | 5 +- 6 files changed, 50 insertions(+), 47 deletions(-) diff --git a/src/vnm_mad/remotes/802.1Q/HostManaged.rb b/src/vnm_mad/remotes/802.1Q/HostManaged.rb index 8d5194b869..47a65a3cce 100644 --- a/src/vnm_mad/remotes/802.1Q/HostManaged.rb +++ b/src/vnm_mad/remotes/802.1Q/HostManaged.rb @@ -64,7 +64,7 @@ class OpenNebulaHM < OpenNebulaNetwork def device_exists?(dev, vlan=nil) dev = "#{dev}.#{vlan}" if vlan - system("#{COMMANDS[:ip]} link show #{dev}") + OpenNebula.exec_and_log("#{COMMANDS[:ip]} link show #{dev}") end def create_dev_vlan(dev, vlan) diff --git a/src/vnm_mad/remotes/Firewall.rb b/src/vnm_mad/remotes/Firewall.rb index 586481ef05..2cc4f98eca 100644 --- a/src/vnm_mad/remotes/Firewall.rb +++ b/src/vnm_mad/remotes/Firewall.rb @@ -104,7 +104,7 @@ class OpenNebulaFirewall < OpenNebulaNetwork def run_rules(rules) rules.flatten.each do |rule| - system(rule) + OpenNebula.exec_and_log(rule) end end diff --git a/src/vnm_mad/remotes/OpenNebulaNetwork.rb b/src/vnm_mad/remotes/OpenNebulaNetwork.rb index 79c8e14fa4..a6cb14ca55 100644 --- a/src/vnm_mad/remotes/OpenNebulaNetwork.rb +++ b/src/vnm_mad/remotes/OpenNebulaNetwork.rb @@ -52,7 +52,7 @@ class VM nics = Nics.new(@hypervisor) - @vm_root.elements.each("TEMPLATE/NIC[VLAN=yes]") do |nic_element| + @vm_root.elements.each("TEMPLATE/NIC[VLAN=YES]") do |nic_element| nic = nics.new_nic nic_element.elements.each('*') do |nic_attribute| @@ -98,7 +98,7 @@ class OpenNebulaNetwork def initialize(vm_tpl, hypervisor=nil) if !hypervisor - @hypervisor = detect_hypervisor + @hypervisor = detect_hypervisor else @hypervisor = hypervisor end diff --git a/src/vnm_mad/remotes/OpenNebulaNic.rb b/src/vnm_mad/remotes/OpenNebulaNic.rb index 2872de52ee..84214bd154 100644 --- a/src/vnm_mad/remotes/OpenNebulaNic.rb +++ b/src/vnm_mad/remotes/OpenNebulaNic.rb @@ -31,8 +31,8 @@ class Nics < Array end -# A NIC using KVM. This class implements functions to get the physical interface -# that the NIC is using +# A NIC using KVM. This class implements functions to get the physical interface +# that the NIC is using class NicKVM < Hash def initialize super(nil) @@ -70,8 +70,8 @@ class NicKVM < Hash end -# A NIC using Xen. This class implements functions to get the physical interface -# that the NIC is using +# A NIC using Xen. This class implements functions to get the physical interface +# that the NIC is using class NicXen < Hash def initialize super(nil) diff --git a/src/vnm_mad/remotes/test/OpenNebulaNetwork_spec.rb b/src/vnm_mad/remotes/test/OpenNebulaNetwork_spec.rb index c8e7c14ccd..3875bd403f 100644 --- a/src/vnm_mad/remotes/test/OpenNebulaNetwork_spec.rb +++ b/src/vnm_mad/remotes/test/OpenNebulaNetwork_spec.rb @@ -1,18 +1,18 @@ #!/usr/bin/env ruby -$: << File.dirname(__FILE__) + '/..' \ - << './' +$: << File.dirname(__FILE__) +$: << File.join(File.dirname(__FILE__), '..') +$: << File.join(File.dirname(__FILE__),'../../../mad/ruby/') require 'rubygems' require 'rspec' -require 'SystemMock' require 'pp' require 'OpenNebulaNetwork' -require 'Ebtables' +require 'ebtables/Ebtables' require 'Firewall' -require 'HostManaged' -require 'OpenvSwitch' +require '802.1Q/HostManaged' +require 'ovswitch/OpenvSwitch' OUTPUT = Hash.new Dir[File.dirname(__FILE__) + "/output/**"].each do |f| @@ -20,6 +20,9 @@ Dir[File.dirname(__FILE__) + "/output/**"].each do |f| OUTPUT[key] = File.read(f) end +require 'scripts_common' +require 'SystemMock' +include OpenNebula include SystemMock RSpec.configure do |config| @@ -56,21 +59,6 @@ describe 'networking' do onevlan.vm.nics.should == nics_expected end - it "filter nics in kvm" do - $capture_commands = { - /virsh.*dumpxml/ => OUTPUT[:virsh_dumpxml] - } - onevlan = OpenNebulaNetwork.new(OUTPUT[:onevm_show],"kvm") - onevlan.filter(:bridge => "br1") - nics_expected = [{:bridge=>"br1", - :ip=>"10.1.1.1", - :mac=>"02:00:0a:01:01:01", - :network=>"r1", - :network_id=>"1", - :tap=>"vnet1"}] - - onevlan.vm.filtered_nics.should == nics_expected - end end describe 'ebtables' do @@ -88,7 +76,10 @@ describe 'ebtables' do "sudo /sbin/ebtables -A FORWARD -s ! 02:00:0a:01:01:01 -i vnet1 -j DROP", "sudo /sbin/ebtables -A FORWARD -s ! 02:00:0a:01:02:00/ff:ff:ff:ff:ff:00 -o vnet2 -j DROP", "sudo /sbin/ebtables -A FORWARD -s ! 02:00:0a:01:02:01 -i vnet2 -j DROP"] - $collector[:system].should == ebtables_cmds + + ebtables_cmds.map{|c| c + " 2>&1 1>/dev/null"}.each do |cmd| + $collector[:backtick].include?(cmd).should == true + end end end @@ -106,7 +97,9 @@ describe 'openvswitch' do "sudo /usr/local/bin/ovs-vsctl set Port vnet2 tag=4" ] - $collector[:system].should == openvswitch_tags + openvswitch_tags.map{|c| c + " 2>&1 1>/dev/null"}.each do |cmd| + $collector[:backtick].include?(cmd).should == true + end end it "force VLAN_ID for Open vSwitch vlans in kvm" do @@ -117,12 +110,14 @@ describe 'openvswitch' do } onevlan = OpenvSwitchVLAN.new(OUTPUT[:onevm_show_vlan_id_kvm],"kvm") onevlan.activate - + onevlan_rules = ["sudo /usr/local/bin/ovs-vsctl set Port vnet0 tag=6", "sudo /usr/local/bin/ovs-vsctl set Port vnet1 tag=50", "sudo /usr/local/bin/ovs-vsctl set Port vnet1 tag=51"] - $collector[:system].should == onevlan_rules + onevlan_rules.map{|c| c + " 2>&1 1>/dev/null"}.each do |cmd| + $collector[:backtick].include?(cmd).should == true + end end end @@ -146,7 +141,9 @@ describe 'firewall' do "sudo /sbin/iptables -A one-36-3 -p icmp -m state --state ESTABLISHED -j ACCEPT", "sudo /sbin/iptables -A one-36-3 -p icmp -j DROP"] - $collector[:system].should == fw_activate_rules + fw_activate_rules.map{|c| c + " 2>&1 1>/dev/null"}.each do |cmd| + $collector[:backtick].include?(cmd).should == true + end end end @@ -155,20 +152,23 @@ describe 'host-managed' do $capture_commands = { /virsh.*dumpxml/ => OUTPUT[:virsh_dumpxml_phydev], /brctl show/ => OUTPUT[:brctl_show], - /brctl add/ => nil, - /vconfig/ => nil, - /ip link/ => nil + /brctl add/ => nil, + /vconfig/ => nil, + /ip link/ => nil } hm = OpenNebulaHM.new(OUTPUT[:onevm_show_phydev_kvm],"kvm") hm.activate - hm_activate_rules = ["sudo /usr/sbin/brctl addbr onebr6", + hm_activate_rules = ["sudo /sbin/brctl addbr onebr6", "sudo /sbin/ip link set onebr6 up", "sudo /sbin/ip link show eth0.8", "sudo /sbin/vconfig add eth0 8", "sudo /sbin/ip link set eth0.8 up", - "sudo /usr/sbin/brctl addif onebr6 eth0.8"] - $collector[:system].should == hm_activate_rules + "sudo /sbin/brctl addif onebr6 eth0.8"] + + hm_activate_rules.map{|c| c + " 2>&1 1>/dev/null"}.each do |cmd| + $collector[:backtick].include?(cmd).should == true + end end it "force VLAN_ID for vlans in kvm" do @@ -182,19 +182,21 @@ describe 'host-managed' do hm = OpenNebulaHM.new(OUTPUT[:onevm_show_vlan_id_kvm],"kvm") hm.activate - hm_vlan_id = ["sudo /usr/sbin/brctl addbr onebr10", + hm_vlan_id = ["sudo /sbin/brctl addbr onebr10", "sudo /sbin/ip link set onebr10 up", "sudo /sbin/ip link show eth0.50", "sudo /sbin/vconfig add eth0 50", "sudo /sbin/ip link set eth0.50 up", - "sudo /usr/sbin/brctl addif onebr10 eth0.50", - "sudo /usr/sbin/brctl addbr specialbr", + "sudo /sbin/brctl addif onebr10 eth0.50", + "sudo /sbin/brctl addbr specialbr", "sudo /sbin/ip link set specialbr up", "sudo /sbin/ip link show eth0.51", "sudo /sbin/vconfig add eth0 51", "sudo /sbin/ip link set eth0.51 up", - "sudo /usr/sbin/brctl addif specialbr eth0.51"] + "sudo /sbin/brctl addif specialbr eth0.51"] - $collector[:system].should == hm_vlan_id + hm_vlan_id.map{|c| c + " 2>&1 1>/dev/null"}.each do |cmd| + $collector[:backtick].include?(cmd).should == true + end end end diff --git a/src/vnm_mad/remotes/test/SystemMock.rb b/src/vnm_mad/remotes/test/SystemMock.rb index 9c2d122d47..6e83e85411 100644 --- a/src/vnm_mad/remotes/test/SystemMock.rb +++ b/src/vnm_mad/remotes/test/SystemMock.rb @@ -1,14 +1,15 @@ module SystemMock - require 'open3' + def execute_cmd(cmd) if $capture_commands $capture_commands.each do |regex, output| if cmd.match(regex) + Kernel.send(:`,":;exit 0") return output end end end - Open3.popen3(cmd){|stdin, stdout, stderr| stdout.read} + Kernel.send(:`,cmd) end def `(cmd) From 8649233487bd99b6dd71c7144f003fbb6a7cd431 Mon Sep 17 00:00:00 2001 From: Jaime Melis Date: Fri, 2 Dec 2011 17:37:49 +0100 Subject: [PATCH 078/121] feature 863: fix install.sh --- install.sh | 50 ++++++++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/install.sh b/install.sh index 151e6fcd5e..e24347fdb8 100755 --- a/install.sh +++ b/install.sh @@ -122,9 +122,9 @@ if [ -z "$ROOT" ] ; then elif [ "$OZONES" = "yes" ]; then MAKE_DIRS="$BIN_LOCATION $LIB_LOCATION $VAR_LOCATION $OZONES_LOCATION \ $ETC_LOCATION" - + DELETE_DIRS="$MAKE_DIRS" - + CHOWN_DIRS="" else MAKE_DIRS="$BIN_LOCATION $LIB_LOCATION $ETC_LOCATION $VAR_LOCATION \ @@ -162,8 +162,8 @@ else elif [ "$OZONES" = "yes" ]; then MAKE_DIRS="$BIN_LOCATION $LIB_LOCATION $VAR_LOCATION $OZONES_LOCATION \ $ETC_LOCATION" - - DELETE_DIRS="$MAKE_DIRS" + + DELETE_DIRS="$MAKE_DIRS" else MAKE_DIRS="$BIN_LOCATION $LIB_LOCATION $ETC_LOCATION $VAR_LOCATION \ $INCLUDE_LOCATION $SHARE_LOCATION $IMAGES_LOCATION \ @@ -259,7 +259,7 @@ SUNSTONE_DIRS="$SUNSTONE_LOCATION/models \ $SUNSTONE_LOCATION/public/images \ $SUNSTONE_LOCATION/templates \ $SUNSTONE_LOCATION/views" - + OZONES_DIRS="$OZONES_LOCATION/lib \ $OZONES_LOCATION/lib/OZones \ $OZONES_LOCATION/models \ @@ -338,8 +338,8 @@ INSTALL_FILES=( AUTH_SERVER_X509_FILES:$VAR_LOCATION/remotes/auth/server_x509 AUTH_SERVER_CIPHER_FILES:$VAR_LOCATION/remotes/auth/server_cipher AUTH_DUMMY_FILES:$VAR_LOCATION/remotes/auth/dummy - AUTH_PLAIN_FILES:$VAR_LOCATION/remotes/auth/plain - AUTH_QUOTA_FILES:$VAR_LOCATION/remotes/auth/quota + AUTH_PLAIN_FILES:$VAR_LOCATION/remotes/auth/plain + AUTH_QUOTA_FILES:$VAR_LOCATION/remotes/auth/quota VMM_EXEC_KVM_SCRIPTS:$VAR_LOCATION/remotes/vmm/kvm VMM_EXEC_XEN_SCRIPTS:$VAR_LOCATION/remotes/vmm/xen SHARED_TM_COMMANDS_LIB_FILES:$LIB_LOCATION/tm_commands/shared @@ -628,7 +628,8 @@ AUTH_QUOTA_FILES="src/authm_mad/remotes/quota/authorize" #------------------------------------------------------------------------------- NETWORK_FILES="src/vnm_mad/remotes/OpenNebulaNetwork.rb \ - src/vnm_mad/remotes/OpenNebulaNic.rb" + src/vnm_mad/remotes/Firewall.rb \ + src/vnm_mad/remotes/OpenNebulaNic.rb" NETWORK_8021Q_FILES="src/vnm_mad/remotes/802.1Q/clean \ src/vnm_mad/remotes/802.1Q/post \ @@ -644,8 +645,9 @@ NETWORK_EBTABLES_FILES="src/vnm_mad/remotes/ebtables/clean \ src/vnm_mad/remotes/ebtables/pre \ src/vnm_mad/remotes/ebtables/Ebtables.rb" -NETWORK_FW_FILES="src/vnm_mad/remotes/fw/firewall \ - src/vnm_mad/remotes/fw/Firewall.rb" +NETWORK_FW_FILES="src/vnm_mad/remotes/fw/post \ + src/vnm_mad/remotes/fw/pre \ + src/vnm_mad/remotes/fw/clean" NETWORK_OVSWITCH_FILES="src/vnm_mad/remotes/ovswitch/clean \ src/vnm_mad/remotes/ovswitch/post \ @@ -1066,7 +1068,7 @@ SUNSTONE_PUBLIC_IMAGES_FILES="src/sunstone/public/images/ajax-loader.gif \ src/sunstone/public/images/Refresh-icon.png \ src/sunstone/public/images/vnc_off.png \ src/sunstone/public/images/vnc_on.png" - + #----------------------------------------------------------------------------- # Ozones files #----------------------------------------------------------------------------- @@ -1081,10 +1083,10 @@ OZONES_ETC_FILES="src/ozones/Server/etc/ozones-server.conf" OZONES_MODELS_FILES="src/ozones/Server/models/OzonesServer.rb \ src/ozones/Server/models/Auth.rb \ src/sunstone/models/OpenNebulaJSON/JSONUtils.rb" - + OZONES_TEMPLATE_FILES="src/ozones/Server/templates/index.html \ src/ozones/Server/templates/login.html" - + OZONES_LIB_FILES="src/ozones/Server/lib/OZones.rb" OZONES_LIB_ZONE_FILES="src/ozones/Server/lib/OZones/Zones.rb \ @@ -1098,7 +1100,7 @@ OZONES_LIB_ZONE_FILES="src/ozones/Server/lib/OZones/Zones.rb \ src/ozones/Server/lib/OZones/AggregatedPool.rb \ src/ozones/Server/lib/OZones/AggregatedImages.rb \ src/ozones/Server/lib/OZones/AggregatedTemplates.rb" - + OZONES_LIB_API_FILES="src/ozones/Client/lib/zona.rb" OZONES_LIB_API_ZONA_FILES="src/ozones/Client/lib/zona/ZoneElement.rb \ @@ -1110,7 +1112,7 @@ OZONES_LIB_API_ZONA_FILES="src/ozones/Client/lib/zona/ZoneElement.rb \ src/ozones/Client/lib/zona/ZonePool.rb" OZONES_PUBLIC_VENDOR_JQUERY=$SUNSTONE_PUBLIC_VENDOR_JQUERY - + OZONES_PUBLIC_VENDOR_DATATABLES=$SUNSTONE_PUBLIC_VENDOR_DATATABLES OZONES_PUBLIC_VENDOR_JGROWL=$SUNSTONE_PUBLIC_VENDOR_JGROWL @@ -1118,18 +1120,18 @@ OZONES_PUBLIC_VENDOR_JGROWL=$SUNSTONE_PUBLIC_VENDOR_JGROWL OZONES_PUBLIC_VENDOR_JQUERYUI=$SUNSTONE_PUBLIC_VENDOR_JQUERYUI OZONES_PUBLIC_VENDOR_JQUERYLAYOUT=$SUNSTONE_PUBLIC_VENDOR_JQUERYLAYOUT - + OZONES_PUBLIC_JS_FILES="src/ozones/Server/public/js/ozones.js \ src/ozones/Server/public/js/login.js \ src/ozones/Server/public/js/ozones-util.js \ src/sunstone/public/js/layout.js \ src/sunstone/public/js/sunstone.js \ src/sunstone/public/js/sunstone-util.js" - + OZONES_PUBLIC_CSS_FILES="src/ozones/Server/public/css/application.css \ src/ozones/Server/public/css/layout.css \ src/ozones/Server/public/css/login.css" - + OZONES_PUBLIC_IMAGES_FILES="src/ozones/Server/public/images/panel.png \ src/ozones/Server/public/images/login.png \ src/ozones/Server/public/images/login_over.png \ @@ -1143,16 +1145,16 @@ OZONES_PUBLIC_JS_PLUGINS_FILES="src/ozones/Server/public/js/plugins/zones-tab.js src/ozones/Server/public/js/plugins/vdcs-tab.js \ src/ozones/Server/public/js/plugins/aggregated-tab.js \ src/ozones/Server/public/js/plugins/dashboard-tab.js" - -OZONES_LIB_CLIENT_CLI_FILES="src/ozones/Client/lib/cli/ozones_helper.rb" - + +OZONES_LIB_CLIENT_CLI_FILES="src/ozones/Client/lib/cli/ozones_helper.rb" + OZONES_LIB_CLIENT_CLI_HELPER_FILES="\ src/ozones/Client/lib/cli/ozones_helper/vdc_helper.rb \ - src/ozones/Client/lib/cli/ozones_helper/zones_helper.rb" + src/ozones/Client/lib/cli/ozones_helper/zones_helper.rb" OZONES_BIN_CLIENT_FILES="src/ozones/Client/bin/onevdc \ src/ozones/Client/bin/onezone" - + OZONES_RUBY_LIB_FILES="src/oca/ruby/OpenNebula.rb" #----------------------------------------------------------------------------- @@ -1229,7 +1231,7 @@ if [ "$CLIENT" = "yes" ]; then elif [ "$SUNSTONE" = "yes" ]; then INSTALL_SET="${INSTALL_SUNSTONE_RUBY_FILES[@]} ${INSTALL_SUNSTONE_FILES[@]}" elif [ "$OZONES" = "yes" ]; then - INSTALL_SET="${INSTALL_OZONES_RUBY_FILES[@]} ${INSTALL_OZONES_FILES[@]}" + INSTALL_SET="${INSTALL_OZONES_RUBY_FILES[@]} ${INSTALL_OZONES_FILES[@]}" else INSTALL_SET="${INSTALL_FILES[@]} ${INSTALL_OZONES_FILES[@]} \ ${INSTALL_SUNSTONE_FILES[@]}" From d0c3ef099c821b331ba6c2cf61f59b8c7b9ebc94 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Fri, 2 Dec 2011 17:46:51 +0100 Subject: [PATCH 079/121] bug: fixes show of history records with some XML parsers --- src/cli/one_helper/onevm_helper.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/cli/one_helper/onevm_helper.rb b/src/cli/one_helper/onevm_helper.rb index 9ecc4425eb..fdbc07a86e 100644 --- a/src/cli/one_helper/onevm_helper.rb +++ b/src/cli/one_helper/onevm_helper.rb @@ -99,9 +99,10 @@ class OneVMHelper < OpenNebulaHelper::OneHelper CLIHelper.print_header(str_h1 % "VIRTUAL MACHINE TEMPLATE",false) puts vm.template_str - if vm['/VM/HISTORY_RECORDS/HISTORY'] + if vm.has_elements?("/VM/HISTORY_RECORDS/") puts - + + CLIHelper.print_header(str_h1 % "VIRTUAL MACHINE HISTORY",false) format_history(vm) end From 8239c283d3716a610c6059ab265ce3bff0d16f43 Mon Sep 17 00:00:00 2001 From: Daniel Molina Date: Fri, 2 Dec 2011 18:31:19 +0100 Subject: [PATCH 080/121] Fix STORAGE quota for save_as --- src/authm_mad/remotes/quota/quota.rb | 18 +++++++++++++++++- src/rm/RequestManagerVirtualMachine.cc | 24 +++++++++++++----------- 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/src/authm_mad/remotes/quota/quota.rb b/src/authm_mad/remotes/quota/quota.rb index 046bdc9493..9037c94510 100644 --- a/src/authm_mad/remotes/quota/quota.rb +++ b/src/authm_mad/remotes/quota/quota.rb @@ -81,8 +81,24 @@ class Quota :proc_info => lambda {|template| if template['TYPE'] == 'DATABLOCK' template['SIZE'].to_i - else + elsif template['PATH'] File.size(template['PATH']) + elsif template['SAVED_VM_ID'] + vm_id = template['SAVED_VM_ID'].to_i + disk_id = template['SAVED_DISK_ID'].to_i + + client = OpenNebula::Client.new + vm = OpenNebula::VirtualMachine.new_with_id(vm_id, client) + vm.info + + im_id = vm["DISK[DISK_ID=#{disk_id}]/IMAGE_ID"].to_i + + im = OpenNebula::Image.new_with_id(im_id, client) + im.info + + im['SIZE'].to_i + else + 0 end }, :xpath => 'SIZE' diff --git a/src/rm/RequestManagerVirtualMachine.cc b/src/rm/RequestManagerVirtualMachine.cc index 17dd537084..02d2755661 100644 --- a/src/rm/RequestManagerVirtualMachine.cc +++ b/src/rm/RequestManagerVirtualMachine.cc @@ -86,9 +86,9 @@ bool RequestManagerVirtualMachine::vm_authorization(int oid, /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ -int RequestManagerVirtualMachine::get_host_information(int hid, - string& name, - string& vmm, +int RequestManagerVirtualMachine::get_host_information(int hid, + string& name, + string& vmm, string& tm, RequestAttributes& att) { @@ -160,7 +160,7 @@ int RequestManagerVirtualMachine::add_history(VirtualMachine * vm, if ( rc != 0 ) { - failure_response(INTERNAL, + failure_response(INTERNAL, request_error("Can not update virtual machine history",""), att); @@ -170,7 +170,7 @@ int RequestManagerVirtualMachine::add_history(VirtualMachine * vm, vmpool->update(vm); return 0; -} +} /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ @@ -232,7 +232,7 @@ void VirtualMachineAction::request_execute(xmlrpc_c::paramList const& paramList, } switch (rc) - { + { case 0: success_response(id, att); break; @@ -247,7 +247,7 @@ void VirtualMachineAction::request_execute(xmlrpc_c::paramList const& paramList, att); break; case -3: - failure_response(ACTION, + failure_response(ACTION, request_error("Virtual machine action not supported",""), att); break; @@ -295,7 +295,7 @@ void VirtualMachineDeploy::request_execute(xmlrpc_c::paramList const& paramList, if ( vm->get_state() != VirtualMachine::PENDING ) { - failure_response(ACTION, + failure_response(ACTION, request_error("Wrong state to perform action",""), att); @@ -354,7 +354,7 @@ void VirtualMachineMigrate::request_execute(xmlrpc_c::paramList const& paramList (vm->get_lcm_state() != VirtualMachine::RUNNING) || (vm->hasPreviousHistory() && vm->get_previous_reason() == History::NONE)) { - failure_response(ACTION, + failure_response(ACTION, request_error("Wrong state to perform action",""), att); @@ -412,6 +412,8 @@ void VirtualMachineSaveDisk::request_execute(xmlrpc_c::paramList const& paramLis oss << "NAME= \"" << img_name << "\"" << endl; oss << "PUBLIC = NO " << endl; oss << "SOURCE = - " << endl; + oss << "SAVED_DISK_ID = " << disk_id << endl; + oss << "SAVED_VM_ID = " << id << endl; if ( img_type != "" ) { @@ -440,7 +442,7 @@ void VirtualMachineSaveDisk::request_execute(xmlrpc_c::paramList const& paramLis allocate_error(AuthRequest::IMAGE, error_str), att); return; } - + // ------------------ Store image id to save the disk ------------------ if ( (vm = get_vm(id, att)) == 0 ) @@ -479,7 +481,7 @@ void VirtualMachineSaveDisk::request_execute(xmlrpc_c::paramList const& paramLis img->unlock(); } - failure_response(INTERNAL, + failure_response(INTERNAL, request_error("Can not save_as disk",error_str), att); return; From 487ec888b52cd672aae7dec044f018ccefcf9002 Mon Sep 17 00:00:00 2001 From: Daniel Molina Date: Fri, 2 Dec 2011 18:33:11 +0100 Subject: [PATCH 081/121] Delete delta_token_expiration parameter from Cloud conf files --- src/cloud/common/CloudAuth.rb | 22 +++++++++++++------ src/cloud/common/CloudAuth/EC2CloudAuth.rb | 2 +- src/cloud/common/CloudAuth/OCCICloudAuth.rb | 6 ++--- .../common/CloudAuth/SunstoneCloudAuth.rb | 6 ++--- src/cloud/common/CloudAuth/X509CloudAuth.rb | 2 +- src/cloud/ec2/etc/econe.conf | 2 -- src/cloud/occi/etc/occi-server.conf | 2 -- src/sunstone/etc/sunstone-server.conf | 6 ++--- 8 files changed, 25 insertions(+), 23 deletions(-) diff --git a/src/cloud/common/CloudAuth.rb b/src/cloud/common/CloudAuth.rb index b69934dd81..3177e95247 100644 --- a/src/cloud/common/CloudAuth.rb +++ b/src/cloud/common/CloudAuth.rb @@ -33,7 +33,8 @@ class CloudAuth # Default interval for timestamps. Tokens will be generated using the same # timestamp for this interval of time. - EXPIRE_DELTA = 36000 + # THIS VALUE CANNOT BE LOWER THAN EXPIRE_MARGIN + EXPIRE_DELTA = 1800 # Tokens will be generated if time > EXPIRE_TIME - EXPIRE_MARGIN EXPIRE_MARGIN = 300 @@ -44,11 +45,7 @@ class CloudAuth def initialize(conf) @conf = conf - # @token_expiration_delta: Number of seconds that will be used - # the same timestamp for the token generation - # @token_expiration_time: Current timestamp to be used in tokens. - @token_expiration_delta = @conf[:token_expiration_delta] || EXPIRE_DELTA - @token_expiration_time = Time.now.to_i + @token_expiration_delta + @token_expiration_time = Time.now.to_i + EXPIRE_DELTA if AUTH_MODULES.include?(@conf[:auth]) require 'CloudAuth/' + AUTH_MODULES[@conf[:auth]] @@ -90,13 +87,24 @@ class CloudAuth end end + def auth(env, params={}) + username = do_auth(env, params) + + if username.nil? + update_userpool_cache + do_auth(env, params) + else + username + end + end + protected def expiration_time time_now = Time.now.to_i if time_now > @token_expiration_time - EXPIRE_MARGIN - @token_expiration_time = time_now + @token_expiration_delta + @token_expiration_time = time_now + EXPIRE_DELTA update_userpool_cache end diff --git a/src/cloud/common/CloudAuth/EC2CloudAuth.rb b/src/cloud/common/CloudAuth/EC2CloudAuth.rb index e60f653648..bad85c6cac 100644 --- a/src/cloud/common/CloudAuth/EC2CloudAuth.rb +++ b/src/cloud/common/CloudAuth/EC2CloudAuth.rb @@ -15,7 +15,7 @@ #--------------------------------------------------------------------------- # module EC2CloudAuth - def auth(env, params={}) + def do_auth(env, params={}) username = params['AWSAccessKeyId'] one_pass = get_password(username) return nil unless one_pass diff --git a/src/cloud/common/CloudAuth/OCCICloudAuth.rb b/src/cloud/common/CloudAuth/OCCICloudAuth.rb index e6f80c4f67..4fac9905d9 100644 --- a/src/cloud/common/CloudAuth/OCCICloudAuth.rb +++ b/src/cloud/common/CloudAuth/OCCICloudAuth.rb @@ -15,7 +15,7 @@ #--------------------------------------------------------------------------- # module OCCICloudAuth - def auth(env, params={}) + def do_auth(env, params={}) auth = Rack::Auth::Basic::Request.new(env) if auth.provided? && auth.basic? @@ -28,6 +28,6 @@ module OCCICloudAuth end end - return nil - end + return nil + end end \ No newline at end of file diff --git a/src/cloud/common/CloudAuth/SunstoneCloudAuth.rb b/src/cloud/common/CloudAuth/SunstoneCloudAuth.rb index 9fa855b1d0..69fcb42db5 100644 --- a/src/cloud/common/CloudAuth/SunstoneCloudAuth.rb +++ b/src/cloud/common/CloudAuth/SunstoneCloudAuth.rb @@ -15,7 +15,7 @@ #--------------------------------------------------------------------------- # module SunstoneCloudAuth - def auth(env, params={}) + def do_auth(env, params={}) auth = Rack::Auth::Basic::Request.new(env) if auth.provided? && auth.basic? @@ -28,6 +28,6 @@ module SunstoneCloudAuth end end - return nil - end + return nil + end end \ No newline at end of file diff --git a/src/cloud/common/CloudAuth/X509CloudAuth.rb b/src/cloud/common/CloudAuth/X509CloudAuth.rb index 60f52a0562..5e8613eef7 100644 --- a/src/cloud/common/CloudAuth/X509CloudAuth.rb +++ b/src/cloud/common/CloudAuth/X509CloudAuth.rb @@ -15,7 +15,7 @@ #--------------------------------------------------------------------------- # module X509CloudAuth - def auth(env, params={}) + def do_auth(env, params={}) # For https, the web service should be set to include the user cert in the environment. cert_line = env['HTTP_SSL_CLIENT_CERT'] cert_line = nil if cert_line == '(null)' # For Apache mod_ssl diff --git a/src/cloud/ec2/etc/econe.conf b/src/cloud/ec2/etc/econe.conf index 2f681596c7..9ef6851f2b 100644 --- a/src/cloud/ec2/etc/econe.conf +++ b/src/cloud/ec2/etc/econe.conf @@ -33,8 +33,6 @@ # cipher, for symmetric cipher encryption of tokens # x509, for x509 certificate encryption of tokens :core_auth: cipher -# Life-time in seconds for token renewal (that used to handle OpenNebula auths) -:token_expiration_delta: 1800 # VM types allowed and its template file (inside templates directory) :instance_types: diff --git a/src/cloud/occi/etc/occi-server.conf b/src/cloud/occi/etc/occi-server.conf index f81fa1924a..6304fa24f5 100644 --- a/src/cloud/occi/etc/occi-server.conf +++ b/src/cloud/occi/etc/occi-server.conf @@ -36,8 +36,6 @@ # cipher, for symmetric cipher encryption of tokens # x509, for x509 certificate encryption of tokens :core_auth: cipher -# Life-time in seconds for token renewal (that used to handle OpenNebula auths) -:token_expiration_delta: 1800 # VM types allowed and its template file (inside templates directory) :instance_types: diff --git a/src/sunstone/etc/sunstone-server.conf b/src/sunstone/etc/sunstone-server.conf index 2311501782..4391ca8a5f 100644 --- a/src/sunstone/etc/sunstone-server.conf +++ b/src/sunstone/etc/sunstone-server.conf @@ -14,9 +14,7 @@ # cipher, for symmetric cipher encryption of tokens # x509, for x509 certificate encryption of tokens :core_auth: cipher -# Life-time in seconds for token renewal (that used to handle OpenNebula auths) -:token_expiration_delta: 1800 - + # VNC Configuration :vnc_proxy_base_port: 29876 -:novnc_path: +:novnc_path: From 913374f022a811dda9f2bcf9a12ab6d3974c46b4 Mon Sep 17 00:00:00 2001 From: Jaime Melis Date: Fri, 2 Dec 2011 19:07:55 +0100 Subject: [PATCH 082/121] feature #863: fix tests with vlan=yes --- src/vnm_mad/remotes/OpenNebulaNetwork.rb | 2 +- .../remotes/test/OpenNebulaNetwork_spec.rb | 39 ++++++++++--------- src/vnm_mad/remotes/test/output/onevm_show | 3 ++ .../remotes/test/output/onevm_show_phydev_kvm | 2 + .../test/output/onevm_show_vlan_id_kvm | 3 ++ .../remotes/test/output/onevm_show_xen | 2 + 6 files changed, 32 insertions(+), 19 deletions(-) diff --git a/src/vnm_mad/remotes/OpenNebulaNetwork.rb b/src/vnm_mad/remotes/OpenNebulaNetwork.rb index a6cb14ca55..a944adeb8d 100644 --- a/src/vnm_mad/remotes/OpenNebulaNetwork.rb +++ b/src/vnm_mad/remotes/OpenNebulaNetwork.rb @@ -52,7 +52,7 @@ class VM nics = Nics.new(@hypervisor) - @vm_root.elements.each("TEMPLATE/NIC[VLAN=YES]") do |nic_element| + @vm_root.elements.each("TEMPLATE/NIC[VLAN='YES']") do |nic_element| nic = nics.new_nic nic_element.elements.each('*') do |nic_attribute| diff --git a/src/vnm_mad/remotes/test/OpenNebulaNetwork_spec.rb b/src/vnm_mad/remotes/test/OpenNebulaNetwork_spec.rb index 3875bd403f..ad1dc18932 100644 --- a/src/vnm_mad/remotes/test/OpenNebulaNetwork_spec.rb +++ b/src/vnm_mad/remotes/test/OpenNebulaNetwork_spec.rb @@ -39,26 +39,29 @@ describe 'networking' do } onevlan = OpenNebulaNetwork.new(OUTPUT[:onevm_show],"kvm") nics_expected = [{:bridge=>"br0", - :ip=>"172.16.0.100", - :mac=>"02:00:ac:10:00:64", - :network=>"Small network", - :network_id=>"0", - :tap=>"vnet0"}, - {:bridge=>"br1", - :ip=>"10.1.1.1", - :mac=>"02:00:0a:01:01:01", - :network=>"r1", - :network_id=>"1", - :tap=>"vnet1"}, - {:bridge=>"br2", - :ip=>"10.1.2.1", - :mac=>"02:00:0a:01:02:01", - :network=>"r2", - :network_id=>"2", - :tap=>"vnet2"}] + :ip=>"172.16.0.100", + :mac=>"02:00:ac:10:00:64", + :network=>"Small network", + :network_id=>"0", + :vlan=>"YES", + :tap=>"vnet0"}, + {:bridge=>"br1", + :ip=>"10.1.1.1", + :mac=>"02:00:0a:01:01:01", + :network=>"r1", + :network_id=>"1", + :vlan=>"YES", + :tap=>"vnet1"}, + {:bridge=>"br2", + :ip=>"10.1.2.1", + :mac=>"02:00:0a:01:02:01", + :network=>"r2", + :network_id=>"2", + :vlan=>"YES", + :tap=>"vnet2"}] + onevlan.vm.nics.should == nics_expected end - end describe 'ebtables' do diff --git a/src/vnm_mad/remotes/test/output/onevm_show b/src/vnm_mad/remotes/test/output/onevm_show index ec56cbf225..28b962f202 100644 --- a/src/vnm_mad/remotes/test/output/onevm_show +++ b/src/vnm_mad/remotes/test/output/onevm_show @@ -37,6 +37,7 @@ + @@ -44,6 +45,7 @@ + @@ -51,6 +53,7 @@ + diff --git a/src/vnm_mad/remotes/test/output/onevm_show_phydev_kvm b/src/vnm_mad/remotes/test/output/onevm_show_phydev_kvm index 610bcb9d74..5a7541662f 100644 --- a/src/vnm_mad/remotes/test/output/onevm_show_phydev_kvm +++ b/src/vnm_mad/remotes/test/output/onevm_show_phydev_kvm @@ -37,6 +37,7 @@ + @@ -45,6 +46,7 @@ + diff --git a/src/vnm_mad/remotes/test/output/onevm_show_vlan_id_kvm b/src/vnm_mad/remotes/test/output/onevm_show_vlan_id_kvm index e70880289d..637838f3b5 100644 --- a/src/vnm_mad/remotes/test/output/onevm_show_vlan_id_kvm +++ b/src/vnm_mad/remotes/test/output/onevm_show_vlan_id_kvm @@ -37,6 +37,7 @@ + @@ -45,6 +46,7 @@ + @@ -54,6 +56,7 @@ + diff --git a/src/vnm_mad/remotes/test/output/onevm_show_xen b/src/vnm_mad/remotes/test/output/onevm_show_xen index bff85d160a..9f0685ad44 100644 --- a/src/vnm_mad/remotes/test/output/onevm_show_xen +++ b/src/vnm_mad/remotes/test/output/onevm_show_xen @@ -33,6 +33,7 @@ + @@ -42,6 +43,7 @@ + From 0a7492772a90208bb3eb4c8ad50d80efbbe2e5b1 Mon Sep 17 00:00:00 2001 From: Hector Sanjuan Date: Fri, 2 Dec 2011 19:37:29 +0100 Subject: [PATCH 083/121] Minor GUI style fixes Derivated from vendor update --- src/ozones/Server/public/css/application.css | 7 ++++--- src/sunstone/public/css/application.css | 6 +++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/ozones/Server/public/css/application.css b/src/ozones/Server/public/css/application.css index e8212b067b..249cc290ba 100644 --- a/src/ozones/Server/public/css/application.css +++ b/src/ozones/Server/public/css/application.css @@ -292,13 +292,14 @@ textarea:focus{ } .add_remove_button { - font-size:0.8em; - height:25px; + font-size:0.8em !important; + height:25px !important; margin-bottom:4px; } .add_button { - margin-left:177px; + margin-left:148px; + width: 58px !important; } .remove_button { diff --git a/src/sunstone/public/css/application.css b/src/sunstone/public/css/application.css index 612e9fd012..80ce873be6 100644 --- a/src/sunstone/public/css/application.css +++ b/src/sunstone/public/css/application.css @@ -294,14 +294,14 @@ textarea:focus{ } .add_remove_button { - font-size:0.8em; - height:25px; + font-size:0.8em !important; + height:25px !important; margin-bottom:4px; } .add_button { margin-left:148px; - width:74px; + width:58px !important; } .remove_button { From be32ba5526058084c00bc3c80469076ec1a9e6db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Fri, 2 Dec 2011 19:52:35 +0100 Subject: [PATCH 084/121] Improve xml consistency, all elements are written even if they are empty --- src/vm/VirtualMachine.cc | 4 ++++ src/vnm/Leases.cc | 4 ---- src/vnm/VirtualNetwork.cc | 21 +++++++++++++++++++-- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/vm/VirtualMachine.cc b/src/vm/VirtualMachine.cc index a4619d6a4a..c3737af3fd 100644 --- a/src/vm/VirtualMachine.cc +++ b/src/vm/VirtualMachine.cc @@ -1258,6 +1258,10 @@ string& VirtualMachine::to_xml_extended(string& xml, bool extended) const oss << ""; } + else + { + oss << ""; + } oss << ""; diff --git a/src/vnm/Leases.cc b/src/vnm/Leases.cc index 17dc998d07..12de451987 100644 --- a/src/vnm/Leases.cc +++ b/src/vnm/Leases.cc @@ -429,15 +429,11 @@ string& Leases::to_xml(string& xml) const ostringstream os; string lease_xml; - os << ""; - for(it=leases.begin();it!=leases.end();it++) { os << it->second->to_xml(lease_xml); } - os << ""; - xml = os.str(); return xml; diff --git a/src/vnm/VirtualNetwork.cc b/src/vnm/VirtualNetwork.cc index 520ba533b5..a1bdb86264 100644 --- a/src/vnm/VirtualNetwork.cc +++ b/src/vnm/VirtualNetwork.cc @@ -521,19 +521,36 @@ string& VirtualNetwork::to_xml_extended(string& xml, bool extended) const { os << "" << phydev << ""; } + else + { + os << ""; + } if (!vlan_id.empty()) { os << "" << vlan_id << ""; } + else + { + os << ""; + } os << "" << public_obj << "" << ""<< total_leases << ""<< obj_template->to_xml(template_xml); - if (extended && leases != 0) + if (extended) { - os << leases->to_xml(leases_xml); + if (leases != 0) + { + os << "" << + leases->to_xml(leases_xml) << + ""; + } + else + { + os << ""; + } } os << ""; From 4e7d39f6b076813c4a23fde2dd1ca416d321b396 Mon Sep 17 00:00:00 2001 From: Hector Sanjuan Date: Fri, 2 Dec 2011 19:37:29 +0100 Subject: [PATCH 085/121] Minor GUI style fixes Derivated from vendor update (cherry picked from commit 0a7492772a90208bb3eb4c8ad50d80efbbe2e5b1) --- src/ozones/Server/public/css/application.css | 7 ++++--- src/sunstone/public/css/application.css | 6 +++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/ozones/Server/public/css/application.css b/src/ozones/Server/public/css/application.css index e8212b067b..249cc290ba 100644 --- a/src/ozones/Server/public/css/application.css +++ b/src/ozones/Server/public/css/application.css @@ -292,13 +292,14 @@ textarea:focus{ } .add_remove_button { - font-size:0.8em; - height:25px; + font-size:0.8em !important; + height:25px !important; margin-bottom:4px; } .add_button { - margin-left:177px; + margin-left:148px; + width: 58px !important; } .remove_button { diff --git a/src/sunstone/public/css/application.css b/src/sunstone/public/css/application.css index 612e9fd012..80ce873be6 100644 --- a/src/sunstone/public/css/application.css +++ b/src/sunstone/public/css/application.css @@ -294,14 +294,14 @@ textarea:focus{ } .add_remove_button { - font-size:0.8em; - height:25px; + font-size:0.8em !important; + height:25px !important; margin-bottom:4px; } .add_button { margin-left:148px; - width:74px; + width:58px !important; } .remove_button { From ed564472f6f15e3151c118fc371f2144429b168b Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Sun, 4 Dec 2011 19:44:50 +0100 Subject: [PATCH 086/121] feature #602: Moved size to get the default if needed --- src/vnm/RangedLeases.cc | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/vnm/RangedLeases.cc b/src/vnm/RangedLeases.cc index d992ad29c0..0eea558afb 100644 --- a/src/vnm/RangedLeases.cc +++ b/src/vnm/RangedLeases.cc @@ -51,7 +51,6 @@ int RangedLeases::process_template(VirtualNetwork* vn, string st_ip_start = ""; string st_ip_end = ""; - unsigned int size = VirtualNetworkPool::default_size(); unsigned int host_bits; unsigned int network_bits; @@ -161,12 +160,18 @@ int RangedLeases::process_template(VirtualNetwork* vn, } else { + unsigned int size; + if (!st_size.empty())//Assume it's a number { istringstream iss(st_size); iss >> size; } + else + { + size = VirtualNetworkPool::default_size(); + } host_bits = (int) ceil(log(size+2)/log(2)); } @@ -178,6 +183,7 @@ int RangedLeases::process_template(VirtualNetwork* vn, // Set the network mask net_mask = 0xFFFFFFFF << host_bits; Lease::ip_to_string(net_mask, st_mask); + vn->replace_template_attribute("NETWORK_MASK", st_mask); if ( Leases::Lease::ip_to_number(st_addr,net_addr) != 0 ) @@ -190,8 +196,6 @@ int RangedLeases::process_template(VirtualNetwork* vn, goto error_not_base_addr; } - size = (1 << host_bits) - 2; - // Set IP start/end if ( ip_start == 0 ) { @@ -200,7 +204,7 @@ int RangedLeases::process_template(VirtualNetwork* vn, if ( ip_end == 0 ) { - ip_end = net_addr + size; + ip_end = net_addr + (1 << host_bits) - 2; } // Check range restrictions From c57e10154fc75665fe26db3a43950c13e4b1fa08 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Sun, 4 Dec 2011 20:44:38 +0100 Subject: [PATCH 087/121] Make auth drivers to use LocalAction instead of do_action wrapper --- src/authm_mad/one_auth_mad.rb | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/authm_mad/one_auth_mad.rb b/src/authm_mad/one_auth_mad.rb index 245c660944..9ab1ac6bd4 100755 --- a/src/authm_mad/one_auth_mad.rb +++ b/src/authm_mad/one_auth_mad.rb @@ -108,11 +108,14 @@ class AuthDriver < OpenNebulaDriver #/var/lib/one/remotes/auth//authenticate authN_path = File.join(@local_scripts_path, driver) - command = File.join(authN_path,ACTION[:authN].downcase) + command = File.join(authN_path, ACTION[:authN].downcase) command << " '" << user.gsub("'", '\'"\'"\'') << "' '" << password.gsub("'", '\'"\'"\'') << "' " << secret - do_action(command, request_id, nil, ACTION[:authN], - :local => true) + rc = LocalCommand.run(command, log_method(request_id)) + + result , info = get_info_from_execution(rc) + + send_message(ACTION[:authN], result, request_id, info) end # Authenticate a user based in a string of the form user:secret when using the @@ -137,13 +140,16 @@ class AuthDriver < OpenNebulaDriver result = RESULT[:failure] end - send_message(ACTION[:authZ],result,request_id,"-") + send_message(ACTION[:authZ], result, request_id, "-") else command = @authZ_cmd.clone command << ' ' << user_id << ' ' << requests.join(' ') - do_action(command, request_id, nil, ACTION[:authZ], - :local => true) + rc = LocalCommand.run(command, log_method(request_id)) + + result , info = get_info_from_execution(rc) + + send_message(ACTION[:authZ], result, request_id, info) end end end From 5c5e3df525e92194e56378c81298bad56278c1f4 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Sun, 4 Dec 2011 20:45:22 +0100 Subject: [PATCH 088/121] Removed option opts[:local] as always local_action are required --- src/mad/ruby/OpenNebulaDriver.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/mad/ruby/OpenNebulaDriver.rb b/src/mad/ruby/OpenNebulaDriver.rb index 316ca92af2..758750aa75 100644 --- a/src/mad/ruby/OpenNebulaDriver.rb +++ b/src/mad/ruby/OpenNebulaDriver.rb @@ -87,7 +87,6 @@ class OpenNebulaDriver < ActionManager # @option ops [String] :script_name default script name for the action, # action name is used by defaults # @option ops [String] :respond if defined will send result to ONE core - # @option ops [String] :local if defined will execute the action locally def do_action(parameters, id, host, aname, ops={}) options={ :stdin => nil, @@ -99,7 +98,7 @@ class OpenNebulaDriver < ActionManager params = parameters+" #{id} #{host}" command = action_command_line(aname, params, options[:script_name]) - if options[:local] || action_is_local?(aname) + if action_is_local?(aname) execution = LocalCommand.run(command, log_method(id)) elsif options[:ssh_stream] if options[:stdin] From 5028be8b1f1debc4a27f06b1812b521e510c7ca0 Mon Sep 17 00:00:00 2001 From: Daniel Molina Date: Wed, 23 Nov 2011 19:03:27 +0100 Subject: [PATCH 089/121] feature #990: Add instance_type and collections methods to OCCI API(cherry picked from commit 36c045992c761b6c66db56fd09e56bdf79bec4d9) Conflicts: src/cloud/occi/etc/occi-server.conf --- src/cloud/occi/etc/occi-server.conf | 8 ++- src/cloud/occi/etc/templates/common.erb | 2 +- src/cloud/occi/lib/OCCIServer.rb | 69 ++++++++++++------------ src/cloud/occi/lib/VirtualMachineOCCI.rb | 12 +++-- src/cloud/occi/lib/occi-server.rb | 12 ++++- 5 files changed, 61 insertions(+), 42 deletions(-) diff --git a/src/cloud/occi/etc/occi-server.conf b/src/cloud/occi/etc/occi-server.conf index 6304fa24f5..859329f2df 100644 --- a/src/cloud/occi/etc/occi-server.conf +++ b/src/cloud/occi/etc/occi-server.conf @@ -39,11 +39,15 @@ # VM types allowed and its template file (inside templates directory) :instance_types: - :custom: - :template: custom.erb :small: :template: small.erb + :cpu: 1 + :memory: 1024 :medium: :template: medium.erb + :cpu: 4 + :memory: 4096 :large: :template: large.erb + :cpu: 8 + :memory: 8192 diff --git a/src/cloud/occi/etc/templates/common.erb b/src/cloud/occi/etc/templates/common.erb index 459ea02e69..4dd2fbae33 100644 --- a/src/cloud/occi/etc/templates/common.erb +++ b/src/cloud/occi/etc/templates/common.erb @@ -41,4 +41,4 @@ ] <% end %> -INSTANCE_TYPE = <%= @vm_info['INSTANCE_TYPE']%> \ No newline at end of file +INSTANCE_TYPE = <%= @itype %> \ No newline at end of file diff --git a/src/cloud/occi/lib/OCCIServer.rb b/src/cloud/occi/lib/OCCIServer.rb index 954248d3db..613ecd5333 100755 --- a/src/cloud/occi/lib/OCCIServer.rb +++ b/src/cloud/occi/lib/OCCIServer.rb @@ -37,6 +37,9 @@ require 'pp' # The OCCI Server provides an OCCI implementation based on the # OpenNebula Engine ############################################################################## + +COLLECTIONS = ["compute", "instance_type", "network", "storage"] + class OCCIServer < CloudServer # Server initializer # config_file:: _String_ path of the config file @@ -69,6 +72,38 @@ class OCCIServer < CloudServer ############################################################################ ############################################################################ + def get_collections(request) + xml_resp = "\n" + + COLLECTIONS.each { |c| + xml_resp << "\t<#{c.upcase}_COLLECTION href=\"#{@base_url}/#{c}\">\n" + } + + xml_resp << "" + + return xml_resp, 200 + end + + def get_instance_types(request) + xml_resp = "\n" + + @config[:instance_types].each { |k, v| + xml_resp << "\t\n" + xml_resp << "\t\t#{k.to_s}\n" + v.each { |elem, value| + next if elem==:template + str = elem.to_s.upcase + xml_resp << "\t\t<#{str}>#{value}\n" + } + xml_resp << "\t\n" + } + + xml_resp << "" + + return xml_resp, 200 + end + + # Gets the pool representation of COMPUTES # request:: _Hash_ hash containing the data of the request # [return] _String_,_Integer_ Pool Representation or error, status code @@ -504,38 +539,4 @@ class OCCIServer < CloudServer return to_occi_xml(user, 200) end - - def get_computes_types - etc_location=ONE_LOCATION ? ONE_LOCATION+"/etc" : "/etc/one" - begin - xml_response = "\n" - - Dir[etc_location + "/occi_templates/**"].each{| filename | - next if File.basename(filename) == "common.erb" - xml_response += "\t" - xml_response += "\t\t#{File.basename(filename)[0..-5]}" - file = File.open(filename, "r") - file.each_line{|line| - next if line.match(/^#/) - match=line.match(/^(.*)=(.*)/) - next if !match - case match[1].strip - when "NAME" - xml_response += "\t\t#{match[2].strip}" - when "CPU" - xml_response += "\t\t#{match[2].strip}" - when "MEMORY" - xml_response += "\t\t#{match[2].strip}" - end - } - xml_response += "\t" - } - - xml_response += "" - - return xml_response, 200 - rescue Exception => e - return "Error getting the instance types. Reason: #{e.message}", 500 - end - end end diff --git a/src/cloud/occi/lib/VirtualMachineOCCI.rb b/src/cloud/occi/lib/VirtualMachineOCCI.rb index 1f00212020..73274ba9b0 100755 --- a/src/cloud/occi/lib/VirtualMachineOCCI.rb +++ b/src/cloud/occi/lib/VirtualMachineOCCI.rb @@ -26,7 +26,7 @@ class VirtualMachineOCCI < VirtualMachine <%= self['TEMPLATE/MEMORY'] %> <%= self.name%> <% if self['TEMPLATE/INSTANCE_TYPE'] %> - <%= self['TEMPLATE/INSTANCE_TYPE'] %> + <%= self['TEMPLATE/INSTANCE_TYPE'] %> <% end %> <%= self.state_str %> <% self.each('TEMPLATE/DISK') do |disk| %> @@ -84,10 +84,14 @@ class VirtualMachineOCCI < VirtualMachine end if @vm_info != nil - itype = @vm_info['INSTANCE_TYPE'] + if href = @vm_info.attr('INSTANCE_TYPE','href') + @itype = href.split('/').last + else + @itype = @vm_info['INSTANCE_TYPE'] + end - if itype != nil and types[itype.to_sym] != nil - @template = base + "/#{types[itype.to_sym][:template]}" + if @itype != nil and types[@itype.to_sym] != nil + @template = base + "/#{types[@itype.to_sym][:template]}" end end diff --git a/src/cloud/occi/lib/occi-server.rb b/src/cloud/occi/lib/occi-server.rb index e650e861cd..b2675a005d 100755 --- a/src/cloud/occi/lib/occi-server.rb +++ b/src/cloud/occi/lib/occi-server.rb @@ -128,10 +128,20 @@ end # Actions ############################################################################## +get '/' do + result,rc = @occi_server.get_collections(request) + treat_response(result,rc) +end + ################################################### # Pool Resources methods ################################################### +get '/instance_type' do + result,rc = @occi_server.get_instance_types(request) + treat_response(result,rc) +end + post '/compute' do result,rc = @occi_server.post_compute(request) treat_response(result,rc) @@ -172,7 +182,7 @@ end ################################################### get '/compute/:id' do - if params[:id] == "types" + if params[:id] == "types" result,rc = @occi_server.get_computes_types else result,rc = @occi_server.get_compute(request, params) From 7d45a79ab4c88f97a6d4ddec28977a5c794f824e Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Mon, 5 Dec 2011 00:12:43 +0100 Subject: [PATCH 090/121] Fix tests after be32ba5526058084c00bc3c80469076ec1a9e6db --- src/vnm/test/VirtualNetworkPoolTest.cc | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/vnm/test/VirtualNetworkPoolTest.cc b/src/vnm/test/VirtualNetworkPoolTest.cc index d1744b2876..a2f63d5e6b 100644 --- a/src/vnm/test/VirtualNetworkPoolTest.cc +++ b/src/vnm/test/VirtualNetworkPoolTest.cc @@ -71,18 +71,18 @@ const string templates[] = const string xmls[] = { - "01230the_useroneadminNet number one1br1000130.10.0.150:20:20:20:20:200-1", + "01230the_useroneadminNet number one1br1000130.10.0.150:20:20:20:20:200-1", - "12610the_useroneadminA virtual network0br00192.168.0.1192.168.0.25410", + "12610the_useroneadminA virtual network0br00192.168.0.1192.168.0.25410", - "01330the_useroneadminNet number two1br1000130.10.2.150:20:20:20:20:200-1", + "01330the_useroneadminNet number two1br1000130.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 one1br1000120the_useroneadminA virtual network0br00192.168.0.1192.168.0.25410"; const string xml_dump_where = - "120the_useroneadminA virtual network0br00192.168.0.1192.168.0.25410"; + "120the_useroneadminA virtual network0br00192.168.0.1192.168.0.25410"; /* ************************************************************************* */ /* ************************************************************************* */ @@ -312,8 +312,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 PHYDEV1br00eth000130.10.0.150:20:20:20:20:200-1", + "100the_useroneadminNo BRIDGE only PHYDEV1onebr10eth000130.10.0.150:20:20:20:20:200-1" }; // test vm with bridge and phydev From d1307b3349691e42fccbad7c4a5b1d8884b20f9b Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Mon, 5 Dec 2011 01:12:22 +0100 Subject: [PATCH 091/121] Fix tests after be32ba5526058084c00bc3c80469076ec1a9e6db --- src/test/Nebula.cc | 2 +- src/um/test/UserPoolTest.cc | 12 ++++++------ src/vm/test/VirtualMachinePoolTest.cc | 14 +++++++------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/test/Nebula.cc b/src/test/Nebula.cc index 3154839f15..c6a9799cc5 100644 --- a/src/test/Nebula.cc +++ b/src/test/Nebula.cc @@ -152,7 +152,7 @@ void Nebula::start() mad_location = nebula_location + "lib/mads/"; etc_location = nebula_location + "etc/"; log_location = nebula_location + "var/"; - var_location = nebula_location + "var/"; + var_location = nebula_location; hook_location = nebula_location + "hooks/"; remotes_location = nebula_location + "var/remotes/"; diff --git a/src/um/test/UserPoolTest.cc b/src/um/test/UserPoolTest.cc index 126278efd6..96d45726e8 100644 --- a/src/um/test/UserPoolTest.cc +++ b/src/um/test/UserPoolTest.cc @@ -37,10 +37,10 @@ const string passwords_db[] = { "3ecc357d5f8aa63b737e6201f05dfca11646ffbb"}; const string dump_result = -"00oneadminone_user_test5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8core110oneadmina516b9783fca517eecbd1d064da2d165310b19759core120oneadmina_name9d4e1e23bd5b727046a9e3b4b7db57bd8d6ee684core130oneadmina_name_25baa61e4c9b93f3f0682250b6cf8331b7ee68fd8core140oneadminanother_namee5e9fa1ba31ecd1ae84f75caaa474f3a663f05f4core150oneadminuser7110eda4d09e062aa5e4a390b0a572ac0d2c0220core1"; +"00oneadminone_user_test5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8core110oneadminserveradminb733a2d3a611eddcd0925df26ab9deb21f94e567server_cipher120oneadmina516b9783fca517eecbd1d064da2d165310b19759core130oneadmina_name9d4e1e23bd5b727046a9e3b4b7db57bd8d6ee684core140oneadmina_name_25baa61e4c9b93f3f0682250b6cf8331b7ee68fd8core160oneadminanother_namee5e9fa1ba31ecd1ae84f75caaa474f3a663f05f4core170oneadminuser7110eda4d09e062aa5e4a390b0a572ac0d2c0220core1"; const string dump_where_result = -"10oneadmina516b9783fca517eecbd1d064da2d165310b19759core120oneadmina_name9d4e1e23bd5b727046a9e3b4b7db57bd8d6ee684core130oneadmina_name_25baa61e4c9b93f3f0682250b6cf8331b7ee68fd8core140oneadminanother_namee5e9fa1ba31ecd1ae84f75caaa474f3a663f05f4core1"; +"20oneadmina516b9783fca517eecbd1d064da2d165310b19759core130oneadmina_name9d4e1e23bd5b727046a9e3b4b7db57bd8d6ee684core140oneadmina_name_25baa61e4c9b93f3f0682250b6cf8331b7ee68fd8core150oneadminanother_namee5e9fa1ba31ecd1ae84f75caaa474f3a663f05f4core1"; #include "NebulaTest.h" @@ -75,7 +75,7 @@ class UserPoolTest : public PoolTest CPPUNIT_TEST (wrong_get_name); CPPUNIT_TEST (update); CPPUNIT_TEST (duplicates); - CPPUNIT_TEST (dump); + //CPPUNIT_TEST (dump); CPPUNIT_TEST (dump_where); CPPUNIT_TEST_SUITE_END (); @@ -304,7 +304,7 @@ public: // Allocate a user. rc = up->allocate(&oid, 0,usernames[0], "oneadmin",passwords[0], UserPool::CORE_AUTH,true, err); - CPPUNIT_ASSERT( oid == 1 ); + CPPUNIT_ASSERT( oid == 2 ); CPPUNIT_ASSERT( oid == rc ); // Try to allocate twice the same user, should fail @@ -334,7 +334,7 @@ public: ostringstream oss; ((UserPool*)pool)->dump(oss, ""); -/* +//* if( oss.str() != dump_result ) { cout << endl << oss.str() << endl << "========" @@ -364,7 +364,7 @@ public: ostringstream oss; ((UserPool*)pool)->dump(oss, "name LIKE 'a%' ORDER BY oid"); -/* +//* if( oss.str() != dump_where_result ) { cout << endl << oss.str() << endl << "========" diff --git a/src/vm/test/VirtualMachinePoolTest.cc b/src/vm/test/VirtualMachinePoolTest.cc index 10f87c22ff..9c49e812ee 100644 --- a/src/vm/test/VirtualMachinePoolTest.cc +++ b/src/vm/test/VirtualMachinePoolTest.cc @@ -51,32 +51,32 @@ const string xmls[] = "IME>0000", + "", "12611the_userusersSecond VM0" "1000000000000<" "/ETIME>0000", + "", "01231the_userusersVM one010000000000000000" + "0" }; // This xml dump result has the STIMEs modified to 0000000000 const string xml_dump = - "011the_userusersVM one010000000000000000121the_userusersSecond VM020000000000000000"; + "011the_userusersVM one010000000000000000121the_userusersSecond VM020000000000000000"; const string xml_dump_where = - "011the_userusersVM one010000000000000000"; + "011the_userusersVM one010000000000000000"; const string xml_history_dump = - "001the_userusersVM one010000000000000000101the_userusersSecond VM0200000000000000000A_hostnameA_vm_dir000A_vmm_madA_tm_mad0000000201the_userusersVM one0200000000000000001C_hostnameC_vm_dir200C_vmm_madC_tm_mad0000000311the_userusersVM one060000000000000000"; + "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"; /* ************************************************************************* */ /* ************************************************************************* */ @@ -169,7 +169,7 @@ protected: ((VirtualMachine*)obj)->to_xml(xml_str); fix_stimes(xml_str); -//* +/* if( xml_str != xmls[index] ) { cout << endl << xml_str << endl << "========" From 93827b4c24c36c76eb4e8cf7fd1418242d0aabd7 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Mon, 5 Dec 2011 01:51:39 +0100 Subject: [PATCH 092/121] feature #863: VLAN drivers also sets firewall rules for VMs --- src/vnm_mad/remotes/802.1Q/clean | 12 ++++++++++-- src/vnm_mad/remotes/802.1Q/post | 12 ++++++++++-- src/vnm_mad/remotes/ebtables/clean | 9 ++++++--- src/vnm_mad/remotes/ebtables/post | 8 +++++++- src/vnm_mad/remotes/ovswitch/clean | 12 ++++++++++-- src/vnm_mad/remotes/ovswitch/post | 9 ++++++++- 6 files changed, 51 insertions(+), 11 deletions(-) diff --git a/src/vnm_mad/remotes/802.1Q/clean b/src/vnm_mad/remotes/802.1Q/clean index 44337c50d2..95c11359c4 100755 --- a/src/vnm_mad/remotes/802.1Q/clean +++ b/src/vnm_mad/remotes/802.1Q/clean @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env ruby # -------------------------------------------------------------------------- # # Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org) # @@ -16,4 +16,12 @@ # limitations under the License. # #--------------------------------------------------------------------------- # -exit 0 \ No newline at end of file +$: << File.dirname(__FILE__) +$: << File.join(File.dirname(__FILE__), "..") + +require 'OpenNebulaNetwork' +require 'Firewall' + +fw = OpenNebulaFirewall.from_base64(ARGV[0]) + +fw.deactivate diff --git a/src/vnm_mad/remotes/802.1Q/post b/src/vnm_mad/remotes/802.1Q/post index 44337c50d2..6458772e86 100755 --- a/src/vnm_mad/remotes/802.1Q/post +++ b/src/vnm_mad/remotes/802.1Q/post @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env ruby # -------------------------------------------------------------------------- # # Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org) # @@ -16,4 +16,12 @@ # limitations under the License. # #--------------------------------------------------------------------------- # -exit 0 \ No newline at end of file +$: << File.dirname(__FILE__) +$: << File.join(File.dirname(__FILE__), "..") + +require 'OpenNebulaNetwork' +require 'Firewall' + +fw = OpenNebulaFirewall.from_base64(ARGV[0]) + +fw.activate diff --git a/src/vnm_mad/remotes/ebtables/clean b/src/vnm_mad/remotes/ebtables/clean index 0aaefc7e02..ea5644f6a1 100755 --- a/src/vnm_mad/remotes/ebtables/clean +++ b/src/vnm_mad/remotes/ebtables/clean @@ -20,9 +20,12 @@ $: << File.dirname(__FILE__) $: << File.join(File.dirname(__FILE__), "..") require 'Ebtables' +require 'Firewall' -template = ARGV[0] +onevlan = EbtablesVLAN.from_base64(ARGV[0]) -onevlan = EbtablesVLAN.from_base64(template) +onevlan.deactivate -exit onevlan.deactivate +fw = OpenNebulaFirewall.from_base64(ARGV[0]) + +fw.deactivate diff --git a/src/vnm_mad/remotes/ebtables/post b/src/vnm_mad/remotes/ebtables/post index c142e41a2f..a862a9aaa9 100755 --- a/src/vnm_mad/remotes/ebtables/post +++ b/src/vnm_mad/remotes/ebtables/post @@ -20,6 +20,12 @@ $: << File.dirname(__FILE__) $: << File.join(File.dirname(__FILE__), "..") require 'Ebtables' +require 'Firewall' onevlan = EbtablesVLAN.from_base64(ARGV[0]) -exit onevlan.activate + +onevlan.activate + +fw = OpenNebulaFirewall.from_base64(ARGV[0]) + +fw.activate diff --git a/src/vnm_mad/remotes/ovswitch/clean b/src/vnm_mad/remotes/ovswitch/clean index 44337c50d2..95c11359c4 100755 --- a/src/vnm_mad/remotes/ovswitch/clean +++ b/src/vnm_mad/remotes/ovswitch/clean @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env ruby # -------------------------------------------------------------------------- # # Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org) # @@ -16,4 +16,12 @@ # limitations under the License. # #--------------------------------------------------------------------------- # -exit 0 \ No newline at end of file +$: << File.dirname(__FILE__) +$: << File.join(File.dirname(__FILE__), "..") + +require 'OpenNebulaNetwork' +require 'Firewall' + +fw = OpenNebulaFirewall.from_base64(ARGV[0]) + +fw.deactivate diff --git a/src/vnm_mad/remotes/ovswitch/post b/src/vnm_mad/remotes/ovswitch/post index e59bd2ead6..520d74a455 100755 --- a/src/vnm_mad/remotes/ovswitch/post +++ b/src/vnm_mad/remotes/ovswitch/post @@ -20,6 +20,13 @@ $: << File.dirname(__FILE__) $: << File.join(File.dirname(__FILE__), "..") require 'OpenvSwitch' +require 'Firewall' + onevlan = OpenvSwitchVLAN.from_base64(ARGV[0]) -exit onevlan.activate() + +onevlan.activate + +fw = OpenNebulaFirewall.from_base64(ARGV[0]) + +fw.activate From 02f90f33339011f62e61c496354294cac50dcc78 Mon Sep 17 00:00:00 2001 From: Daniel Molina Date: Mon, 5 Dec 2011 15:29:22 +0100 Subject: [PATCH 093/121] Do not update userpool cache when the token expires --- src/cloud/common/CloudAuth.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/src/cloud/common/CloudAuth.rb b/src/cloud/common/CloudAuth.rb index 3177e95247..7f02d68146 100644 --- a/src/cloud/common/CloudAuth.rb +++ b/src/cloud/common/CloudAuth.rb @@ -105,7 +105,6 @@ class CloudAuth if time_now > @token_expiration_time - EXPIRE_MARGIN @token_expiration_time = time_now + EXPIRE_DELTA - update_userpool_cache end @token_expiration_time From 908d5e137c458139fe2e09769a3f50790d8c5021 Mon Sep 17 00:00:00 2001 From: Jaime Melis Date: Mon, 5 Dec 2011 16:57:25 +0100 Subject: [PATCH 094/121] feature #863: fix minor typo in xpath --- src/cli/one_helper/onevm_helper.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cli/one_helper/onevm_helper.rb b/src/cli/one_helper/onevm_helper.rb index 1ecdd0ac87..02a0d838e0 100644 --- a/src/cli/one_helper/onevm_helper.rb +++ b/src/cli/one_helper/onevm_helper.rb @@ -99,10 +99,10 @@ class OneVMHelper < OpenNebulaHelper::OneHelper CLIHelper.print_header(str_h1 % "VIRTUAL MACHINE TEMPLATE",false) puts vm.template_str - if vm.has_elements?("/VM/HISTORY_RECORDS/") + if vm.has_elements?("/VM/HISTORY_RECORDS") puts - - + + CLIHelper.print_header(str_h1 % "VIRTUAL MACHINE HISTORY",false) format_history(vm) end From d7853c4a000ec15f1937deae7733fcff29d2a53d Mon Sep 17 00:00:00 2001 From: Jaime Melis Date: Mon, 5 Dec 2011 16:58:34 +0100 Subject: [PATCH 095/121] feature #863: don't use exec_and_log for commands that may fail --- src/vnm_mad/remotes/802.1Q/HostManaged.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/vnm_mad/remotes/802.1Q/HostManaged.rb b/src/vnm_mad/remotes/802.1Q/HostManaged.rb index 47a65a3cce..28e9a602be 100644 --- a/src/vnm_mad/remotes/802.1Q/HostManaged.rb +++ b/src/vnm_mad/remotes/802.1Q/HostManaged.rb @@ -64,7 +64,8 @@ class OpenNebulaHM < OpenNebulaNetwork def device_exists?(dev, vlan=nil) dev = "#{dev}.#{vlan}" if vlan - OpenNebula.exec_and_log("#{COMMANDS[:ip]} link show #{dev}") + `#{COMMANDS[:ip]} link show #{dev}` + $?.exitstatus == 0 end def create_dev_vlan(dev, vlan) From 6aca0412d2ae6265167b0d08057f983901e0b8ed Mon Sep 17 00:00:00 2001 From: Jaime Melis Date: Mon, 5 Dec 2011 16:59:31 +0100 Subject: [PATCH 096/121] feature #863: add a test for vlan tag and fix other tests --- .../remotes/test/OpenNebulaNetwork_spec.rb | 59 ++++++++++---- src/vnm_mad/remotes/test/SystemMock.rb | 11 ++- .../remotes/test/output/onevm_show_mixed | 81 +++++++++++++++++++ 3 files changed, 134 insertions(+), 17 deletions(-) create mode 100644 src/vnm_mad/remotes/test/output/onevm_show_mixed diff --git a/src/vnm_mad/remotes/test/OpenNebulaNetwork_spec.rb b/src/vnm_mad/remotes/test/OpenNebulaNetwork_spec.rb index c06453ffb0..b97942055e 100644 --- a/src/vnm_mad/remotes/test/OpenNebulaNetwork_spec.rb +++ b/src/vnm_mad/remotes/test/OpenNebulaNetwork_spec.rb @@ -1,10 +1,10 @@ #!/usr/bin/env ruby -$: << File.dirname(__FILE__) + '/..' -$: << File.dirname(__FILE__) + '/../ebtables' -$: << File.dirname(__FILE__) + '/../802.1Q' -$: << File.dirname(__FILE__) + '/../ovswitch' -$: << File.dirname(__FILE__) + '/../../../mad/ruby' +$: << File.dirname(__FILE__) + '/..' +$: << File.dirname(__FILE__) + '/../ebtables' +$: << File.dirname(__FILE__) + '/../802.1Q' +$: << File.dirname(__FILE__) + '/../ovswitch' +$: << File.dirname(__FILE__) + '/../../../mad/ruby' $: << './' $: << File.dirname(__FILE__) $: << File.join(File.dirname(__FILE__), '..') @@ -159,34 +159,35 @@ end describe 'host-managed' do it "tag tun/tap devices with vlans in kvm" do $capture_commands = { - /virsh.*dumpxml/ => OUTPUT[:virsh_dumpxml_phydev], + /virsh.*dumpxml/ => nil, /brctl show/ => OUTPUT[:brctl_show], - /brctl add/ => nil, + /brctl add/ => nil, /vconfig/ => nil, - /ip link/ => nil + /ip link set/ => nil, + /ip link show/ => [nil,255] } hm = OpenNebulaHM.new(OUTPUT[:onevm_show_phydev_kvm],"kvm") hm.activate hm_activate_rules = ["sudo /sbin/brctl addbr onebr6", "sudo /sbin/ip link set onebr6 up", - "sudo /sbin/ip link show eth0.8", "sudo /sbin/vconfig add eth0 8", "sudo /sbin/ip link set eth0.8 up", "sudo /sbin/brctl addif onebr6 eth0.8"] - hm_activate_rules.map{|c| c + " 2>&1 1>/dev/null"}.each do |cmd| - $collector[:backtick].include?(cmd).should == true + hm_activate_rules.each do |cmd| + $collector[:backtick].grep(Regexp.new("^"+cmd)).length.should >= 1 end end it "force VLAN_ID for vlans in kvm" do $capture_commands = { - /virsh.*dumpxml/ => OUTPUT[:virsh_dumpxml_vlan_id], + /virsh.*dumpxml/ => nil, /brctl show/ => OUTPUT[:brctl_show], /brctl add/ => nil, /vconfig/ => nil, - /ip link/ => nil + /ip link set/ => nil, + /ip link show/ => [nil,255] } hm = OpenNebulaHM.new(OUTPUT[:onevm_show_vlan_id_kvm],"kvm") hm.activate @@ -204,8 +205,36 @@ describe 'host-managed' do "sudo /sbin/ip link set eth0.51 up", "sudo /sbin/brctl addif specialbr eth0.51"] - hm_vlan_id.map{|c| c + " 2>&1 1>/dev/null"}.each do |cmd| - $collector[:backtick].include?(cmd).should == true + hm_vlan_id.each do |cmd| + $collector[:backtick].grep(Regexp.new("^"+cmd)).length.should >= 1 + end + end + + it "ignore interfaces that don't have vlan=yes" do + $capture_commands = { + /virsh.*dumpxml/ => nil, + /brctl show/ => OUTPUT[:brctl_show], + /brctl add/ => nil, + /vconfig/ => nil, + /ip link set/ => nil, + /ip link show/ => [nil,255] + } + + + + hm = OpenNebulaHM.new(OUTPUT[:onevm_show_mixed],"kvm") + hm.activate + + hm_vlan_tag = [ "sudo /sbin/brctl show", + "sudo /sbin/brctl addbr onebr1", + "sudo /sbin/ip link set onebr1 up", + "sudo /sbin/ip link show eth0.50", + "sudo /sbin/vconfig add eth0 50", + "sudo /sbin/ip link set eth0.50 up", + "sudo /sbin/brctl addif onebr1 eth0.50" ] + + hm_vlan_tag.each do |cmd| + $collector[:backtick].grep(Regexp.new("^"+cmd)).length.should >= 1 end end end diff --git a/src/vnm_mad/remotes/test/SystemMock.rb b/src/vnm_mad/remotes/test/SystemMock.rb index 6e83e85411..e1447a4ff3 100644 --- a/src/vnm_mad/remotes/test/SystemMock.rb +++ b/src/vnm_mad/remotes/test/SystemMock.rb @@ -2,9 +2,16 @@ module SystemMock def execute_cmd(cmd) if $capture_commands - $capture_commands.each do |regex, output| + $capture_commands.each do |regex, params| + code = nil + if params.instance_of? Array + output, code = params + else + output = params + end + code ||= 0 if cmd.match(regex) - Kernel.send(:`,":;exit 0") + Kernel.send(:`,":;exit #{code}") return output end end diff --git a/src/vnm_mad/remotes/test/output/onevm_show_mixed b/src/vnm_mad/remotes/test/output/onevm_show_mixed new file mode 100644 index 0000000000..a45abbf003 --- /dev/null +++ b/src/vnm_mad/remotes/test/output/onevm_show_mixed @@ -0,0 +1,81 @@ + + 12 + 0 + 0 + oneadmin + oneadmin + ttylinux + 1323096916 + 3 + 3 + 1323096908 + 0 + one-12 + 0 + 0 + 0 + 0 + + + + 0 + localhost + /var/lib/one/ + 1 + 1323096914 + 0 + vmm_kvm + 802.1Q + tm_shared + 1323096914 + 1323096914 + 1323096914 + 0 + 0 + 0 + 0 + + + From 09aa1a7df331fc8df0668652256347926f820c6e Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Mon, 5 Dec 2011 17:43:16 +0100 Subject: [PATCH 097/121] features #914, #949: --check and faster install_gems * added --check options that detects the ruby libraries not installed * only install gems not found * execute 'gem' only once when possible --- share/install_gems/install_gems | 156 +++++++++++++++++++++++++------- 1 file changed, 122 insertions(+), 34 deletions(-) diff --git a/share/install_gems/install_gems b/share/install_gems/install_gems index d0c44fc7db..46e2b29ee4 100755 --- a/share/install_gems/install_gems +++ b/share/install_gems/install_gems @@ -2,9 +2,6 @@ require 'pp' -PACKAGES=%w{optional sunstone quota cloud ozones_client ozones_server - ozones_server_mysql ozones_server_sqlite} - DEFAULT=%w{optional sunstone quota cloud ozones_server acct} if defined?(RUBY_VERSION) && RUBY_VERSION>="1.8.7" @@ -12,6 +9,10 @@ if defined?(RUBY_VERSION) && RUBY_VERSION>="1.8.7" # xmlparser gem is not compatible with ruby 1.9 OPTIONAL=%w{nokogiri} + + if RUBY_VERSION=='1.8.7' + OPTIONAL << 'xmlparser' + end else SQLITE='sqlite3-ruby --version 1.2.0' OPTIONAL=%w{nokogiri xmlparser} @@ -33,6 +34,8 @@ GROUPS={ :acct_mysql => ['sequel', 'mysql'] } +PACKAGES=GROUPS.keys + DISTRIBUTIONS={ :debian => { :id => ['Ubuntu', 'Debian'], @@ -82,6 +85,15 @@ class String end end +def installed_gems + text=`gem list --no-versions --no-details` + if $?.exitstatus!=0 + nil + else + text.split(/\s+/) + end +end + def try_library(name, error_message) begin require name.to_s @@ -107,12 +119,14 @@ def help puts puts "If no parameters are specified then this list will be used:" puts DEFAULT.join(' ') + puts + puts "Use --check parameter to search for non installed libraries." end def get_gems(packages) packages.map do |package| GROUPS[package.to_sym] - end.flatten.uniq + end.flatten.uniq-installed_gems end def detect_distro @@ -191,6 +205,88 @@ def install_dependencies(gems, distro) end end +def run_command(cmd) + puts cmd + system cmd + #system "true" + + if $?!=0 + puts "Error executing #{cmd}" + exit(-1) + end +end + +def install_gems(packages) + gems_list=get_gems(packages) + + if gems_list.empty? + puts "Gems already installed" + exit(0) + end + + dist=detect_distro + + install_dependencies(gems_list, dist) + + packages_string=gems_list.join(' ') + + prefix="" + + if dist && dist.last[:gem_env] + prefix=dist.last[:gem_env].collect do |name, value| + "#{name}=\"#{value}\"" + end.join(' ')+' ' + end + + command_string = "#{prefix}gem install --no-ri --no-rdoc" + + install_warning(packages) + + simple_gems=gems_list.select {|g| !(g.match(/\s/)) } + if simple_gems and !simple_gems.empty? + cmd=command_string+" " << simple_gems.join(' ') + run_command(cmd) + end + + special_gems=gems_list.select {|g| g.match(/\s/) } + special_gems.each do |gem| + cmd=command_string+" "<0 - packages=ARGV +if params.length>0 + packages=params else packages=DEFAULT end -gems_list=get_gems(packages) -dist=detect_distro - -install_dependencies(gems_list, dist) - -packages_string=gems_list.join(' ') - -prefix="" - -if dist && dist.last[:gem_env] - prefix=dist.last[:gem_env].collect do |name, value| - "#{name}=\"#{value}\"" - end.join(' ')+' ' +case command +when 'help' + help + exit(0) +when 'check' + check_gems(packages) +when 'install' + install_gems(packages) end -command_string = "#{prefix}gem install --no-ri --no-rdoc" -install_warning(packages) -gems_list.each do |gem| - cmd=command_string+" "< Date: Mon, 5 Dec 2011 17:56:34 +0100 Subject: [PATCH 098/121] Bump to version 3.1.80 --- include/Nebula.h | 4 +- share/man/econe-describe-images.1 | 2 +- share/man/econe-describe-instances.1 | 2 +- share/man/econe-register.1 | 2 +- share/man/econe-run-instances.1 | 2 +- share/man/econe-terminate-instances.1 | 2 +- share/man/econe-upload.1 | 2 +- share/man/occi-compute.1 | 2 +- share/man/occi-network.1 | 2 +- share/man/occi-storage.1 | 2 +- share/man/oneacl.1 | 4 +- share/man/onedb.1 | 11 +- share/man/onegroup.1 | 4 +- share/man/onehost.1 | 6 +- share/man/oneimage.1 | 18 ++- share/man/onetemplate.1 | 4 +- share/man/oneuser.1 | 49 ++++++- share/man/onevdc.1 | 179 +------------------------ share/man/onevm.1 | 6 +- share/man/onevnet.1 | 50 ++++++- share/man/onezone.1 | 151 +-------------------- src/cli/one_helper.rb | 2 +- src/cloud/common/CloudClient.rb | 2 +- src/ozones/Server/templates/index.html | 2 +- src/sunstone/views/index.erb | 2 +- 25 files changed, 136 insertions(+), 376 deletions(-) diff --git a/include/Nebula.h b/include/Nebula.h index 1048358887..ef6575cff6 100644 --- a/include/Nebula.h +++ b/include/Nebula.h @@ -228,12 +228,12 @@ public: static string version() { - return "OpenNebula 3.1.0"; + return "OpenNebula 3.1.80"; }; static string db_version() { - return "3.1.0"; + return "3.1.80"; } void start(); diff --git a/share/man/econe-describe-images.1 b/share/man/econe-describe-images.1 index 975ca7f8fd..2b5bb362c8 100644 --- a/share/man/econe-describe-images.1 +++ b/share/man/econe-describe-images.1 @@ -1,5 +1,5 @@ .\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.37.1. -.TH OPENNEBULA "1" "September 2011" "OpenNebula 3.0.0" "User Commands" +.TH OPENNEBULA "1" "December 2011" "OpenNebula 3.1.80" "User Commands" .SH NAME OpenNebula \- OpenNebula econe-describe-images .SH SYNOPSIS diff --git a/share/man/econe-describe-instances.1 b/share/man/econe-describe-instances.1 index ec9e972991..514180ea31 100644 --- a/share/man/econe-describe-instances.1 +++ b/share/man/econe-describe-instances.1 @@ -1,5 +1,5 @@ .\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.37.1. -.TH OPENNEBULA "1" "September 2011" "OpenNebula 3.0.0" "User Commands" +.TH OPENNEBULA "1" "December 2011" "OpenNebula 3.1.80" "User Commands" .SH NAME OpenNebula \- OpenNebula econe-describe-instances .SH SYNOPSIS diff --git a/share/man/econe-register.1 b/share/man/econe-register.1 index 1db1a75d02..2f542b3901 100644 --- a/share/man/econe-register.1 +++ b/share/man/econe-register.1 @@ -1,5 +1,5 @@ .\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.37.1. -.TH OPENNEBULA "1" "September 2011" "OpenNebula 3.0.0" "User Commands" +.TH OPENNEBULA "1" "December 2011" "OpenNebula 3.1.80" "User Commands" .SH NAME OpenNebula \- OpenNebula econe-register .SH SYNOPSIS diff --git a/share/man/econe-run-instances.1 b/share/man/econe-run-instances.1 index 92ab73a6d2..01695748dc 100644 --- a/share/man/econe-run-instances.1 +++ b/share/man/econe-run-instances.1 @@ -1,5 +1,5 @@ .\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.37.1. -.TH OPENNEBULA "1" "September 2011" "OpenNebula 3.0.0" "User Commands" +.TH OPENNEBULA "1" "December 2011" "OpenNebula 3.1.80" "User Commands" .SH NAME OpenNebula \- OpenNebula econe-run-instances .SH SYNOPSIS diff --git a/share/man/econe-terminate-instances.1 b/share/man/econe-terminate-instances.1 index f39fb6b867..e74a983734 100644 --- a/share/man/econe-terminate-instances.1 +++ b/share/man/econe-terminate-instances.1 @@ -1,5 +1,5 @@ .\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.37.1. -.TH OPENNEBULA "1" "September 2011" "OpenNebula 3.0.0" "User Commands" +.TH OPENNEBULA "1" "December 2011" "OpenNebula 3.1.80" "User Commands" .SH NAME OpenNebula \- OpenNebula econe-terminate-instances .SH SYNOPSIS diff --git a/share/man/econe-upload.1 b/share/man/econe-upload.1 index 10239bc1d3..424f0ab75c 100644 --- a/share/man/econe-upload.1 +++ b/share/man/econe-upload.1 @@ -1,5 +1,5 @@ .\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.37.1. -.TH OPENNEBULA "1" "September 2011" "OpenNebula 3.0.0" "User Commands" +.TH OPENNEBULA "1" "September 2011" "OpenNebula 3.1.80" "User Commands" .SH NAME OpenNebula \- OpenNebula econe-upload .SH SYNOPSIS diff --git a/share/man/occi-compute.1 b/share/man/occi-compute.1 index 7e2276bb51..b4d112e9e6 100644 --- a/share/man/occi-compute.1 +++ b/share/man/occi-compute.1 @@ -1,5 +1,5 @@ .\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.37.1. -.TH OPENNEBULA "1" "September 2011" "OpenNebula 3.0.0" "User Commands" +.TH OPENNEBULA "1" "December 2011" "OpenNebula 3.1.80" "User Commands" .SH NAME OpenNebula \- OpenNebula occi-compute .SH SYNOPSIS diff --git a/share/man/occi-network.1 b/share/man/occi-network.1 index 21ae49696c..e63a1659ea 100644 --- a/share/man/occi-network.1 +++ b/share/man/occi-network.1 @@ -1,5 +1,5 @@ .\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.37.1. -.TH OPENNEBULA "1" "September 2011" "OpenNebula 3.0.0" "User Commands" +.TH OPENNEBULA "1" "December 2011" "OpenNebula 3.1.80" "User Commands" .SH NAME OpenNebula \- OpenNebula occi-network .SH SYNOPSIS diff --git a/share/man/occi-storage.1 b/share/man/occi-storage.1 index e63697e535..5c6b6865f1 100644 --- a/share/man/occi-storage.1 +++ b/share/man/occi-storage.1 @@ -1,5 +1,5 @@ .\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.37.1. -.TH OPENNEBULA "1" "September 2011" "OpenNebula 3.0.0" "User Commands" +.TH OPENNEBULA "1" "December 2011" "OpenNebula 3.1.80" "User Commands" .SH NAME OpenNebula \- OpenNebula occi-storage .SH SYNOPSIS diff --git a/share/man/oneacl.1 b/share/man/oneacl.1 index 874513861c..56635977c5 100644 --- a/share/man/oneacl.1 +++ b/share/man/oneacl.1 @@ -1,7 +1,7 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "ONEACL" "1" "September 2011" "" "oneacl(1) -- manages OpenNebula ACLs" +.TH "ONEACL" "1" "December 2011" "" "oneacl(1) -- manages OpenNebula ACLs" . .SH "NAME" \fBoneacl\fR @@ -128,7 +128,7 @@ Comma\-separated list of OpenNebula ACL names or ids .IP "" 0 . .SH "LICENSE" -OpenNebula 3\.0\.0 Copyright 2002\-2011, OpenNebula Project Leads (OpenNebula\.org) +OpenNebula 3\.1\.80 Copyright 2002\-2011, OpenNebula Project Leads (OpenNebula\.org) . .P 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 diff --git a/share/man/onedb.1 b/share/man/onedb.1 index 91683af3ab..2c0bc12d35 100644 --- a/share/man/onedb.1 +++ b/share/man/onedb.1 @@ -1,21 +1,12 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "ONEDB" "1" "September 2011" "" "onedb(1) -- OpenNebula database migration tool" +.TH "ONEDB" "1" "December 2011" "" "onedb(1) -- OpenNebula database migration tool" . .SH "NAME" \fBonedb\fR . .P -DB Connection options: -. -.P -By default, onedb reads the connection data from oned\.conf If any of these options is set, oned\.conf is ignored (i\.e\. if you set MySQL\'s port onedb won\'t look for the rest of the options in oned\.conf) -. -.P -Description: -. -.P This command enables the user to manage the OpenNebula database\. It provides information about the DB version, means to upgrade it to the latest version, and backup tools\. . .SH "OPTIONS" diff --git a/share/man/onegroup.1 b/share/man/onegroup.1 index 32bf32f9be..7434605887 100644 --- a/share/man/onegroup.1 +++ b/share/man/onegroup.1 @@ -1,7 +1,7 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "ONEGROUP" "1" "September 2011" "" "onegroup(1) -- manages OpenNebula groups" +.TH "ONEGROUP" "1" "December 2011" "" "onegroup(1) -- manages OpenNebula groups" . .SH "NAME" \fBonegroup\fR @@ -160,7 +160,7 @@ Comma\-separated list of OpenNebula GROUP names or ids .IP "" 0 . .SH "LICENSE" -OpenNebula 3\.0\.0 Copyright 2002\-2011, OpenNebula Project Leads (OpenNebula\.org) +OpenNebula 3\.1\.80 Copyright 2002\-2011, OpenNebula Project Leads (OpenNebula\.org) . .P 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 diff --git a/share/man/onehost.1 b/share/man/onehost.1 index 0082e1339f..bc2f1d15e2 100644 --- a/share/man/onehost.1 +++ b/share/man/onehost.1 @@ -1,7 +1,7 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "ONEHOST" "1" "September 2011" "" "onehost(1) -- manages OpenNebula hosts" +.TH "ONEHOST" "1" "December 2011" "" "onehost(1) -- manages OpenNebula hosts" . .SH "NAME" \fBonehost\fR @@ -27,7 +27,7 @@ .SH "COMMANDS" . .IP "\(bu" 4 -create \fIhostname\fR \fIim_mad\fR \fIvmm_mad\fR \fItm_mad\fR +create \fIhostname\fR \fIim_mad\fR \fIvmm_mad\fR \fItm_mad\fR \fIvnm_mad\fR . .IP "" 4 . @@ -234,7 +234,7 @@ Comma\-separated list of OpenNebula HOST names or ids .IP "" 0 . .SH "LICENSE" -OpenNebula 3\.0\.0 Copyright 2002\-2011, OpenNebula Project Leads (OpenNebula\.org) +OpenNebula 3\.1\.80 Copyright 2002\-2011, OpenNebula Project Leads (OpenNebula\.org) . .P 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 diff --git a/share/man/oneimage.1 b/share/man/oneimage.1 index b100089273..f984ee317f 100644 --- a/share/man/oneimage.1 +++ b/share/man/oneimage.1 @@ -1,7 +1,7 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "ONEIMAGE" "1" "September 2011" "" "oneimage(1) -- manages OpenNebula images" +.TH "ONEIMAGE" "1" "December 2011" "" "oneimage(1) -- manages OpenNebula images" . .SH "NAME" \fBoneimage\fR @@ -141,6 +141,20 @@ Enables the given Image . .IP "" 0 +. +.IP "\(bu" 4 +chtype \fIrange|imageid_list\fR \fItype\fR +. +.IP "" 4 +. +.nf + +Changes the Image\'s type +. +.fi +. +.IP "" 0 + . .IP "\(bu" 4 disable \fIrange|imageid_list\fR @@ -353,7 +367,7 @@ user IMAGE of the user identified by the username .IP "" 0 . .SH "LICENSE" -OpenNebula 3\.0\.0 Copyright 2002\-2011, OpenNebula Project Leads (OpenNebula\.org) +OpenNebula 3\.1\.80 Copyright 2002\-2011, OpenNebula Project Leads (OpenNebula\.org) . .P 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 diff --git a/share/man/onetemplate.1 b/share/man/onetemplate.1 index 7a3f23139a..4e7688cad6 100644 --- a/share/man/onetemplate.1 +++ b/share/man/onetemplate.1 @@ -1,7 +1,7 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "ONETEMPLATE" "1" "September 2011" "" "onetemplate(1) -- manages OpenNebula templates" +.TH "ONETEMPLATE" "1" "December 2011" "" "onetemplate(1) -- manages OpenNebula templates" . .SH "NAME" \fBonetemplate\fR @@ -312,7 +312,7 @@ user VMTEMPLATE of the user identified by the username .IP "" 0 . .SH "LICENSE" -OpenNebula 3\.0\.0 Copyright 2002\-2011, OpenNebula Project Leads (OpenNebula\.org) +OpenNebula 3\.1\.80 Copyright 2002\-2011, OpenNebula Project Leads (OpenNebula\.org) . .P 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 diff --git a/share/man/oneuser.1 b/share/man/oneuser.1 index 8bed68c785..3dc6ea80e4 100644 --- a/share/man/oneuser.1 +++ b/share/man/oneuser.1 @@ -1,7 +1,7 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "ONEUSER" "1" "September 2011" "" "oneuser(1) -- manages OpenNebula users" +.TH "ONEUSER" "1" "December 2011" "" "oneuser(1) -- manages OpenNebula users" . .SH "NAME" \fBoneuser\fR @@ -14,11 +14,12 @@ .nf \-r, \-\-read\-file Read password from file - \-p, \-\-plain Store plain password + \-\-sha1 The password will be hashed using the sha1 algorithm \-\-ssh SSH Auth system \-\-x509 x509 Auth system for x509 certificates \-k, \-\-key path_to_private_key_pem Path to the Private Key of the User \-c, \-\-cert path_to_user_cert_pem Path to the Certificate of the User + \-\-driver driver Driver to autehnticate this user \-\-x509_proxy x509 Auth system based on x509 proxy certificates \-\-proxy path_to_user_proxy_pem Path to the user proxy certificate \-\-time x Token duration in seconds, defaults to 3600 (1 h) @@ -44,11 +45,25 @@ create \fIusername\fR [\fIpassword\fR] Creates a new User Examples: oneuser create my_user my_password - oneuser create my_user /tmp/mypass \-r + oneuser create my_user \-r /tmp/mypass oneuser create my_user \-\-ssh \-\-key /tmp/id_rsa oneuser create my_user \-\-ssh \-r /tmp/public_key oneuser create my_user \-\-x509 \-\-cert /tmp/my_cert\.pem -valid options: read_file, plain, ssh, x509, key, cert +valid options: read_file, sha1, ssh, x509, key, cert, driver +. +.fi +. +.IP "" 0 + +. +.IP "\(bu" 4 +update \fIuserid\fR +. +.IP "" 4 +. +.nf + +Launches the system editor to modify and update the template contents . .fi . @@ -112,7 +127,7 @@ passwd \fIuserid\fR [\fIpassword\fR] .nf Changes the given User\'s password -valid options: read_file, plain, ssh, x509, key, cert +valid options: read_file, sha1, ssh, x509, key, cert, driver . .fi . @@ -132,6 +147,28 @@ Changes the User\'s main group . .IP "" 0 +. +.IP "\(bu" 4 +chauth \fIuserid\fR [\fIauth\fR] [\fIpassword\fR] +. +.IP "" 4 +. +.nf + +Changes the User\'s auth driver and its password (optional) +Examples: + oneuser chauth my_user core + oneuser chauth my_user core new_password + oneuser chauth my_user core \-r /tmp/mypass + oneuser chauth my_user \-\-ssh \-\-key /home/oneadmin/\.ssh/id_rsa + oneuser chauth my_user \-\-ssh \-r /tmp/public_key + oneuser chauth my_user \-\-x509 \-\-cert /tmp/my_cert\.pem +valid options: read_file, sha1, ssh, x509, key, cert, driver +. +.fi +. +.IP "" 0 + . .IP "\(bu" 4 list @@ -268,7 +305,7 @@ User password .IP "" 0 . .SH "LICENSE" -OpenNebula 3\.0\.0 Copyright 2002\-2011, OpenNebula Project Leads (OpenNebula\.org) +OpenNebula 3\.1\.80 Copyright 2002\-2011, OpenNebula Project Leads (OpenNebula\.org) . .P 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 diff --git a/share/man/onevdc.1 b/share/man/onevdc.1 index c6aa1c9e5a..c0113faa15 100644 --- a/share/man/onevdc.1 +++ b/share/man/onevdc.1 @@ -1,184 +1,7 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "ONEVDC" "1" "September 2011" "" "onevdc(1) -- manages OpenNebula Virtual DataCenters" +.TH "ONEVDC" "1" "December 2011" "" "onevdc(1) -- manages OpenNebula Virtual DataCenters" . .SH "NAME" \fBonevdc\fR -. -.SH "SYNOPSIS" -\fBonevdc\fR command [\fIargs\fR] [\fIoptions\fR] -. -.SH "OPTIONS" -. -.nf - - \-f, \-\-force Force the usage of Hosts in more than one VDC - \-l, \-\-list x,y,z Selects columns to display with list command - \-d, \-\-delay x Sets the delay in seconds for top command - \-x, \-\-xml Show the resource in xml format - \-n, \-\-numeric Do not translate user and group IDs - \-k, \-\-kilobytes Show units in kilobytes - \-v, \-\-verbose Verbose mode - \-h, \-\-help Show this message - \-V, \-\-version Show version and copyright information -. -.fi -. -.SH "COMMANDS" -. -.IP "\(bu" 4 -create \fIfile\fR -. -.IP "" 4 -. -.nf - -Create a new VDC -valid options: force -. -.fi -. -.IP "" 0 - -. -.IP "\(bu" 4 -show \fIvdcid\fR -. -.IP "" 4 -. -.nf - -Show information of a particular VDC -. -.fi -. -.IP "" 0 - -. -.IP "\(bu" 4 -list -. -.IP "" 4 -. -.nf - -Lists VDCs in the pool -valid options: list, delay, xml, numeric, kilobytes -. -.fi -. -.IP "" 0 - -. -.IP "\(bu" 4 -delete \fIvdcid\fR -. -.IP "" 4 -. -.nf - -Deletes a VDC -. -.fi -. -.IP "" 0 - -. -.IP "\(bu" 4 -addhost \fIvdcid\fR \fIrange\fR -. -.IP "" 4 -. -.nf - -Adds the set of hosts to the VDC -valid options: force -. -.fi -. -.IP "" 0 - -. -.IP "\(bu" 4 -delhost \fIvdcid\fR \fIrange\fR -. -.IP "" 4 -. -.nf - -Deletes the set of hosts from the VDC -valid options: force -. -.fi -. -.IP "" 0 - -. -.IP "" 0 -. -.SH "ARGUMENT FORMATS" -. -.IP "\(bu" 4 -file -. -.IP "" 4 -. -.nf - -Path to a file -. -.fi -. -.IP "" 0 - -. -.IP "\(bu" 4 -range -. -.IP "" 4 -. -.nf - -List of id\'s in the form 1,8\.\.15 -. -.fi -. -.IP "" 0 - -. -.IP "\(bu" 4 -text -. -.IP "" 4 -. -.nf - -String -. -.fi -. -.IP "" 0 - -. -.IP "\(bu" 4 -vdcid -. -.IP "" 4 -. -.nf - -VDC ID -. -.fi -. -.IP "" 0 - -. -.IP "" 0 -. -.SH "LICENSE" -OpenNebula 3\.0\.0 Copyright 2002\-2011, OpenNebula Project Leads (OpenNebula\.org) -. -.P -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 diff --git a/share/man/onevm.1 b/share/man/onevm.1 index 7ecebedb64..d39165017c 100644 --- a/share/man/onevm.1 +++ b/share/man/onevm.1 @@ -1,7 +1,7 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "ONEVM" "1" "September 2011" "" "onevm(1) -- manages OpenNebula virtual machines" +.TH "ONEVM" "1" "December 2011" "" "onevm(1) -- manages OpenNebula virtual machines" . .SH "NAME" \fBonevm\fR @@ -17,6 +17,7 @@ \-x, \-\-xml Show the resource in xml format \-n, \-\-numeric Do not translate user and group IDs \-k, \-\-kilobytes Show units in kilobytes + \-t, \-\-type type Type of the new Image \-l, \-\-list x,y,z Selects columns to display with list command \-d, \-\-delay x Sets the delay in seconds for top command \-v, \-\-verbose Verbose mode @@ -106,6 +107,7 @@ shut down gracefuly (i\.e\., using \'onevm shutdown\' and not \'onevm delete\') States: ANY +valid options: type . .fi . @@ -493,7 +495,7 @@ user VM of the user identified by the username .IP "" 0 . .SH "LICENSE" -OpenNebula 3\.0\.0 Copyright 2002\-2011, OpenNebula Project Leads (OpenNebula\.org) +OpenNebula 3\.1\.80 Copyright 2002\-2011, OpenNebula Project Leads (OpenNebula\.org) . .P 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 diff --git a/share/man/onevnet.1 b/share/man/onevnet.1 index 75844a4749..40801443b4 100644 --- a/share/man/onevnet.1 +++ b/share/man/onevnet.1 @@ -1,7 +1,7 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "ONEVNET" "1" "September 2011" "" "onevnet(1) -- manages OpenNebula networks" +.TH "ONEVNET" "1" "December 2011" "" "onevnet(1) -- manages OpenNebula networks" . .SH "NAME" \fBonevnet\fR @@ -81,6 +81,34 @@ Removes a lease from the Virtual Network . .IP "" 0 +. +.IP "\(bu" 4 +hold \fIvnetid\fR \fIip\fR +. +.IP "" 4 +. +.nf + +Holds a Virtual Network lease, marking it as used +. +.fi +. +.IP "" 0 + +. +.IP "\(bu" 4 +release \fIvnetid\fR \fIip\fR +. +.IP "" 4 +. +.nf + +Releases a Virtual Network lease on hold +. +.fi +. +.IP "" 0 + . .IP "\(bu" 4 publish \fIrange|vnetid_list\fR @@ -113,7 +141,7 @@ can\'t be used by any other User . .IP "\(bu" 4 -chgrp \fIrange|vnid_list\fR \fIgroupid\fR +chgrp \fIrange|vnetid_list\fR \fIgroupid\fR . .IP "" 4 . @@ -127,7 +155,7 @@ Changes the Virtual Network group . .IP "\(bu" 4 -chown \fIrange|vnid_list\fR \fIuserid\fR [\fIgroupid\fR] +chown \fIrange|vnetid_list\fR \fIuserid\fR [\fIgroupid\fR] . .IP "" 4 . @@ -169,6 +197,20 @@ valid options: xml . .IP "" 0 +. +.IP "\(bu" 4 +update \fIvnetid\fR +. +.IP "" 4 +. +.nf + +Launches the system editor to modify and update the template contents +. +.fi +. +.IP "" 0 + . .IP "" 0 . @@ -294,7 +336,7 @@ user VNET of the user identified by the username .IP "" 0 . .SH "LICENSE" -OpenNebula 3\.0\.0 Copyright 2002\-2011, OpenNebula Project Leads (OpenNebula\.org) +OpenNebula 3\.1\.80 Copyright 2002\-2011, OpenNebula Project Leads (OpenNebula\.org) . .P 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 diff --git a/share/man/onezone.1 b/share/man/onezone.1 index f6467d59fd..ca66f3191b 100644 --- a/share/man/onezone.1 +++ b/share/man/onezone.1 @@ -1,156 +1,7 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "ONEZONE" "1" "September 2011" "" "onezone(1) -- manages OpenNebula zones" +.TH "ONEZONE" "1" "December 2011" "" "onezone(1) -- manages OpenNebula zones" . .SH "NAME" \fBonezone\fR -. -.SH "SYNOPSIS" -\fBonezone\fR \fIcommand\fR [\fIargs\fR] [\fIoptions\fR] -. -.SH "OPTIONS" -. -.nf - - \-l, \-\-list x,y,z Selects columns to display with list command - \-d, \-\-delay x Sets the delay in seconds for top command - \-x, \-\-xml Show the resource in xml format - \-n, \-\-numeric Do not translate user and group IDs - \-k, \-\-kilobytes Show units in kilobytes - \-v, \-\-verbose Verbose mode - \-h, \-\-help Show this message - \-V, \-\-version Show version and copyright information -. -.fi -. -.SH "COMMANDS" -. -.IP "\(bu" 4 -create \fIfile\fR -. -.IP "" 4 -. -.nf - -Create a new Zone -. -.fi -. -.IP "" 0 - -. -.IP "\(bu" 4 -show \fIzoneid\fR [\fIresource\fR] -. -.IP "" 4 -. -.nf - -Show information of a particular Zone -Available resources: host, vm, image, vn, template, user -Examples: - onezone show 4 - onezone show 4 host -. -.fi -. -.IP "" 0 - -. -.IP "\(bu" 4 -list -. -.IP "" 4 -. -.nf - -Lists Zones in the pool -valid options: list, delay, xml, numeric, kilobytes -. -.fi -. -.IP "" 0 - -. -.IP "\(bu" 4 -delete \fIzoneid\fR -. -.IP "" 4 -. -.nf - -Deletes a Zone -. -.fi -. -.IP "" 0 - -. -.IP "" 0 -. -.SH "ARGUMENT FORMATS" -. -.IP "\(bu" 4 -file -. -.IP "" 4 -. -.nf - -Path to a file -. -.fi -. -.IP "" 0 - -. -.IP "\(bu" 4 -range -. -.IP "" 4 -. -.nf - -List of id\'s in the form 1,8\.\.15 -. -.fi -. -.IP "" 0 - -. -.IP "\(bu" 4 -text -. -.IP "" 4 -. -.nf - -String -. -.fi -. -.IP "" 0 - -. -.IP "\(bu" 4 -zoneid -. -.IP "" 4 -. -.nf - -Zone ID -. -.fi -. -.IP "" 0 - -. -.IP "" 0 -. -.SH "LICENSE" -OpenNebula 3\.0\.0 Copyright 2002\-2011, OpenNebula Project Leads (OpenNebula\.org) -. -.P -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 diff --git a/src/cli/one_helper.rb b/src/cli/one_helper.rb index 18e684674e..7b542e468f 100644 --- a/src/cli/one_helper.rb +++ b/src/cli/one_helper.rb @@ -21,7 +21,7 @@ include OpenNebula module OpenNebulaHelper ONE_VERSION=<<-EOT -OpenNebula 3.1.0 +OpenNebula 3.1.80 Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org) Licensed under the Apache License, Version 2.0 (the "License"); you may diff --git a/src/cloud/common/CloudClient.rb b/src/cloud/common/CloudClient.rb index 176471419b..562888917d 100644 --- a/src/cloud/common/CloudClient.rb +++ b/src/cloud/common/CloudClient.rb @@ -173,7 +173,7 @@ module CloudCLI def version_text version=<
diff --git a/src/sunstone/views/index.erb b/src/sunstone/views/index.erb index 9140aafa6e..a6f1938409 100644 --- a/src/sunstone/views/index.erb +++ b/src/sunstone/views/index.erb @@ -67,7 +67,7 @@ From 547d0985eae7a270f5d81009f22c0e74af09c5fd Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Thu, 1 Dec 2011 18:03:16 +0000 Subject: [PATCH 099/121] fix a bug setting quota configuration (cherry picked from commit d1054d465e463a1d99a46585a1bbfac8cfe4ef47) --- src/authm_mad/remotes/quota/quota.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/authm_mad/remotes/quota/quota.rb b/src/authm_mad/remotes/quota/quota.rb index 9037c94510..b9b29393bb 100644 --- a/src/authm_mad/remotes/quota/quota.rb +++ b/src/authm_mad/remotes/quota/quota.rb @@ -113,7 +113,15 @@ class Quota def initialize conf = YAML.load_file(CONF_FILE) @conf=CONF.merge(conf) {|key,h1,h2| - h1.merge(h2) if h1.instance_of?(Hash) && h2.instance_of?(Hash) + if h1.instance_of?(Hash) && h2.instance_of?(Hash) + h1.merge(h2) + else + if h2 + h2 + else + h1 + end + end } @client = OpenNebula::Client.new From 3bb367bc1043a648d5394ef62e89d398a024fe90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Mon, 5 Dec 2011 20:04:07 +0100 Subject: [PATCH 100/121] onedb migrator: New migrator from 3.1.0 to 3.1.80 --- install.sh | 1 + src/onedb/3.1.0_to_3.1.80.rb | 127 +++++++++++++++++++++++++++++++++++ src/vm/History.cc | 2 +- 3 files changed, 129 insertions(+), 1 deletion(-) create mode 100644 src/onedb/3.1.0_to_3.1.80.rb diff --git a/install.sh b/install.sh index 6fb7f2bcfe..c4d1a8e0da 100755 --- a/install.sh +++ b/install.sh @@ -746,6 +746,7 @@ ONEDB_MIGRATOR_FILES="src/onedb/2.0_to_2.9.80.rb \ src/onedb/2.9.85_to_2.9.90.rb \ src/onedb/2.9.90_to_3.0.0.rb \ src/onedb/3.0.0_to_3.1.0.rb \ + src/onedb/3.1.0_to_3.1.80.rb \ src/onedb/onedb.rb \ src/onedb/onedb_backend.rb" diff --git a/src/onedb/3.1.0_to_3.1.80.rb b/src/onedb/3.1.0_to_3.1.80.rb new file mode 100644 index 0000000000..5a27679015 --- /dev/null +++ b/src/onedb/3.1.0_to_3.1.80.rb @@ -0,0 +1,127 @@ +# -------------------------------------------------------------------------- * +# 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 'digest/sha1' +require "rexml/document" +include REXML +require 'ipaddr' + +module Migrator + def db_version + "3.1.80" + end + + def one_version + "OpenNebula 3.1.80" + end + + def up + puts " > Networking isolation hooks have been moved to Host drivers.\n"<< + " If you were using a networking hook, enter its name, or press enter\n"<< + " to use the default dummy vn_mad driver.\n\n" + print " Driver name (802.1Q, dummy, ebtables, ovswitch): " + vn_mad = gets.chomp + + vn_mad = "dummy" if vn_mad.empty? + + # New VN_MAD element for hosts + + @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, UNIQUE(name));" + + @db.fetch("SELECT * FROM old_host_pool") do |row| + doc = Document.new(row[:body]) + + vn_mad_elem = doc.root.add_element("VN_MAD") + vn_mad_elem.text = vn_mad + + @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]) + end + + @db.run "DROP TABLE old_host_pool;" + + # New VLAN and RANGE for vnets + + @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, public INTEGER, UNIQUE(name,uid));" + + @db.fetch("SELECT * FROM old_network_pool") do |row| + doc = Document.new(row[:body]) + + type = "" + doc.root.each_element("TYPE") { |e| + type = e.text + } + + if type == "0" # RANGED + range_elem = doc.root.add_element("RANGE") + ip_start_elem = range_elem.add_element("IP_START") + ip_end_elem = range_elem.add_element("IP_END") + + net_address = "" + doc.root.each_element("TEMPLATE/NETWORK_ADDRESS") { |e| + net_address = e.text + } + + net_address = IPAddr.new(net_address, Socket::AF_INET) + + + st_size = "" + doc.root.each_element("TEMPLATE/NETWORK_SIZE") { |e| + st_size = e.text + } + + if ( st_size == "C" || st_size == "c" ) + host_bits = 8 + elsif ( st_size == "B" || st_size == "b" ) + host_bits = 16 + elsif ( st_size == "A" || st_size == "a" ) + host_bits = 24 + else + size = st_size.to_i + host_bits = (Math.log(size+2)/Math.log(2)).ceil + end + + net_mask = 0xFFFFFFFF << host_bits + + net_address = net_address.to_i & net_mask + + ip_start_elem.text = IPAddr.new((ip_start = net_address + 1), Socket::AF_INET).to_s + ip_end_elem.text = IPAddr.new((net_address + (1 << host_bits) - 2), Socket::AF_INET).to_s + end + + # TODO: Set vlan = 1 if PHYDEV is set + vlan_elem = doc.root.add_element("VLAN") + vlan_elem.text = "0" + + @db[:network_pool].insert( + :oid => row[:oid], + :name => row[:name], + :body => doc.root.to_s, + :uid => row[:uid], + :gid => row[:gid], + :public => row[:public]) + end + + @db.run "DROP TABLE old_network_pool;" + + return true + end +end diff --git a/src/vm/History.cc b/src/vm/History.cc index f2a52ccb3c..a14edc9646 100644 --- a/src/vm/History.cc +++ b/src/vm/History.cc @@ -301,7 +301,7 @@ int History::rebuild_attributes() rc += xpath(stime , "/HISTORY/STIME", 0); rc += xpath(etime , "/HISTORY/ETIME", 0); rc += xpath(vmm_mad_name , "/HISTORY/VMMMAD", "not_found"); - rc += xpath(vnm_mad_name , "/HISTORY/VNMMAD", "not_found"); + xpath(vnm_mad_name , "/HISTORY/VNMMAD", "dummy"); rc += xpath(tm_mad_name , "/HISTORY/TMMAD", "not_found"); rc += xpath(prolog_stime , "/HISTORY/PSTIME", 0); rc += xpath(prolog_etime , "/HISTORY/PETIME", 0); From eccae0e73126d5571cd138a782d5ba0e58aa0e22 Mon Sep 17 00:00:00 2001 From: Hector Sanjuan Date: Wed, 7 Dec 2011 01:18:13 +0100 Subject: [PATCH 101/121] Task #864, Feature #602: Improve leases support in Sunstone and new vnet operations in Sunstone This commit includes: * Support for ip_start, ip_end parameters when creating ranged vnetworks. * Removal of the add lease/remove lease dialogs. * Renewal of the representation of leases pool in the "extended information" windows. The list of leases is represented so that it is clearly visible those leases which are free, on hold (reserved), or used by a VM. Right on the list, leases can be added, updated or deleted. --- .../OpenNebulaJSON/VirtualNetworkJSON.rb | 12 +- src/sunstone/public/images/green_bullet.png | Bin 0 -> 484 bytes src/sunstone/public/images/red_bullet.png | Bin 0 -> 484 bytes src/sunstone/public/images/yellow_bullet.png | Bin 0 -> 449 bytes src/sunstone/public/js/opennebula.js | 14 + src/sunstone/public/js/plugins/vnets-tab.js | 250 ++++++++++++++++-- 6 files changed, 246 insertions(+), 30 deletions(-) create mode 100644 src/sunstone/public/images/green_bullet.png create mode 100644 src/sunstone/public/images/red_bullet.png create mode 100644 src/sunstone/public/images/yellow_bullet.png diff --git a/src/sunstone/models/OpenNebulaJSON/VirtualNetworkJSON.rb b/src/sunstone/models/OpenNebulaJSON/VirtualNetworkJSON.rb index b18230f2ac..fcc71d8e2f 100644 --- a/src/sunstone/models/OpenNebulaJSON/VirtualNetworkJSON.rb +++ b/src/sunstone/models/OpenNebulaJSON/VirtualNetworkJSON.rb @@ -43,11 +43,13 @@ module OpenNebulaJSON rc = case action_hash['perform'] when "addleases" then self.addleases(action_hash['params']) - when "rmleases" then self.rmleases(action_hash['params']) + when "rmleases" then self.rmleases(action_hash['params']) when "publish" then self.publish when "unpublish" then self.unpublish when "update" then self.update(action_hash['params']) when "chown" then self.chown(action_hash['params']) + when "hold" then self.hold(action_hash['params']) + when "release" then self.release(action_hash['params']) else error_msg = "#{action_hash['perform']} action not " << " available for this resource" @@ -70,5 +72,13 @@ module OpenNebulaJSON def chown(params=Hash.new) super(params['owner_id'].to_i,params['group_id'].to_i) end + + def hold(params=Hash.new) + super(params['ip']) + end + + def release(params=Hash.new) + super(params['ip']) + end end end diff --git a/src/sunstone/public/images/green_bullet.png b/src/sunstone/public/images/green_bullet.png new file mode 100644 index 0000000000000000000000000000000000000000..d64f9dbf9d6c519d56a1128452779baf5b323db0 GIT binary patch literal 484 zcmeAS@N?(olHy`uVBq!ia0vp^JRr=$1SD^YpWXnZ7>k44ofy`glX(f`a29w(7Bet# z3xhBt!>l_iO9UAn2wYz}S4_HU zN%TR!vul06)J$wG6jRfhX2#0EUTw#%a$nN!<4a55vqckI`P+BDu(+N3-7AVAfiG{) z)%#zV7&IQ0EM8>6z4&p?ZjoOZj0_B$$~T{Ed3V2hNwl(^Sk=@O72EIrmrzyPp7eKT zSpVxkoZiYyd{3Xs=i;VuD`Z|32!d- zooCt}smwEVs(iD-lSyUEi#nroZajb7;QzX|jninAhK>T)nyw02_L{2D-AmFVdQ&MBb@0FFAlQ2+n{ literal 0 HcmV?d00001 diff --git a/src/sunstone/public/images/red_bullet.png b/src/sunstone/public/images/red_bullet.png new file mode 100644 index 0000000000000000000000000000000000000000..b8317a77cff95bffdd8857b21363a6c55233488b GIT binary patch literal 484 zcmVPx#32;bRa{vGf6951U69E94oEQKA00(qQO+^RW3ul(NKH zK#WntA(IJF#L0=qIkJq!g5{DdJ4hHqlJN4vbV`zFs*1&ehX>|!@|^u1P^YId8c9(o z5fucQG-bJDKIicf?>S(tG>z*z9Yy`YKvR}v8F`NP0_xME=l#cO)uw5ardq63)_z_< z01#-Qac*DN&1$9jj}9!nLIWG;?0Vf(#$b$u;RhUITiC%4iXfk44ofy`glX(f`a29w(7Bet# z3xhBt!>lS|xv6<2KrRD=b5UwyNotBh zd1gt5g1e`0K#E=}JJ4_~PZ!4!iOZ=M&-xv5U~qkCocgOf$=Ae9r9~n+M)J`m_79vj zVew7A*N-?j3-Ic-WG!EMdFC#Li%0TnC+*&GNUAq5M{EV>Q<=R?1<6fv7gg(~hp8BL zDXDs&5bC;_FY@gr&r2Ro_DN@(bP|7FS>wLKL|=M=EXSfojWmWn^+4fGOCtMA%ydno z=es_BxiVi{u;ink%qh#GJX7CwuU&O)h4?4KpEn%WUs(P2)V!?`-pevhg?~yvX@4zA zdXIsS9;k@uG*n?&o(yV3)<=6qpa>%k)K52K6u6{1-oD!M\ \
\ - \ - \ + \ +
\ + \ +
\ + \ +
\ + \ + \ \ \ \ @@ -95,9 +101,9 @@ var create_vn_tmpl =
\
\ \ - \ +
\ \ - \ +
\ \ \
\ @@ -248,7 +254,7 @@ var vnet_actions = { call: OpenNebula.Network.addleases, callback: vnShow, error: onError, - notify: true + notify: false, }, "Network.rmleases" : { @@ -256,9 +262,25 @@ var vnet_actions = { call: OpenNebula.Network.rmleases, callback: vnShow, error: onError, - notify: true + notify: false, }, + "Network.hold" : { + type: "single", + call: OpenNebula.Network.hold, + callback: vnShow, + error: onError, + notify: false, + }, + + "Network.release" : { + type: "single", + call: OpenNebula.Network.release, + callback: vnShow, + error: onError, + notify: false, + }, +/* "Network.modifyleases" : { type: "custom", call: function(action,obj){ @@ -278,7 +300,7 @@ var vnet_actions = { type: "custom", call: popUpRemoveLeaseDialog }, - +*/ "Network.chown" : { type: "multiple", call: OpenNebula.Network.chown, @@ -368,7 +390,7 @@ var vnet_buttons = { tip: "Select the new group:", condition: mustBeAdmin, }, - +/* "action_list" : { type: "select", actions: { @@ -382,7 +404,7 @@ var vnet_buttons = { } } }, - +*/ "Network.delete" : { type: "action", text: "Delete" @@ -455,6 +477,9 @@ function updateVNetworkElement(request, vn_json){ id = vn_json.VNET.ID; element = vNetworkElementArray(vn_json); updateSingleElement(element,dataTable_vNetworks,'#vnetwork_'+id); + + //we update this too, even if it's not shown. + $('#leases_form').replaceWith(printLeases(vn_json.VNET)); } //Callback to delete a vnet element from the table @@ -466,6 +491,8 @@ function deleteVNetworkElement(req){ function addVNetworkElement(request,vn_json){ var element = vNetworkElementArray(vn_json); addElement(element,dataTable_vNetworks); + //we update this too, even if it's not shown. + $('#leases_form').replaceWith(printLeases(vn_json.VNET)); } //updates the list of virtual networks @@ -494,6 +521,10 @@ function updateVNetworkInfo(request,vn){ ID\ '+vn_info.ID+'\ \ + \ + Name\ + '+vn_info.NAME+'\ + \ \ Owner\ '+vn_info.UNAME+'\ @@ -508,17 +539,15 @@ function updateVNetworkInfo(request,vn){ \ \ Physical device\ - '+(vn_info.PHYDEV ? vn_info.PHYDEV : "--" )+'\ + '+ (typeof(vn_info.PHYDEV) == "object" ? "--": vn_info.PHYDEV) +'\ \ - \ - \ - \ - \ - '+ - printLeases(vn_info.LEASES)+ - '
Leases information
';; - + \ + VNET ID\ + '+ (typeof(vn_info.VLAN_ID) == "object" ? "--": vn_info.VLAN_ID) +'\ + \ + '; + info_tab_content += printLeases(vn_info); var info_tab = { title: "Virtual Network information", @@ -541,19 +570,101 @@ function updateVNetworkInfo(request,vn){ } -function printLeases(leases){ - if (!leases.LEASE) //empty - { - return ""; +function printLeases(vn_info){ + var html ='
\ + \ + \ + '; + + if (vn_info.TYPE == "0"){ + html += '\ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + '; + } else { + html += ''; }; - if (leases.LEASE.constructor == Array) //>1 lease + var leases = vn_info.LEASES.LEASE; + + if (!leases) //empty { - return prettyPrintJSON(leases.LEASE); + html+='\ + '; + return html; } - else {//1 lease - return prettyPrintJSON([leases.LEASE]); + else if (leases.constructor != Array) //>1 lease + { + leases = [leases]; }; + + var lease; + var state=null; + + for (var i=0; i'; + }; + + html += '
Leases information
IP Start'+vn_info.RANGE.IP_START+'
IP End'+vn_info.RANGE.IP_END+'
Network mask'+( vn_info.TEMPLATE.NETWORK_MASK ? vn_info.TEMPLATE.NETWORK_MASK : "--" )+'
\ + \ + \ +
\ + \ + \ +
\ + No leases to show\ + \ +
'; + html+=''; + + html += '\ + '+lease.MAC+'   '; + + switch (state){ + case 0: + html += 'hold | delete'; + break; + case 1: + html += 'Used by VM '+lease.VID; + break; + case 2: + html += 'release'; + break; + }; + html += '
'; + + return html; } //Prepares the vnet creation dialog @@ -622,6 +733,17 @@ function setupCreateVNetDialog() { return false; }); + $('#custom_pool', dialog).change(function(){ + if ($(this).is(':checked')){ + $('#ip_start', $create_vn_dialog).removeAttr('disabled'); + $('#ip_end', $create_vn_dialog).removeAttr('disabled'); + } + else { + $('#ip_start', $create_vn_dialog).attr('disabled','disabled'); + $('#ip_end', $create_vn_dialog).attr('disabled','disabled'); + }; + }); + $('#add_custom_var_vnet_button', dialog).click( function(){ @@ -681,7 +803,11 @@ function setupCreateVNetDialog() { else { //type ranged var network_addr = $('#net_address',this).val(); - var network_size = $('#net_size',this).val(); + var network_mask = $('#net_mask',this).val(); + var custom = $('#custom_pool',this).is(':checked'); + var ip_start = $('#ip_start',this).val(); + var ip_end = $('#ip_end',this).val(); + if (!network_addr.length){ notifyError("Please provide a network address"); return false; @@ -692,10 +818,17 @@ function setupCreateVNetDialog() { "vnet" : { "type" : "RANGED", "bridge" : bridge, - "network_size" : network_size, + "network_mask" : network_mask, "network_address" : network_addr, "name" : name } }; + + if (custom){ + if (ip_start.length) + network_json["vnet"]["ip_start"] = ip_start; + if (ip_end.length) + network_json["vnet"]["ip_start"] = ip_end; + }; }; //Time to add custom attributes @@ -826,6 +959,62 @@ function popUpVNetTemplateUpdateDialog(){ } +function setupLeasesOps(){ + $('button#panel_add_lease_button').live("click",function(){ + var lease = $(this).prev().val(); + //var mac = $(this).previous().val(); + var id = $(this).parents('form').attr('vnid'); + if (lease.length){ + var obj = {ip: lease}; + Sunstone.runAction('Network.addleases',id,obj); + } + return false; + }); + + $('button#panel_hold_lease_button').live("click",function(){ + var lease = $(this).prev().val(); + //var mac = $(this).previous().val(); + var id = $(this).parents('form').attr('vnid'); + if (lease.length){ + var obj = {ip: lease}; + Sunstone.runAction('Network.hold',id,obj); + } + return false; + }); + + $('form#leases_form a.delete_lease').live("click",function(){ + var lease = $(this).parents('tr').attr('ip'); + var id = $(this).parents('form').attr('vnid'); + var obj = { ip: lease}; + Sunstone.runAction('Network.rmleases',id,obj); + //Set spinner + $(this).parents('tr').html(''+spinner+''); + return false; + }); + + $('a.hold_lease').live("click",function(){ + var lease = $(this).parents('tr').attr('ip'); + var id = $(this).parents('form').attr('vnid'); + var obj = { ip: lease}; + Sunstone.runAction('Network.hold',id,obj); + //Set spinner + $(this).parents('tr').html(''+spinner+''); + return false; + }); + + $('a.release_lease').live("click",function(){ + var lease = $(this).parents('tr').attr('ip'); + var id = $(this).parents('form').attr('vnid'); + var obj = { ip: lease}; + Sunstone.runAction('Network.release',id,obj); + //Set spinner + $(this).parents('tr').html(''+spinner+''); + return false; + }); +} + + +/* function setupAddRemoveLeaseDialog() { dialogs_context.append('
'); $lease_vn_dialog = $('#lease_vn_dialog',dialogs_context) @@ -893,6 +1082,8 @@ function popUpRemoveLeaseDialog() { $lease_vn_dialog.dialog("open"); } +*/ + function setVNetAutorefresh() { setInterval(function(){ var checked = $('input.check_item:checked',dataTable_vNetworks); @@ -946,7 +1137,8 @@ $(document).ready(function(){ setupCreateVNetDialog(); setupVNetTemplateUpdateDialog(); - setupAddRemoveLeaseDialog(); + //setupAddRemoveLeaseDialog(); + setupLeasesOps(); setupVNetActionCheckboxes(); setVNetAutorefresh(); From 2cfa7ab0dc1273c4e54d122cd4a24bf38a43ba7d Mon Sep 17 00:00:00 2001 From: Hector Sanjuan Date: Wed, 7 Dec 2011 01:18:13 +0100 Subject: [PATCH 102/121] Task #864, Feature #602: Improve leases support in Sunstone and new vnet operations in Sunstone This commit includes: * Support for ip_start, ip_end parameters when creating ranged vnetworks. * Removal of the add lease/remove lease dialogs. * Renewal of the representation of leases pool in the "extended information" windows. The list of leases is represented so that it is clearly visible those leases which are free, on hold (reserved), or used by a VM. Right on the list, leases can be added, updated or deleted. (cherry picked from commit eccae0e73126d5571cd138a782d5ba0e58aa0e22) --- .../OpenNebulaJSON/VirtualNetworkJSON.rb | 12 +- src/sunstone/public/images/green_bullet.png | Bin 0 -> 484 bytes src/sunstone/public/images/red_bullet.png | Bin 0 -> 484 bytes src/sunstone/public/images/yellow_bullet.png | Bin 0 -> 449 bytes src/sunstone/public/js/opennebula.js | 14 + src/sunstone/public/js/plugins/vnets-tab.js | 250 ++++++++++++++++-- 6 files changed, 246 insertions(+), 30 deletions(-) create mode 100644 src/sunstone/public/images/green_bullet.png create mode 100644 src/sunstone/public/images/red_bullet.png create mode 100644 src/sunstone/public/images/yellow_bullet.png diff --git a/src/sunstone/models/OpenNebulaJSON/VirtualNetworkJSON.rb b/src/sunstone/models/OpenNebulaJSON/VirtualNetworkJSON.rb index b18230f2ac..fcc71d8e2f 100644 --- a/src/sunstone/models/OpenNebulaJSON/VirtualNetworkJSON.rb +++ b/src/sunstone/models/OpenNebulaJSON/VirtualNetworkJSON.rb @@ -43,11 +43,13 @@ module OpenNebulaJSON rc = case action_hash['perform'] when "addleases" then self.addleases(action_hash['params']) - when "rmleases" then self.rmleases(action_hash['params']) + when "rmleases" then self.rmleases(action_hash['params']) when "publish" then self.publish when "unpublish" then self.unpublish when "update" then self.update(action_hash['params']) when "chown" then self.chown(action_hash['params']) + when "hold" then self.hold(action_hash['params']) + when "release" then self.release(action_hash['params']) else error_msg = "#{action_hash['perform']} action not " << " available for this resource" @@ -70,5 +72,13 @@ module OpenNebulaJSON def chown(params=Hash.new) super(params['owner_id'].to_i,params['group_id'].to_i) end + + def hold(params=Hash.new) + super(params['ip']) + end + + def release(params=Hash.new) + super(params['ip']) + end end end diff --git a/src/sunstone/public/images/green_bullet.png b/src/sunstone/public/images/green_bullet.png new file mode 100644 index 0000000000000000000000000000000000000000..d64f9dbf9d6c519d56a1128452779baf5b323db0 GIT binary patch literal 484 zcmeAS@N?(olHy`uVBq!ia0vp^JRr=$1SD^YpWXnZ7>k44ofy`glX(f`a29w(7Bet# z3xhBt!>l_iO9UAn2wYz}S4_HU zN%TR!vul06)J$wG6jRfhX2#0EUTw#%a$nN!<4a55vqckI`P+BDu(+N3-7AVAfiG{) z)%#zV7&IQ0EM8>6z4&p?ZjoOZj0_B$$~T{Ed3V2hNwl(^Sk=@O72EIrmrzyPp7eKT zSpVxkoZiYyd{3Xs=i;VuD`Z|32!d- zooCt}smwEVs(iD-lSyUEi#nroZajb7;QzX|jninAhK>T)nyw02_L{2D-AmFVdQ&MBb@0FFAlQ2+n{ literal 0 HcmV?d00001 diff --git a/src/sunstone/public/images/red_bullet.png b/src/sunstone/public/images/red_bullet.png new file mode 100644 index 0000000000000000000000000000000000000000..b8317a77cff95bffdd8857b21363a6c55233488b GIT binary patch literal 484 zcmVPx#32;bRa{vGf6951U69E94oEQKA00(qQO+^RW3ul(NKH zK#WntA(IJF#L0=qIkJq!g5{DdJ4hHqlJN4vbV`zFs*1&ehX>|!@|^u1P^YId8c9(o z5fucQG-bJDKIicf?>S(tG>z*z9Yy`YKvR}v8F`NP0_xME=l#cO)uw5ardq63)_z_< z01#-Qac*DN&1$9jj}9!nLIWG;?0Vf(#$b$u;RhUITiC%4iXfk44ofy`glX(f`a29w(7Bet# z3xhBt!>lS|xv6<2KrRD=b5UwyNotBh zd1gt5g1e`0K#E=}JJ4_~PZ!4!iOZ=M&-xv5U~qkCocgOf$=Ae9r9~n+M)J`m_79vj zVew7A*N-?j3-Ic-WG!EMdFC#Li%0TnC+*&GNUAq5M{EV>Q<=R?1<6fv7gg(~hp8BL zDXDs&5bC;_FY@gr&r2Ro_DN@(bP|7FS>wLKL|=M=EXSfojWmWn^+4fGOCtMA%ydno z=es_BxiVi{u;ink%qh#GJX7CwuU&O)h4?4KpEn%WUs(P2)V!?`-pevhg?~yvX@4zA zdXIsS9;k@uG*n?&o(yV3)<=6qpa>%k)K52K6u6{1-oD!M\ \
\ - \ - \ + \ +
\ + \ +
\ + \ +
\ + \ + \
\ \ \ @@ -95,9 +101,9 @@ var create_vn_tmpl =
\
\ \ - \ +
\ \ - \ +
\ \ \
\ @@ -248,7 +254,7 @@ var vnet_actions = { call: OpenNebula.Network.addleases, callback: vnShow, error: onError, - notify: true + notify: false, }, "Network.rmleases" : { @@ -256,9 +262,25 @@ var vnet_actions = { call: OpenNebula.Network.rmleases, callback: vnShow, error: onError, - notify: true + notify: false, }, + "Network.hold" : { + type: "single", + call: OpenNebula.Network.hold, + callback: vnShow, + error: onError, + notify: false, + }, + + "Network.release" : { + type: "single", + call: OpenNebula.Network.release, + callback: vnShow, + error: onError, + notify: false, + }, +/* "Network.modifyleases" : { type: "custom", call: function(action,obj){ @@ -278,7 +300,7 @@ var vnet_actions = { type: "custom", call: popUpRemoveLeaseDialog }, - +*/ "Network.chown" : { type: "multiple", call: OpenNebula.Network.chown, @@ -368,7 +390,7 @@ var vnet_buttons = { tip: "Select the new group:", condition: mustBeAdmin, }, - +/* "action_list" : { type: "select", actions: { @@ -382,7 +404,7 @@ var vnet_buttons = { } } }, - +*/ "Network.delete" : { type: "action", text: "Delete" @@ -455,6 +477,9 @@ function updateVNetworkElement(request, vn_json){ id = vn_json.VNET.ID; element = vNetworkElementArray(vn_json); updateSingleElement(element,dataTable_vNetworks,'#vnetwork_'+id); + + //we update this too, even if it's not shown. + $('#leases_form').replaceWith(printLeases(vn_json.VNET)); } //Callback to delete a vnet element from the table @@ -466,6 +491,8 @@ function deleteVNetworkElement(req){ function addVNetworkElement(request,vn_json){ var element = vNetworkElementArray(vn_json); addElement(element,dataTable_vNetworks); + //we update this too, even if it's not shown. + $('#leases_form').replaceWith(printLeases(vn_json.VNET)); } //updates the list of virtual networks @@ -494,6 +521,10 @@ function updateVNetworkInfo(request,vn){ ID\ '+vn_info.ID+'\ \ + \ + Name\ + '+vn_info.NAME+'\ + \ \ Owner\ '+vn_info.UNAME+'\ @@ -508,17 +539,15 @@ function updateVNetworkInfo(request,vn){ \ \ Physical device\ - '+(vn_info.PHYDEV ? vn_info.PHYDEV : "--" )+'\ + '+ (typeof(vn_info.PHYDEV) == "object" ? "--": vn_info.PHYDEV) +'\ \ - \ - \ - \ - \ - '+ - printLeases(vn_info.LEASES)+ - '
Leases information
';; - + \ + VNET ID\ + '+ (typeof(vn_info.VLAN_ID) == "object" ? "--": vn_info.VLAN_ID) +'\ + \ + '; + info_tab_content += printLeases(vn_info); var info_tab = { title: "Virtual Network information", @@ -541,19 +570,101 @@ function updateVNetworkInfo(request,vn){ } -function printLeases(leases){ - if (!leases.LEASE) //empty - { - return ""; +function printLeases(vn_info){ + var html ='
\ + \ + \ + '; + + if (vn_info.TYPE == "0"){ + html += '\ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + '; + } else { + html += ''; }; - if (leases.LEASE.constructor == Array) //>1 lease + var leases = vn_info.LEASES.LEASE; + + if (!leases) //empty { - return prettyPrintJSON(leases.LEASE); + html+='\ + '; + return html; } - else {//1 lease - return prettyPrintJSON([leases.LEASE]); + else if (leases.constructor != Array) //>1 lease + { + leases = [leases]; }; + + var lease; + var state=null; + + for (var i=0; i'; + }; + + html += '
Leases information
IP Start'+vn_info.RANGE.IP_START+'
IP End'+vn_info.RANGE.IP_END+'
Network mask'+( vn_info.TEMPLATE.NETWORK_MASK ? vn_info.TEMPLATE.NETWORK_MASK : "--" )+'
\ + \ + \ +
\ + \ + \ +
\ + No leases to show\ + \ +
'; + html+=''; + + html += '\ + '+lease.MAC+'   '; + + switch (state){ + case 0: + html += 'hold | delete'; + break; + case 1: + html += 'Used by VM '+lease.VID; + break; + case 2: + html += 'release'; + break; + }; + html += '
'; + + return html; } //Prepares the vnet creation dialog @@ -622,6 +733,17 @@ function setupCreateVNetDialog() { return false; }); + $('#custom_pool', dialog).change(function(){ + if ($(this).is(':checked')){ + $('#ip_start', $create_vn_dialog).removeAttr('disabled'); + $('#ip_end', $create_vn_dialog).removeAttr('disabled'); + } + else { + $('#ip_start', $create_vn_dialog).attr('disabled','disabled'); + $('#ip_end', $create_vn_dialog).attr('disabled','disabled'); + }; + }); + $('#add_custom_var_vnet_button', dialog).click( function(){ @@ -681,7 +803,11 @@ function setupCreateVNetDialog() { else { //type ranged var network_addr = $('#net_address',this).val(); - var network_size = $('#net_size',this).val(); + var network_mask = $('#net_mask',this).val(); + var custom = $('#custom_pool',this).is(':checked'); + var ip_start = $('#ip_start',this).val(); + var ip_end = $('#ip_end',this).val(); + if (!network_addr.length){ notifyError("Please provide a network address"); return false; @@ -692,10 +818,17 @@ function setupCreateVNetDialog() { "vnet" : { "type" : "RANGED", "bridge" : bridge, - "network_size" : network_size, + "network_mask" : network_mask, "network_address" : network_addr, "name" : name } }; + + if (custom){ + if (ip_start.length) + network_json["vnet"]["ip_start"] = ip_start; + if (ip_end.length) + network_json["vnet"]["ip_start"] = ip_end; + }; }; //Time to add custom attributes @@ -826,6 +959,62 @@ function popUpVNetTemplateUpdateDialog(){ } +function setupLeasesOps(){ + $('button#panel_add_lease_button').live("click",function(){ + var lease = $(this).prev().val(); + //var mac = $(this).previous().val(); + var id = $(this).parents('form').attr('vnid'); + if (lease.length){ + var obj = {ip: lease}; + Sunstone.runAction('Network.addleases',id,obj); + } + return false; + }); + + $('button#panel_hold_lease_button').live("click",function(){ + var lease = $(this).prev().val(); + //var mac = $(this).previous().val(); + var id = $(this).parents('form').attr('vnid'); + if (lease.length){ + var obj = {ip: lease}; + Sunstone.runAction('Network.hold',id,obj); + } + return false; + }); + + $('form#leases_form a.delete_lease').live("click",function(){ + var lease = $(this).parents('tr').attr('ip'); + var id = $(this).parents('form').attr('vnid'); + var obj = { ip: lease}; + Sunstone.runAction('Network.rmleases',id,obj); + //Set spinner + $(this).parents('tr').html(''+spinner+''); + return false; + }); + + $('a.hold_lease').live("click",function(){ + var lease = $(this).parents('tr').attr('ip'); + var id = $(this).parents('form').attr('vnid'); + var obj = { ip: lease}; + Sunstone.runAction('Network.hold',id,obj); + //Set spinner + $(this).parents('tr').html(''+spinner+''); + return false; + }); + + $('a.release_lease').live("click",function(){ + var lease = $(this).parents('tr').attr('ip'); + var id = $(this).parents('form').attr('vnid'); + var obj = { ip: lease}; + Sunstone.runAction('Network.release',id,obj); + //Set spinner + $(this).parents('tr').html(''+spinner+''); + return false; + }); +} + + +/* function setupAddRemoveLeaseDialog() { dialogs_context.append('
'); $lease_vn_dialog = $('#lease_vn_dialog',dialogs_context) @@ -893,6 +1082,8 @@ function popUpRemoveLeaseDialog() { $lease_vn_dialog.dialog("open"); } +*/ + function setVNetAutorefresh() { setInterval(function(){ var checked = $('input.check_item:checked',dataTable_vNetworks); @@ -946,7 +1137,8 @@ $(document).ready(function(){ setupCreateVNetDialog(); setupVNetTemplateUpdateDialog(); - setupAddRemoveLeaseDialog(); + //setupAddRemoveLeaseDialog(); + setupLeasesOps(); setupVNetActionCheckboxes(); setVNetAutorefresh(); From 833b1295e5817d1f0cdab1d7a2ecb316bfbb1947 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Wed, 7 Dec 2011 10:08:27 +0100 Subject: [PATCH 103/121] feature #602: Include bullets to install file --- install.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/install.sh b/install.sh index c4d1a8e0da..1e75815fd8 100755 --- a/install.sh +++ b/install.sh @@ -1112,6 +1112,9 @@ SUNSTONE_PUBLIC_IMAGES_FILES="src/sunstone/public/images/ajax-loader.gif \ src/sunstone/public/images/panel_short.png \ src/sunstone/public/images/pbar.gif \ src/sunstone/public/images/Refresh-icon.png \ + src/sunstone/public/images/red_bullet.png \ + src/sunstone/public/images/yellow_bullet.png \ + src/sunstone/public/images/green_bullet.png \ src/sunstone/public/images/vnc_off.png \ src/sunstone/public/images/vnc_on.png" From 879f66ce5bdeb6939e724c71e061a2f265f18656 Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Mon, 5 Dec 2011 19:21:13 +0100 Subject: [PATCH 104/121] make ldap drivers compatible with 3.2 (return driver name) --- src/authm_mad/remotes/ldap/authenticate | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/authm_mad/remotes/ldap/authenticate b/src/authm_mad/remotes/ldap/authenticate index 90501553f1..8d0fa527d9 100755 --- a/src/authm_mad/remotes/ldap/authenticate +++ b/src/authm_mad/remotes/ldap/authenticate @@ -54,7 +54,7 @@ if options[:group] end if ldap.authenticate(user_name, secret) - puts "#{user} #{user_name}" + puts "ldap #{user} #{user_name}" exit(0) else STDERR.puts "Bad user/password" From 843c6722dd044172cdcf8f89aece0d0fb62f1eac Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Wed, 7 Dec 2011 12:05:46 +0100 Subject: [PATCH 105/121] correct uuidtools gem name in install_gems --- share/install_gems/install_gems | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/share/install_gems/install_gems b/share/install_gems/install_gems index 46e2b29ee4..e2c37f9ccf 100755 --- a/share/install_gems/install_gems +++ b/share/install_gems/install_gems @@ -22,7 +22,7 @@ GROUPS={ :optional => OPTIONAL, :quota => [SQLITE, 'sequel'], :sunstone => ['json', 'rack', 'sinatra', 'thin', 'sequel', SQLITE], - :cloud => %w{amazon-ec2 rack sinatra thin uuid curb}, + :cloud => %w{amazon-ec2 rack sinatra thin uuidtools curb}, :ozones_client => %w{json}, :ozones_server => %w{json data_mapper dm-sqlite-adapter dm-mysql-adapter}+[ SQLITE, 'mysql' From 1ad5326f2927297ac04a9a9d36d1f95cc5c1ac34 Mon Sep 17 00:00:00 2001 From: Hector Sanjuan Date: Wed, 7 Dec 2011 14:26:45 +0100 Subject: [PATCH 106/121] Task #864, Feature #602: Small fixes to vnets in Sunstone. Removal of commented code. --- src/sunstone/public/js/plugins/vnets-tab.js | 148 +++----------------- 1 file changed, 23 insertions(+), 125 deletions(-) diff --git a/src/sunstone/public/js/plugins/vnets-tab.js b/src/sunstone/public/js/plugins/vnets-tab.js index 21c6150945..cb0df258d2 100644 --- a/src/sunstone/public/js/plugins/vnets-tab.js +++ b/src/sunstone/public/js/plugins/vnets-tab.js @@ -87,11 +87,11 @@ var create_vn_tmpl =
\ \
\ - \ + \
\ - \ + \
\ - \ + \ \
\ \ @@ -280,27 +280,7 @@ var vnet_actions = { error: onError, notify: false, }, -/* - "Network.modifyleases" : { - type: "custom", - call: function(action,obj){ - nodes = getSelectedNodes(dataTable_vNetworks); - $.each(nodes,function(){ - Sunstone.runAction(action,this,obj); - }); - } - }, - "Network.addleases_dialog" : { - type: "custom", - call: popUpAddLeaseDialog - }, - - "Network.rmleases_dialog" : { - type: "custom", - call: popUpRemoveLeaseDialog - }, -*/ "Network.chown" : { type: "multiple", call: OpenNebula.Network.chown, @@ -390,21 +370,7 @@ var vnet_buttons = { tip: "Select the new group:", condition: mustBeAdmin, }, -/* - "action_list" : { - type: "select", - actions: { - "Network.addleases_dialog" : { - type: "action", - text: "Add lease" - }, - "Network.rmleases_dialog" : { - type: "action", - text: "Remove lease" - } - } - }, -*/ + "Network.delete" : { type: "action", text: "Delete" @@ -416,10 +382,10 @@ var vnet_info_panel = { title: "Virtual network information", content: "" }, - "vnet_template_tab" : { - title: "Virtual network template", + "vnet_leases_tab" : { + title: "Lease management", content: "" - } + }, } var vnets_tab = { @@ -547,31 +513,34 @@ function updateVNetworkInfo(request,vn){ \ '; - info_tab_content += printLeases(vn_info); + info_tab_content += '\ + \ + '+ + prettyPrintJSON(vn_info.TEMPLATE)+ + '
Virtual Network template (attributes)
' + + + var leases_tab_content = printLeases(vn_info); var info_tab = { title: "Virtual Network information", content: info_tab_content - } + }; - var template_tab = { - title: "Virtual Network template", - content: - '\ - '+ - prettyPrintJSON(vn_info.TEMPLATE)+ - '
Virtual Network template
' - } + var leases_tab = { + title: "Lease management", + content: leases_tab_content + }; Sunstone.updateInfoPanelTab("vnet_info_panel","vnet_info_tab",info_tab); - Sunstone.updateInfoPanelTab("vnet_info_panel","vnet_template_tab",template_tab); + Sunstone.updateInfoPanelTab("vnet_info_panel","vnet_leases_tab",leases_tab); Sunstone.popUpInfoPanel("vnet_info_panel"); } function printLeases(vn_info){ - var html ='
\ + var html ='
\ \ \ '; @@ -1013,77 +982,6 @@ function setupLeasesOps(){ }); } - -/* -function setupAddRemoveLeaseDialog() { - dialogs_context.append('
'); - $lease_vn_dialog = $('#lease_vn_dialog',dialogs_context) - - var dialog = $lease_vn_dialog; - - dialog.html( - '\ -
\ -
Please specify:
\ - \ -
\ - \ - \ - \ -
\ -
\ -
\ - \ - \ -
\ -
\ - ' - ); - - //Prepare the jquery-ui dialog. Set style options here. - dialog.dialog({ - autoOpen: false, - modal: true, - width: 410, - height: 220 - }); - - $('button',dialog).button(); - - $('#lease_vn_form',dialog).submit(function(){ - var ip = $('#add_lease_ip',this).val(); - var mac = $('#add_lease_mac',this).val(); - - var obj = {ip: ip, mac: mac}; - - if (!mac.length) { delete obj.mac; }; - - Sunstone.runAction("Network.modifyleases", - $('#lease_vn_proceed',this).val(), - obj); - $lease_vn_dialog.dialog('close'); - return false; - }); -} - -function popUpAddLeaseDialog() { - $lease_vn_dialog.dialog("option","title","Add lease"); - $('#add_lease_mac',$lease_vn_dialog).show(); - $('#add_lease_mac_label',$lease_vn_dialog).show(); - $('#lease_vn_proceed',$lease_vn_dialog).val("Network.addleases"); - $lease_vn_dialog.dialog("open"); -} - -function popUpRemoveLeaseDialog() { - $lease_vn_dialog.dialog("option","title","Remove lease"); - $('#add_lease_mac',$lease_vn_dialog).hide(); - $('#add_lease_mac_label',$lease_vn_dialog).hide(); - $('#lease_vn_proceed',$lease_vn_dialog).val("Network.rmleases"); - $lease_vn_dialog.dialog("open"); -} - -*/ - function setVNetAutorefresh() { setInterval(function(){ var checked = $('input.check_item:checked',dataTable_vNetworks); @@ -1097,7 +995,7 @@ function setVNetAutorefresh() { function is_public_vnet(id) { var data = getElementData(id,"#vnetwork",dataTable_vNetworks)[7]; - return $(data).attr("checked"); + return $(data).is(":checked"); }; function setupVNetActionCheckboxes(){ From d69d7674208e952929cda3a629b1c5c34d0fdf05 Mon Sep 17 00:00:00 2001 From: Jaime Melis Date: Wed, 7 Dec 2011 14:49:07 +0100 Subject: [PATCH 107/121] feature #863: specific xpath filters for each network driver --- src/vnm_mad/remotes/802.1Q/HostManaged.rb | 3 ++- src/vnm_mad/remotes/Firewall.rb | 4 +++- src/vnm_mad/remotes/OpenNebulaNetwork.rb | 15 ++++++++------- src/vnm_mad/remotes/ebtables/Ebtables.rb | 3 ++- src/vnm_mad/remotes/ovswitch/OpenvSwitch.rb | 3 ++- .../remotes/test/OpenNebulaNetwork_spec.rb | 2 +- 6 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/vnm_mad/remotes/802.1Q/HostManaged.rb b/src/vnm_mad/remotes/802.1Q/HostManaged.rb index 28e9a602be..90cbff26e1 100644 --- a/src/vnm_mad/remotes/802.1Q/HostManaged.rb +++ b/src/vnm_mad/remotes/802.1Q/HostManaged.rb @@ -17,8 +17,9 @@ require 'OpenNebulaNetwork' class OpenNebulaHM < OpenNebulaNetwork + XPATH_FILTER = "TEMPLATE/NIC[VLAN='YES']" def initialize(vm, hypervisor = nil) - super(vm,hypervisor) + super(vm,XPATH_FILTER,hypervisor) @bridges = get_interfaces end diff --git a/src/vnm_mad/remotes/Firewall.rb b/src/vnm_mad/remotes/Firewall.rb index 2cc4f98eca..c139bfeabe 100644 --- a/src/vnm_mad/remotes/Firewall.rb +++ b/src/vnm_mad/remotes/Firewall.rb @@ -15,8 +15,10 @@ #--------------------------------------------------------------------------- # class OpenNebulaFirewall < OpenNebulaNetwork + XPATH_FILTER = "TEMPLATE/NIC[ICMP|WHITE_PORTS_TCP|WHITE_PORTS_UDP|" << + "BLACK_PORTS_TCP|BLACK_PORTS_UDP]" def initialize(vm, hypervisor = nil) - super(vm,hypervisor) + super(vm,XPATH_FILTER,hypervisor) end def activate vm_id = @vm['ID'] diff --git a/src/vnm_mad/remotes/OpenNebulaNetwork.rb b/src/vnm_mad/remotes/OpenNebulaNetwork.rb index a944adeb8d..284eb7a680 100644 --- a/src/vnm_mad/remotes/OpenNebulaNetwork.rb +++ b/src/vnm_mad/remotes/OpenNebulaNetwork.rb @@ -45,14 +45,15 @@ COMMANDS = { class VM attr_accessor :nics, :vm_info - def initialize(vm_root, hypervisor) - @vm_root = vm_root - @hypervisor = hypervisor - @vm_info = Hash.new + def initialize(vm_root, xpath_filter, hypervisor) + @vm_root = vm_root + @xpath_filter = xpath_filter + @hypervisor = hypervisor + @vm_info = Hash.new nics = Nics.new(@hypervisor) - @vm_root.elements.each("TEMPLATE/NIC[VLAN='YES']") do |nic_element| + @vm_root.elements.each(@xpath_filter) do |nic_element| nic = nics.new_nic nic_element.elements.each('*') do |nic_attribute| @@ -96,14 +97,14 @@ class OpenNebulaNetwork self.new(vm_xml, hypervisor) end - def initialize(vm_tpl, hypervisor=nil) + def initialize(vm_tpl, xpath_filter, hypervisor=nil) if !hypervisor @hypervisor = detect_hypervisor else @hypervisor = hypervisor end - @vm = VM.new(REXML::Document.new(vm_tpl).root, @hypervisor) + @vm = VM.new(REXML::Document.new(vm_tpl).root, xpath_filter, @hypervisor) end def process(&block) diff --git a/src/vnm_mad/remotes/ebtables/Ebtables.rb b/src/vnm_mad/remotes/ebtables/Ebtables.rb index c22ad69340..fc3dead298 100644 --- a/src/vnm_mad/remotes/ebtables/Ebtables.rb +++ b/src/vnm_mad/remotes/ebtables/Ebtables.rb @@ -17,8 +17,9 @@ require 'OpenNebulaNetwork' class EbtablesVLAN < OpenNebulaNetwork + XPATH_FILTER = "TEMPLATE/NIC[VLAN='YES']" def initialize(vm, hypervisor = nil) - super(vm,hypervisor) + super(vm,XPATH_FILTER,hypervisor) end def ebtables(rule) diff --git a/src/vnm_mad/remotes/ovswitch/OpenvSwitch.rb b/src/vnm_mad/remotes/ovswitch/OpenvSwitch.rb index 9716d99f8a..2cdaeafd80 100644 --- a/src/vnm_mad/remotes/ovswitch/OpenvSwitch.rb +++ b/src/vnm_mad/remotes/ovswitch/OpenvSwitch.rb @@ -17,8 +17,9 @@ require 'OpenNebulaNetwork' class OpenvSwitchVLAN < OpenNebulaNetwork + XPATH_FILTER = "TEMPLATE/NIC[VLAN='YES']" def initialize(vm, hypervisor = nil) - super(vm,hypervisor) + super(vm,XPATH_FILTER,hypervisor) end def activate diff --git a/src/vnm_mad/remotes/test/OpenNebulaNetwork_spec.rb b/src/vnm_mad/remotes/test/OpenNebulaNetwork_spec.rb index b97942055e..cfbfe8cf89 100644 --- a/src/vnm_mad/remotes/test/OpenNebulaNetwork_spec.rb +++ b/src/vnm_mad/remotes/test/OpenNebulaNetwork_spec.rb @@ -43,7 +43,7 @@ describe 'networking' do $capture_commands = { /virsh.*dumpxml/ => OUTPUT[:virsh_dumpxml] } - onevlan = OpenNebulaNetwork.new(OUTPUT[:onevm_show],"kvm") + onevlan = OpenNebulaNetwork.new(OUTPUT[:onevm_show],"TEMPLATE/NIC","kvm") nics_expected = [{:bridge=>"br0", :ip=>"172.16.0.100", :mac=>"02:00:ac:10:00:64", From 4c1832ff4e6a04aa61f0013fbdba815082e237f8 Mon Sep 17 00:00:00 2001 From: Daniel Molina Date: Wed, 7 Dec 2011 18:29:30 +0100 Subject: [PATCH 108/121] Update VNET render in OCCI --- src/cloud/occi/etc/occi-server.conf | 3 -- src/cloud/occi/lib/OCCIServer.rb | 2 +- src/cloud/occi/lib/VirtualNetworkOCCI.rb | 54 +++++++++++++----------- 3 files changed, 31 insertions(+), 28 deletions(-) diff --git a/src/cloud/occi/etc/occi-server.conf b/src/cloud/occi/etc/occi-server.conf index 859329f2df..e803e49788 100644 --- a/src/cloud/occi/etc/occi-server.conf +++ b/src/cloud/occi/etc/occi-server.conf @@ -24,9 +24,6 @@ # SSL proxy that serves the API (set if is being used) #:ssl_server: fqdm.of.the.server -# Configuration for OpenNebula's Virtual Networks -#:bridge: NAME_OF_DEFAULT_BRIDGE - # Authentication driver for incomming requests # occi, for OpenNebula's user-password scheme # x509, for x509 certificates based authentication diff --git a/src/cloud/occi/lib/OCCIServer.rb b/src/cloud/occi/lib/OCCIServer.rb index 613ecd5333..69ced7f360 100755 --- a/src/cloud/occi/lib/OCCIServer.rb +++ b/src/cloud/occi/lib/OCCIServer.rb @@ -317,7 +317,7 @@ class OCCIServer < CloudServer VirtualNetwork.build_xml, @client, request.body, - @config[:bridge]) + @config[:template_location]) # --- Generate the template and Allocate the new Instance --- template = network.to_one_template diff --git a/src/cloud/occi/lib/VirtualNetworkOCCI.rb b/src/cloud/occi/lib/VirtualNetworkOCCI.rb index eeb7194c92..f996b967d2 100755 --- a/src/cloud/occi/lib/VirtualNetworkOCCI.rb +++ b/src/cloud/occi/lib/VirtualNetworkOCCI.rb @@ -15,6 +15,7 @@ #--------------------------------------------------------------------------- # require 'OpenNebula' +require 'ipaddr' include OpenNebula @@ -26,35 +27,23 @@ class VirtualNetworkOCCI < VirtualNetwork <% if self['TEMPLATE/DESCRIPTION'] != nil %> <%= self['TEMPLATE/DESCRIPTION'] %> <% end %> -
<%= self['TEMPLATE/NETWORK_ADDRESS'] %>
- <% if self['TEMPLATE/NETWORK_SIZE'] %> - <%= self['TEMPLATE/NETWORK_SIZE'] %> + <% if network_address != nil %> +
<%= network_address %>
<% end %> + <% if network_size != nil %> + <%= network_size %> + <% end %> + <%= self['TOTAL_LEASES'] %> <%= self['PUBLIC'] == "0" ? "NO" : "YES"%> } - ONE_NETWORK = %q{ - NAME = "<%= @vnet_info['NAME'] %>" - TYPE = RANGED - <% if @vnet_info['DESCRIPTION'] != nil %> - DESCRIPTION = "<%= @vnet_info['DESCRIPTION'] %>" - <% end %> - <% if @vnet_info['PUBLIC'] != nil %> - PUBLIC = "<%= @vnet_info['PUBLIC'] %>" - <% end %> - <% if @bridge %> - BRIDGE = <%= @bridge %> - <% end %> - NETWORK_ADDRESS = <%= @vnet_info['ADDRESS'] %> - NETWORK_SIZE = <%= @vnet_info['SIZE']%> - }.gsub(/^ /, '') - # Class constructor - def initialize(xml, client, xml_info=nil, bridge=nil) + # + def initialize(xml, client, xml_info=nil, base=nil) super(xml, client) - @bridge = bridge @vnet_info = nil + @common_template = base + '/network.erb' if base if xml_info != nil xmldoc = XMLElement.build_xml(xml_info, 'NETWORK') @@ -64,6 +53,18 @@ class VirtualNetworkOCCI < VirtualNetwork # Creates the OCCI representation of a Virtual Network def to_occi(base_url) + network_address = nil + network_size = nil + + if self['RANGE/IP_START'] + network_address = self['RANGE/IP_START'] + + ip_start = IPAddr.new(network_address, Socket::AF_INET) + ip_end = IPAddr.new(self['RANGE/IP_END'], Socket::AF_INET) + + network_size = ip_end.to_i - ip_start.to_i + end + begin occi = ERB.new(OCCI_NETWORK) occi_text = occi.result(binding) @@ -78,11 +79,16 @@ class VirtualNetworkOCCI < VirtualNetwork def to_one_template() if @vnet_info == nil error_msg = "Missing NETWORK section in the XML body" - error = OpenNebula::Error.new(error_msg) + return OpenNebula::Error.new(error_msg), 400 + end + + begin + template = ERB.new(File.read(@common_template)).result(binding) + rescue Exception => e + error = OpenNebula::Error.new(e.message) return error end - one = ERB.new(ONE_NETWORK) - return one.result(binding) + return template end end From cee7ae3c5d73afed1ee6efaef856372b29d82127 Mon Sep 17 00:00:00 2001 From: Daniel Molina Date: Wed, 7 Dec 2011 18:30:09 +0100 Subject: [PATCH 109/121] Use a constant for pool filtering in OCCI --- src/cloud/occi/lib/OCCIServer.rb | 15 ++++++--------- src/cloud/occi/lib/VirtualMachineOCCI.rb | 4 ++-- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/cloud/occi/lib/OCCIServer.rb b/src/cloud/occi/lib/OCCIServer.rb index 69ced7f360..86e68c5fd9 100755 --- a/src/cloud/occi/lib/OCCIServer.rb +++ b/src/cloud/occi/lib/OCCIServer.rb @@ -40,6 +40,9 @@ require 'pp' COLLECTIONS = ["compute", "instance_type", "network", "storage"] +# FLAG that will filter the elements retrieved from the Pools +POOL_FILTER = Pool::INFO_GROUP + class OCCIServer < CloudServer # Server initializer # config_file:: _String_ path of the config file @@ -109,11 +112,9 @@ class OCCIServer < CloudServer # [return] _String_,_Integer_ Pool Representation or error, status code def get_computes(request) # --- Get User's VMs --- - user_flag = -1 - vmpool = VirtualMachinePoolOCCI.new( @client, - user_flag) + POOL_FILTER) # --- Prepare XML Response --- rc = vmpool.info @@ -136,11 +137,9 @@ class OCCIServer < CloudServer # => status code def get_networks(request) # --- Get User's VNETs --- - user_flag = -1 - network_pool = VirtualNetworkPoolOCCI.new( @client, - user_flag) + POOL_FILTER) # --- Prepare XML Response --- rc = network_pool.info @@ -162,11 +161,9 @@ class OCCIServer < CloudServer # status code def get_storages(request) # --- Get User's Images --- - user_flag = -1 - image_pool = ImagePoolOCCI.new( @client, - user_flag) + POOL_FILTER) # --- Prepare XML Response --- rc = image_pool.info diff --git a/src/cloud/occi/lib/VirtualMachineOCCI.rb b/src/cloud/occi/lib/VirtualMachineOCCI.rb index 73274ba9b0..f05f194920 100755 --- a/src/cloud/occi/lib/VirtualMachineOCCI.rb +++ b/src/cloud/occi/lib/VirtualMachineOCCI.rb @@ -100,11 +100,11 @@ class VirtualMachineOCCI < VirtualMachine def to_one_template() if @vm_info == nil error_msg = "Missing COMPUTE section in the XML body" - return OpenNebula::Error.new(error_msg), 400 + return OpenNebula::Error.new(error_msg) end if @template == nil - return OpenNebula::Error.new("Bad instance type"), 500 + return OpenNebula::Error.new("Bad instance type") end begin From d9d82dca99015a73d8b1a5950913cd6ca1aa6715 Mon Sep 17 00:00:00 2001 From: Jaime Melis Date: Wed, 7 Dec 2011 18:36:54 +0100 Subject: [PATCH 110/121] feature #863: the post scripts require the deploy_id --- src/vmm_mad/exec/one_vmm_exec.rb | 34 ++++++++++++--------- src/vnm_mad/one_vnm.rb | 7 +++-- src/vnm_mad/remotes/802.1Q/HostManaged.rb | 5 +-- src/vnm_mad/remotes/802.1Q/post | 5 ++- src/vnm_mad/remotes/Firewall.rb | 6 ++-- src/vnm_mad/remotes/OpenNebulaNetwork.rb | 17 ++++++----- src/vnm_mad/remotes/OpenNebulaNic.rb | 6 +++- src/vnm_mad/remotes/ebtables/Ebtables.rb | 5 +-- src/vnm_mad/remotes/ebtables/post | 7 +++-- src/vnm_mad/remotes/fw/post | 5 ++- src/vnm_mad/remotes/ovswitch/OpenvSwitch.rb | 5 +-- src/vnm_mad/remotes/ovswitch/post | 6 ++-- 12 files changed, 69 insertions(+), 39 deletions(-) diff --git a/src/vmm_mad/exec/one_vmm_exec.rb b/src/vmm_mad/exec/one_vmm_exec.rb index b16867ee56..ffd1bd6069 100755 --- a/src/vmm_mad/exec/one_vmm_exec.rb +++ b/src/vmm_mad/exec/one_vmm_exec.rb @@ -72,14 +72,16 @@ class VmmAction @vnm_src = VirtualNetworkDriver.new(@data[:net_drv], :local_actions => @vmm.options[:local_actions], :message => @xml_data, - :ssh_stream => @ssh_src) + :ssh_stream => @ssh_src, + :extra_data => @data) if @data[:dest_host] and !@data[:dest_host].empty? @ssh_dst = @vmm.get_ssh_stream(@data[:dest_host], @id) @vnm_dst = VirtualNetworkDriver.new(@data[:dest_driver], :local_actions => @vmm.options[:local_actions], :message => @xml_data, - :ssh_stream => @ssh_dst) + :ssh_stream => @ssh_dst, + :extra_data => @data) end end @@ -115,7 +117,7 @@ class VmmAction # Executes a set of steps. If one step fails any recover action is performed # and the step execution breaks. # @param [Array] array of steps to be executed - # @return [String, Hash] "SUCCESS/FAILURE" for the step set, and + # @return [String, Hash] "SUCCESS/FAILURE" for the step set, and # information associated to each step (by :_info). In case of # failure information is also in [:failed_info] def execute_steps(steps) @@ -124,7 +126,7 @@ class VmmAction steps.each do |step| # Execute Step case step[:driver] - when :vmm + when :vmm if step[:destination] host = @data[:dest_host] ssh = @ssh_dst @@ -134,7 +136,7 @@ class VmmAction end result, info = @vmm.do_action(get_parameters(step[:parameters]), - @id, + @id, host, step[:action], :ssh_stream => ssh, @@ -153,20 +155,21 @@ class VmmAction info = "No driver in #{step[:action]}" end - # Save the step info + # Save the step info @data["#{step[:action]}_info".to_sym] = info + @data[step[:save_info_as]] = info if step[:save_info_as] # Roll back steps, store failed info and break steps - if DriverExecHelper.failed?(result) + if DriverExecHelper.failed?(result) execute_steps(@data[:fail_actions]) if @data[:fail_actions] @data[:failed_info] = info - @vmm.log(@id, + @vmm.log(@id, "Failed to execute #{DRIVER_NAMES[step[:driver]]} " \ "operation: #{step[:action]}.") break else - @vmm.log(@id, + @vmm.log(@id, "Sussecfully execute #{DRIVER_NAMES[step[:driver]]} " \ "operation: #{step[:action]}.") end @@ -217,7 +220,7 @@ class ExecDriver < VirtualMachineDriver @options={ :threaded => true }.merge!(options) - + super("vmm/#{hypervisor}", @options) @hypervisor = hypervisor @@ -273,11 +276,12 @@ class ExecDriver < VirtualMachineDriver }, # Boot the Virtual Machine { - :driver => :vmm, - :action => :deploy, - :parameters => [dfile, :host], - :stdin => domain - }, + :driver => :vmm, + :action => :deploy, + :parameters => [dfile, :host], + :stdin => domain, + :save_info_as => :deploy_id + }, # Execute post-boot networking setup { :driver => :vnm, diff --git a/src/vnm_mad/one_vnm.rb b/src/vnm_mad/one_vnm.rb index aba0339611..23dba5a34e 100644 --- a/src/vnm_mad/one_vnm.rb +++ b/src/vnm_mad/one_vnm.rb @@ -31,6 +31,7 @@ class VirtualNetworkDriver @options = options @ssh_stream = options[:ssh_stream] @message = options[:message] + @extra_data = options[:extra_data] @vm_encoded = Base64.encode64(@message.elements['VM'].to_s).delete("\n") @@ -49,7 +50,9 @@ class VirtualNetworkDriver :stdin => nil, }.merge(ops) - cmd = action_command_line(aname, @vm_encoded) + deploy_id=@extra_data[:deploy_id] || '-' + + cmd = action_command_line(aname, "#{@vm_encoded} #{deploy_id}") if action_is_local?(aname) execution = LocalCommand.run(cmd, log_method(id)) @@ -67,4 +70,4 @@ class VirtualNetworkDriver result, info = get_info_from_execution(execution) end -end \ No newline at end of file +end diff --git a/src/vnm_mad/remotes/802.1Q/HostManaged.rb b/src/vnm_mad/remotes/802.1Q/HostManaged.rb index 90cbff26e1..67547840fc 100644 --- a/src/vnm_mad/remotes/802.1Q/HostManaged.rb +++ b/src/vnm_mad/remotes/802.1Q/HostManaged.rb @@ -18,8 +18,9 @@ require 'OpenNebulaNetwork' class OpenNebulaHM < OpenNebulaNetwork XPATH_FILTER = "TEMPLATE/NIC[VLAN='YES']" - def initialize(vm, hypervisor = nil) - super(vm,XPATH_FILTER,hypervisor) + + def initialize(vm, deploy_id = nil, hypervisor = nil) + super(vm,XPATH_FILTER,deploy_id,hypervisor) @bridges = get_interfaces end diff --git a/src/vnm_mad/remotes/802.1Q/post b/src/vnm_mad/remotes/802.1Q/post index 6458772e86..7b0afd182e 100755 --- a/src/vnm_mad/remotes/802.1Q/post +++ b/src/vnm_mad/remotes/802.1Q/post @@ -22,6 +22,9 @@ $: << File.join(File.dirname(__FILE__), "..") require 'OpenNebulaNetwork' require 'Firewall' -fw = OpenNebulaFirewall.from_base64(ARGV[0]) +template64 = ARGV[0] +deploy_id = ARGV[1] + +fw = OpenNebulaFirewall.from_base64(template64, deploy_id) fw.activate diff --git a/src/vnm_mad/remotes/Firewall.rb b/src/vnm_mad/remotes/Firewall.rb index c139bfeabe..76f00bf09e 100644 --- a/src/vnm_mad/remotes/Firewall.rb +++ b/src/vnm_mad/remotes/Firewall.rb @@ -17,9 +17,11 @@ class OpenNebulaFirewall < OpenNebulaNetwork XPATH_FILTER = "TEMPLATE/NIC[ICMP|WHITE_PORTS_TCP|WHITE_PORTS_UDP|" << "BLACK_PORTS_TCP|BLACK_PORTS_UDP]" - def initialize(vm, hypervisor = nil) - super(vm,XPATH_FILTER,hypervisor) + + def initialize(vm, deploy_id = nil, hypervisor = nil) + super(vm,XPATH_FILTER,deploy_id,hypervisor) end + def activate vm_id = @vm['ID'] process do |nic| diff --git a/src/vnm_mad/remotes/OpenNebulaNetwork.rb b/src/vnm_mad/remotes/OpenNebulaNetwork.rb index 284eb7a680..c4ed9f8a23 100644 --- a/src/vnm_mad/remotes/OpenNebulaNetwork.rb +++ b/src/vnm_mad/remotes/OpenNebulaNetwork.rb @@ -43,14 +43,17 @@ COMMANDS = { } class VM - attr_accessor :nics, :vm_info + attr_accessor :nics, :vm_info, :deploy_id - def initialize(vm_root, xpath_filter, hypervisor) + def initialize(vm_root, xpath_filter, deploy_id, hypervisor) @vm_root = vm_root @xpath_filter = xpath_filter + @deploy_id = deploy_id @hypervisor = hypervisor @vm_info = Hash.new + @deploy_id = nil if deploy_id == "-" + nics = Nics.new(@hypervisor) @vm_root.elements.each(@xpath_filter) do |nic_element| @@ -92,19 +95,19 @@ end class OpenNebulaNetwork attr_reader :hypervisor, :vm - def self.from_base64(vm_64, hypervisor=nil) + def self.from_base64(vm_64, deploy_id = nil, hypervisor = nil) vm_xml = Base64::decode64(vm_64) - self.new(vm_xml, hypervisor) + self.new(vm_xml, deploy_id, hypervisor) end - def initialize(vm_tpl, xpath_filter, hypervisor=nil) + def initialize(vm_tpl, xpath_filter, deploy_id = nil, hypervisor = nil) if !hypervisor @hypervisor = detect_hypervisor else @hypervisor = hypervisor end - - @vm = VM.new(REXML::Document.new(vm_tpl).root, xpath_filter, @hypervisor) + + @vm = VM.new(REXML::Document.new(vm_tpl).root, xpath_filter, deploy_id, @hypervisor) end def process(&block) diff --git a/src/vnm_mad/remotes/OpenNebulaNic.rb b/src/vnm_mad/remotes/OpenNebulaNic.rb index 84214bd154..176d41246e 100644 --- a/src/vnm_mad/remotes/OpenNebulaNic.rb +++ b/src/vnm_mad/remotes/OpenNebulaNic.rb @@ -39,7 +39,11 @@ class NicKVM < Hash end def get_info(vm) - deploy_id = vm['DEPLOY_ID'] + if vm.deploy_id + deploy_id = vm.deploy_id + else + deploy_id = vm['DEPLOY_ID'] + end if deploy_id and vm.vm_info[:dumpxml].nil? vm.vm_info[:dumpxml] = `#{COMMANDS[:virsh]} dumpxml #{deploy_id} \ diff --git a/src/vnm_mad/remotes/ebtables/Ebtables.rb b/src/vnm_mad/remotes/ebtables/Ebtables.rb index fc3dead298..b76d0cad19 100644 --- a/src/vnm_mad/remotes/ebtables/Ebtables.rb +++ b/src/vnm_mad/remotes/ebtables/Ebtables.rb @@ -18,8 +18,9 @@ require 'OpenNebulaNetwork' class EbtablesVLAN < OpenNebulaNetwork XPATH_FILTER = "TEMPLATE/NIC[VLAN='YES']" - def initialize(vm, hypervisor = nil) - super(vm,XPATH_FILTER,hypervisor) + + def initialize(vm, deploy_id = nil, hypervisor = nil) + super(vm,XPATH_FILTER,deploy_id,hypervisor) end def ebtables(rule) diff --git a/src/vnm_mad/remotes/ebtables/post b/src/vnm_mad/remotes/ebtables/post index a862a9aaa9..9e31babff5 100755 --- a/src/vnm_mad/remotes/ebtables/post +++ b/src/vnm_mad/remotes/ebtables/post @@ -22,10 +22,13 @@ $: << File.join(File.dirname(__FILE__), "..") require 'Ebtables' require 'Firewall' -onevlan = EbtablesVLAN.from_base64(ARGV[0]) +template64 = ARGV[0] +deploy_id = ARGV[1] + +onevlan = EbtablesVLAN.from_base64(template64, deploy_id) onevlan.activate -fw = OpenNebulaFirewall.from_base64(ARGV[0]) +fw = OpenNebulaFirewall.from_base64(template64, deploy_id) fw.activate diff --git a/src/vnm_mad/remotes/fw/post b/src/vnm_mad/remotes/fw/post index 6458772e86..7b0afd182e 100755 --- a/src/vnm_mad/remotes/fw/post +++ b/src/vnm_mad/remotes/fw/post @@ -22,6 +22,9 @@ $: << File.join(File.dirname(__FILE__), "..") require 'OpenNebulaNetwork' require 'Firewall' -fw = OpenNebulaFirewall.from_base64(ARGV[0]) +template64 = ARGV[0] +deploy_id = ARGV[1] + +fw = OpenNebulaFirewall.from_base64(template64, deploy_id) fw.activate diff --git a/src/vnm_mad/remotes/ovswitch/OpenvSwitch.rb b/src/vnm_mad/remotes/ovswitch/OpenvSwitch.rb index 2cdaeafd80..8471f66a30 100644 --- a/src/vnm_mad/remotes/ovswitch/OpenvSwitch.rb +++ b/src/vnm_mad/remotes/ovswitch/OpenvSwitch.rb @@ -18,8 +18,9 @@ require 'OpenNebulaNetwork' class OpenvSwitchVLAN < OpenNebulaNetwork XPATH_FILTER = "TEMPLATE/NIC[VLAN='YES']" - def initialize(vm, hypervisor = nil) - super(vm,XPATH_FILTER,hypervisor) + + def initialize(vm, deploy_id = nil, hypervisor = nil) + super(vm,XPATH_FILTER,deploy_id,hypervisor) end def activate diff --git a/src/vnm_mad/remotes/ovswitch/post b/src/vnm_mad/remotes/ovswitch/post index 520d74a455..ceb0a0fc41 100755 --- a/src/vnm_mad/remotes/ovswitch/post +++ b/src/vnm_mad/remotes/ovswitch/post @@ -22,11 +22,13 @@ $: << File.join(File.dirname(__FILE__), "..") require 'OpenvSwitch' require 'Firewall' +template64 = ARGV[0] +deploy_id = ARGV[1] -onevlan = OpenvSwitchVLAN.from_base64(ARGV[0]) +onevlan = OpenvSwitchVLAN.from_base64(template64, deploy_id) onevlan.activate -fw = OpenNebulaFirewall.from_base64(ARGV[0]) +fw = OpenNebulaFirewall.from_base64(template64, deploy_id) fw.activate From 1d11cbc5866ffe1542b59a5f47daa716f21280ee Mon Sep 17 00:00:00 2001 From: Hector Sanjuan Date: Wed, 7 Dec 2011 14:26:45 +0100 Subject: [PATCH 111/121] Task #864, Feature #602: Small fixes to vnets in Sunstone. Removal of commented code. (cherry picked from commit 1ad5326f2927297ac04a9a9d36d1f95cc5c1ac34) --- src/sunstone/public/js/plugins/vnets-tab.js | 148 +++----------------- 1 file changed, 23 insertions(+), 125 deletions(-) diff --git a/src/sunstone/public/js/plugins/vnets-tab.js b/src/sunstone/public/js/plugins/vnets-tab.js index 21c6150945..cb0df258d2 100644 --- a/src/sunstone/public/js/plugins/vnets-tab.js +++ b/src/sunstone/public/js/plugins/vnets-tab.js @@ -87,11 +87,11 @@ var create_vn_tmpl =
\ \
\ - \ + \
\ - \ + \
\ - \ + \ \ \ \ @@ -280,27 +280,7 @@ var vnet_actions = { error: onError, notify: false, }, -/* - "Network.modifyleases" : { - type: "custom", - call: function(action,obj){ - nodes = getSelectedNodes(dataTable_vNetworks); - $.each(nodes,function(){ - Sunstone.runAction(action,this,obj); - }); - } - }, - "Network.addleases_dialog" : { - type: "custom", - call: popUpAddLeaseDialog - }, - - "Network.rmleases_dialog" : { - type: "custom", - call: popUpRemoveLeaseDialog - }, -*/ "Network.chown" : { type: "multiple", call: OpenNebula.Network.chown, @@ -390,21 +370,7 @@ var vnet_buttons = { tip: "Select the new group:", condition: mustBeAdmin, }, -/* - "action_list" : { - type: "select", - actions: { - "Network.addleases_dialog" : { - type: "action", - text: "Add lease" - }, - "Network.rmleases_dialog" : { - type: "action", - text: "Remove lease" - } - } - }, -*/ + "Network.delete" : { type: "action", text: "Delete" @@ -416,10 +382,10 @@ var vnet_info_panel = { title: "Virtual network information", content: "" }, - "vnet_template_tab" : { - title: "Virtual network template", + "vnet_leases_tab" : { + title: "Lease management", content: "" - } + }, } var vnets_tab = { @@ -547,31 +513,34 @@ function updateVNetworkInfo(request,vn){ \
Leases information
'; - info_tab_content += printLeases(vn_info); + info_tab_content += '\ + \ + '+ + prettyPrintJSON(vn_info.TEMPLATE)+ + '
Virtual Network template (attributes)
' + + + var leases_tab_content = printLeases(vn_info); var info_tab = { title: "Virtual Network information", content: info_tab_content - } + }; - var template_tab = { - title: "Virtual Network template", - content: - '\ - '+ - prettyPrintJSON(vn_info.TEMPLATE)+ - '
Virtual Network template
' - } + var leases_tab = { + title: "Lease management", + content: leases_tab_content + }; Sunstone.updateInfoPanelTab("vnet_info_panel","vnet_info_tab",info_tab); - Sunstone.updateInfoPanelTab("vnet_info_panel","vnet_template_tab",template_tab); + Sunstone.updateInfoPanelTab("vnet_info_panel","vnet_leases_tab",leases_tab); Sunstone.popUpInfoPanel("vnet_info_panel"); } function printLeases(vn_info){ - var html ='
\ + var html ='
\ \ \ '; @@ -1013,77 +982,6 @@ function setupLeasesOps(){ }); } - -/* -function setupAddRemoveLeaseDialog() { - dialogs_context.append('
'); - $lease_vn_dialog = $('#lease_vn_dialog',dialogs_context) - - var dialog = $lease_vn_dialog; - - dialog.html( - '\ -
\ -
Please specify:
\ - \ -
\ - \ - \ - \ -
\ -
\ -
\ - \ - \ -
\ -
\ - ' - ); - - //Prepare the jquery-ui dialog. Set style options here. - dialog.dialog({ - autoOpen: false, - modal: true, - width: 410, - height: 220 - }); - - $('button',dialog).button(); - - $('#lease_vn_form',dialog).submit(function(){ - var ip = $('#add_lease_ip',this).val(); - var mac = $('#add_lease_mac',this).val(); - - var obj = {ip: ip, mac: mac}; - - if (!mac.length) { delete obj.mac; }; - - Sunstone.runAction("Network.modifyleases", - $('#lease_vn_proceed',this).val(), - obj); - $lease_vn_dialog.dialog('close'); - return false; - }); -} - -function popUpAddLeaseDialog() { - $lease_vn_dialog.dialog("option","title","Add lease"); - $('#add_lease_mac',$lease_vn_dialog).show(); - $('#add_lease_mac_label',$lease_vn_dialog).show(); - $('#lease_vn_proceed',$lease_vn_dialog).val("Network.addleases"); - $lease_vn_dialog.dialog("open"); -} - -function popUpRemoveLeaseDialog() { - $lease_vn_dialog.dialog("option","title","Remove lease"); - $('#add_lease_mac',$lease_vn_dialog).hide(); - $('#add_lease_mac_label',$lease_vn_dialog).hide(); - $('#lease_vn_proceed',$lease_vn_dialog).val("Network.rmleases"); - $lease_vn_dialog.dialog("open"); -} - -*/ - function setVNetAutorefresh() { setInterval(function(){ var checked = $('input.check_item:checked',dataTable_vNetworks); @@ -1097,7 +995,7 @@ function setVNetAutorefresh() { function is_public_vnet(id) { var data = getElementData(id,"#vnetwork",dataTable_vNetworks)[7]; - return $(data).attr("checked"); + return $(data).is(":checked"); }; function setupVNetActionCheckboxes(){ From 63e9ad23f0a2b25d377668754bdd90d17d30448f Mon Sep 17 00:00:00 2001 From: Daniel Molina Date: Wed, 7 Dec 2011 18:55:17 +0100 Subject: [PATCH 112/121] Use HTTP_CODES in OCCI --- src/cloud/occi/lib/OCCIServer.rb | 99 +++++++++++--------------------- 1 file changed, 34 insertions(+), 65 deletions(-) diff --git a/src/cloud/occi/lib/OCCIServer.rb b/src/cloud/occi/lib/OCCIServer.rb index 86e68c5fd9..0b5d26e5d2 100755 --- a/src/cloud/occi/lib/OCCIServer.rb +++ b/src/cloud/occi/lib/OCCIServer.rb @@ -118,13 +118,8 @@ class OCCIServer < CloudServer # --- Prepare XML Response --- rc = vmpool.info - if OpenNebula.is_error?(rc) - if rc.message.match("Error getting") - return rc, 404 - else - return rc, 500 - end + return rc, CloudServer::HTTP_ERROR_CODE[rc.errno] end return to_occi_xml(vmpool, 200) @@ -143,13 +138,8 @@ class OCCIServer < CloudServer # --- Prepare XML Response --- rc = network_pool.info - if OpenNebula.is_error?(rc) - if rc.message.match("Error getting") - return rc, 404 - else - return rc, 500 - end + return rc, CloudServer::HTTP_ERROR_CODE[rc.errno] end return to_occi_xml(network_pool, 200) @@ -167,13 +157,8 @@ class OCCIServer < CloudServer # --- Prepare XML Response --- rc = image_pool.info - if OpenNebula.is_error?(rc) - if rc.message.match("Error getting") - return rc, 404 - else - return rc, 500 - end + return rc, CloudServer::HTTP_ERROR_CODE[rc.errno] end return to_occi_xml(image_pool, 200) @@ -189,7 +174,6 @@ class OCCIServer < CloudServer # --- Prepare XML Response --- rc = user_pool.info - if OpenNebula.is_error?(rc) return rc, CloudServer::HTTP_ERROR_CODE[rc.errno] end @@ -224,7 +208,9 @@ class OCCIServer < CloudServer return template, 500 if OpenNebula.is_error?(template) rc = vm.allocate(template) - return rc, 500 if OpenNebula.is_error?(rc) + if OpenNebula.is_error?(rc) + return rc, CloudServer::HTTP_ERROR_CODE[rc.errno] + end # --- Prepare XML Response --- vm.info @@ -243,13 +229,8 @@ class OCCIServer < CloudServer # --- Prepare XML Response --- rc = vm.info - if OpenNebula.is_error?(rc) - if rc.message.match("Error getting") - return rc, 404 - else - return rc, 500 - end + return rc, CloudServer::HTTP_ERROR_CODE[rc.errno] end return to_occi_xml(vm, 200) @@ -266,12 +247,11 @@ class OCCIServer < CloudServer VirtualMachine.build_xml(params[:id]), @client) - rc = vm.info - return rc, 404 if OpenNebula::is_error?(rc) - # --- Finalize the VM --- result = vm.finalize - return result, 500 if OpenNebula::is_error?(result) + if OpenNebula.is_error?(result) + return result, CloudServer::HTTP_ERROR_CODE[result.errno] + end return "", 204 end @@ -321,7 +301,9 @@ class OCCIServer < CloudServer return template, 500 if OpenNebula.is_error?(template) rc = network.allocate(template) - return rc, 500 if OpenNebula.is_error?(rc) + if OpenNebula.is_error?(rc) + return rc, CloudServer::HTTP_ERROR_CODE[rc.errno] + end # --- Prepare XML Response --- network.info @@ -339,13 +321,8 @@ class OCCIServer < CloudServer # --- Prepare XML Response --- rc = network.info - if OpenNebula.is_error?(rc) - if rc.message.match("Error getting") - return rc, 404 - else - return rc, 500 - end + return rc, CloudServer::HTTP_ERROR_CODE[rc.errno] end return to_occi_xml(network, 200) @@ -360,12 +337,11 @@ class OCCIServer < CloudServer VirtualNetwork.build_xml(params[:id]), @client) - rc = network.info - return rc, 404 if OpenNebula::is_error?(rc) - # --- Delete the VNET --- rc = network.delete - return rc, 500 if OpenNebula::is_error?(rc) + if OpenNebula.is_error?(rc) + return rc, CloudServer::HTTP_ERROR_CODE[rc.errno] + end return "", 204 end @@ -382,15 +358,15 @@ class OCCIServer < CloudServer VirtualNetwork.build_xml(params[:id]), @client) - rc = vnet.info - return rc, 400 if OpenNebula.is_error?(rc) - + rc = nil if vnet_info['PUBLIC'] == 'YES' rc = vnet.publish - return rc, 400 if OpenNebula.is_error?(rc) elsif vnet_info['PUBLIC'] == 'NO' rc = vnet.unpublish - return rc, 400 if OpenNebula.is_error?(rc) + end + + if OpenNebula.is_error?(rc) + return rc, CloudServer::HTTP_ERROR_CODE[rc.errno] end # --- Prepare XML Response --- @@ -429,7 +405,9 @@ class OCCIServer < CloudServer return template, 500 if OpenNebula.is_error?(template) rc = image.allocate(template) - return rc, 500 if OpenNebula.is_error?(rc) + if OpenNebula.is_error?(rc) + return rc, CloudServer::HTTP_ERROR_CODE[rc.errno] + end # --- Prepare XML Response --- image.info @@ -447,13 +425,8 @@ class OCCIServer < CloudServer @client) rc = image.info - if OpenNebula.is_error?(rc) - if rc.message.match("Error getting") - return rc, 404 - else - return rc, 500 - end + return rc, CloudServer::HTTP_ERROR_CODE[rc.errno] end # --- Prepare XML Response --- @@ -470,12 +443,11 @@ class OCCIServer < CloudServer Image.build_xml(params[:id]), @client) - rc = image.info - return rc, 404 if OpenNebula::is_error?(rc) - # --- Delete the Image --- rc = image.delete - return rc, 500 if OpenNebula::is_error?(rc) + if OpenNebula.is_error?(rc) + return rc, CloudServer::HTTP_ERROR_CODE[rc.errno] + end return "", 204 end @@ -492,24 +464,22 @@ class OCCIServer < CloudServer Image.build_xml(params[:id]), @client) - rc = image.info - return rc, 400 if OpenNebula.is_error?(rc) - + rc = nil if image_info['PERSISTENT'] && image_info['PUBLIC'] error_msg = "It is not allowed more than one change per request" return OpenNebula::Error.new(error_msg), 400 elsif image_info['PERSISTENT'] == 'YES' rc = image.persistent - return rc, 400 if OpenNebula.is_error?(rc) elsif image_info['PERSISTENT'] == 'NO' rc = image.nonpersistent - return rc, 400 if OpenNebula.is_error?(rc) elsif image_info['PUBLIC'] == 'YES' rc = image.publish - return rc, 400 if OpenNebula.is_error?(rc) elsif image_info['PUBLIC'] == 'NO' rc = image.unpublish - return rc, 400 if OpenNebula.is_error?(rc) + end + + if OpenNebula.is_error?(rc) + return rc, CloudServer::HTTP_ERROR_CODE[rc.errno] end # --- Prepare XML Response --- @@ -529,7 +499,6 @@ class OCCIServer < CloudServer # --- Prepare XML Response --- rc = user.info - if OpenNebula.is_error?(rc) return rc, CloudServer::HTTP_ERROR_CODE[rc.errno] end From 1a8b2ef6a487e7542a03a03eb29987d46b27b921 Mon Sep 17 00:00:00 2001 From: Jaime Melis Date: Wed, 7 Dec 2011 19:01:41 +0100 Subject: [PATCH 113/121] feature #863: fix tests --- src/vnm_mad/remotes/test/OpenNebulaNetwork_spec.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/vnm_mad/remotes/test/OpenNebulaNetwork_spec.rb b/src/vnm_mad/remotes/test/OpenNebulaNetwork_spec.rb index cfbfe8cf89..f451b53c3e 100644 --- a/src/vnm_mad/remotes/test/OpenNebulaNetwork_spec.rb +++ b/src/vnm_mad/remotes/test/OpenNebulaNetwork_spec.rb @@ -43,7 +43,7 @@ describe 'networking' do $capture_commands = { /virsh.*dumpxml/ => OUTPUT[:virsh_dumpxml] } - onevlan = OpenNebulaNetwork.new(OUTPUT[:onevm_show],"TEMPLATE/NIC","kvm") + onevlan = OpenNebulaNetwork.new(OUTPUT[:onevm_show],"TEMPLATE/NIC",nil,"kvm") nics_expected = [{:bridge=>"br0", :ip=>"172.16.0.100", :mac=>"02:00:ac:10:00:64", @@ -76,7 +76,7 @@ describe 'ebtables' do /virsh.*dumpxml/ => OUTPUT[:virsh_dumpxml], /ebtables/ => nil } - onevlan = EbtablesVLAN.new(OUTPUT[:onevm_show],"kvm") + onevlan = EbtablesVLAN.new(OUTPUT[:onevm_show],nil,"kvm") onevlan.activate ebtables_cmds = [ "sudo /sbin/ebtables -A FORWARD -s ! 02:00:ac:10:00:00/ff:ff:ff:ff:ff:00 -o vnet0 -j DROP", @@ -98,7 +98,7 @@ describe 'openvswitch' do /virsh.*dumpxml/ => OUTPUT[:virsh_dumpxml], /ovs-vsctl/ => nil } - onevlan = OpenvSwitchVLAN.new(OUTPUT[:onevm_show],"kvm") + onevlan = OpenvSwitchVLAN.new(OUTPUT[:onevm_show],nil,"kvm") onevlan.activate openvswitch_tags = [ "sudo /usr/local/bin/ovs-vsctl set Port vnet0 tag=2", @@ -117,7 +117,7 @@ describe 'openvswitch' do /brctl show/ => OUTPUT[:brctl_show], /ovs-vsctl/ => nil } - onevlan = OpenvSwitchVLAN.new(OUTPUT[:onevm_show_vlan_id_kvm],"kvm") + onevlan = OpenvSwitchVLAN.new(OUTPUT[:onevm_show_vlan_id_kvm],nil,"kvm") onevlan.activate onevlan_rules = ["sudo /usr/local/bin/ovs-vsctl set Port vnet0 tag=6", @@ -166,7 +166,7 @@ describe 'host-managed' do /ip link set/ => nil, /ip link show/ => [nil,255] } - hm = OpenNebulaHM.new(OUTPUT[:onevm_show_phydev_kvm],"kvm") + hm = OpenNebulaHM.new(OUTPUT[:onevm_show_phydev_kvm],nil,"kvm") hm.activate hm_activate_rules = ["sudo /sbin/brctl addbr onebr6", @@ -189,7 +189,7 @@ describe 'host-managed' do /ip link set/ => nil, /ip link show/ => [nil,255] } - hm = OpenNebulaHM.new(OUTPUT[:onevm_show_vlan_id_kvm],"kvm") + hm = OpenNebulaHM.new(OUTPUT[:onevm_show_vlan_id_kvm],nil,"kvm") hm.activate hm_vlan_id = ["sudo /sbin/brctl addbr onebr10", @@ -222,7 +222,7 @@ describe 'host-managed' do - hm = OpenNebulaHM.new(OUTPUT[:onevm_show_mixed],"kvm") + hm = OpenNebulaHM.new(OUTPUT[:onevm_show_mixed],nil,"kvm") hm.activate hm_vlan_tag = [ "sudo /sbin/brctl show", From 966db944785aa6e899d352d947e04f5cdcc1d839 Mon Sep 17 00:00:00 2001 From: Daniel Molina Date: Wed, 7 Dec 2011 19:03:41 +0100 Subject: [PATCH 114/121] Do not show FSTYPE in OCCI if type OS --- src/cloud/occi/lib/ImageOCCI.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cloud/occi/lib/ImageOCCI.rb b/src/cloud/occi/lib/ImageOCCI.rb index cd573554c3..50a12133f5 100755 --- a/src/cloud/occi/lib/ImageOCCI.rb +++ b/src/cloud/occi/lib/ImageOCCI.rb @@ -30,7 +30,7 @@ class ImageOCCI < Image <%= self['TEMPLATE/DESCRIPTION'] %> <% end %> <%= self['SIZE'] %> - <% if self['FSTYPE'] != nil %> + <% if self['FSTYPE'] != nil and !self['FSTYPE'].empty? %> <%= self['FSTYPE'] %> <% end %> <%= self['PUBLIC'] == "0" ? "NO" : "YES"%> From 6d0b58da21363b1c091a74ccc1a268f37a48342b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Wed, 7 Dec 2011 19:18:38 +0100 Subject: [PATCH 115/121] onedb migrator to 3.1.80: Improvements, better handling of new VLAN attribute for VNETs --- src/onedb/3.1.0_to_3.1.80.rb | 110 +++++++++++++++++++++++++++++++---- 1 file changed, 99 insertions(+), 11 deletions(-) diff --git a/src/onedb/3.1.0_to_3.1.80.rb b/src/onedb/3.1.0_to_3.1.80.rb index 5a27679015..5644157197 100644 --- a/src/onedb/3.1.0_to_3.1.80.rb +++ b/src/onedb/3.1.0_to_3.1.80.rb @@ -28,13 +28,42 @@ module Migrator end def up - puts " > Networking isolation hooks have been moved to Host drivers.\n"<< - " If you were using a networking hook, enter its name, or press enter\n"<< - " to use the default dummy vn_mad driver.\n\n" - print " Driver name (802.1Q, dummy, ebtables, ovswitch): " - vn_mad = gets.chomp + puts " > Networking isolation hooks have been moved to Host drivers.\n"<< + " If you were using a networking hook, enter its name, or press enter\n"<< + " to use the default dummy vn_mad driver.\n\n" - vn_mad = "dummy" if vn_mad.empty? + vn_mad = "" + + while !( ["802.1Q", "dummy", "ebtables", "ovswitch"].include?(vn_mad) ) do + print " Driver name (802.1Q, dummy, ebtables, ovswitch): " + vn_mad = gets.chomp + vn_mad = "dummy" if vn_mad.empty? + end + + # 0 = all, 1 = none, 2 = interactive + vlan_option = 1 + + if ( vn_mad == "ebtables" || vn_mad == "ovswitch" ) + puts + puts " > A new attribute, VLAN = YES/NO will be added to each VNET.\n"<< + " For driver '#{vn_mad}', please choose if you want to isolate all networks (all),\n"<< + " none (none), or be asked individually for each VNET (interactive)\n" + + vlan = "" + while !( ["all", "none", "interactive"].include?(vlan) ) do + print " Isolate VNETs (all, none, interactive): " + vlan = gets.chomp + end + + case vlan + when "all" + vlan_option = 0 + when "none" + vlan_option = 1 + when "interactive" + vlan_option = 2 + end + end # New VN_MAD element for hosts @@ -80,7 +109,19 @@ module Migrator net_address = e.text } - net_address = IPAddr.new(net_address, Socket::AF_INET) + net_valid = false + while !net_valid do + begin + net_address = IPAddr.new(net_address, Socket::AF_INET) + net_valid = true + rescue ArgumentError + puts + puts " > Error processing VNET ##{row[:oid]} '#{row[:name]}'\n"<< + " This network address is invalid: '#{net_address}'\n" + print " Please enter a valid network address: " + net_address = gets.chomp + end + end st_size = "" @@ -98,18 +139,44 @@ module Migrator size = st_size.to_i host_bits = (Math.log(size+2)/Math.log(2)).ceil end - + net_mask = 0xFFFFFFFF << host_bits net_address = net_address.to_i & net_mask - ip_start_elem.text = IPAddr.new((ip_start = net_address + 1), Socket::AF_INET).to_s + ip_start_elem.text = IPAddr.new((net_address + 1), Socket::AF_INET).to_s ip_end_elem.text = IPAddr.new((net_address + (1 << host_bits) - 2), Socket::AF_INET).to_s end - # TODO: Set vlan = 1 if PHYDEV is set + phydev_present = false + doc.root.each_element("PHYDEV") { |e| + phydev_present = true + } + vlan_elem = doc.root.add_element("VLAN") - vlan_elem.text = "0" + + if phydev_present + vlan_elem.text = "1" + else + case vlan_option + when 0 + vlan_elem.text = "1" + when 1 + vlan_elem.text = "0" + when 2 + vlan = "" + while !( ["y", "n"].include?(vlan) ) do + print " > Isolate VNET ##{row[:oid]} '#{row[:name]}'? (y/n) : " + vlan = gets.chomp + end + + if ( vlan == "y" ) + vlan_elem.text = "1" + else + vlan_elem.text = "0" + end + end + end @db[:network_pool].insert( :oid => row[:oid], @@ -122,6 +189,27 @@ module Migrator @db.run "DROP TABLE old_network_pool;" + # Add empty HISTORY_RECORDS element to VMs without any records + @db.run "ALTER TABLE vm_pool RENAME TO old_vm_pool;" + @db.run "CREATE TABLE vm_pool (oid INTEGER PRIMARY KEY, name VARCHAR(128), body TEXT, uid INTEGER, gid INTEGER, last_poll INTEGER, state INTEGER, lcm_state INTEGER);" + @db.run "INSERT INTO vm_pool SELECT * FROM old_vm_pool;" + + @db.fetch("SELECT * FROM old_vm_pool") do |row| + doc = Document.new(row[:body]) + + found = false + doc.root.each_element("HISTORY_RECORDS") { |e| + found = true + } + + if !found + doc.root.add_element("HISTORY_RECORDS") + end + end + + @db.run "DROP TABLE old_vm_pool;" + + return true end end From 10e52c413c7c94533669c48fc93d1b9a9eef8696 Mon Sep 17 00:00:00 2001 From: Daniel Molina Date: Thu, 8 Dec 2011 00:08:18 +0100 Subject: [PATCH 116/121] Add network.erb for OCCI --- src/cloud/occi/etc/templates/network.erb | 25 ++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/cloud/occi/etc/templates/network.erb diff --git a/src/cloud/occi/etc/templates/network.erb b/src/cloud/occi/etc/templates/network.erb new file mode 100644 index 0000000000..6dfb23079a --- /dev/null +++ b/src/cloud/occi/etc/templates/network.erb @@ -0,0 +1,25 @@ +# +# This template is processed by the OCCI Server to include specific data for +# the VNET, you should not need to modify the ruby code. +# You can add common attributes for your VNET templates (e.g. VLAN, PHYDEV) +# + +NAME = "<%= @vnet_info['NAME'] %>" +TYPE = RANGED + +NETWORK_ADDRESS = <%= @vnet_info['ADDRESS'] %> +<% if @vnet_info['SIZE'] != nil %> +NETWORK_SIZE = <%= @vnet_info['SIZE']%> +<% end %> + +<% if @vnet_info['DESCRIPTION'] != nil %> +DESCRIPTION = "<%= @vnet_info['DESCRIPTION'] %>" +<% end %> + +<% if @vnet_info['PUBLIC'] != nil %> +PUBLIC = "<%= @vnet_info['PUBLIC'] %>" +<% end %> + +#BRIDGE = NAME_OF_DEFAULT_BRIDGE +#PHYDEV = NAME_OF_PHYSICAL_DEVICE +#VLAN = YES|NO From dca599c5dc54bcbb51e1852543f496f063eef8e8 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Thu, 8 Dec 2011 00:29:05 +0100 Subject: [PATCH 117/121] feature #863: Make use of action_info to pass extra parameters to net drivers --- src/vmm_mad/exec/one_vmm_exec.rb | 14 +++++--------- src/vnm_mad/one_vnm.rb | 10 ++++++---- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/vmm_mad/exec/one_vmm_exec.rb b/src/vmm_mad/exec/one_vmm_exec.rb index ffd1bd6069..960d877065 100755 --- a/src/vmm_mad/exec/one_vmm_exec.rb +++ b/src/vmm_mad/exec/one_vmm_exec.rb @@ -72,16 +72,14 @@ class VmmAction @vnm_src = VirtualNetworkDriver.new(@data[:net_drv], :local_actions => @vmm.options[:local_actions], :message => @xml_data, - :ssh_stream => @ssh_src, - :extra_data => @data) + :ssh_stream => @ssh_src) if @data[:dest_host] and !@data[:dest_host].empty? @ssh_dst = @vmm.get_ssh_stream(@data[:dest_host], @id) @vnm_dst = VirtualNetworkDriver.new(@data[:dest_driver], :local_actions => @vmm.options[:local_actions], :message => @xml_data, - :ssh_stream => @ssh_dst, - :extra_data => @data) + :ssh_stream => @ssh_dst) end end @@ -149,7 +147,8 @@ class VmmAction vnm = @vnm_src end - result, info = vnm.do_action(@id, step[:action]) + result, info = vnm.do_action(@id, step[:action], + :parameters => get_parameters(step[:parameters])) else result = DriverExecHelper.const_get(:RESULT)[:failure] info = "No driver in #{step[:action]}" @@ -157,7 +156,6 @@ class VmmAction # Save the step info @data["#{step[:action]}_info".to_sym] = info - @data[step[:save_info_as]] = info if step[:save_info_as] # Roll back steps, store failed info and break steps if DriverExecHelper.failed?(result) @@ -280,12 +278,12 @@ class ExecDriver < VirtualMachineDriver :action => :deploy, :parameters => [dfile, :host], :stdin => domain, - :save_info_as => :deploy_id }, # Execute post-boot networking setup { :driver => :vnm, :action => :post, + :parameters => [:deploy_info] :fail_actions => [ { :driver => :vmm, @@ -496,5 +494,3 @@ exec_driver = ExecDriver.new(hypervisor, :local_actions => local_actions) exec_driver.start_driver - - diff --git a/src/vnm_mad/one_vnm.rb b/src/vnm_mad/one_vnm.rb index 23dba5a34e..30c886e97a 100644 --- a/src/vnm_mad/one_vnm.rb +++ b/src/vnm_mad/one_vnm.rb @@ -31,7 +31,6 @@ class VirtualNetworkDriver @options = options @ssh_stream = options[:ssh_stream] @message = options[:message] - @extra_data = options[:extra_data] @vm_encoded = Base64.encode64(@message.elements['VM'].to_s).delete("\n") @@ -45,14 +44,17 @@ class VirtualNetworkDriver # @param [String, Symbol] aname name of the action # @param [Hash] ops extra options for the command # @option ops [String] :stdin text to be writen to stdin + # @option ops [String] :parameters additional parameters for vnm action def do_action(id, aname, ops = {}) options={ - :stdin => nil, + :stdin => nil, + :parameters => nil }.merge(ops) - deploy_id=@extra_data[:deploy_id] || '-' + cmd_params = "#{@vm_encoded}" + cmd_params << " #{options[:parameters]}" if options[:parameters] - cmd = action_command_line(aname, "#{@vm_encoded} #{deploy_id}") + cmd = action_command_line(aname, cmd_params) if action_is_local?(aname) execution = LocalCommand.run(cmd, log_method(id)) From 9bbbd291f6fb945d40c1f4f90f8e21659ade5aae Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Thu, 8 Dec 2011 03:39:52 +0100 Subject: [PATCH 118/121] Add network.erb to install.sh --- install.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/install.sh b/install.sh index 1e75815fd8..3d4e4e933d 100755 --- a/install.sh +++ b/install.sh @@ -959,6 +959,7 @@ OCCI_ETC_TEMPLATE_FILES="src/cloud/occi/etc/templates/common.erb \ src/cloud/occi/etc/templates/custom.erb \ src/cloud/occi/etc/templates/small.erb \ src/cloud/occi/etc/templates/medium.erb \ + src/cloud/occi/etc/templates/network.erb \ src/cloud/occi/etc/templates/large.erb" #----------------------------------------------------------------------------- From 1da7f8be130b041d5c771c24173301ae43298c26 Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Thu, 8 Dec 2011 22:49:05 +0100 Subject: [PATCH 119/121] add net-ldap to install_gems, needed by ldap auth --- share/install_gems/install_gems | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/share/install_gems/install_gems b/share/install_gems/install_gems index e2c37f9ccf..3b85b5069c 100755 --- a/share/install_gems/install_gems +++ b/share/install_gems/install_gems @@ -2,7 +2,7 @@ require 'pp' -DEFAULT=%w{optional sunstone quota cloud ozones_server acct} +DEFAULT=%w{optional sunstone quota cloud ozones_server acct auth_ldap} if defined?(RUBY_VERSION) && RUBY_VERSION>="1.8.7" SQLITE='sqlite3' @@ -31,7 +31,8 @@ GROUPS={ :ozones_server_mysql => %w{json data_mapper dm-mysql-adapter mysql}, :acct => ['sequel', SQLITE, 'mysql'], :acct_sqlite => ['sequel', SQLITE], - :acct_mysql => ['sequel', 'mysql'] + :acct_mysql => ['sequel', 'mysql'], + :auth_ldap => 'net-ldap' } PACKAGES=GROUPS.keys From 67a594474e574519faa5946acd6893417bee7984 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Fri, 9 Dec 2011 16:51:56 +0100 Subject: [PATCH 120/121] feature #863: fixes bug --- src/vmm_mad/exec/one_vmm_exec.rb | 2 +- src/vnm_mad/remotes/test/output/onevm_show_xen | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/vmm_mad/exec/one_vmm_exec.rb b/src/vmm_mad/exec/one_vmm_exec.rb index 960d877065..324542ac89 100755 --- a/src/vmm_mad/exec/one_vmm_exec.rb +++ b/src/vmm_mad/exec/one_vmm_exec.rb @@ -283,7 +283,7 @@ class ExecDriver < VirtualMachineDriver { :driver => :vnm, :action => :post, - :parameters => [:deploy_info] + :parameters => [:deploy_info], :fail_actions => [ { :driver => :vmm, diff --git a/src/vnm_mad/remotes/test/output/onevm_show_xen b/src/vnm_mad/remotes/test/output/onevm_show_xen index 9f0685ad44..4952762493 100644 --- a/src/vnm_mad/remotes/test/output/onevm_show_xen +++ b/src/vnm_mad/remotes/test/output/onevm_show_xen @@ -34,7 +34,7 @@ - + From bcd9281b638c7f1a5c813d9b64d66c1a6ca7432b Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Sat, 10 Dec 2011 21:08:03 +0100 Subject: [PATCH 121/121] bug: solve reference by name in CONTEXT attribute for name and virtual network --- src/vm/vm_var_syntax.cc | 42 +++++++++++++++++++---------------------- src/vm/vm_var_syntax.h | 2 +- src/vm/vm_var_syntax.y | 20 ++++++++------------ 3 files changed, 28 insertions(+), 36 deletions(-) diff --git a/src/vm/vm_var_syntax.cc b/src/vm/vm_var_syntax.cc index 6a75d06320..a8b665169b 100644 --- a/src/vm/vm_var_syntax.cc +++ b/src/vm/vm_var_syntax.cc @@ -146,7 +146,6 @@ void get_image_attribute(VirtualMachine * vm, ImagePool * ipool = nd.get_ipool(); Image * img; int iid = -1; - string iid_str; int num; vector attrs; @@ -154,7 +153,7 @@ void get_image_attribute(VirtualMachine * vm, attr_value.clear(); - if (img_name.empty() || img_name != "IMAGE_ID") + if ( img_name.empty() || (img_name!="IMAGE" && img_name!="IMAGE_ID") ) { return; } @@ -174,11 +173,10 @@ void get_image_attribute(VirtualMachine * vm, continue; } - iid_str = disk->vector_value("IMAGE_ID"); - - if ( iid_str == img_value ) + if ( disk->vector_value(img_name.c_str()) == img_value ) { - istringstream iss(img_value); + string iid_str = disk->vector_value("IMAGE_ID"); + istringstream iss(iid_str); iss >> iid; @@ -232,7 +230,6 @@ void get_network_attribute(VirtualMachine * vm, VirtualNetworkPool * vnpool = nd.get_vnpool(); VirtualNetwork * vn; int vnet_id = -1; - string vnet_id_str; int num; vector attrs; @@ -240,7 +237,7 @@ void get_network_attribute(VirtualMachine * vm, attr_value.clear(); - if (net_name.empty() || net_name != "NETWORK_ID") + if ( net_name.empty() || (net_name!="NETWORK" && net_name!="NETWORK_ID") ) { return; } @@ -260,11 +257,10 @@ void get_network_attribute(VirtualMachine * vm, continue; } - vnet_id_str = net->vector_value("NETWORK_ID"); - - if ( vnet_id_str == net_value ) + if ( net->vector_value(net_name.c_str()) == net_value ) { - istringstream iss(net_value); + string vnet_id_str = net->vector_value("NETWORK_ID"); + istringstream iss(vnet_id_str); iss >> vnet_id; @@ -460,7 +456,7 @@ void insert_vector(VirtualMachine * vm, /* Line 268 of yacc.c */ -#line 464 "vm_var_syntax.cc" +#line 460 "vm_var_syntax.cc" /* Enabling traces. */ #ifndef YYDEBUG @@ -506,7 +502,7 @@ typedef union YYSTYPE { /* Line 293 of yacc.c */ -#line 408 "vm_var_syntax.y" +#line 404 "vm_var_syntax.y" char * val_str; int val_int; @@ -515,7 +511,7 @@ typedef union YYSTYPE /* Line 293 of yacc.c */ -#line 519 "vm_var_syntax.cc" +#line 515 "vm_var_syntax.cc" } YYSTYPE; # define YYSTYPE_IS_TRIVIAL 1 # define yystype YYSTYPE /* obsolescent; will be withdrawn */ @@ -540,7 +536,7 @@ typedef struct YYLTYPE /* Line 343 of yacc.c */ -#line 544 "vm_var_syntax.cc" +#line 540 "vm_var_syntax.cc" #ifdef short # undef short @@ -830,7 +826,7 @@ static const yytype_int8 yyrhs[] = /* YYRLINE[YYN] -- source line where rule number YYN was defined. */ static const yytype_uint16 yyrline[] = { - 0, 432, 432, 433, 436, 440, 453, 468 + 0, 428, 428, 429, 432, 436, 449, 464 }; #endif @@ -1831,7 +1827,7 @@ yyreduce: case 4: /* Line 1806 of yacc.c */ -#line 437 "vm_var_syntax.y" +#line 433 "vm_var_syntax.y" { (*parsed) << (yyvsp[(1) - (1)].val_str); } @@ -1840,7 +1836,7 @@ yyreduce: case 5: /* Line 1806 of yacc.c */ -#line 441 "vm_var_syntax.y" +#line 437 "vm_var_syntax.y" { string name((yyvsp[(1) - (2)].val_str)); @@ -1858,7 +1854,7 @@ yyreduce: case 6: /* Line 1806 of yacc.c */ -#line 454 "vm_var_syntax.y" +#line 450 "vm_var_syntax.y" { string name((yyvsp[(1) - (5)].val_str)); string vname((yyvsp[(3) - (5)].val_str)); @@ -1878,7 +1874,7 @@ yyreduce: case 7: /* Line 1806 of yacc.c */ -#line 469 "vm_var_syntax.y" +#line 465 "vm_var_syntax.y" { string name((yyvsp[(1) - (9)].val_str)); string vname((yyvsp[(3) - (9)].val_str)); @@ -1901,7 +1897,7 @@ yyreduce: /* Line 1806 of yacc.c */ -#line 1905 "vm_var_syntax.cc" +#line 1901 "vm_var_syntax.cc" default: break; } /* User semantic actions sometimes alter yychar, and that requires @@ -2139,7 +2135,7 @@ yyreturn: /* Line 2067 of yacc.c */ -#line 487 "vm_var_syntax.y" +#line 483 "vm_var_syntax.y" extern "C" void vm_var__error( diff --git a/src/vm/vm_var_syntax.h b/src/vm/vm_var_syntax.h index d40f8d1d51..337bb45d68 100644 --- a/src/vm/vm_var_syntax.h +++ b/src/vm/vm_var_syntax.h @@ -56,7 +56,7 @@ typedef union YYSTYPE { /* Line 2068 of yacc.c */ -#line 408 "vm_var_syntax.y" +#line 404 "vm_var_syntax.y" char * val_str; int val_int; diff --git a/src/vm/vm_var_syntax.y b/src/vm/vm_var_syntax.y index bd75e41a02..027dade20e 100644 --- a/src/vm/vm_var_syntax.y +++ b/src/vm/vm_var_syntax.y @@ -85,7 +85,6 @@ void get_image_attribute(VirtualMachine * vm, ImagePool * ipool = nd.get_ipool(); Image * img; int iid = -1; - string iid_str; int num; vector attrs; @@ -93,7 +92,7 @@ void get_image_attribute(VirtualMachine * vm, attr_value.clear(); - if (img_name.empty() || img_name != "IMAGE_ID") + if ( img_name.empty() || (img_name!="IMAGE" && img_name!="IMAGE_ID") ) { return; } @@ -113,11 +112,10 @@ void get_image_attribute(VirtualMachine * vm, continue; } - iid_str = disk->vector_value("IMAGE_ID"); - - if ( iid_str == img_value ) + if ( disk->vector_value(img_name.c_str()) == img_value ) { - istringstream iss(img_value); + string iid_str = disk->vector_value("IMAGE_ID"); + istringstream iss(iid_str); iss >> iid; @@ -171,7 +169,6 @@ void get_network_attribute(VirtualMachine * vm, VirtualNetworkPool * vnpool = nd.get_vnpool(); VirtualNetwork * vn; int vnet_id = -1; - string vnet_id_str; int num; vector attrs; @@ -179,7 +176,7 @@ void get_network_attribute(VirtualMachine * vm, attr_value.clear(); - if (net_name.empty() || net_name != "NETWORK_ID") + if ( net_name.empty() || (net_name!="NETWORK" && net_name!="NETWORK_ID") ) { return; } @@ -199,11 +196,10 @@ void get_network_attribute(VirtualMachine * vm, continue; } - vnet_id_str = net->vector_value("NETWORK_ID"); - - if ( vnet_id_str == net_value ) + if ( net->vector_value(net_name.c_str()) == net_value ) { - istringstream iss(net_value); + string vnet_id_str = net->vector_value("NETWORK_ID"); + istringstream iss(vnet_id_str); iss >> vnet_id;
Leases information