From f6ce18bfb4f6d4064cb0ca3b0aa8fcca8c50bc45 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Thu, 10 Nov 2011 11:15:58 +0100 Subject: [PATCH 01/66] 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 02/66] 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 03/66] 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 04/66] 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 05/66] 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 06/66] 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 07/66] 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 08/66] 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 09/66] 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 10/66] 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 11/66] 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 12/66] 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 13/66] 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 14/66] 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 15/66] 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 16/66] 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 17/66] 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 18/66] 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 19/66] 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 20/66] 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 21/66] 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 22/66] 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 23/66] 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 24/66] 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 25/66] 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 26/66] 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 27/66] 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 28/66] 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 29/66] 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 30/66] 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 31/66] 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 32/66] 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 33/66] 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 34/66] 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 35/66] 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 36/66] 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 37/66] 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 38/66] 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 39/66] 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 40/66] 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 41/66] 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 42/66] 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 43/66] 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 44/66] 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 23e33e32003ea08cda38c66bc3df1be112c23afc Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Sat, 26 Nov 2011 01:12:24 +0100 Subject: [PATCH 45/66] 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 46/66] 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 47/66] 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 37debbf02ff5a2f2bbed162e013abab4111485e9 Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Mon, 28 Nov 2011 17:07:28 +0100 Subject: [PATCH 48/66] 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 c472c6c9f570add9a1032516ff321868f448551e Mon Sep 17 00:00:00 2001 From: Hector Sanjuan Date: Wed, 16 Nov 2011 16:36:35 +0100 Subject: [PATCH 49/66] 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 09fe832399d175dcb12884d4f817788ad3b03fd9 Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Tue, 29 Nov 2011 11:51:27 +0100 Subject: [PATCH 50/66] 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 51/66] 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 b2c04d65cdd9ddfd60862aad5f47e41346c0fd52 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Wed, 30 Nov 2011 22:56:30 +0100 Subject: [PATCH 52/66] 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 53/66] 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 1467190510a9014b0abf3413794f3f8b4e16b2a7 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Thu, 1 Dec 2011 19:29:46 +0100 Subject: [PATCH 54/66] 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 55/66] 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 56/66] 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 57/66] 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 58/66] 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 59/66] 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 7a11688738b9b02f7b7c1e2e8724b048dfdaff95 Mon Sep 17 00:00:00 2001 From: Jaime Melis Date: Fri, 2 Dec 2011 12:35:55 +0100 Subject: [PATCH 60/66] 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 61/66] 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 62/66] =?UTF-8?q?feature-#863:=20=C3Change=20arguments=20f?= =?UTF-8?q?or=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 63/66] 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 64/66] 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 65/66] 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 913374f022a811dda9f2bcf9a12ab6d3974c46b4 Mon Sep 17 00:00:00 2001 From: Jaime Melis Date: Fri, 2 Dec 2011 19:07:55 +0100 Subject: [PATCH 66/66] 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 @@ +