diff --git a/README.md b/README.md index ddd0e2410b..2480dac71f 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ distributed data center infrastructures. Complete documentation can be found at - http://opennebula.org/documentation:rel2.0 + http://opennebula.org/documentation:rel2.4 ## INSTALLATION @@ -111,7 +111,7 @@ where **install_options** can be one or more of: ## CONFIGURATION -Information on how to configure OpenNebula is located at http://opennebula.org/documentation:rel2.0 +Information on how to configure OpenNebula is located at http://opennebula.org/documentation:rel2.4 ## CONTACT diff --git a/SConstruct b/SConstruct index 3bf25cec2b..818ee83cfa 100644 --- a/SConstruct +++ b/SConstruct @@ -205,6 +205,7 @@ build_scripts=[ 'src/um/SConstruct', 'src/authm/SConstruct', 'src/xml/SConstruct', + 'share/man/SConstruct' ] # Testing diff --git a/include/Attribute.h b/include/Attribute.h index e5213333f1..d390e92ee7 100644 --- a/include/Attribute.h +++ b/include/Attribute.h @@ -39,6 +39,17 @@ public: attribute_name.end(), attribute_name.begin(), (int(*)(int))toupper); + + // FIX Attribute name if it does not conform XML element + // naming conventions + + int size = attribute_name.size(); + + if ((size >0 && !isalpha(aname[0]))|| + (size >=3 && (aname[0]=='X' && aname[1]=='M' && aname[2]=='L'))) + { + attribute_name.insert(0,"ONE_"); + } }; virtual ~Attribute(){}; diff --git a/include/AuthManager.h b/include/AuthManager.h index e456f02fee..0042d5d8a8 100644 --- a/include/AuthManager.h +++ b/include/AuthManager.h @@ -457,13 +457,6 @@ private: */ void do_action(const string &name, void *args){}; - /** - * Base 64 encoding - * @param in the string to encoded - * @return a pointer to the encoded string (must be freed) or 0 in case of - * error - */ - static string * base64_encode(const string& in); }; diff --git a/include/Image.h b/include/Image.h index 6e72bc0fb2..1ce8c795c8 100644 --- a/include/Image.h +++ b/include/Image.h @@ -103,6 +103,15 @@ public: return source; } + /** + * Returns the source path of the image + * @return source of image + */ + void set_source(const string& _source) + { + source = _source; + } + /** * Returns the type of the image * @return type @@ -250,14 +259,6 @@ public: */ int disk_attribute(VectorAttribute * disk, int* index, ImageType* img_type); - /** - * Generates the source path for the repository. - * @param uid of the image owner - * @param name of the image - * @return source for the image - */ - static string generate_source(int uid, const string& name); - private: // ------------------------------------------------------------------------- diff --git a/include/ImageManagerDriver.h b/include/ImageManagerDriver.h index 4844a3b68d..7a07c73350 100644 --- a/include/ImageManagerDriver.h +++ b/include/ImageManagerDriver.h @@ -70,12 +70,13 @@ private: */ //Template driver_conf; - void cp(int oid, const string& source, const string& destination) const; + void cp(int oid, const string& source) const; /** * Sends a move request to the MAD: "MV IMAGE_ID SRC_PATH DST_PATH" * @param oid the image id. - * @param destination is the path to the image to be created + * @param destination is a driver specific location or "-" if not + * initialized * @param size_mb of the image to be created */ void mv(int oid, const string& source, const string& destination) const; @@ -83,12 +84,10 @@ private: /** * Sends a make filesystem request to the MAD: "MKFS IMAGE_ID PATH SIZE_MB" * @param oid the image id. - * @param destination is the path to the image to be created * @param fs type * @param size_mb of the image to be created */ void mkfs(int oid, - const string& destination, const string& fs, const string& size_mb) const; /** diff --git a/include/ImagePool.h b/include/ImagePool.h index d319ff1dda..9dae46d2ed 100644 --- a/include/ImagePool.h +++ b/include/ImagePool.h @@ -39,7 +39,6 @@ class ImagePool : public PoolSQL public: ImagePool(SqlDB * db, - const string& _source_prefix, const string& _default_type, const string& _default_dev_prefix); @@ -146,11 +145,6 @@ public: */ void authorize_disk(VectorAttribute * disk, int uid, AuthRequest * ar); - static const string& source_prefix() - { - return _source_prefix; - }; - static const string& default_type() { return _default_type; @@ -165,10 +159,6 @@ private: //-------------------------------------------------------------------------- // Configuration Attributes for Images // ------------------------------------------------------------------------- - /** - * Path to the image repository - **/ - static string _source_prefix; /** * Default image type diff --git a/include/MySqlDB.h b/include/MySqlDB.h index b733020de2..a32cd03c31 100644 --- a/include/MySqlDB.h +++ b/include/MySqlDB.h @@ -43,11 +43,11 @@ class MySqlDB : public SqlDB { public: - MySqlDB(const string& server, - int port, - const string& user, - const string& password, - const char * database); + MySqlDB(const string& _server, + int _port, + const string& _user, + const string& _password, + const string& _database); ~MySqlDB(); @@ -81,6 +81,19 @@ private: */ MYSQL * db; + /** + * MySQL Connection parameters + */ + string server; + + int port; + + string user; + + string password; + + string database; + /** * Fine-grain mutex for DB access */ @@ -113,7 +126,7 @@ public: int port, string user, string password, - const char * database) + string database) { throw runtime_error("Aborting oned, MySQL support not compiled!"); }; diff --git a/include/Nebula.h b/include/Nebula.h index a677815583..e48209774e 100644 --- a/include/Nebula.h +++ b/include/Nebula.h @@ -37,7 +37,9 @@ #include "AuthManager.h" #include "ImageManager.h" -class Nebula +#include "Callbackable.h" + +class Nebula : public Callbackable { public: @@ -222,6 +224,11 @@ public: return "OpenNebula 2.3.0"; }; + static int db_version() + { + return 1; + }; + void start(); void get_configuration_attribute( @@ -424,6 +431,28 @@ private: // --------------------------------------------------------------- friend void nebula_signal_handler (int sig); + + /** + * Bootstraps the database control tables + */ + void bootstrap(); + + /** + * Callback function to TODO + * @param _loaded_db_version TODO + * @param num the number of columns read from the DB + * @param names the column names + * @param vaues the column values + * @return 0 on success + */ + int select_cb(void *_loaded_db_version, int num, char **values, + char **names); + + /* + * TODO + * @return 0 ok, -1 version mismatch, -2 needs bootstrap + */ + int check_db_version(); }; #endif /*NEBULA_H_*/ diff --git a/include/PoolObjectSQL.h b/include/PoolObjectSQL.h index 178370f928..5fedef7216 100644 --- a/include/PoolObjectSQL.h +++ b/include/PoolObjectSQL.h @@ -104,6 +104,14 @@ public: pthread_mutex_unlock(&mutex); }; + /** + * Function to print the object into a string in XML format + * base64 encoded + * @param xml the resulting XML string + * @return a reference to the generated string + */ + virtual string& to_xml64(string &xml64); + /** * Function to print the object into a string in XML format * @param xml the resulting XML string @@ -189,11 +197,10 @@ public: const string& name, const string& value) { - SingleAttribute * sattr; + SingleAttribute * sattr = new SingleAttribute(name,value); - obj_template->erase(name); + obj_template->erase(sattr->name()); - sattr = new SingleAttribute(name,value); obj_template->set(sattr); return 0; diff --git a/include/PoolSQL.h b/include/PoolSQL.h index fef4fee546..1031b9ca1f 100644 --- a/include/PoolSQL.h +++ b/include/PoolSQL.h @@ -47,7 +47,7 @@ public: * counter). If null the OID counter is not updated. * @param with_uid the Pool objects have an owner id (uid) */ - PoolSQL(SqlDB * _db, const char * table); + PoolSQL(SqlDB * _db, const char * _table); virtual ~PoolSQL(); @@ -189,6 +189,11 @@ private: */ int lastOID; + /** + * Tablename for this pool + */ + string table; + /** * The pool is implemented with a Map of SQL object pointers, using the * OID as key. @@ -253,6 +258,11 @@ private: return key.str(); }; + /** + * Inserts the last oid into the pool_control table + */ + void update_lastOID(); + /* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */ diff --git a/include/SSLTools.h b/include/SSLTools.h new file mode 100644 index 0000000000..8edef40653 --- /dev/null +++ b/include/SSLTools.h @@ -0,0 +1,51 @@ +/* ------------------------------------------------------------------------ */ +/* 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. */ +/* -------------------------------------------------------------------------*/ + +#ifndef SSL_TOOLS_H_ +#define SSL_TOOLS_H_ + +#include + +using namespace std; + +/** + * The SSLTools class provides a simple interface to common SSL utils used + * in OpenNebula + */ +class SSLTools +{ +public: + /** + * sha1 digest + * @param in the string to be hashed + * @return sha1 hash of str + */ + static string sha1_digest(const string& in); + + /** + * Base 64 encoding + * @param in the string to encoded + * @return a pointer to the encoded string (must be freed) or 0 in case of + * error + */ + static string * base64_encode(const string& in); + +private: + SSLTools(){}; + ~SSLTools(){}; +}; + +#endif /*SSL_TOOLS_H_*/ diff --git a/include/User.h b/include/User.h index be2acaecae..437dd28f87 100644 --- a/include/User.h +++ b/include/User.h @@ -94,13 +94,6 @@ public: **/ static int split_secret(const string secret, string& user, string& pass); - /** - * "Encrypts" the password with SHA1 digest - * @param password - * @return sha1 encrypted password - */ - static string sha1_digest(const string& pass); - private: // ------------------------------------------------------------------------- // Friends diff --git a/include/test/NebulaTest.h b/include/test/NebulaTest.h index 9078500764..52c551799d 100644 --- a/include/test/NebulaTest.h +++ b/include/test/NebulaTest.h @@ -97,7 +97,6 @@ public: virtual UserPool* create_upool(SqlDB* db); virtual ImagePool* create_ipool( SqlDB* db, - string repository_path, string default_image_type, string default_device_prefix); diff --git a/include/test/OneUnitTest.h b/include/test/OneUnitTest.h index e3a4823438..ff07a79775 100644 --- a/include/test/OneUnitTest.h +++ b/include/test/OneUnitTest.h @@ -57,7 +57,7 @@ public: if (mysql) { db = new MySqlDB( "localhost",0, - "oneadmin","oneadmin",NULL); + "oneadmin","oneadmin",db_name); ostringstream oss1; oss1 << "DROP DATABASE IF EXISTS " << db_name; diff --git a/install.sh b/install.sh index 7aab37d628..7e48aaa9d7 100755 --- a/install.sh +++ b/install.sh @@ -31,8 +31,8 @@ usage() { echo "Usage: install.sh [-u install_user] [-g install_group] [-k keep conf]" echo " [-d ONE_LOCATION] [-c occi|ec2] [-r] [-h]" echo - echo "-u: user that will run opennebula, defults to user executing install.sh" - echo "-g: group of the user that will run opennebula, defults to user" + echo "-u: user that will run opennebula, defaults to user executing install.sh" + echo "-g: group of the user that will run opennebula, defaults to user" echo " executing install.sh" echo "-k: keep configuration files of existing OpenNebula installation, useful" echo " when upgrading. This flag should not be set when installing" @@ -98,7 +98,7 @@ if [ -z "$ROOT" ] ; then LOCK_LOCATION="/var/lock/one" INCLUDE_LOCATION="/usr/include" SHARE_LOCATION="/usr/share/one" - MAN_LOCATION="/usr/share/man/man8" + MAN_LOCATION="/usr/share/man/man1" if [ "$CLIENT" = "yes" ]; then MAKE_DIRS="$BIN_LOCATION $LIB_LOCATION" @@ -133,7 +133,7 @@ else IMAGES_LOCATION="$VAR_LOCATION/images" INCLUDE_LOCATION="$ROOT/include" SHARE_LOCATION="$ROOT/share" - MAN_LOCATION="$ROOT/share/man/man8" + MAN_LOCATION="$ROOT/share/man/man1" if [ "$CLIENT" = "yes" ]; then MAKE_DIRS="$BIN_LOCATION $LIB_LOCATION" @@ -181,21 +181,13 @@ LIB_DIRS="$LIB_LOCATION/ruby \ $LIB_LOCATION/ruby/cloud/econe \ $LIB_LOCATION/ruby/cloud/econe/views \ $LIB_LOCATION/ruby/cloud/occi \ + $LIB_LOCATION/onedb \ $LIB_LOCATION/tm_commands \ $LIB_LOCATION/tm_commands/nfs \ $LIB_LOCATION/tm_commands/ssh \ $LIB_LOCATION/tm_commands/dummy \ $LIB_LOCATION/tm_commands/lvm \ $LIB_LOCATION/mads \ - $LIB_LOCATION/remotes \ - $LIB_LOCATION/remotes/im \ - $LIB_LOCATION/remotes/im/kvm.d \ - $LIB_LOCATION/remotes/im/xen.d \ - $LIB_LOCATION/remotes/im/ganglia.d \ - $LIB_LOCATION/remotes/vmm/xen \ - $LIB_LOCATION/remotes/vmm/kvm \ - $LIB_LOCATION/remotes/image \ - $LIB_LOCATION/remotes/image/fs \ $LIB_LOCATION/sh" VAR_DIRS="$VAR_LOCATION/remotes \ @@ -258,9 +250,11 @@ INSTALL_FILES=( LIB_FILES:$LIB_LOCATION RUBY_LIB_FILES:$LIB_LOCATION/ruby RUBY_OPENNEBULA_LIB_FILES:$LIB_LOCATION/ruby/OpenNebula + MAD_RUBY_LIB_FILES:$LIB_LOCATION/ruby + MAD_RUBY_LIB_FILES:$VAR_LOCATION/remotes MAD_SH_LIB_FILES:$LIB_LOCATION/sh - MAD_SH_LIB_FILES:$LIB_LOCATION/remotes MAD_SH_LIB_FILES:$VAR_LOCATION/remotes + ONEDB_MIGRATOR_FILES:$LIB_LOCATION/onedb MADS_LIB_FILES:$LIB_LOCATION/mads IM_PROBES_FILES:$VAR_LOCATION/remotes/im IM_PROBES_KVM_FILES:$VAR_LOCATION/remotes/im/kvm.d @@ -272,23 +266,13 @@ INSTALL_FILES=( VMM_SSH_XEN_KVM_POLL:$VAR_LOCATION/remotes/vmm/xen/poll VMM_SSH_GANGLIA_POLL:$VAR_LOCATION/remotes/vmm/kvm/poll_local VMM_SSH_GANGLIA_POLL:$VAR_LOCATION/remotes/vmm/xen/poll_local - IM_PROBES_FILES:$LIB_LOCATION/remotes/im - IM_PROBES_KVM_FILES:$LIB_LOCATION/remotes/im/kvm.d - IM_PROBES_XEN_FILES:$LIB_LOCATION/remotes/im/xen.d - IM_PROBES_GANGLIA_FILES:$LIB_LOCATION/remotes/im/ganglia.d - VMM_SSH_KVM_SCRIPTS:$LIB_LOCATION/remotes/vmm/kvm - VMM_SSH_XEN_SCRIPTS:$LIB_LOCATION/remotes/vmm/xen - VMM_SSH_XEN_KVM_POLL:$LIB_LOCATION/remotes/vmm/kvm/poll - VMM_SSH_XEN_KVM_POLL:$LIB_LOCATION/remotes/vmm/xen/poll - VMM_SSH_GANGLIA_POLL:$LIB_LOCATION/remotes/vmm/kvm/poll_local - VMM_SSH_GANGLIA_POLL:$LIB_LOCATION/remotes/vmm/xen/poll_local NFS_TM_COMMANDS_LIB_FILES:$LIB_LOCATION/tm_commands/nfs SSH_TM_COMMANDS_LIB_FILES:$LIB_LOCATION/tm_commands/ssh DUMMY_TM_COMMANDS_LIB_FILES:$LIB_LOCATION/tm_commands/dummy LVM_TM_COMMANDS_LIB_FILES:$LIB_LOCATION/tm_commands/lvm - IMAGE_DRIVER_FS_SCRIPTS:$LIB_LOCATION/remotes/image/fs IMAGE_DRIVER_FS_SCRIPTS:$VAR_LOCATION/remotes/image/fs EXAMPLE_SHARE_FILES:$SHARE_LOCATION/examples + INSTALL_NOVNC_SHARE_FILE:$SHARE_LOCATION TM_EXAMPLE_SHARE_FILES:$SHARE_LOCATION/examples/tm HOOK_SHARE_FILES:$SHARE_LOCATION/hooks COMMON_CLOUD_LIB_FILES:$LIB_LOCATION/ruby/cloud @@ -350,6 +334,7 @@ INSTALL_ETC_FILES=( ECO_ETC_TEMPLATE_FILES:$ETC_LOCATION/ec2query_templates OCCI_ETC_FILES:$ETC_LOCATION OCCI_ETC_TEMPLATE_FILES:$ETC_LOCATION/occi_templates + SUNSTONE_ETC_FILES:$ETC_LOCATION ) #------------------------------------------------------------------------------- @@ -365,6 +350,7 @@ BIN_FILES="src/nebula/oned \ src/cli/oneimage \ src/cli/onecluster \ src/cli/onetemplate \ + src/cli/onedb \ share/scripts/one \ src/authm_mad/oneauth" @@ -415,11 +401,12 @@ RUBY_OPENNEBULA_LIB_FILES="src/oca/ruby/OpenNebula/Host.rb \ #----------------------------------------------------------------------------- -# MAD ShellScript library files, to be installed under $LIB_LOCATION/sh +# MAD Script library files, to be installed under $LIB_LOCATION/'; + document.write(script); +} +loadVNC(); var vms_tab_content = '
\ @@ -32,6 +38,7 @@ var vms_tab_content = Memory\ Hostname\ Start Time\ + VNC Access\ \ \ \ @@ -59,6 +66,7 @@ var create_vm_tmpl ='\ var vmachine_list_json = {}; var dataTable_vMachines; +var rfb; var vm_actions = { "VM.create" : { @@ -236,12 +244,20 @@ var vm_actions = { {data:obj, success: function (req) { Sunstone.runAction("VM.show", - req.request.data[0]); + req.request.data[0][0]); }, error: onError }); } }, - + + "VM.saveas_disks" : { + type: "single", + call: OpenNebula.VM.show, + callback: saveasDisksCallback, + error: onError, + notify: false + }, + "VM.shutdown" : { type: "multiple", call: OpenNebula.VM.shutdown, @@ -281,13 +297,14 @@ var vm_actions = { //update the tab and pop it up again var log_lines = res.split("\n"); var colored_log = ''; - for (line in log_lines){ - line = log_lines[line]; + for (var i = 0; i < log_lines.length;i++){ + var line = log_lines[i]; if (line.match(/\[E\]/)){ - line = ''+line+'' + line = ''+line+''; } colored_log += line + "\n"; } + var log_tab = { title: "VM log", content: '
'+colored_log+'
' @@ -300,6 +317,22 @@ var vm_actions = { $("#vm_log pre").html(''); onError(request,error_json); } + }, + + "VM.startvnc" : { + type: "single", + call: OpenNebula.VM.startvnc, + callback: vncCallback, + error: onError, + notify: true + }, + + "VM.stopvnc" : { + type: "single", + call: OpenNebula.VM.stopvnc, + callback: null, + error: onError, + notify: true } } @@ -467,6 +500,8 @@ function vMachineElementArray(vm_json){ if (state == "ACTIVE") { state = OpenNebula.Helper.resource_state("vm_lcm",vm.LCM_STATE); } + + return [ '', vm.ID, @@ -476,7 +511,8 @@ function vMachineElementArray(vm_json){ vm.CPU, humanize_size(vm.MEMORY), vm.HISTORY ? vm.HISTORY.HOSTNAME : "--", - str_start_time(vm) + str_start_time(vm), + vncIcon(vm) ] } @@ -485,7 +521,7 @@ function vMachineElementArray(vm_json){ function vMachineInfoListener(){ $('#tbodyvmachines tr').live("click", function(e){ - if ($(e.target).is('input')) {return true;} + if ($(e.target).is('input') || $(e.target).is('a img')) {return true;} popDialogLoading(); var aData = dataTable_vMachines.fnGetData(this); var id = $(aData[0]).val(); @@ -511,8 +547,6 @@ function addVMachineElement(request,vm_json){ var id = vm_json.VM.ID; var element = vMachineElementArray(vm_json); addElement(element,dataTable_vMachines); - //Popup info panel after creation. - updateVMInfo(null,vm_json); } @@ -584,6 +618,10 @@ function updateVMInfo(request,vm){ Used CPU\ '+vm_info.CPU+'\ \ + \ + VNC Session\ + '+vncIcon(vm_info)+'\ + \ ' } @@ -659,10 +697,10 @@ function setupSaveasDialog(){ \
\
\ -
\ - \ - \ -
\ +
\ + \ + \ +
\ \
'); @@ -681,7 +719,7 @@ function setupSaveasDialog(){ var id = $('#vm_id',this).text(); var disk_id = $('#vm_disk_id',this).val(); var image_name = $('#image_name',this).val(); - var type = $('#image_type',this).val(); + //var type = $('#image_type',this).val(); if (!id.length || !disk_id.length || !image_name.length) { notifyError("Skipping VM "+id+ @@ -691,8 +729,8 @@ function setupSaveasDialog(){ var obj = { vm_id: id, disk_id : disk_id, - image_name : image_name, - type: type + image_name : image_name + //type: type }; args.push(id); Sunstone.runAction("VM.saveas",obj); @@ -725,35 +763,68 @@ function popUpSaveasDialog(elems){
Saveas for VM with ID '+this+'
\
\
\ - \ - \ + \ + \
\
\ \ \
\ + \
\ '; $('#saveas_vm_dialog #saveas_tabs').append(tab); + Sunstone.runAction("VM.saveas_disks",this); }); $('#saveas_vm_dialog #saveas_tabs').tabs(); $('#saveas_vm_dialog button').button(); - $('#saveas_vm_dialog').dialog('open'); } +function saveasDisksCallback(req,response){ + var vm_info = response.VM; + var id=vm_info.ID; + var select=""; + + var gen_option = function(id, name, source){ + if (name){ + return ''; + } + else { + return ''; + } + } + + var disks = vm_info.TEMPLATE.DISK; + if (!disks) { select = '';} + else if (disks.constructor == Array) //several disks + { + for (var i=0;i'); + + $('#vnc_dialog').html('\ +
\ + \ + \ + \ +
Loading
\ + \ +
\ +
\ + \ + Canvas not supported.\ + \ + '); + + $('#sendCtrlAltDelButton').click(function(){ + rfb.sendCtrlAltDel(); + return false; + }); + + $('#vnc_dialog').dialog({ + autoOpen:false, + width:700, + modal:true, + height:500, + resizable:true, + }); + + $( "#vnc_dialog" ).bind( "dialogclose", function(event, ui) { + var id = $("#vnc_dialog").attr("vm_id"); + Sunstone.runAction("VM.stopvnc",id); + + }); + + $('.vnc').live("click",function(){ + //Which VM is it? + var id = $(this).attr("vm_id"); + //Set attribute to dialog + $('#vnc_dialog').attr("vm_id",id); + //Request proxy server start + Sunstone.runAction("VM.startvnc",id); + return false; + }); + +} + +function vncCallback(request,response){ + rfb = new RFB({'target': $D('VNC_canvas'), + 'encrypt': false, + 'true_color': true, + 'local_cursor': true, + 'shared': true, + 'updateState': updateVNCState}); + //fetch things from clicked element host - port - password + vnc_port = response["port"]; + + //Hopefully this is returning sunstone server address, where + //the proxy is running + vnc_host = window.location.hostname; + vnc_pw = response["password"]; + + setTimeout(function(){ + rfb.connect(vnc_host, vnc_port, vnc_pw); + $('#vnc_dialog').dialog('open'); + },4000); + + + +} + +function vncIcon(vm){ + var graphics = vm.TEMPLATE.GRAPHICS; + var state = OpenNebula.Helper.resource_state("vm_lcm",vm.LCM_STATE); + var gr_icon; + if (graphics && graphics.TYPE == "vnc" && state == "RUNNING"){ + gr_icon = ''; + gr_icon += 'Open VNC Session'; + } + else { + gr_icon = 'VNC Disabled'; + } + return gr_icon; + +} + // At this point the DOM is ready and the sunstone.js ready() has been run. $(document).ready(function(){ @@ -776,7 +972,7 @@ $(document).ready(function(){ "aoColumnDefs": [ { "bSortable": false, "aTargets": ["check"] }, { "sWidth": "60px", "aTargets": [0] }, - { "sWidth": "35px", "aTargets": [1] }, + { "sWidth": "35px", "aTargets": [1,9] }, { "sWidth": "100px", "aTargets": [2] } ] }); @@ -784,12 +980,13 @@ $(document).ready(function(){ dataTable_vMachines.fnClearTable(); addElement([ spinner, - '','','','','','','',''],dataTable_vMachines); + '','','','','','','','',''],dataTable_vMachines); Sunstone.runAction("VM.list"); setupCreateVMDialog(); setupSaveasDialog(); setVMAutorefresh(); + setupVNC(); initCheckAllBoxes(dataTable_vMachines); tableCheckboxesListener(dataTable_vMachines); diff --git a/src/sunstone/public/js/plugins/vnets-tab.js b/src/sunstone/public/js/plugins/vnets-tab.js index da05b8a849..e5a66e37c6 100644 --- a/src/sunstone/public/js/plugins/vnets-tab.js +++ b/src/sunstone/public/js/plugins/vnets-tab.js @@ -308,7 +308,8 @@ function vNetworkInfoListener(){ //updates the vnet select different options function updateNetworkSelect(){ - vnetworks_select= makeSelectOptions(dataTable_vNetworks,1,3,6,"no") + vnetworks_select= + makeSelectOptions(dataTable_vNetworks,1,3,6,"no",2); //update static selectors: //in the VM creation dialog @@ -380,7 +381,7 @@ function updateVNetworkInfo(request,vn){ \ Leases information\ '+ - prettyPrintJSON(vn_info.LEASES)+ + prettyPrintJSON(vn_info.LEASES.LEASE)+ ''; } diff --git a/src/sunstone/public/js/sunstone-util.js b/src/sunstone/public/js/sunstone-util.js index 359f203aec..ca9ca9eabc 100644 --- a/src/sunstone/public/js/sunstone-util.js +++ b/src/sunstone/public/js/sunstone-util.js @@ -40,7 +40,7 @@ function pretty_time(time_seconds) var hour = pad(d.getHours(),2); var mins = pad(d.getMinutes(),2); var day = pad(d.getDate(),2); - var month = pad(d.getMonth(),2); + var month = pad(d.getMonth()+1,2); //getMonths returns 0-11 var year = d.getFullYear(); return hour + ":" + mins +":" + secs + " " + month + "/" + day + "/" + year; @@ -187,20 +187,87 @@ function notifyError(msg){ $.jGrowl(msg, {theme: "jGrowl-notify-error", sticky: true }); } +function notifyMessage(msg){ + msg = "

Info

" + msg; + + $.jGrowl(msg, {theme: "jGrowl-notify-submit"}); +} + // Returns an HTML string with the json keys and values in the form // key: value
-// It recursively explores objects, and flattens their contents in -// the result. -function prettyPrintJSON(template_json){ - var str = "" - for (field in template_json) { - if (typeof template_json[field] == 'object'){ - str += prettyPrintJSON(template_json[field]) + ''; - } else { - str += ''+field+''+template_json[field]+''; - }; - }; - return str; +// It recursively explores objects +function prettyPrintJSON(template_json,padding,weight, border_bottom,padding_top_bottom){ + var str = "" + if (!template_json){ return "Not defined";} + if (!padding) {padding=0}; + if (!weight) {weight="bold";} + if (!border_bottom) {border_bottom = "1px solid #CCCCCC";} + if (!padding_top_bottom) {padding_top_bottom=6;} + var field = null; + + if (template_json.constructor == Array){ + for (field = 0; field < template_json.length; ++field){ + str += prettyPrintRowJSON(field,template_json[field],padding,weight, border_bottom,padding_top_bottom); + } + } else { + for (field in template_json) { + str += prettyPrintRowJSON(field,template_json[field],padding,weight, border_bottom,padding_top_bottom); + } + } + return str; +} + +function prettyPrintRowJSON(field,value,padding,weight, border_bottom,padding_top_bottom){ + var str=""; + + if (typeof value == 'object'){ + //name of field row + str += '\ + ' + +field+ + '\ + \ + \ + '; + //attributes rows + //empty row - prettyprint - empty row + str += '\ + \ + \ + ' + + prettyPrintJSON(value,padding+25,"normal","0",1) + + '\ + \ + \ + '; + } else { + str += '\ + '+ + field+ + '\ + '+ + value+ + '\ + '; + }; + + return str; } //Add a listener to the check-all box of a datatable, enabling it to @@ -285,7 +352,7 @@ function onError(request,error_json) { var value; rows = ["method","action","object","id","reason"]; message = ""; - for (i in rows){ + for (i = 0; iPlease select"; var array; @@ -390,13 +461,23 @@ function makeSelectOptions(dataTable,id_col,name_col,status_col,status_bad){ var id = this[id_col]; var name = this[name_col]; var status = this[status_col]; - if (status != status_bad){ + var user = user_col > 0 ? this[user_col] : false; + var isMine = user ? (username == user) || (uid == user) : true; + + + if ((status != status_bad) || isMine ){ select +=''; } }); return select; } +//Escape " in a string and return it +function escapeDoubleQuotes(string){ + string = string.replace(/\\"/g,'"'); + return string.replace(/"/g,'\\"'); +} + //functions that used as true and false conditions for testing mainly function True(){ return true; diff --git a/src/sunstone/sunstone-server.rb b/src/sunstone/sunstone-server.rb index 0f8440a631..b614b24bfa 100755 --- a/src/sunstone/sunstone-server.rb +++ b/src/sunstone/sunstone-server.rb @@ -16,20 +16,40 @@ # limitations under the License. # #--------------------------------------------------------------------------- # +ONE_LOCATION = ENV["ONE_LOCATION"] + +if !ONE_LOCATION + LOG_LOCATION = "/var/log/one" + VAR_LOCATION = "/var/lib/one" + RUBY_LIB_LOCATION = "/usr/lib/one/ruby" + CONFIGURATION_FILE = "/etc/one/sunstone-server.conf" +else + VAR_LOCATION = ONE_LOCATION+"/var" + LOG_LOCATION = ONE_LOCATION+"/var" + RUBY_LIB_LOCATION = ONE_LOCATION+"/lib/ruby" + CONFIGURATION_FILE = ONE_LOCATION+"/etc/sunstone-server.conf" +end + +$: << RUBY_LIB_LOCATION +$: << File.dirname(__FILE__)+'/models' + ############################################################################## # Required libraries ############################################################################## require 'rubygems' require 'sinatra' -require 'models/SunstoneServer' +require 'cloud/Configuration' +require 'SunstoneServer' +set :config, Configuration.new(CONFIGURATION_FILE) ############################################################################## # Sinatra Configuration ############################################################################## use Rack::Session::Pool - +set :host, settings.config[:host] +set :port, settings.config[:port] ############################################################################## # Helpers @@ -163,6 +183,56 @@ post '/:pool' do @SunstoneServer.create_resource(params[:pool], request.body.read) end +############################################################################## +# Stop the VNC Session of a target VM +############################################################################## +post '/vm/:id/stopvnc' do + vm_id = params[:id] + vnc_hash = session['vnc'] + + if !vnc_hash || !vnc_hash[vm_id] + msg = "It seems there is no VNC proxy running for this machine" + return [403, OpenNebula::Error.new(msg).to_json] + end + + rc = @SunstoneServer.stopvnc(vm_id, vnc_hash[vm_id][:pipe]) + if rc[0] == 200 + session['vnc'].delete(vm_id) + end + + rc +end + +############################################################################## +# Start a VNC Session for a target VM +############################################################################## +post '/vm/:id/startvnc' do + vm_id = params[:id] + + vnc_hash = session['vnc'] + + if !vnc_hash + session['vnc']= {} + elsif vnc_hash[vm_id] + #return existing information + info = vnc_hash[vm_id].clone + info.delete(:pipe) + + return [200, info.to_json] + end + + rc = @SunstoneServer.startvnc(vm_id, settings.config) + if rc[0] == 200 + info = rc[1] + session['vnc'][vm_id] = info.clone + info.delete(:pipe) + + [200, info.to_json] + else + rc + end +end + ############################################################################## # Perform an action on a Resource ############################################################################## diff --git a/src/sunstone/templates/index.html b/src/sunstone/templates/index.html index e07d76051f..37560374d2 100644 --- a/src/sunstone/templates/index.html +++ b/src/sunstone/templates/index.html @@ -3,18 +3,21 @@ OpenNebula Admin Console - + + + + diff --git a/src/template/Template.cc b/src/template/Template.cc index eb5f8dd948..f880cf78c2 100644 --- a/src/template/Template.cc +++ b/src/template/Template.cc @@ -14,8 +14,6 @@ /* limitations under the License. */ /* -------------------------------------------------------------------------- */ -#include - #include "Template.h" #include "template_syntax.h" diff --git a/src/test/Nebula.cc b/src/test/Nebula.cc index ea1355ed8f..1324dff46e 100644 --- a/src/test/Nebula.cc +++ b/src/test/Nebula.cc @@ -144,7 +144,7 @@ void Nebula::start() log_location = nebula_location + "var/"; var_location = nebula_location + "var/"; hook_location = nebula_location + "share/hooks/"; - remotes_location = nebula_location + "lib/remotes/"; + remotes_location = nebula_location + "var/remotes/"; if ( nebula_configuration != 0) { @@ -183,7 +183,6 @@ void Nebula::start() { string mac_prefix = "00:00"; int size = 1; - string repository_path; string default_image_type; string default_device_prefix; @@ -210,7 +209,6 @@ void Nebula::start() if (tester->need_image_pool) { ipool = tester->create_ipool(db, - repository_path, default_image_type, default_device_prefix); } diff --git a/src/test/NebulaTest.cc b/src/test/NebulaTest.cc index 1b9f8ab4c8..c0a6b04808 100644 --- a/src/test/NebulaTest.cc +++ b/src/test/NebulaTest.cc @@ -41,12 +41,10 @@ UserPool* NebulaTest::create_upool(SqlDB* db) } ImagePool* NebulaTest::create_ipool( SqlDB* db, - string repository_path, string default_image_type, string default_device_prefix) { - return new ImagePool(db,repository_path,default_image_type, - default_device_prefix); + return new ImagePool(db,default_image_type,default_device_prefix); } ClusterPool* NebulaTest::create_cpool(SqlDB* db) diff --git a/src/tm_mad/lvm/tm_context.sh b/src/tm_mad/lvm/tm_context.sh index ee7fd40603..6d6aea06ab 100755 --- a/src/tm_mad/lvm/tm_context.sh +++ b/src/tm_mad/lvm/tm_context.sh @@ -52,7 +52,7 @@ exec_and_log "mkdir -p $ISO_DIR" for f in $SRC; do case $f in http://*) - exec_and_log "$WGET -O $ISO_DIR $f" + exec_and_log "$WGET -P $ISO_DIR $f" ;; *) diff --git a/src/tm_mad/nfs/tm_context.sh b/src/tm_mad/nfs/tm_context.sh index f211024f3d..db05f2dda0 100755 --- a/src/tm_mad/nfs/tm_context.sh +++ b/src/tm_mad/nfs/tm_context.sh @@ -48,7 +48,7 @@ exec_and_log "mkdir -p $ISO_DIR" for f in $SRC; do case $f in http://*) - exec_and_log "$WGET -O $ISO_DIR $f" \ + exec_and_log "$WGET -P $ISO_DIR $f" \ "Error downloading $f" ;; diff --git a/src/tm_mad/ssh/tm_context.sh b/src/tm_mad/ssh/tm_context.sh index 322ebdaf1b..d5c16f6721 100755 --- a/src/tm_mad/ssh/tm_context.sh +++ b/src/tm_mad/ssh/tm_context.sh @@ -53,7 +53,7 @@ exec_and_log "mkdir -p $ISO_DIR" \ for f in $SRC; do case $f in http://*) - exec_and_log "$WGET -O $ISO_DIR $f" \ + exec_and_log "$WGET -P $ISO_DIR $f" \ "Error downloading $f" ;; diff --git a/src/um/User.cc b/src/um/User.cc index 6721ac6f4d..d3c49c407c 100644 --- a/src/um/User.cc +++ b/src/um/User.cc @@ -20,8 +20,6 @@ #include #include - -#include #include #include "User.h" @@ -206,29 +204,3 @@ int User::split_secret(const string secret, string& user, string& pass) /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ -string User::sha1_digest(const string& pass) -{ - EVP_MD_CTX mdctx; - unsigned char md_value[EVP_MAX_MD_SIZE]; - unsigned int md_len; - ostringstream oss; - - EVP_MD_CTX_init(&mdctx); - EVP_DigestInit_ex(&mdctx, EVP_sha1(), NULL); - - EVP_DigestUpdate(&mdctx, pass.c_str(), pass.length()); - - EVP_DigestFinal_ex(&mdctx,md_value,&md_len); - EVP_MD_CTX_cleanup(&mdctx); - - for(unsigned int i = 0; i #include @@ -85,7 +86,7 @@ UserPool::UserPool(SqlDB * db):PoolSQL(db,User::table) if (User::split_secret(one_token,one_name,one_pass) == 0) { string error_str; - string sha1_pass = User::sha1_digest(one_pass); + string sha1_pass = SSLTools::sha1_digest(one_pass); allocate(&one_uid, one_name, sha1_pass, true, error_str); } diff --git a/src/um/test/UserPoolTest.cc b/src/um/test/UserPoolTest.cc index 9815c3d111..238a557e4d 100644 --- a/src/um/test/UserPoolTest.cc +++ b/src/um/test/UserPoolTest.cc @@ -20,6 +20,7 @@ #include "UserPool.h" #include "PoolTest.h" +#include "SSLTools.h" using namespace std; @@ -119,7 +120,7 @@ public: string st = "top_secret_string"; string sha1 = "773260f433f7fd6f89c1f1bfc32e080fc0748478"; - CPPUNIT_ASSERT( sha1 == User::sha1_digest(st) ); + CPPUNIT_ASSERT( sha1 == SSLTools::sha1_digest(st) ); } void split_secret() @@ -151,7 +152,7 @@ public: CPPUNIT_ASSERT( user->get_oid() == 0 ); CPPUNIT_ASSERT( user->get_name() == "one_user_test" ); - CPPUNIT_ASSERT( user->get_password() == User::sha1_digest("password") ); + CPPUNIT_ASSERT( user->get_password() == SSLTools::sha1_digest("password") ); } void authenticate() diff --git a/src/vm/VirtualMachineHook.cc b/src/vm/VirtualMachineHook.cc index 6283408b39..8d98e970e6 100644 --- a/src/vm/VirtualMachineHook.cc +++ b/src/vm/VirtualMachineHook.cc @@ -21,11 +21,36 @@ // ----------------------------------------------------------------------------- // ----------------------------------------------------------------------------- +static void parse_vm_arguments(VirtualMachine *vm, string& parsed) +{ + size_t found; + + found = parsed.find("$VMID"); + + if ( found !=string::npos ) + { + ostringstream oss; + oss << vm->get_oid(); + + parsed.replace(found,5,oss.str()); + } + + found = parsed.find("$TEMPLATE"); + + if ( found != string::npos ) + { + string templ; + parsed.replace(found,9,vm->to_xml64(templ)); + } +} + +// ----------------------------------------------------------------------------- +// ----------------------------------------------------------------------------- + void VirtualMachineAllocateHook::do_hook(void *arg) { VirtualMachine * vm; - int rc; - string parsed_args; + string parsed_args = args; vm = static_cast(arg); @@ -34,18 +59,15 @@ void VirtualMachineAllocateHook::do_hook(void *arg) return; } - rc = vm->parse_template_attribute(args, parsed_args); + parse_vm_arguments(vm, parsed_args); - if ( rc == 0) + Nebula& ne = Nebula::instance(); + HookManager * hm = ne.get_hm(); + const HookManagerDriver * hmd = hm->get(); + + if ( hmd != 0 ) { - Nebula& ne = Nebula::instance(); - HookManager * hm = ne.get_hm(); - const HookManagerDriver * hmd = hm->get(); - - if ( hmd != 0 ) - { - hmd->execute(vm->get_oid(),name,cmd,parsed_args); - } + hmd->execute(vm->get_oid(),name,cmd,parsed_args); } } @@ -143,29 +165,28 @@ void VirtualMachineStateHook::do_hook(void *arg) if ( cur_lcm == lcm && cur_vm == this->vm ) { - string parsed_args; + string parsed_args = args; - if ( vm->parse_template_attribute(args, parsed_args) == 0) + parse_vm_arguments(vm,parsed_args); + + Nebula& ne = Nebula::instance(); + HookManager * hm = ne.get_hm(); + + const HookManagerDriver * hmd = hm->get(); + + if ( hmd != 0 ) { - Nebula& ne = Nebula::instance(); - HookManager * hm = ne.get_hm(); - - const HookManagerDriver * hmd = hm->get(); - - if ( hmd != 0 ) + if ( ! remote ) { - if ( ! remote ) - { - hmd->execute(vm->get_oid(),name,cmd,parsed_args); - } - else if ( vm->hasHistory() ) - { - hmd->execute(vm->get_oid(), - name, - vm->get_hostname(), - cmd, - parsed_args); - } + hmd->execute(vm->get_oid(),name,cmd,parsed_args); + } + else if ( vm->hasHistory() ) + { + hmd->execute(vm->get_oid(), + name, + vm->get_hostname(), + cmd, + parsed_args); } } } diff --git a/src/vm/vm_var_parser.c b/src/vm/vm_var_parser.c index 62cc4142d7..b689e8673c 100644 --- a/src/vm/vm_var_parser.c +++ b/src/vm/vm_var_parser.c @@ -392,8 +392,8 @@ static void yy_fatal_error (yyconst char msg[] ); *yy_cp = '\0'; \ (yy_c_buf_p) = yy_cp; -#define YY_NUM_RULES 11 -#define YY_END_OF_BUFFER 12 +#define YY_NUM_RULES 12 +#define YY_END_OF_BUFFER 13 /* This struct is not used in this scanner, but its presence is necessary. */ struct yy_trans_info @@ -401,11 +401,12 @@ struct yy_trans_info flex_int32_t yy_verify; flex_int32_t yy_nxt; }; -static yyconst flex_int16_t yy_accept[30] = +static yyconst flex_int16_t yy_accept[34] = { 0, - 0, 0, 0, 0, 12, 10, 1, 9, 9, 11, - 9, 8, 3, 6, 2, 4, 5, 10, 0, 3, - 2, 5, 0, 7, 3, 6, 2, 4, 0 + 0, 0, 0, 0, 0, 0, 13, 11, 1, 10, + 10, 12, 9, 3, 6, 2, 4, 5, 12, 8, + 11, 0, 3, 2, 5, 3, 6, 2, 4, 0, + 7, 8, 0 } ; static yyconst flex_int32_t yy_ec[256] = @@ -419,7 +420,7 @@ static yyconst flex_int32_t yy_ec[256] = 8, 1, 1, 1, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, - 9, 1, 10, 1, 7, 1, 7, 7, 7, 7, + 9, 1, 10, 1, 11, 1, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, @@ -440,49 +441,52 @@ static yyconst flex_int32_t yy_ec[256] = 1, 1, 1, 1, 1 } ; -static yyconst flex_int32_t yy_meta[11] = +static yyconst flex_int32_t yy_meta[12] = { 0, - 1, 1, 1, 1, 2, 1, 1, 1, 1, 1 + 1, 1, 1, 1, 2, 1, 3, 1, 1, 1, + 3 } ; -static yyconst flex_int16_t yy_base[33] = +static yyconst flex_int16_t yy_base[39] = { 0, - 29, 28, 0, 0, 32, 0, 35, 35, 9, 35, - 27, 35, 28, 22, 26, 25, 35, 0, 0, 24, - 23, 35, 20, 35, 16, 9, 12, 11, 35, 19, - 11, 21 + 41, 40, 0, 0, 8, 12, 44, 0, 47, 47, + 18, 47, 47, 41, 0, 40, 39, 47, 32, 20, + 0, 0, 23, 21, 47, 20, 0, 19, 16, 13, + 47, 7, 47, 28, 31, 34, 10, 37 } ; -static yyconst flex_int16_t yy_def[33] = +static yyconst flex_int16_t yy_def[39] = { 0, - 30, 30, 29, 3, 29, 31, 29, 29, 29, 29, - 32, 29, 29, 29, 29, 29, 29, 31, 9, 29, - 29, 29, 32, 29, 29, 29, 29, 29, 0, 29, - 29, 29 + 34, 34, 33, 3, 35, 35, 33, 36, 33, 33, + 33, 33, 33, 33, 37, 33, 33, 33, 38, 33, + 36, 11, 33, 33, 33, 33, 37, 33, 33, 38, + 33, 33, 0, 33, 33, 33, 33, 33 } ; -static yyconst flex_int16_t yy_nxt[46] = +static yyconst flex_int16_t yy_nxt[59] = { 0, - 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, - 19, 18, 28, 27, 20, 26, 21, 25, 22, 6, - 6, 23, 23, 24, 27, 25, 28, 27, 26, 25, - 24, 29, 7, 7, 5, 29, 29, 29, 29, 29, - 29, 29, 29, 29, 29 + 10, 11, 12, 10, 13, 14, 15, 16, 17, 18, + 15, 19, 27, 32, 20, 19, 31, 29, 20, 22, + 28, 26, 28, 23, 26, 24, 32, 25, 8, 8, + 8, 12, 12, 12, 21, 31, 21, 30, 30, 30, + 29, 28, 26, 33, 9, 9, 7, 33, 33, 33, + 33, 33, 33, 33, 33, 33, 33, 33 } ; -static yyconst flex_int16_t yy_chk[46] = +static yyconst flex_int16_t yy_chk[59] = { 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 9, 31, 28, 27, 9, 26, 9, 25, 9, 30, - 30, 32, 32, 23, 21, 20, 16, 15, 14, 13, - 11, 5, 2, 1, 29, 29, 29, 29, 29, 29, - 29, 29, 29, 29, 29 + 3, 5, 37, 32, 5, 6, 30, 29, 6, 11, + 28, 26, 24, 11, 23, 11, 20, 11, 34, 34, + 34, 35, 35, 35, 36, 19, 36, 38, 38, 38, + 17, 16, 14, 7, 2, 1, 33, 33, 33, 33, + 33, 33, 33, 33, 33, 33, 33, 33 } ; /* Table of booleans, true if rule could match eol. */ -static yyconst flex_int32_t yy_rule_can_match_eol[12] = +static yyconst flex_int32_t yy_rule_can_match_eol[13] = { 0, -0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, }; +0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, }; static yy_state_type yy_last_accepting_state; static char *yy_last_accepting_cpos; @@ -532,10 +536,12 @@ char *vm_var_text; llocp->first_column = llocp->last_column; \ llocp->last_column += vm_var_leng; -#line 536 "vm_var_parser.c" + +#line 541 "vm_var_parser.c" #define INITIAL 0 #define VAR 1 +#define VALUE 2 #ifndef YY_NO_UNISTD_H /* Special case for "unistd.h", since it is non-ANSI. We include it way @@ -713,7 +719,7 @@ YY_DECL register char *yy_cp, *yy_bp; register int yy_act; -#line 42 "vm_var_parser.l" +#line 43 "vm_var_parser.l" /* ------------------------------------------------------------------------- */ @@ -724,7 +730,7 @@ YY_DECL /* $NUM.CONTEXT_VARIABLE */ /* ------------------------------------------------------------------------- */ -#line 728 "vm_var_parser.c" +#line 734 "vm_var_parser.c" if ( !(yy_init) ) { @@ -777,13 +783,13 @@ yy_match: while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) { yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 30 ) + if ( yy_current_state >= 34 ) yy_c = yy_meta[(unsigned int) yy_c]; } yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; ++yy_cp; } - while ( yy_base[yy_current_state] != 35 ); + while ( yy_base[yy_current_state] != 47 ); yy_find_action: yy_act = yy_accept[yy_current_state]; @@ -819,60 +825,69 @@ do_action: /* This label is used only to access EOF actions. */ case 1: YY_RULE_SETUP -#line 52 "vm_var_parser.l" +#line 53 "vm_var_parser.l" { BEGIN VAR;} YY_BREAK case 2: YY_RULE_SETUP -#line 54 "vm_var_parser.l" -{ return EQUAL;} +#line 55 "vm_var_parser.l" +{ BEGIN VALUE; return EQUAL; } YY_BREAK case 3: YY_RULE_SETUP -#line 55 "vm_var_parser.l" +#line 56 "vm_var_parser.l" { return COMMA;} YY_BREAK case 4: YY_RULE_SETUP -#line 56 "vm_var_parser.l" +#line 57 "vm_var_parser.l" { return OBRACKET;} YY_BREAK case 5: YY_RULE_SETUP -#line 57 "vm_var_parser.l" +#line 58 "vm_var_parser.l" { return CBRACKET;} YY_BREAK case 6: YY_RULE_SETUP -#line 59 "vm_var_parser.l" +#line 60 "vm_var_parser.l" { lvalp->val_str = - mem_collector_strdup(mc,vm_var_text); + mem_collector_strdup(mc,vm_var_text); return VARIABLE;} YY_BREAK case 7: /* rule 7 can match eol */ YY_RULE_SETUP -#line 63 "vm_var_parser.l" +#line 64 "vm_var_parser.l" { lvalp->val_str = - mem_collector_strdup(mc,vm_var_text+1); + mem_collector_strdup(mc,vm_var_text+1); lvalp->val_str[vm_var_leng-2] = '\0'; + BEGIN(VAR); return STRING;} YY_BREAK case 8: YY_RULE_SETUP -#line 68 "vm_var_parser.l" -{ lvalp->val_char = '\0'; - return EOA;} +#line 70 "vm_var_parser.l" +{ lvalp->val_str = + mem_collector_strdup(mc,vm_var_text); + BEGIN(VAR); + return STRING;} YY_BREAK case 9: YY_RULE_SETUP -#line 71 "vm_var_parser.l" +#line 75 "vm_var_parser.l" +{ lvalp->val_char = '\0'; + return EOA;} + YY_BREAK +case 10: +YY_RULE_SETUP +#line 78 "vm_var_parser.l" { lvalp->val_char = *vm_var_text; BEGIN(INITIAL); return EOA;} YY_BREAK case YY_STATE_EOF(VAR): -#line 75 "vm_var_parser.l" +#line 82 "vm_var_parser.l" { lvalp->val_char = '\0'; BEGIN(INITIAL); return EOA;} @@ -880,19 +895,20 @@ case YY_STATE_EOF(VAR): /* ------------------------------------------------------------------------- */ /* Just copy the string verbatim till we find a variable (starts with $) */ /* ------------------------------------------------------------------------- */ -case 10: -/* rule 10 can match eol */ +case 11: +/* rule 11 can match eol */ YY_RULE_SETUP -#line 83 "vm_var_parser.l" +#line 90 "vm_var_parser.l" { lvalp->val_str = mem_collector_strdup(mc,vm_var_text); return RSTRING;} YY_BREAK -case 11: +case 12: YY_RULE_SETUP -#line 85 "vm_var_parser.l" +#line 92 "vm_var_parser.l" ECHO; YY_BREAK -#line 895 "vm_var_parser.c" +#line 910 "vm_var_parser.c" case YY_STATE_EOF(INITIAL): +case YY_STATE_EOF(VALUE): yyterminate(); case YY_END_OF_BUFFER: @@ -1183,7 +1199,7 @@ static int yy_get_next_buffer (void) while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) { yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 30 ) + if ( yy_current_state >= 34 ) yy_c = yy_meta[(unsigned int) yy_c]; } yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; @@ -1211,11 +1227,11 @@ static int yy_get_next_buffer (void) while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) { yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 30 ) + if ( yy_current_state >= 34 ) yy_c = yy_meta[(unsigned int) yy_c]; } yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; - yy_is_jam = (yy_current_state == 29); + yy_is_jam = (yy_current_state == 33); return yy_is_jam ? 0 : yy_current_state; } @@ -1860,7 +1876,7 @@ void vm_var_free (void * ptr ) #define YYTABLES_NAME "yytables" -#line 85 "vm_var_parser.l" +#line 92 "vm_var_parser.l" diff --git a/src/vm/vm_var_parser.l b/src/vm/vm_var_parser.l index 48a39cf8b6..7a3b39007e 100644 --- a/src/vm/vm_var_parser.l +++ b/src/vm/vm_var_parser.l @@ -39,6 +39,7 @@ %option yylineno %x VAR +%x VALUE %% /* ------------------------------------------------------------------------- */ @@ -51,18 +52,24 @@ \$ { BEGIN VAR;} -[[:blank:]]*=[[:blank:]]* { return EQUAL;} +[[:blank:]]*=[[:blank:]]* { BEGIN VALUE; return EQUAL; } [[:blank:]]*,[[:blank:]]* { return COMMA;} \[[[:blank:]]* { return OBRACKET;} [[:blank:]]*\] { return CBRACKET;} [[:alnum:]_]+ { lvalp->val_str = - mem_collector_strdup(mc,yytext); + mem_collector_strdup(mc,yytext); return VARIABLE;} -\"[^\"]*\" { lvalp->val_str = - mem_collector_strdup(mc,yytext+1); +\"[^\"]*\" { lvalp->val_str = + mem_collector_strdup(mc,yytext+1); lvalp->val_str[yyleng-2] = '\0'; + BEGIN(VAR); + return STRING;} + +[[:alnum:]]+ { lvalp->val_str = + mem_collector_strdup(mc,yytext); + BEGIN(VAR); return STRING;} \$ { lvalp->val_char = '\0'; diff --git a/src/vm/vm_var_syntax.cc b/src/vm/vm_var_syntax.cc index a4f2f659cf..30866385ae 100644 --- a/src/vm/vm_var_syntax.cc +++ b/src/vm/vm_var_syntax.cc @@ -136,6 +136,92 @@ extern "C" /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ +void get_image_attribute(VirtualMachine * vm, + const string& attr_name, + const string& img_name, + const string& img_value, + string& attr_value) +{ + Nebula& nd = Nebula::instance(); + + ImagePool * ipool = nd.get_ipool(); + Image * img; + int iid = -1; + string iid_str; + + int num; + vector attrs; + const VectorAttribute * disk; + + attr_value.clear(); + + if (img_name.empty() || img_name != "IMAGE_ID") + { + return; + } + + // ---------------------------------------------- + // Check that the image is in the template, so + // are sure that we can access the image template + // ---------------------------------------------- + num = vm->get_template_attribute("DISK",attrs); + + for (int i=0; i < num ;i++) + { + disk = dynamic_cast(attrs[i]); + + if ( disk == 0 ) + { + continue; + } + + iid_str = disk->vector_value("IMAGE_ID"); + + if ( iid_str == img_value ) + { + istringstream iss(img_value); + + iss >> iid; + + if (iss.fail()) + { + iid = -1; + } + + break; + } + } + + if (iid == -1) + { + return; + } + + // ---------------------------------------------- + // Get the attribute template from the image + // ---------------------------------------------- + img = ipool->get(iid, true); + + if ( img == 0 ) + { + return; + } + + if (attr_name == "TEMPLATE") + { + attr_value = img->to_xml64(attr_value); + } + else + { + img->get_template_attribute(attr_name.c_str(),attr_value); + } + + img->unlock(); +} + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + void get_network_attribute(VirtualMachine * vm, const string& attr_name, const string& net_name, @@ -146,52 +232,112 @@ void get_network_attribute(VirtualMachine * vm, VirtualNetworkPool * vnpool = nd.get_vnpool(); VirtualNetwork * vn; + int vnet_id = -1; + string vnet_id_str; - string network = ""; + int num; + vector attrs; + const VectorAttribute * net; - attr_value = ""; + attr_value.clear(); - if (net_name.empty()) - { - vector nics; - const VectorAttribute * nic; - - if (vm->get_template_attribute("NIC",nics) == 0) - { - return; - } - - nic = dynamic_cast(nics[0]); - - if ( nic == 0 ) - { - return; - } - - network = nic->vector_value("NETWORK"); - } - else if (net_name == "NAME") - { - network = net_value; - } - - if ( network.empty() ) + if (net_name.empty() || net_name != "NETWORK_ID") { return; } - vn = vnpool->get(network, vm->get_uid(), true); + // ---------------------------------------------- + // Check that the network is in the template, so + // are sure that we can access its template + // ---------------------------------------------- + num = vm->get_template_attribute("NIC",attrs); + + for (int i=0; i < num ;i++) + { + net = dynamic_cast(attrs[i]); + + if ( net == 0 ) + { + continue; + } + + vnet_id_str = net->vector_value("NETWORK_ID"); + + if ( vnet_id_str == net_value ) + { + istringstream iss(net_value); + + iss >> vnet_id; + + if (iss.fail()) + { + vnet_id = -1; + } + + break; + } + } + + if (vnet_id == -1) + { + return; + } + + // ---------------------------------------------- + // Get the attribute template from the image + // ---------------------------------------------- + vn = vnpool->get(vnet_id, true); if ( vn == 0 ) { return; } - vn->get_template_attribute(attr_name.c_str(),attr_value); + if (attr_name == "TEMPLATE") + { + attr_value = vn->to_xml64(attr_value); + } + else + { + vn->get_template_attribute(attr_name.c_str(),attr_value); + } vn->unlock(); } +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ +/* +void get_user_attribute(VirtualMachine * vm, + const string& attr_name, + string& attr_value) +{ + Nebula& nd = Nebula::instance(); + + UserPool * upool = nd.get_upool(); + User * user; + + attr_value.clear(); + + user = upool->get(vm->get_uid(), true); + + if ( user == 0 ) + { + return; + } + + if (attr_name == "TEMPLATE") + { + attr_value = user->to_xml64(attr_value); + } + else + { + user->get_template_attribute(attr_name.c_str(),attr_value); + } + + user->unlock(); +} +*/ /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ @@ -201,9 +347,23 @@ void insert_single(VirtualMachine * vm, { string value = ""; - vm->get_template_attribute(name.c_str(),value); + if (name == "TEMPLATE") + { + vm->to_xml64(value); + } + else if (name == "UID") + { + parsed << vm->get_uid(); + } + else + { + vm->get_template_attribute(name.c_str(),value); + } - parsed << value; + if (!value.empty()) + { + parsed << value; + } } /* -------------------------------------------------------------------------- */ @@ -222,7 +382,7 @@ void insert_vector(VirtualMachine * vm, int num; - if ( name == "NETWORK") + if (name == "NETWORK") { string value; @@ -235,35 +395,50 @@ void insert_vector(VirtualMachine * vm, return; } - - if ( ( num = vm->get_template_attribute(name.c_str(),values) ) <= 0 ) + else if (name == "IMAGE") { + string value; + + get_image_attribute(vm,vname,vvar,vval,value); + + if (!value.empty()) + { + parsed << value; + } + return; } - - if ( vvar.empty() ) - { - vattr = dynamic_cast(values[0]); - } else { - const VectorAttribute * tmp = 0; - - for (int i=0 ; i < num ; i++) + if ( ( num = vm->get_template_attribute(name.c_str(),values) ) <= 0 ) { - tmp = dynamic_cast(values[i]); + return; + } - if ( tmp && ( tmp->vector_value(vvar.c_str()) == vval )) + if ( vvar.empty() ) + { + vattr = dynamic_cast(values[0]); + } + else + { + const VectorAttribute * tmp = 0; + + for (int i=0 ; i < num ; i++) { - vattr = tmp; - break; + tmp = dynamic_cast(values[i]); + + if ( tmp && ( tmp->vector_value(vvar.c_str()) == vval )) + { + vattr = tmp; + break; + } } } - } - if ( vattr != 0 ) - { - parsed << vattr->vector_value(vname.c_str()); + if ( vattr != 0 ) + { + parsed << vattr->vector_value(vname.c_str()); + } } } @@ -273,7 +448,7 @@ void insert_vector(VirtualMachine * vm, /* Line 189 of yacc.c */ -#line 277 "vm_var_syntax.cc" +#line 452 "vm_var_syntax.cc" /* Enabling traces. */ #ifndef YYDEBUG @@ -319,7 +494,7 @@ typedef union YYSTYPE { /* Line 214 of yacc.c */ -#line 220 "vm_var_syntax.y" +#line 395 "vm_var_syntax.y" char * val_str; int val_int; @@ -328,7 +503,7 @@ typedef union YYSTYPE /* Line 214 of yacc.c */ -#line 332 "vm_var_syntax.cc" +#line 507 "vm_var_syntax.cc" } YYSTYPE; # define YYSTYPE_IS_TRIVIAL 1 # define yystype YYSTYPE /* obsolescent; will be withdrawn */ @@ -353,7 +528,7 @@ typedef struct YYLTYPE /* Line 264 of yacc.c */ -#line 357 "vm_var_syntax.cc" +#line 532 "vm_var_syntax.cc" #ifdef short # undef short @@ -639,7 +814,7 @@ static const yytype_int8 yyrhs[] = /* YYRLINE[YYN] -- source line where rule number YYN was defined. */ static const yytype_uint16 yyrline[] = { - 0, 244, 244, 245, 248, 252, 265, 280 + 0, 419, 419, 420, 423, 427, 440, 455 }; #endif @@ -1612,7 +1787,7 @@ yyreduce: case 4: /* Line 1464 of yacc.c */ -#line 249 "vm_var_syntax.y" +#line 424 "vm_var_syntax.y" { (*parsed) << (yyvsp[(1) - (1)].val_str); ;} @@ -1621,7 +1796,7 @@ yyreduce: case 5: /* Line 1464 of yacc.c */ -#line 253 "vm_var_syntax.y" +#line 428 "vm_var_syntax.y" { string name((yyvsp[(1) - (2)].val_str)); @@ -1639,7 +1814,7 @@ yyreduce: case 6: /* Line 1464 of yacc.c */ -#line 266 "vm_var_syntax.y" +#line 441 "vm_var_syntax.y" { string name((yyvsp[(1) - (5)].val_str)); string vname((yyvsp[(3) - (5)].val_str)); @@ -1659,7 +1834,7 @@ yyreduce: case 7: /* Line 1464 of yacc.c */ -#line 281 "vm_var_syntax.y" +#line 456 "vm_var_syntax.y" { string name((yyvsp[(1) - (9)].val_str)); string vname((yyvsp[(3) - (9)].val_str)); @@ -1682,7 +1857,7 @@ yyreduce: /* Line 1464 of yacc.c */ -#line 1686 "vm_var_syntax.cc" +#line 1861 "vm_var_syntax.cc" default: break; } YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc); @@ -1901,7 +2076,7 @@ yyreturn: /* Line 1684 of yacc.c */ -#line 299 "vm_var_syntax.y" +#line 474 "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 f14220c3a3..8d099c1d0a 100644 --- a/src/vm/vm_var_syntax.h +++ b/src/vm/vm_var_syntax.h @@ -57,7 +57,7 @@ typedef union YYSTYPE { /* Line 1685 of yacc.c */ -#line 220 "vm_var_syntax.y" +#line 395 "vm_var_syntax.y" char * val_str; int val_int; diff --git a/src/vm/vm_var_syntax.y b/src/vm/vm_var_syntax.y index 8887bdd6fb..ae83471f07 100644 --- a/src/vm/vm_var_syntax.y +++ b/src/vm/vm_var_syntax.y @@ -74,6 +74,92 @@ extern "C" /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ +void get_image_attribute(VirtualMachine * vm, + const string& attr_name, + const string& img_name, + const string& img_value, + string& attr_value) +{ + Nebula& nd = Nebula::instance(); + + ImagePool * ipool = nd.get_ipool(); + Image * img; + int iid = -1; + string iid_str; + + int num; + vector attrs; + const VectorAttribute * disk; + + attr_value.clear(); + + if (img_name.empty() || img_name != "IMAGE_ID") + { + return; + } + + // ---------------------------------------------- + // Check that the image is in the template, so + // are sure that we can access the image template + // ---------------------------------------------- + num = vm->get_template_attribute("DISK",attrs); + + for (int i=0; i < num ;i++) + { + disk = dynamic_cast(attrs[i]); + + if ( disk == 0 ) + { + continue; + } + + iid_str = disk->vector_value("IMAGE_ID"); + + if ( iid_str == img_value ) + { + istringstream iss(img_value); + + iss >> iid; + + if (iss.fail()) + { + iid = -1; + } + + break; + } + } + + if (iid == -1) + { + return; + } + + // ---------------------------------------------- + // Get the attribute template from the image + // ---------------------------------------------- + img = ipool->get(iid, true); + + if ( img == 0 ) + { + return; + } + + if (attr_name == "TEMPLATE") + { + attr_value = img->to_xml64(attr_value); + } + else + { + img->get_template_attribute(attr_name.c_str(),attr_value); + } + + img->unlock(); +} + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + void get_network_attribute(VirtualMachine * vm, const string& attr_name, const string& net_name, @@ -84,52 +170,112 @@ void get_network_attribute(VirtualMachine * vm, VirtualNetworkPool * vnpool = nd.get_vnpool(); VirtualNetwork * vn; + int vnet_id = -1; + string vnet_id_str; - string network = ""; + int num; + vector attrs; + const VectorAttribute * net; - attr_value = ""; + attr_value.clear(); - if (net_name.empty()) - { - vector nics; - const VectorAttribute * nic; - - if (vm->get_template_attribute("NIC",nics) == 0) - { - return; - } - - nic = dynamic_cast(nics[0]); - - if ( nic == 0 ) - { - return; - } - - network = nic->vector_value("NETWORK"); - } - else if (net_name == "NAME") - { - network = net_value; - } - - if ( network.empty() ) + if (net_name.empty() || net_name != "NETWORK_ID") { return; } - vn = vnpool->get(network, vm->get_uid(), true); + // ---------------------------------------------- + // Check that the network is in the template, so + // are sure that we can access its template + // ---------------------------------------------- + num = vm->get_template_attribute("NIC",attrs); + + for (int i=0; i < num ;i++) + { + net = dynamic_cast(attrs[i]); + + if ( net == 0 ) + { + continue; + } + + vnet_id_str = net->vector_value("NETWORK_ID"); + + if ( vnet_id_str == net_value ) + { + istringstream iss(net_value); + + iss >> vnet_id; + + if (iss.fail()) + { + vnet_id = -1; + } + + break; + } + } + + if (vnet_id == -1) + { + return; + } + + // ---------------------------------------------- + // Get the attribute template from the image + // ---------------------------------------------- + vn = vnpool->get(vnet_id, true); if ( vn == 0 ) { return; } - vn->get_template_attribute(attr_name.c_str(),attr_value); + if (attr_name == "TEMPLATE") + { + attr_value = vn->to_xml64(attr_value); + } + else + { + vn->get_template_attribute(attr_name.c_str(),attr_value); + } vn->unlock(); } +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ +/* +void get_user_attribute(VirtualMachine * vm, + const string& attr_name, + string& attr_value) +{ + Nebula& nd = Nebula::instance(); + + UserPool * upool = nd.get_upool(); + User * user; + + attr_value.clear(); + + user = upool->get(vm->get_uid(), true); + + if ( user == 0 ) + { + return; + } + + if (attr_name == "TEMPLATE") + { + attr_value = user->to_xml64(attr_value); + } + else + { + user->get_template_attribute(attr_name.c_str(),attr_value); + } + + user->unlock(); +} +*/ /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ @@ -139,9 +285,23 @@ void insert_single(VirtualMachine * vm, { string value = ""; - vm->get_template_attribute(name.c_str(),value); + if (name == "TEMPLATE") + { + vm->to_xml64(value); + } + else if (name == "UID") + { + parsed << vm->get_uid(); + } + else + { + vm->get_template_attribute(name.c_str(),value); + } - parsed << value; + if (!value.empty()) + { + parsed << value; + } } /* -------------------------------------------------------------------------- */ @@ -160,7 +320,7 @@ void insert_vector(VirtualMachine * vm, int num; - if ( name == "NETWORK") + if (name == "NETWORK") { string value; @@ -173,35 +333,50 @@ void insert_vector(VirtualMachine * vm, return; } - - if ( ( num = vm->get_template_attribute(name.c_str(),values) ) <= 0 ) + else if (name == "IMAGE") { + string value; + + get_image_attribute(vm,vname,vvar,vval,value); + + if (!value.empty()) + { + parsed << value; + } + return; } - - if ( vvar.empty() ) - { - vattr = dynamic_cast(values[0]); - } else { - const VectorAttribute * tmp = 0; - - for (int i=0 ; i < num ; i++) + if ( ( num = vm->get_template_attribute(name.c_str(),values) ) <= 0 ) { - tmp = dynamic_cast(values[i]); + return; + } - if ( tmp && ( tmp->vector_value(vvar.c_str()) == vval )) + if ( vvar.empty() ) + { + vattr = dynamic_cast(values[0]); + } + else + { + const VectorAttribute * tmp = 0; + + for (int i=0 ; i < num ; i++) { - vattr = tmp; - break; + tmp = dynamic_cast(values[i]); + + if ( tmp && ( tmp->vector_value(vvar.c_str()) == vval )) + { + vattr = tmp; + break; + } } } - } - if ( vattr != 0 ) - { - parsed << vattr->vector_value(vname.c_str()); + if ( vattr != 0 ) + { + parsed << vattr->vector_value(vname.c_str()); + } } } diff --git a/src/vm_template/test/VMTemplatePoolTest.cc b/src/vm_template/test/VMTemplatePoolTest.cc index 944c3bda14..8648f410b9 100644 --- a/src/vm_template/test/VMTemplatePoolTest.cc +++ b/src/vm_template/test/VMTemplatePoolTest.cc @@ -491,9 +491,9 @@ public: string result = oss.str(); - result.replace(128, 10, replacement); - result.replace(391, 10, replacement); - result.replace(656, 10, replacement); + result.replace(130, 10, replacement); + result.replace(393, 10, replacement); + result.replace(658, 10, replacement); /* if( result != xml_dump ) @@ -527,8 +527,8 @@ public: string result = oss.str(); - result.replace(128, 10, replacement); - result.replace(391, 10, replacement); + result.replace(130, 10, replacement); + result.replace(393, 10, replacement); /* if( result != xml_dump_where ) diff --git a/src/vmm/LibVirtDriverKVM.cc b/src/vmm/LibVirtDriverKVM.cc index ce71f4e658..ea7924c874 100644 --- a/src/vmm/LibVirtDriverKVM.cc +++ b/src/vmm/LibVirtDriverKVM.cc @@ -53,7 +53,9 @@ int LibVirtDriver::deployment_description_kvm( string bus = ""; string ro = ""; string driver = ""; - string default_driver = ""; + string cache = ""; + string default_driver = ""; + string default_driver_cache = ""; bool readonly; const VectorAttribute * nic; @@ -62,6 +64,9 @@ int LibVirtDriver::deployment_description_kvm( string bridge = ""; string script = ""; string model = ""; + string ip = ""; + string filter = ""; + string default_filter = ""; const VectorAttribute * graphics; @@ -251,9 +256,8 @@ int LibVirtDriver::deployment_description_kvm( attrs.clear(); // ------------------------------------------------------------------------ - // Disks + // DEVICES SECTION // ------------------------------------------------------------------------ - file << "\t" << endl; if (emulator == "kvm") @@ -268,6 +272,9 @@ int LibVirtDriver::deployment_description_kvm( file << "\t\t" << emulator_path << "" << endl; } + // ------------------------------------------------------------------------ + // Disks + // ------------------------------------------------------------------------ get_default("DISK","DRIVER",default_driver); if (default_driver.empty()) @@ -275,6 +282,15 @@ int LibVirtDriver::deployment_description_kvm( default_driver = "raw"; } + get_default("DISK","CACHE",default_driver_cache); + + if (default_driver_cache.empty()) + { + default_driver_cache = "default"; + } + + // ------------------------------------------------------------------------ + num = vm->get_template_attribute("DISK",attrs); for (int i=0; i < num ;i++) @@ -291,6 +307,7 @@ int LibVirtDriver::deployment_description_kvm( ro = disk->vector_value("READONLY"); bus = disk->vector_value("BUS"); driver = disk->vector_value("DRIVER"); + cache = disk->vector_value("CACHE"); if (target.empty()) { @@ -363,11 +380,22 @@ int LibVirtDriver::deployment_description_kvm( if ( !driver.empty() ) { - file << driver << "'/>" << endl; + file << driver; } else { - file << default_driver << "'/>" << endl; + file << default_driver; + } + + file << "' cache='"; + + if ( !cache.empty() ) + { + file << cache << "'/>" << endl; + } + else + { + file << default_driver_cache << "'/>" << endl; } file << "\t\t" << endl; @@ -419,6 +447,8 @@ int LibVirtDriver::deployment_description_kvm( // Network interfaces // ------------------------------------------------------------------------ + get_default("NIC","FILTER",default_filter); + num = vm->get_template_attribute("NIC",attrs); for(int i=0; ivector_value("TARGET"); script = nic->vector_value("SCRIPT"); model = nic->vector_value("MODEL"); + ip = nic->vector_value("IP"); + filter = nic->vector_value("FILTER"); if ( bridge.empty() ) { @@ -466,8 +498,29 @@ int LibVirtDriver::deployment_description_kvm( file << "\t\t\t" << endl; } - file << "\t\t" << endl; + if (!ip.empty() ) + { + string * the_filter = 0; + if (!filter.empty()) + { + the_filter = &filter; + } + else if (!default_filter.empty()) + { + the_filter = &default_filter; + } + + if ( the_filter != 0 ) + { + file <<"\t\t\t"<" << endl; + file << "\t\t\t" << endl; + } + } + + file << "\t\t" << endl; } attrs.clear(); diff --git a/src/vmm/LibVirtDriverVMware.cc b/src/vmm/LibVirtDriverVMware.cc index ade02db1b5..ffe9f14cae 100644 --- a/src/vmm/LibVirtDriverVMware.cc +++ b/src/vmm/LibVirtDriverVMware.cc @@ -166,11 +166,6 @@ int LibVirtDriver::deployment_description_vmware( get_default("DISK","DRIVER",default_driver); - if (default_driver.empty()) - { - default_driver = "raw"; - } - num = vm->get_template_attribute("DISK",attrs); if (num!=0) @@ -252,7 +247,10 @@ int LibVirtDriver::deployment_description_vmware( } else { - file << default_driver << "'/>" << endl; + if (!default_driver.empty()) + { + file << default_driver << "'/>" << endl; + } } if (readonly) diff --git a/src/vmm/VirtualMachineManagerDriver.cc b/src/vmm/VirtualMachineManagerDriver.cc index 1a753a0713..4b58f06f2f 100644 --- a/src/vmm/VirtualMachineManagerDriver.cc +++ b/src/vmm/VirtualMachineManagerDriver.cc @@ -453,6 +453,9 @@ void VirtualMachineManagerDriver::protocol( int net_rx = -1; char state = '-'; + string monitor_str = is.str(); + bool parse_error = false; + while(is.good()) { is >> tmp >> ws; @@ -461,12 +464,8 @@ void VirtualMachineManagerDriver::protocol( if ( pos == string::npos ) { - os.str(""); - os << "Error parsing monitoring attribute: " << tmp; - - vm->log("VMM",Log::ERROR,os); - - break; + parse_error = true; + continue; } tmp.replace(pos,1," "); @@ -475,7 +474,13 @@ void VirtualMachineManagerDriver::protocol( tiss.str(tmp); - tiss >> var; + tiss >> var >> ws; + + if (!tiss.good()) + { + parse_error = true; + continue; + } if (var == "USEDMEMORY") { @@ -502,8 +507,7 @@ void VirtualMachineManagerDriver::protocol( string val; os.str(""); - os << "Unknown monitoring attribute (adding/updating" - << " template): " << tmp; + os << "Adding custom monitoring attribute: " << tmp; vm->log("VMM",Log::WARNING,os); @@ -513,6 +517,20 @@ void VirtualMachineManagerDriver::protocol( } } + if (parse_error) + { + os.str(""); + os << "Error parsing monitoring str:\"" << monitor_str <<"\""; + + vm->log("VMM",Log::ERROR,os); + + vm->set_template_error_message(os.str()); + vmpool->update(vm); + + vm->unlock(); + return; + } + vm->update_info(memory,cpu,net_tx,net_rx); vmpool->update(vm); diff --git a/src/vmm_mad/ssh/vmm_ssh_kvm.conf b/src/vmm_mad/ssh/vmm_ssh_kvm.conf index af6920d24e..949eae153b 100644 --- a/src/vmm_mad/ssh/vmm_ssh_kvm.conf +++ b/src/vmm_mad/ssh/vmm_ssh_kvm.conf @@ -23,7 +23,8 @@ # - cpu # - vcpu # - features [acpi, pae] -# - disk [driver ]A +# - disk [driver, cache] +# - nic [filter] #EMULATOR = /usr/libexec/qemu-kvm @@ -33,4 +34,6 @@ OS = [ boot = "hd", arch = "i686" ] FEATURES = [ PAE = "no", ACPI = "yes" ] -DISK = [ driver = "raw" ] +DISK = [ driver = "raw" , cache = "default"] + +#NIC = [ filter = "clean-traffic" ] diff --git a/src/vmm_mad/ssh/vmm_sshrc b/src/vmm_mad/ssh/vmm_sshrc index b039809d7b..52c0e6dab0 100644 --- a/src/vmm_mad/ssh/vmm_sshrc +++ b/src/vmm_mad/ssh/vmm_sshrc @@ -13,8 +13,3 @@ # See the License for the specific language governing permissions and # # limitations under the License. # #--------------------------------------------------------------------------- # - -# To change the directory where the VMM scripts are copied on the remote node -# uncomment and change the path of VMMM_REMOTE_DIR -# -#VMM_REMOTE_DIR=/tmp/ne_im_scripts diff --git a/src/vnm/VirtualNetwork.cc b/src/vnm/VirtualNetwork.cc index 228f26f24f..bc5279b4eb 100644 --- a/src/vnm/VirtualNetwork.cc +++ b/src/vnm/VirtualNetwork.cc @@ -571,15 +571,11 @@ int VirtualNetwork::nic_attribute(VectorAttribute *nic, int vid) { int rc; - string model; string ip; string mac; ostringstream vnid; - map new_nic; - - model = nic->vector_value("MODEL"); ip = nic->vector_value("IP"); vnid << oid; @@ -605,18 +601,11 @@ int VirtualNetwork::nic_attribute(VectorAttribute *nic, int vid) // NEW NIC ATTRIBUTES //-------------------------------------------------------------------------- - new_nic.insert(make_pair("NETWORK" ,name)); - new_nic.insert(make_pair("MAC" ,mac)); - new_nic.insert(make_pair("BRIDGE" ,bridge)); - new_nic.insert(make_pair("NETWORK_ID",vnid.str())); - new_nic.insert(make_pair("IP" ,ip)); - - if (!model.empty()) - { - new_nic.insert(make_pair("MODEL",model)); - } - - nic->replace(new_nic); + nic->replace("NETWORK" ,name); + nic->replace("NETWORK_ID",vnid.str()); + nic->replace("BRIDGE" ,bridge); + nic->replace("MAC" ,mac); + nic->replace("IP" ,ip); return 0; }