From ee411e7963f5d607dac78d9d03c3f804c9489cff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Constantino=20V=C3=A1zquez=20Blanco?= Date: Thu, 13 Nov 2008 16:21:17 +0000 Subject: [PATCH] Merged TransferManager and VirtualNetworkManager branches. git-svn-id: http://svn.opennebula.org/one/trunk@230 3034c82b-c49b-4eb3-8279-a7acafdc01c0 --- SConstruct | 4 +- include/Attribute.h | 34 +- include/DispatchManager.h | 2 +- include/FixedLeases.h | 115 ++++ include/History.h | 14 +- include/Host.h | 2 +- include/HostShare.h | 2 +- include/Leases.h | 315 +++++++++ include/Nebula.h | 24 +- include/PoolSQL.h | 4 +- include/RangedLeases.h | 101 +++ include/RequestManager.h | 82 ++- include/Template.h | 11 +- include/TemplateSQL.h | 3 +- include/TransferManager.h | 72 +- include/TransferManagerDriver.h | 84 +++ include/VirtualMachine.h | 148 +++-- include/VirtualNetwork.h | 349 ++++++++++ include/VirtualNetworkPool.h | 144 ++++ include/VirtualNetworkTemplate.h | 47 ++ install.sh | 33 +- share/etc/oned.conf | 54 +- share/examples/private.net | 5 + share/examples/public.net | 9 + share/examples/vm.schema | 9 +- share/examples/vm.template | 3 + src/client/ruby/client_utilities.rb | 20 + src/client/ruby/one.rb | 189 ++++-- src/client/ruby/onehost | 36 +- src/client/ruby/onenetwork | 225 +++++++ src/client/ruby/onevm | 46 +- src/common/Attribute.cc | 9 +- src/dm/DispatchManagerActions.cc | 8 +- src/dm/DispatchManagerStates.cc | 6 +- src/host/Host.cc | 16 +- src/host/HostPool.cc | 2 +- src/host/HostShare.cc | 18 +- src/im_mad/im_ssh/one_im_ssh.rb | 54 +- src/lcm/LifeCycleActions.cc | 19 +- src/lcm/LifeCycleStates.cc | 22 +- src/mad/ruby/ThreadScheduler.rb | 116 ++++ src/mad/ruby/one_mad.rb | 33 +- src/mad/ruby/one_ssh.rb | 79 +-- src/nebula/Nebula.cc | 38 +- src/nebula/NebulaTemplate.cc | 28 +- src/nebula/SConstruct | 8 +- src/rm/RequestManager.cc | 15 + src/rm/RequestManagerDeploy.cc | 2 +- src/rm/RequestManagerMigrate.cc | 2 +- .../RequestManagerVirtualNetworkAllocate.cc | 83 +++ src/rm/RequestManagerVirtualNetworkDelete.cc | 85 +++ src/rm/RequestManagerVirtualNetworkInfo.cc | 89 +++ src/rm/SConstruct | 5 +- src/scheduler/SConstruct | 3 +- src/template/Template.cc | 24 +- src/template/TemplateSQL.cc | 12 +- src/tm/SConstruct | 3 +- src/tm/TransferManager.cc | 615 +++++++++++++++++- src/tm/TransferManagerDriver.cc | 222 +++++++ src/tm_mad/TMScript.rb | 237 +++++++ src/tm_mad/nfs/tm_clone.sh | 33 + src/tm_mad/nfs/tm_delete.sh | 11 + src/tm_mad/nfs/tm_ln.sh | 12 + src/tm_mad/nfs/tm_mkimage.sh | 5 + src/tm_mad/nfs/tm_mkswap.sh | 17 + src/tm_mad/nfs/tm_mv.sh | 23 + src/tm_mad/nfs/tm_nfs.conf | 6 + src/tm_mad/nfs/tm_nfsrc | 16 + src/tm_mad/one_tm | 25 + src/tm_mad/one_tm.rb | 84 +++ src/tm_mad/ssh/tm_clone.sh | 36 + src/tm_mad/ssh/tm_delete.sh | 12 + src/tm_mad/ssh/tm_ln.sh | 11 + src/tm_mad/ssh/tm_mkimage.sh | 5 + src/tm_mad/ssh/tm_mkswap.sh | 21 + src/tm_mad/ssh/tm_mv.sh | 19 + src/tm_mad/ssh/tm_ssh.conf | 6 + src/tm_mad/ssh/tm_sshrc | 16 + src/tm_mad/tm_common.sh | 96 +++ src/vm/History.cc | 67 +- src/vm/VirtualMachine.cc | 195 ++++-- src/vm/VirtualMachinePool.cc | 14 +- src/vm/VirtualMachineTemplate.cc | 4 +- src/vmm/LibVirtDriver.cc | 12 +- src/vmm/VirtualMachineManager.cc | 8 +- src/vmm/VirtualMachineManagerDriver.cc | 25 +- src/vmm/XenDriver.cc | 14 +- src/vmm_mad/xen/one_vmm_xen.rb | 29 +- src/vnm/FixedLeases.cc | 188 ++++++ src/vnm/Leases.cc | 407 ++++++++++++ src/vnm/RangedLeases.cc | 155 +++++ src/vnm/SConstruct | 19 + src/vnm/VirtualNetwork.cc | 414 ++++++++++++ src/vnm/VirtualNetworkPool.cc | 173 +++++ src/vnm/VirtualNetworkTemplate.cc | 24 + 95 files changed, 5768 insertions(+), 473 deletions(-) create mode 100644 include/FixedLeases.h create mode 100644 include/Leases.h create mode 100644 include/RangedLeases.h create mode 100644 include/TransferManagerDriver.h create mode 100644 include/VirtualNetwork.h create mode 100644 include/VirtualNetworkPool.h create mode 100644 include/VirtualNetworkTemplate.h create mode 100644 share/examples/private.net create mode 100644 share/examples/public.net create mode 100755 src/client/ruby/onenetwork create mode 100644 src/mad/ruby/ThreadScheduler.rb create mode 100644 src/rm/RequestManagerVirtualNetworkAllocate.cc create mode 100644 src/rm/RequestManagerVirtualNetworkDelete.cc create mode 100644 src/rm/RequestManagerVirtualNetworkInfo.cc create mode 100644 src/tm/TransferManagerDriver.cc create mode 100644 src/tm_mad/TMScript.rb create mode 100755 src/tm_mad/nfs/tm_clone.sh create mode 100755 src/tm_mad/nfs/tm_delete.sh create mode 100755 src/tm_mad/nfs/tm_ln.sh create mode 100755 src/tm_mad/nfs/tm_mkimage.sh create mode 100755 src/tm_mad/nfs/tm_mkswap.sh create mode 100755 src/tm_mad/nfs/tm_mv.sh create mode 100644 src/tm_mad/nfs/tm_nfs.conf create mode 100644 src/tm_mad/nfs/tm_nfsrc create mode 100755 src/tm_mad/one_tm create mode 100755 src/tm_mad/one_tm.rb create mode 100755 src/tm_mad/ssh/tm_clone.sh create mode 100755 src/tm_mad/ssh/tm_delete.sh create mode 100755 src/tm_mad/ssh/tm_ln.sh create mode 100755 src/tm_mad/ssh/tm_mkimage.sh create mode 100755 src/tm_mad/ssh/tm_mkswap.sh create mode 100755 src/tm_mad/ssh/tm_mv.sh create mode 100755 src/tm_mad/ssh/tm_ssh.conf create mode 100644 src/tm_mad/ssh/tm_sshrc create mode 100644 src/tm_mad/tm_common.sh create mode 100644 src/vnm/FixedLeases.cc create mode 100644 src/vnm/Leases.cc create mode 100644 src/vnm/RangedLeases.cc create mode 100644 src/vnm/SConstruct create mode 100644 src/vnm/VirtualNetwork.cc create mode 100644 src/vnm/VirtualNetworkPool.cc create mode 100644 src/vnm/VirtualNetworkTemplate.cc diff --git a/SConstruct b/SConstruct index e679f4d926..89eae53a67 100644 --- a/SConstruct +++ b/SConstruct @@ -35,6 +35,7 @@ main_env.Append(LIBPATH=[ cwd+'/src/dm', cwd+'/src/im', cwd+'/src/rm', + cwd+'/src/vnm', ]) # Compile flags @@ -103,7 +104,8 @@ build_scripts=[ 'src/tm/SConstruct', 'src/im/SConstruct', 'src/dm/SConstruct', - 'src/scheduler/SConstruct', + 'src/scheduler/SConstruct', + 'src/vnm/SConstruct', ] for script in build_scripts: diff --git a/include/Attribute.h b/include/Attribute.h index 84d7a016c2..23599c48ca 100644 --- a/include/Attribute.h +++ b/include/Attribute.h @@ -33,7 +33,7 @@ class Attribute { public: - Attribute(string& aname):attribute_name(aname) + Attribute(const string& aname):attribute_name(aname) { transform ( attribute_name.begin(), @@ -77,7 +77,7 @@ public: /** * Builds a new attribute from a string. */ - virtual void unmarshall(string& sattr) = 0; + virtual void unmarshall(const string& sattr) = 0; /** * Returns the attribute type @@ -104,12 +104,12 @@ class SingleAttribute : public Attribute { public: - SingleAttribute(string& name):Attribute(name){}; + SingleAttribute(const string& name):Attribute(name){}; - SingleAttribute(string& name, string& value): + SingleAttribute(const string& name, const string& value): Attribute(name),attribute_value(value){}; - SingleAttribute(const char * name, string& value): + SingleAttribute(const char * name, const string& value): Attribute(name),attribute_value(value){}; ~SingleAttribute(){}; @@ -139,11 +139,19 @@ public: /** * Builds a new attribute from a string. */ - void unmarshall(string& sattr) + void unmarshall(const string& sattr) { attribute_value = sattr; }; - + + /** + * Replaces the attribute value from a string. + */ + void replace(const string& sattr) + { + attribute_value = sattr; + }; + /** * Returns the attribute type */ @@ -169,9 +177,9 @@ class VectorAttribute : public Attribute { public: - VectorAttribute(string& name):Attribute(name){}; + VectorAttribute(const string& name):Attribute(name){}; - VectorAttribute(string& name, map& value): + VectorAttribute(const string& name,const map& value): Attribute(name),attribute_value(value){}; ~VectorAttribute(){}; @@ -201,7 +209,13 @@ public: * Builds a new attribute from a string of the form: * "VAL_NAME_1=VAL_VALUE_1,...,VAL_NAME_N=VAL_VALUE_N". */ - void unmarshall(string& sattr); + void unmarshall(const string& sattr); + + /** + * Replace the value of the given attribute with the provided map + */ + void replace(const map& attr); + /** * Returns the attribute type diff --git a/include/DispatchManager.h b/include/DispatchManager.h index eeaffddac3..ce4b278050 100644 --- a/include/DispatchManager.h +++ b/include/DispatchManager.h @@ -214,7 +214,7 @@ private: HostPool * hpool; /** - * Pointer to the Host Pool, to access hosts + * Pointer to the Virtual Machine Pool, to access hosts */ VirtualMachinePool * vmpool; diff --git a/include/FixedLeases.h b/include/FixedLeases.h new file mode 100644 index 0000000000..d864087278 --- /dev/null +++ b/include/FixedLeases.h @@ -0,0 +1,115 @@ +/* -------------------------------------------------------------------------- */ +/* Copyright 2002-2008, Distributed Systems Architecture Group, Universidad */ +/* Complutense de Madrid (dsa-research.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 FIXED_LEASES_H_ +#define FIXED_LEASES_H_ + +#include "Leases.h" + +using namespace std; + +/** + * The FixedLeases class represents a pool of fixed IP-MAC leases. A lease can + * be either a IP (the MAC is then PREFIX:IP) or the IP and MAC addresses. The + * pool is read from a template file, each lease is in the form: + * LEASE = [ IP = "", MAC = ""] + */ +class FixedLeases : public Leases +{ +public: + /** + * Create a FixedLeases from template + */ + FixedLeases(SqliteDB * db, + int _oid, + unsigned int _mac_prefix, + vector& vector_leases); + /** + * Create a plain FixedLeases, you can populate the lease pool using + * select() + */ + FixedLeases(SqliteDB * db, + int _oid, + unsigned int _mac_prefix): + Leases(db,_oid,0), + mac_prefix(_mac_prefix), + current(leases.begin()){}; + + ~FixedLeases(){}; + + /** + * Returns an unused lease, which becomes used + * @param vid identifier of the VM getting this lease + * @param ip ip of the returned lease + * @param mac mac of the returned lease + * @return 0 if success + */ + int get(int vid, string& ip, string& mac); + + /** + * Release an used lease, which becomes unused + * @param ip of the lease in use + */ + void release(const string& ip) + { + del(ip); + } + + /** + * Loads the leases from the DB. + */ + int select(SqliteDB * db) + { + //Read the leases from the DB + int rc = Leases::select(db); + //Update the size + size = leases.size(); + + return rc; + } + +private: + + /** + * The default MAC prefix for the OpenNebula cluster + */ + unsigned int mac_prefix; + + /** + * Current lease pointer + */ + map::iterator current; + + /** + * Add a lease, from the Lease interface + * @param ip ip of the lease + * @param mac mac of the lease + * @param vid identifier of the VM getting this lease + * @return 0 if success + */ + int add(const string& ip, const string& mac, int vid, bool used=true); + + /** + * Remove a lease, from the Lease interface + * @param db pointer to DB + * @param ip ip of the lease to be deleted + * @return 0 if success + */ + int del(const string& ip); +}; + +#endif /*FIXED_LEASES_H_*/ diff --git a/include/History.h b/include/History.h index ce7aa5f0d8..9b5f367ea6 100644 --- a/include/History.h +++ b/include/History.h @@ -66,7 +66,7 @@ private: // ---------------------------------------- enum ColNames { - OID = 0, + VID = 0, SEQ = 1, HOSTNAME = 2, VM_DIR = 3, @@ -115,7 +115,7 @@ private: int seq; string hostname; - string vm_rdir; + string vm_dir; int hid; @@ -138,13 +138,13 @@ private: //Non-persistent history fields string vm_lhome; + string transfer_file; + string deployment_file; + string vm_rhome; - - string deployment_lfile; - string deployment_rfile; - string checkpoint_file; - + string rdeployment_file; + friend int history_select_cb ( void * _history, int num, diff --git a/include/Host.h b/include/Host.h index dd20c65659..879808a7f1 100644 --- a/include/Host.h +++ b/include/Host.h @@ -425,7 +425,7 @@ protected: enum ColNames { - HID = 0, + OID = 0, HOST_NAME = 1, STATE = 2, IM_MAD = 3, diff --git a/include/HostShare.h b/include/HostShare.h index 1943c5fcd3..5b3b603122 100644 --- a/include/HostShare.h +++ b/include/HostShare.h @@ -171,7 +171,7 @@ private: enum ColNames { - HSID = 0, + HID = 0, ENDPOINT = 1, DISK_USAGE = 2, MEM_USAGE = 3, diff --git a/include/Leases.h b/include/Leases.h new file mode 100644 index 0000000000..3337a19f25 --- /dev/null +++ b/include/Leases.h @@ -0,0 +1,315 @@ +/* -------------------------------------------------------------------------- */ +/* Copyright 2002-2008, Distributed Systems Architecture Group, Universidad */ +/* Complutense de Madrid (dsa-research.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 LEASES_H_ +#define LEASES_H_ + +#include +#include "ObjectSQL.h" +#include "Attribute.h" + +#include +#include +#include + +using namespace std; + +extern "C" int leases_select_cb ( + void * _lease, + int num, + char ** values, + char ** names); + +/** + * The Leases class represents all the IP and MAC addresses (lease) that can + * be asigned (or are asigned) in a Virtual Network + */ +class Leases : public ObjectSQL +{ +public: + /** + * Creates a new Lease set for a given Virtual Network (oid) + * @param _db pinter to the DB object used to store the leases + * @param _oid the virtual network unique identifier + * @param _size the max number of leases + */ + Leases(SqliteDB * _db, int _oid, unsigned long _size): + oid(_oid), size(_size), db(_db){}; + + virtual ~Leases() + { + map::iterator it; + + for(it=leases.begin();it!=leases.end();it++) + { + delete it->second; + } + }; + + friend ostream& operator<<(ostream& os, Leases& _leases); + + /** + * Returns an unused lease, which becomes used + * @param vid identifier of the VM getting this lease + * @param ip ip of the returned lease + * @param mac mac of the returned lease + * @return 0 if success + */ + virtual int get(int vid, + string& ip, + string& mac) = 0; + + /** + * Release an used lease, which becomes unused + * @param ip of the lease in use + */ + virtual void release(const string& ip) = 0; + + // ------------------------------------------------------------------------- + // ------------------------------------------------------------------------- + +protected: + /** + * The Lease class, it represents a pair of IP and MAC assigned to + * a Virtual Machine + */ + class Lease + { + public: + /** + * Creates a new lease, string form. This constructor throws a runtime + * exception if the IP or MAC format is wrong. + * @param _ip, the Lease IP in string format + * @param _mac, the Lease MAC in string format + * @param _vid, the ID of the VM owning the lease + * @param _used, the lease is in use + */ + //Lease(const string& _ip, const string& _mac,int _vid, bool _used=true); + + /** + * Creates a new lease, numeric form. + * @param _ip, the Lease IP in numeric format + * @param _mac, the Lease MAC in numeric format + * @param _vid, the ID of the VM owning the lease + * @param _used, the lease is in use + */ + Lease(unsigned int _ip, unsigned int _mac[], int _vid, bool _used=true) + :ip(_ip), vid(_vid), used(_used) + { + // TODO check size + mac[PREFIX]=_mac[PREFIX]; + mac[SUFFIX]=_mac[SUFFIX]; + }; + + ~Lease(){}; + + /** + * Converts this lease's IP and MAC to string + * @param ip ip of the lease in string + * @param mac mac of the lease in string + */ + void to_string(string& _ip, string& _mac); + + /** + * Conversion from string IP to unsigned int IP + * @return 0 if success + */ + static int ip_to_number(const string& ip, unsigned int& i_ip); + + /** + * Conversion from unsigned int IP to string IP + */ + static void ip_to_string(const unsigned int i_ip, string& ip); + + /** + * Conversion from string MAC to unsigned int[] MAC + * @return 0 if success + */ + static int mac_to_number(const string& mac, unsigned int i_mac[]); + + /** + * Conversion from string IP to unsigned int IP + */ + static void mac_to_string(const unsigned int i_mac[], string& mac); + + /** + * Prints a Lease in a single line + */ + friend ostream& operator<<(ostream& os, Lease& _lease); + + /** + * Constants to access the array storing the MAC address + */ + enum MACIndex + { + SUFFIX = 0,/**< Lower significant 4 bytes */ + PREFIX = 1 /**< Higher significant 2 bytes */ + }; + + unsigned int ip; + + unsigned int mac [2]; + + int vid; + + bool used; + }; + + friend ostream& operator<<(ostream& os, Lease& _lease); + + friend class VirtualNetwork; + + // ------------------------------------------------------------------------- + // Leases fields + // ------------------------------------------------------------------------- + /** + * Leases indentifier. Connects it to a Virtual Network + */ + int oid; + + /** + * Number of possible leases (free + asigned) + */ + unsigned int size; + + /** + * Hash of leases, indexed by lease.ip + */ + map leases; + + // ------------------------------------------------------------------------- + // DataBase implementation variables + // ------------------------------------------------------------------------- + /** + * Pointer to the DataBase + */ + SqliteDB * db; + + enum ColNames + { + OID = 0, + IP = 1, + MAC_PREFIX = 2, + MAC_SUFFIX = 3, + VID = 4, + USED = 5, + LIMIT = 6 + }; + + static const char * table; + + static const char * db_names; + + static const char * db_bootstrap; + + // ------------------------------------------------------------------------- + // Leases methods + // ------------------------------------------------------------------------- + /** + * Check if the passed ip corresponds with a given lease + * @param ip of the lease to be checked + * @return true if the ip was already assigned + */ + bool check(const string& ip); + + bool check(unsigned int ip); + + /** + * Reads the leases from the DB, and updates the lease hash table + * @param db pointer to the database. + * @return 0 on success. + */ + virtual int select(SqliteDB * db); + +private: + + friend int leases_select_cb ( + void * _leases, + int num, + char ** values, + char ** names); + + /** + * Function to unmarshall a leases object + * @param num the number of columns read from the DB + * @para names the column names + * @para vaues the column values + * @return 0 on success + */ + int unmarshall(int num, char **names, char ** values); + + /** + * This method should not be called, leases are added/removed/updated + * through add/del interface + * @param db pointer to the database. + * @return 0 on success. + */ + int insert(SqliteDB * db); + + /** + * Leases are added/removed/updated through add/del interface + * This method is for pool management. + * @param db pointer to the database. + * @return 0 on success. + */ + int drop(SqliteDB * db); + + /** + * This method should not be called, leases are added/removed/updated + * through add/del interface + * @param db pointer to the database. + * @return 0 on success. + */ + int update(SqliteDB * db); + + /** + * Sets the value of a column in the pool for a given object + * @param db pointer to Database + * @param column to be selected + * @param where condition to select the column + * @param value of the column + * @return 0 on success + */ + int update_column( + SqliteDB * db, + const string& column, + const string& where, + const string& value) + { + return ObjectSQL::update_column(db,table,column,where,value); + } + + /** + * Gets the value of a column in the pool for a given object + * @param db pointer to Database + * @param column to be selected + * @param where condition to select the column + * @param value of the column + * @return 0 on success + */ + int select_column( + SqliteDB * db, + const string& column, + const string& where, + string * value) + { + return ObjectSQL::select_column(db,table,column,where,value); + } +}; + +#endif /*LEASES_H_*/ + diff --git a/include/Nebula.h b/include/Nebula.h index 71fc6f00a3..bf9ccb46b7 100644 --- a/include/Nebula.h +++ b/include/Nebula.h @@ -24,6 +24,7 @@ #include "NebulaTemplate.h" #include "VirtualMachinePool.h" +#include "VirtualNetworkPool.h" #include "HostPool.h" #include "VirtualMachineManager.h" @@ -87,6 +88,11 @@ public: { return hpool; }; + + VirtualNetworkPool * get_vnpool() + { + return vnpool; + }; // -------------------------------------------------------------- // Manager Accessors @@ -121,14 +127,20 @@ public: // Environment & Configuration // -------------------------------------------------------------- - string& get_nebula_location() + const string& get_nebula_location() { return nebula_location; }; + + const string& get_nebula_hostname() + { + return hostname; + }; + static string version() { - return "ONE0.1"; + return "ONE1.1"; }; void start(); @@ -148,7 +160,7 @@ private: //Constructors and = are private to only access the class through instance // ----------------------------------------------------------------------- - Nebula():nebula_configuration(0),db(0),vmpool(0),hpool(0),lcm(0), + Nebula():nebula_configuration(0),db(0),vmpool(0),hpool(0),vnpool(0),lcm(0), vmm(0),im(0),tm(0),dm(0),rm(0){}; ~Nebula() @@ -213,6 +225,7 @@ private: // --------------------------------------------------------------- string nebula_location; + string hostname; // --------------------------------------------------------------- // Configuration @@ -224,9 +237,10 @@ private: // Nebula Pools // --------------------------------------------------------------- - SqliteDB * db; + SqliteDB * db; VirtualMachinePool * vmpool; - HostPool * hpool; + HostPool * hpool; + VirtualNetworkPool * vnpool; // --------------------------------------------------------------- // Nebula Managers diff --git a/include/PoolSQL.h b/include/PoolSQL.h index 76a19f5e51..c803b443d2 100644 --- a/include/PoolSQL.h +++ b/include/PoolSQL.h @@ -156,7 +156,7 @@ private: int lastOID; /** - * The pool is implemented with a Map, of SQL object pointers, using the + * The pool is implemented with a Map of SQL object pointers, using the * OID as key. */ map pool; @@ -175,7 +175,7 @@ private: /** * FIFO-like replacement policy function. Before removing an object (pop) - * from the cache it's lock is checked. The object is removed only if + * from the cache its lock is checked. The object is removed only if * the associated mutex IS NOT blocked. Otherwise the oid is sent to the * back of the queue. */ diff --git a/include/RangedLeases.h b/include/RangedLeases.h new file mode 100644 index 0000000000..8b6fda24c2 --- /dev/null +++ b/include/RangedLeases.h @@ -0,0 +1,101 @@ +/* -------------------------------------------------------------------------- */ +/* Copyright 2002-2008, Distributed Systems Architecture Group, Universidad */ +/* Complutense de Madrid (dsa-research.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 RANGED_LEASES_H_ +#define RANGED_LEASES_H_ + +#include "Leases.h" + +using namespace std; + +class RangedLeases : public Leases +{ +public: + + // ************************************************************************* + // Constructor + // ************************************************************************* + RangedLeases(SqliteDB * db, + int _oid, + unsigned long _size, + unsigned int _mac_prefix, + const string& _network_address); + + ~RangedLeases(){}; + + /** + * Returns an unused lease, which becomes used + * @param vid identifier of the VM getting this lease + * @param ip ip of the returned lease + * @param mac mac of the returned lease + * @return 0 if success + */ + int get(int vid, string& ip, string& mac); + + /** + * Release an used lease, which becomes unused + * @param ip of the lease in use + */ + void release(const string& ip) + { + del(ip); + } + + /** + * Loads the leases from the DB. + */ + int select(SqliteDB * db) + { + //Read the leases from the DB + int rc = Leases::select(db); + + return rc; + } + +private: + /** + * The default MAC prefix for the OpenNebula cluster + */ + unsigned int mac_prefix; + + /** + * The Network address to generate leases + */ + unsigned int network_address; + + unsigned int current; + + /** + * Add a lease, from the Lease interface + * @param ip ip of the lease + * @param mac mac of the lease + * @param vid identifier of the VM getting this lease + * @return 0 if success + */ + int add(unsigned int ip, unsigned int mac[], int vid, bool used=true); + + /** + * Remove a lease, from the Lease interface + * @param db pointer to DB + * @param ip ip of the lease to be deleted + * @return 0 if success + */ + int del(const string& ip); + +}; + +#endif /*RANGED_LEASES_H_*/ diff --git a/include/RequestManager.h b/include/RequestManager.h index 138166fdca..358b5c0dd0 100644 --- a/include/RequestManager.h +++ b/include/RequestManager.h @@ -21,7 +21,7 @@ #include "ActionManager.h" #include "VirtualMachinePool.h" #include "HostPool.h" - +#include "VirtualNetworkPool.h" #include #include @@ -40,9 +40,10 @@ public: RequestManager( VirtualMachinePool * _vmpool, HostPool * _hpool, + VirtualNetworkPool * _vnpool, int _port, string _xml_log_file) - :vmpool(_vmpool),hpool(_hpool),port(_port),socket_fd(-1), + :vmpool(_vmpool),hpool(_hpool),vnpool(_vnpool),port(_port),socket_fd(-1), xml_log_file(_xml_log_file) { am.addListener(this); @@ -98,7 +99,7 @@ private: pthread_t rm_xml_server_thread; /** - * Pointer to the Host Pool, to access hosts + * Pointer to the VM Pool, to access Virtual Machines */ VirtualMachinePool * vmpool; @@ -106,6 +107,11 @@ private: * Pointer to the Host Pool, to access hosts */ HostPool * hpool; + + /** + * Pointer to the VN Pool, to access Virtual Netowrks + */ + VirtualNetworkPool * vnpool; /** * Port number where the connection will be open @@ -352,7 +358,75 @@ private: private: HostPool * hpool; - }; + }; + + /* ---------------------------------------------------------------------- */ + /* Virtual Network Interface */ + /* ---------------------------------------------------------------------- */ + + + class VirtualNetworkAllocate: public xmlrpc_c::method + { + public: + VirtualNetworkAllocate(VirtualNetworkPool * _vnpool):vnpool(_vnpool) + { + _signature="A:ss"; + _help="Creates a virtual network"; + }; + + ~VirtualNetworkAllocate(){}; + + void execute( + xmlrpc_c::paramList const& paramList, + xmlrpc_c::value * const retvalP); + + private: + VirtualNetworkPool * vnpool; + }; + + /* ---------------------------------------------------------------------- */ + + class VirtualNetworkInfo: public xmlrpc_c::method + { + public: + VirtualNetworkInfo(VirtualNetworkPool * _vnpool):vnpool(_vnpool) + { + _signature="A:si"; + _help="Returns virtual network information"; + }; + + ~VirtualNetworkInfo(){}; + + void execute( + xmlrpc_c::paramList const& paramList, + xmlrpc_c::value * const retvalP); + + private: + VirtualNetworkPool * vnpool; + + }; + + /* ---------------------------------------------------------------------- */ + + class VirtualNetworkDelete: public xmlrpc_c::method + { + public: + VirtualNetworkDelete(VirtualNetworkPool * _vnpool):vnpool(_vnpool) + { + _signature="A:si"; + _help="Deletes a virtual network"; + }; + + ~VirtualNetworkDelete(){}; + + void execute( + xmlrpc_c::paramList const& paramList, + xmlrpc_c::value * const retvalP); + + private: + VirtualNetworkPool * vnpool; + + }; }; /* -------------------------------------------------------------------------- */ diff --git a/include/Template.h b/include/Template.h index 566da06a84..fd106b752b 100644 --- a/include/Template.h +++ b/include/Template.h @@ -96,8 +96,17 @@ public: * @returns the number of elements in the vector */ virtual int get( - string& name, + const string& name, vector& values) const; + + /** + * Gets all the attributes with the given name, non-const version + * @param name the attribute name. + * @returns the number of elements in the vector + */ + virtual int get( + const string& name, + vector& values); /** * Gets the value of a Single attributes (string) with the given name. diff --git a/include/TemplateSQL.h b/include/TemplateSQL.h index 9c784a3b1a..0e286f0945 100644 --- a/include/TemplateSQL.h +++ b/include/TemplateSQL.h @@ -92,7 +92,8 @@ protected: * @param name of the attribute. * @param value of the new attribute. */ - int replace_attribute(SqliteDB * db, string& name, string& value); + int replace_attribute(SqliteDB * db, const string& name, const string& value); + }; /* -------------------------------------------------------------------------- */ diff --git a/include/TransferManager.h b/include/TransferManager.h index 89fa2a76d2..71bf34acfe 100644 --- a/include/TransferManager.h +++ b/include/TransferManager.h @@ -22,6 +22,7 @@ #include "ActionManager.h" #include "VirtualMachinePool.h" #include "LifeCycleManager.h" +#include "TransferManagerDriver.h" using namespace std; @@ -32,10 +33,12 @@ class TransferManager : public MadManager, public ActionListener public: TransferManager( - VirtualMachinePool * pool, + VirtualMachinePool * _vmpool, + HostPool * _hpool, vector& _mads): MadManager(_mads), - hpool(pool) + vmpool(_vmpool), + hpool(_hpool) { am.addListener(this); }; @@ -45,7 +48,10 @@ public: enum Actions { PROLOG, + PROLOG_MIGR, + PROLOG_RESUME, EPILOG, + EPILOG_STOP, CHECKPOINT, FINALIZE }; @@ -75,7 +81,7 @@ public: * identity will be used. Otherwise the Mad will be loaded through the * sudo application. */ - void load_mads(int uid){}; + void load_mads(int uid); /** * Gets the thread identification. @@ -93,15 +99,54 @@ private: pthread_t tm_thread; /** - * Pointer to the VM Pool, to access virtual machines + * Pointer to the Virtual Machine Pool, to access VMs */ - VirtualMachinePool * hpool; + VirtualMachinePool * vmpool; + + /** + * Pointer to the Host Pool, to access hosts + */ + HostPool * hpool; /** * Action engine for the Manager */ - ActionManager am; + ActionManager am; + /** + * Returns a pointer to a Transfer Manager driver. + * @param uid of the owner of the driver + * @param name of an attribute of the driver (e.g. its type) + * @param value of the attribute + * @return the TM driver owned by uid with attribute name equal to value + * or 0 in not found + */ + const TransferManagerDriver * get( + int uid, + const string& name, + const string& value) + { + return static_cast + (MadManager::get(uid,name,value)); + }; + + /** + * Returns a pointer to a Transfer Manager driver. The driver is + * searched by its name. + * @param uid of the owner of the driver + * @param name the name of the driver + * @return the TM driver owned by uid with attribute name equal to value + * or 0 in not found + */ + const TransferManagerDriver * get( + int uid, + const string& name) + { + string _name("NAME"); + return static_cast + (MadManager::get(uid,_name,name)); + }; + /** * Function to execute the Manager action loop method within a new pthread * (requires C linkage) @@ -122,11 +167,26 @@ private: */ void prolog_action(int vid); + /** + * This function starts the prolog migration sequence + */ + void prolog_migr_action(int vid); + + /** + * This function starts the prolog resume sequence + */ + void prolog_resume_action(int vid); + /** * This function starts the epilog sequence */ void epilog_action(int vid); + /** + * This function starts the epilog_stop sequence + */ + void epilog_stop_action(int vid); + /** * This function starts the epilog sequence */ diff --git a/include/TransferManagerDriver.h b/include/TransferManagerDriver.h new file mode 100644 index 0000000000..def17acebf --- /dev/null +++ b/include/TransferManagerDriver.h @@ -0,0 +1,84 @@ +/* -------------------------------------------------------------------------- */ +/* Copyright 2002-2008, Distributed Systems Architecture Group, Universidad */ +/* Complutense de Madrid (dsa-research.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 TRANSFER_MANAGER_DRIVER_H_ +#define TRANSFER_MANAGER_DRIVER_H_ + +#include +#include +#include + +#include "Mad.h" +#include "VirtualMachinePool.h" + +using namespace std; + +/** + * TransferManagerDriver provides a base class to implement TM + * Drivers. This class implements the protocol and recover functions + * from the Mad interface. + */ +class TransferManagerDriver : public Mad +{ +public: + + TransferManagerDriver( + int userid, + const map& attrs, + bool sudo, + VirtualMachinePool * pool); + + virtual ~TransferManagerDriver(){}; + + /** + * Implements the VM Manager driver protocol. + * @param message the string read from the driver + */ + void protocol( + string& message); + + /** + * TODO: What do we need here? Check on-going xfr? + */ + void recover(); + +private: + friend class TransferManager; + + /** + * Configuration file for the driver + */ + Template driver_conf; + + /** + * Pointer to the Virtual Machine Pool, to access VMs + */ + VirtualMachinePool * vmpool; + + /** + * Sends a transfer request to the MAD: "TRANSFER ID XFR_FILE" + * @param oid the virtual machine id. + * @param xfr_file is the path to the transfer script + */ + void transfer (const int oid, const string& xfr_file) const; +}; + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + +#endif /*TRANSFER_MANAGER_DRIVER_H_*/ + diff --git a/include/VirtualMachine.h b/include/VirtualMachine.h index 1a8b74acb9..7e68a6ee44 100644 --- a/include/VirtualMachine.h +++ b/include/VirtualMachine.h @@ -72,10 +72,11 @@ public: SAVE_SUSPEND = 6, SAVE_MIGRATE = 7, PROLOG_MIGRATE = 8, - EPILOG_STOP = 9, - EPILOG = 10, - SHUTDOWN = 11, - CANCEL = 12 + PROLOG_RESUME = 9, + EPILOG_STOP = 10, + EPILOG = 11, + SHUTDOWN = 12, + CANCEL = 13 }; // ------------------------------------------------------------------------- @@ -250,34 +251,71 @@ public: }; /** - * Returns the deployment filename (local path). The hasHistory() - * function MUST be called before this one. - * @return the deployment filename + * Returns the transfer filename. The transfer file is in the form: + * $ONE_LOCATION/var/$VM_ID/transfer.$SEQ + * The hasHistory() function MUST be called before this one. + * @return the transfer filename */ - const string & get_deployment_lfile() const + const string & get_transfer_file() const { - return history->deployment_lfile; + return history->transfer_file; }; /** - * Returns the deployment filename for the current host (remote). The - * hasHistory() function MUST be called before this one. + * Returns the deployment filename. The deployment file is in the form: + * $ONE_LOCATION/var/$VM_ID/deployment.$SEQ + * The hasHistory() function MUST be called before this one. * @return the deployment filename */ - const string & get_deployment_rfile() const + const string & get_deployment_file() const { - return history->deployment_rfile; + return history->deployment_file; }; + + /** + * Returns the remote deployment filename. The file is in the form: + * $VM_DIR/$VM_ID/images/deployment.$SEQ + * The hasHistory() function MUST be called before this one. + * @return the deployment filename + */ + const string & get_remote_deployment_file() const + { + return history->rdeployment_file; + }; /** - * Returns the checkpoint filename for the current host (remote). The - * hasHistory() function MUST be called before this one. + * Returns the checkpoint filename for the current host. The checkpoint file + * is in the form: + * $VM_DIR/$VM_ID/images/checkpoint + * The hasHistory() function MUST be called before this one. * @return the checkpoint filename */ const string & get_checkpoint_file() const { return history->checkpoint_file; }; + + /** + * Returns the remote VM directory. The VM remote dir is in the form: + * $VM_DIR/$VM_ID/ + * The hasHistory() function MUST be called before this one. + * @return the remote directory + */ + const string & get_remote_dir() const + { + return history->vm_rhome; + }; + + /** + * Returns the local VM directory. The VM local dir is in the form: + * $ONE_LOCATION/var/$VM_ID/ + * The hasHistory() function MUST be called before this one. + * @return the remote directory + */ + const string & get_local_dir() const + { + return history->vm_lhome; + }; /** * Returns the hostname for the current host. The hasHistory() @@ -299,6 +337,15 @@ public: return previous_history->hostname; }; + /** + * Returns the reason that originated the VM migration in the previous host + * @return the migration reason to leave this host + */ + const History::MigrationReason get_previous_reason() const + { + return previous_history->reason; + }; + /** * Get host id where the VM is or is going to execute. The hasHistory() * function MUST be called before this one. @@ -532,6 +579,7 @@ public: { return uid; }; + // ------------------------------------------------------------------------ // Timers @@ -561,6 +609,15 @@ public: * @param disk */ void get_requirements (int& cpu, int& memory, int& disk); + + // ------------------------------------------------------------------------ + // Leases + // ------------------------------------------------------------------------ + + /** + * Releases all network leases taken by this Virtual Machine + */ + void release_leases(); private: @@ -578,20 +635,11 @@ private: // ************************************************************************* // Virtual Machine Attributes // ************************************************************************* - + // ------------------------------------------------------------------------- // Identification variables // ------------------------------------------------------------------------- - /** - * Array id - */ - int aid; - - /** - * Task id - */ - int tid; - + /** * User (owner) id */ @@ -599,22 +647,7 @@ private: // ------------------------------------------------------------------------- // VM Scheduling & Managing Information - // ------------------------------------------------------------------------- - /** - * Static scheduling priority - */ - int priority; - - /** - * The VM reschedule flag - */ - bool reschedule; - - /** - * Last time (in epoch) that the VM was rescheduled - */ - time_t last_reschedule; - + // ------------------------------------------------------------------------- /** * Last time (in epoch) that the VM was polled to get its status */ @@ -783,24 +816,19 @@ protected: enum ColNames { OID = 0, - AID = 1, - TID = 2, - UID = 3, - PRIORITY = 4, - RESCHEDULE = 5, - LAST_RESCHEDULE = 6, - LAST_POLL = 7, - TEMPLATE_ID = 8, - STATE = 9, - LCM_STATE = 10, - STIME = 11, - ETIME = 12, - DEPLOY_ID = 13, - MEMORY = 14, - CPU = 15, - NET_TX = 16, - NET_RX = 17, - LIMIT = 18 + UID = 1, + LAST_POLL = 2, + TEMPLATE_ID = 3, + STATE = 4, + LCM_STATE = 5, + STIME = 6, + ETIME = 7, + DEPLOY_ID = 8, + MEMORY = 9, + CPU = 10, + NET_TX = 11, + NET_RX = 12, + LIMIT = 13 }; static const char * table; diff --git a/include/VirtualNetwork.h b/include/VirtualNetwork.h new file mode 100644 index 0000000000..cbfcc384f9 --- /dev/null +++ b/include/VirtualNetwork.h @@ -0,0 +1,349 @@ +/* -------------------------------------------------------------------------- */ +/* Copyright 2002-2008, Distributed Systems Architecture Group, Universidad */ +/* Complutense de Madrid (dsa-research.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 VIRTUAL_NETWORK_H_ +#define VIRTUAL_NETWORK_H_ + + +#include "PoolSQL.h" +#include "VirtualNetworkTemplate.h" +#include "Leases.h" + +#include +#include +#include + +#include +#include + +using namespace std; + +extern "C" int vn_select_cb (void * _vn, int num,char ** values, char ** names); + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + +/** + * The Virtual Network class. It represents a Virtual Network at manages its leases. + * One lease is formed by one IP and one MAC address. + * MAC address are derived from IP addresses. + */ +class VirtualNetwork : public PoolObjectSQL +{ +public: + + /** + * Possible types of networks + */ + + enum NetworkType + { + UNINITIALIZED = -1, + RANGED = 0, + FIXED = 1, + }; + + // ************************************************************************* + // Virtual Network Public Methods + // ************************************************************************* + /** + * Gets a new lease for a specific VM + * @param vid VM identifier + * @param _ip pointer to string for IP to be stored into + * @param _mac pointer to string for MAC to be stored into + * @param _bridge name of the physical bridge this VN binds to + * @return 0 if success + */ + int get_lease(int vid, string& _ip, string& _mac, string& _bridge) + { + _bridge = bridge; + return leases->get(vid,_ip,_mac); + }; + + /** + * Release previously given lease + * @param _ip IP identifying the lease + * @return 0 if success + */ + void release_lease(const string& ip) + { + return leases->release(ip); + }; + + /** + * Gets size of the network (used + free) + * @return number of hosts that can be fitted in this network + */ + unsigned int get_size() + { + return leases->size; + }; + + /** + * Function to write a Virtual Network in an output stream + */ + friend ostream& operator<<(ostream& os, VirtualNetwork& vn); + +private: + + // ------------------------------------------------------------------------- + // Friends + // ------------------------------------------------------------------------- + friend class VirtualNetworkPool; + + friend int vn_select_cb ( + void * _vm, + int num, + char ** values, + char ** names); + + // ************************************************************************* + // Virtual Network Private Attributes + // ************************************************************************* + + // ------------------------------------------------------------------------- + // Identification variables + // ------------------------------------------------------------------------- + /** + * Name of the Virtual Network + */ + string name; + + /** + * Owner of the Virtual Network + */ + int uid; + + // ------------------------------------------------------------------------- + // Binded physical attributes + // ------------------------------------------------------------------------- + + /** + * Name of the bridge this VNW binds to + */ + string bridge; + + // ------------------------------------------------------------------------- + // Virtual Network Description + // ------------------------------------------------------------------------- + /** + * Holds the type of this network + */ + NetworkType type; + + /** + * Pointer to leases class, can be fixed or ranged. + * Holds information on given (and, optionally, possible) leases + */ + Leases * leases; + + /** + * The Virtual Network template, holds the VNW attributes. + */ + VirtualNetworkTemplate vn_template; + + // ************************************************************************* + // Non persistent data members from Nebula.conf + // ************************************************************************* + + /** + * MAC prefix for this OpenNebula site + */ + unsigned int mac_prefix; + + /** + * Default size for virtual networks + */ + int default_size; + + // ************************************************************************* + // DataBase implementation (Private) + // ************************************************************************* + + /** + * Bootstraps the database table(s) associated to the Virtual Network + */ + static void bootstrap(SqliteDB * db) + { + db->exec(VirtualNetwork::db_bootstrap); + + db->exec(VirtualNetworkTemplate::db_bootstrap); + + db->exec(Leases::db_bootstrap); + }; + + /** + * Function to unmarshall a VNW object, and associated classes. + * @param num the number of columns read from the DB + * @para names the column names + * @para vaues the column values + * @return 0 on success + */ + int unmarshall(int num, char **names, char ** values); + + /** + * Function to drop VN entry in vn_pool + * @return 0 on success + */ + int vn_drop(SqliteDB * db); + + // ------------------------------------------------------------------------ + // Template + // ------------------------------------------------------------------------ + + /** + * Gets the values of a template attribute + * @param name of the attribute + * @param values of the attribute + * @return the number of values + */ + int get_template_attribute( + string& name, + vector& values) const + { + return vn_template.get(name,values); + }; + + /** + * Gets the values of a template attribute + * @param name of the attribute + * @param values of the attribute + * @return the number of values + */ + int get_template_attribute( + const char *name, + vector& values) const + { + string str=name; + return vn_template.get(str,values); + }; + + /** + * Gets a string based VN attribute + * @param name of the attribute + * @param value of the attribute (a string), will be "" if not defined + */ + void get_template_attribute( + const char * name, + string& value) const + { + string str=name; + vn_template.get(str,value); + } + + /** + * Gets a string based VN attribute + * @param name of the attribute + * @param value of the attribute (an int), will be 0 if not defined + */ + void get_template_attribute( + const char * name, + int& value) const + { + string str=name; + vn_template.get(str,value); + } + + /** + * Updates the template of a VNW, adding a new attribute (replacing it if + * already defined), the VN's mutex SHOULD be locked + * @param vm pointer to the virtual network object + * @param name of the new attribute + * @param value of the new attribute + * @return 0 on success + */ + int update_template_attribute( + SqliteDB * db, + string& name, + string& value) + { + return vn_template.replace_attribute(db,name,value); + } + +protected: + + //************************************************************************** + // Constructor + //************************************************************************** + + VirtualNetwork(unsigned int _mac_prefix, int _default_size); + + ~VirtualNetwork(); + + // ************************************************************************* + // DataBase implementation + // ************************************************************************* + + enum ColNames + { + OID = 0, + UID = 1, + NAME = 2, + TYPE = 3, + BRIDGE = 4, + LIMIT = 5 + }; + + static const char * table; + + static const char * db_names; + + static const char * db_bootstrap; + + /** + * Reads the Virtual Network (identified with its OID) from the database. + * @param db pointer to the db + * @return 0 on success + */ + int select(SqliteDB * db); + + /** + * Writes the Virtual Network and its associated template and leases in the database. + * @param db pointer to the db + * @return 0 on success + */ + int insert(SqliteDB * db); + + /** + * Writes/updates the Virtual Network data fields in the database. + * @param db pointer to the db + * @return 0 on success + */ + int update(SqliteDB * db); + + /** + * Deletes a VNW from the database and all its associated information: + * - VNW template + * - given leases + * @param db pointer to the db + * @return 0 on success + */ + int drop(SqliteDB * db) + { + int rc; + + rc = vn_template.drop(db); + + rc += leases->drop(db); + + rc += vn_drop(db); + + return rc; + } +}; + +#endif /*VIRTUAL_NETWORK_H_*/ diff --git a/include/VirtualNetworkPool.h b/include/VirtualNetworkPool.h new file mode 100644 index 0000000000..30cea2383b --- /dev/null +++ b/include/VirtualNetworkPool.h @@ -0,0 +1,144 @@ +/* -------------------------------------------------------------------------- */ +/* Copyright 2002-2008, Distributed Systems Architecture Group, Universidad */ +/* Complutense de Madrid (dsa-research.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 VIRTUAL_NETWORK_POOL_H_ +#define VIRTUAL_NETWORK_POOL_H_ + +#include "PoolSQL.h" +#include "VirtualNetwork.h" + +#include + +using namespace std; + + +/** + * The Virtual Network Pool class. ... + */ +class VirtualNetworkPool : public PoolSQL +{ +public: + + VirtualNetworkPool(SqliteDB * db, + const string& str_mac_prefix, + int default_size); + + ~VirtualNetworkPool(){}; + + /** + * Function to allocate a new VN object + * @param uid user identifier + * @param stemplate a string describing the VN + * @param oid the id assigned to the VM (output) + * @return 0 on success, -1 error inserting in DB,-2 error parsing + * the template, -3 wrong attributes in template + */ + int allocate ( + int uid, + const string& stemplate, + int * oid); + + /** + * Function to get a VN from the pool, if the object is not in memory + * it is loaded from the DB + * @param oid VN unique id + * @param lock locks the VN mutex + * @return a pointer to the VN, 0 if the VN could not be loaded + */ + VirtualNetwork * get( + int oid, + bool lock) + { + return static_cast(PoolSQL::get(oid,lock)); + }; + + /** + * Function to get a VN from the pool using the network name + * If the object is not in memory it is loaded from the DB + * @param name VN unique name + * @param lock locks the VN mutex + * @return a pointer to the VN, 0 if the VN could not be loaded + */ + VirtualNetwork * get( + const string& name, + bool lock); + + //-------------------------------------------------------------------------- + // Virtual Network DB access functions + //-------------------------------------------------------------------------- + + /** + * Updates the template of a VN, adding a new attribute (replacing it if + * already defined), the VN's mutex SHOULD be locked + * @param vn pointer to the virtual network object + * @param name of the new attribute + * @param value of the new attribute + * @return 0 on success + */ + int update_template_attribute( + VirtualNetwork * vn, + string& name, + string& value) + { + return vn->update_template_attribute(db,name,value); + }; + + /** + * Bootstraps the database table(s) associated to the VirtualNetwork pool + */ + void bootstrap() + { + VirtualNetwork::bootstrap(db); + }; + + /** Drops a VN from the cache & DB, the VN mutex MUST BE locked + * @param vn pointer to VN + */ + int drop(VirtualNetwork * vn) + { + int rc = vn->drop(db); + + if ( rc == 0) + { + remove(static_cast(vn)); + } + + return rc; + }; + +private: + /** + * Factory method to produce VN objects + * @return a pointer to the new VN + */ + PoolObjectSQL * create() + { + return new VirtualNetwork(mac_prefix, default_size); + }; + + /** + * Holds the system-wide MAC prefix + */ + unsigned int mac_prefix; + + /** + * Default size for Virtual Networks + */ + unsigned int default_size; +}; + +#endif /*VIRTUAL_NETWORK_POOL_H_*/ diff --git a/include/VirtualNetworkTemplate.h b/include/VirtualNetworkTemplate.h new file mode 100644 index 0000000000..4a2b1cd52e --- /dev/null +++ b/include/VirtualNetworkTemplate.h @@ -0,0 +1,47 @@ +/* -------------------------------------------------------------------------- */ +/* Copyright 2002-2008, Distributed Systems Architecture Group, Universidad */ +/* Complutense de Madrid (dsa-research.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 VIRTUAL_NETWORK_TEMPLATE_H_ +#define VIRTUAL_NETWORK_TEMPLATE_H_ + +#include "TemplateSQL.h" + +using namespace std; + +/** + * Virtual Network Template class, it represents a VN configuration file. + */ +class VirtualNetworkTemplate : public TemplateSQL +{ +public: + VirtualNetworkTemplate(int tid = -1): + TemplateSQL(table,tid){}; + + ~VirtualNetworkTemplate(){}; + +private: + friend class VirtualNetwork; + + static const char * table; + + static const char * db_bootstrap; +}; + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + +#endif /*VIRTUAL_NETWORK_TEMPLATE_H_*/ diff --git a/install.sh b/install.sh index 7aa3984277..10418d19b1 100755 --- a/install.sh +++ b/install.sh @@ -30,7 +30,7 @@ if [ -z "$SRC_DIR" -o -z "$DST_DIR" ]; then exit -1 fi -DIRS="/bin /include /etc /etc/im_kvm /etc/im_xen /etc/vmm_kvm /etc/vmm_xen /libexec /lib/ruby /var /share/examples /lib/im_probes /etc/vmm_ec2 /etc/im_ec2" +DIRS="/bin /include /etc /etc/im_kvm /etc/im_xen /etc/vmm_kvm /etc/vmm_xen /libexec /lib/ruby /var /share/examples /lib/im_probes /lib/tm_commands/nfs /lib/tm_commands/ssh /etc/vmm_ec2 /etc/im_ec2 /etc/tm_nfs /etc/tm_ssh" for d in $DIRS; do mkdir -p $DST_DIR$d @@ -43,6 +43,7 @@ inst_ln src/scheduler/mm_sched bin inst_ln src/client/ruby/onevm bin inst_ln src/client/ruby/onehost bin +inst_ln src/client/ruby/onenetwork bin inst_ln share/scripts/madcommon.sh libexec inst_ln share/scripts/one bin @@ -56,6 +57,7 @@ inst_ln include/OneClient.h include/ inst_ln src/mad/ruby/one_mad.rb lib/ruby inst_ln src/mad/ruby/one_ssh.rb lib/ruby +inst_ln src/mad/ruby/ThreadScheduler.rb lib/ruby inst_ln src/client/ruby/one.rb lib/ruby inst_ln src/client/ruby/client_utilities.rb lib/ruby @@ -115,6 +117,35 @@ inst_ln src/im_mad/host_probes/architecture.sh lib/im_probes inst_ln src/im_mad/host_probes/cpu.sh lib/im_probes inst_ln src/im_mad/host_probes/name.sh lib/im_probes +# -- Transfer manager -- + +inst_ln src/tm_mad/one_tm bin +inst_ln src/tm_mad/one_tm.rb bin + +inst_ln src/tm_mad/TMScript.rb lib/ruby +inst_ln src/tm_mad/tm_common.sh libexec + +inst_ln src/tm_mad/nfs/tm_nfs.conf etc/tm_nfs +inst_ln src/tm_mad/nfs/tm_nfsrc etc/tm_nfs + +inst_ln src/tm_mad/nfs/tm_clone.sh lib/tm_commands/nfs +inst_ln src/tm_mad/nfs/tm_delete.sh lib/tm_commands/nfs +inst_ln src/tm_mad/nfs/tm_ln.sh lib/tm_commands/nfs +inst_ln src/tm_mad/nfs/tm_mkswap.sh lib/tm_commands/nfs +inst_ln src/tm_mad/nfs/tm_mkimage.sh lib/tm_commands/nfs +inst_ln src/tm_mad/nfs/tm_mv.sh lib/tm_commands/nfs + +inst_ln src/tm_mad/ssh/tm_ssh.conf etc/tm_ssh +inst_ln src/tm_mad/ssh/tm_sshrc etc/tm_ssh + +inst_ln src/tm_mad/ssh/tm_clone.sh lib/tm_commands/ssh +inst_ln src/tm_mad/ssh/tm_delete.sh lib/tm_commands/ssh +inst_ln src/tm_mad/ssh/tm_ln.sh lib/tm_commands/ssh +inst_ln src/tm_mad/ssh/tm_mkswap.sh lib/tm_commands/ssh +inst_ln src/tm_mad/ssh/tm_mkimage.sh lib/tm_commands/ssh +inst_ln src/tm_mad/ssh/tm_mv.sh lib/tm_commands/ssh + + # --- Examples --- inst_cp share/examples/vm.template share/examples diff --git a/share/etc/oned.conf b/share/etc/oned.conf index 3cff47a7e2..083176bb1d 100644 --- a/share/etc/oned.conf +++ b/share/etc/oned.conf @@ -9,25 +9,42 @@ # HOST_MONITORING_INTERVAL: Time in seconds between host monitorization # VM_POLLING_INTERVAL: Time in seconds between virtual machine monitorization # -# VM_RDIR: The remote nodes must have access to $ONE_LOCATION/var, so this must -# be shared between the ONE server and the remote nodes. If the mount point of -# $ONE_LOCATION/var has a different path in the remote nodes than in the ONE server, -# set here the mount point of the _remote_ nodes +# VM_DIR: Remote path to store the VM images, it should be shared between all +# the cluster nodes to perform live migrations. This variable is the default +# for all the hosts in the cluster. You can set it in a per host basis when +# adding a host (onehost add) # # PORT: Port where oned will listen for xmlrpc calls. # +# MAC_PREFIX: Default MAC prefix to generate virtual network MAC addresses +# +# NETWORK_SIZE: Default size fot virtual networks +# # DEBUG_LEVEL: 0 = ERROR, 1 = WARNING, 2 = INFO, 3 = DEBUG #------------------------------------------------------------------------------- HOST_MONITORING_INTERVAL = 10 VM_POLLING_INTERVAL = 10 -#VM_RDIR=/vCluster/var +#VM_DIR=/vCluster/var PORT=2633 DEBUG_LEVEL=3 +#------------------------------------------------------------------------------- +# Physical Networks configuration +#------------------------------------------------------------------------------- +# Here you can define the default size for the virtual networks +# +# Also, the default MAC prefix to be used to create the auto-generated MAC addresses +# is defined here (this can be overrided by the Virtual Network template) +#-------------------------------------------------------------------------------- + +MAC_PREFIX="00:01" + +NETWORK_SIZE=254 + #------------------------------------------------------------------------------- # Information Driver Configuration #------------------------------------------------------------------------------- @@ -106,4 +123,31 @@ VM_MAD = [ #------------------------------------------------------------------------------- +#------------------------------------------------------------------------------- +# Transfer Manager Driver Configuration +#------------------------------------------------------------------------------- +# You can add more transfer managers with different configurations but make +# sure it has different names. +# name : name for this transfer manager +# executable: path of the transfer manager executable, can be an +# absolute path or a relative path from $ONE_LOCATION +# arguments : for the driver executable +# default : default values and configuration parameters for the driver +#------------------------------------------------------------------------------- + +TM_MAD = [ + name = "tm_nfs", + executable = "bin/one_tm", + arguments = "etc/tm_nfs/tm_nfs.conf", + default = "etc/tm_nfs/tm_nfs.conf" ] +#------------------------------------------------------------------------------- +# Physical Networks configuration +#------------------------------------------------------------------------------- +# Here you can define available physical networks by giving them a name +# and specifying which bridge of the physical hosts VMs should be tied to. +# +# Also, the default MAC prefix to be used to create the auto-generated MAC addresses +# is defined here (this can be overrided by the Virtual Network template) +#-------------------------------------------------------------------------------- + diff --git a/share/examples/private.net b/share/examples/private.net new file mode 100644 index 0000000000..73c5ba30e9 --- /dev/null +++ b/share/examples/private.net @@ -0,0 +1,5 @@ +NAME = "Private LAN" +TYPE = RANGED +BRIDGE = eth0 +NETWORK_SIZE = 250 +NETWORK_ADDRESS= 10.0.0.0 diff --git a/share/examples/public.net b/share/examples/public.net new file mode 100644 index 0000000000..1bf28c93dc --- /dev/null +++ b/share/examples/public.net @@ -0,0 +1,9 @@ +NAME = "Public LAN" +TYPE = FIXED +BRIDGE= eth1 +LEASES= [IP=130.10.0.1,MAC=50:20:20:20:20:20] +LEASES= [IP=130.10.0.2,MAC=50:20:20:20:20:21] +LEASES= [IP=130.10.0.3,MAC=50:20:20:20:20:22] +LEASES= [IP=130.10.0.4] +LEASES= [IP=130.10.0.5] +LEASES= [IP=130.10.0.6] diff --git a/share/examples/vm.schema b/share/examples/vm.schema index fbe4ee4ded..2f864eb41e 100644 --- a/share/examples/vm.schema +++ b/share/examples/vm.schema @@ -42,12 +42,15 @@ FEATURES = [ #--------------------------------------- DISK = [ - type = "floppy|disk|cdrom", #Optional, KVM + type = "floppy|disk|cdrom|swap", #Optional, KVM ,XEN(only swap) source = "path_to_disk_image_file|physical_dev", #Mandatory, XEN, KVM + size = "size_in_GB", #Optional, KVM, XEN (only for swap, defaults 1G) target = "device_to_map_disk", #Mandatory, XEN, KVM bus = "ide|scsi|virtio|xen", #Optional, KVM - readonly = "yes|no" ] #Optional, XEN, KVM - + readonly = "yes|no", #Optional, XEN, KVM + clone = "yes|no", #Optional, XEN, KVM + save = "path_to_disk_image_file" ] #Optional, XEN, KVM + #--------------------------------------- # Network Interfaces #--------------------------------------- diff --git a/share/examples/vm.template b/share/examples/vm.template index a2216ef84a..6e88726446 100644 --- a/share/examples/vm.template +++ b/share/examples/vm.template @@ -30,6 +30,9 @@ DISK = [ NIC = [ mac="00:ff:72:17:20:27"] +NIC = [ NETWORK="Private LAN"] + + # --- VNC server --- GRAPHICS = [ diff --git a/src/client/ruby/client_utilities.rb b/src/client/ruby/client_utilities.rb index 8a437c7968..d5effd0243 100644 --- a/src/client/ruby/client_utilities.rb +++ b/src/client/ruby/client_utilities.rb @@ -259,3 +259,23 @@ def get_host_id(host, name) result end + +def get_vn_id(vn, name) + vn_id=vn.get_vn_id(name) + + result=nil + + if vn_id + if vn_id.kind_of?(Array) + puts "There are multiple virtual networks with name #{name}." + exit -1 + else + result=vn_id + end + else + puts "Virtual networks named #{name} not found." + exit -1 + end + + result +end diff --git a/src/client/ruby/one.rb b/src/client/ruby/one.rb index cf7e9e1b99..51e8358181 100644 --- a/src/client/ruby/one.rb +++ b/src/client/ruby/one.rb @@ -33,17 +33,18 @@ module ONE ONE_LOCATION=ENV["ONE_LOCATION"] TABLES={ - "vmpool" => %w{oid aid tid uid priority reschedule last_reschedule - last_poll template state lcm_state stime etime deploy_id memory - cpu net_tx net_rx}, - "history" => %w{oid seq hostname vm_dir hid vmmad tmmad stime + "vm_pool" => %w{oid uid last_poll template_id state lcm_state + stime etime deploy_id memory cpu net_tx net_rx}, + "history" => %w{vid seq host_name vm_dir hid vm_mad tm_mad stime etime pstime petime rstime retime estime eetime reason}, - "vm_template" => %w{id name type value}, - "hostpool" => %w{hid host_name state im_mad vm_mad tm_mad + "vm_attributes" => %w{id name type value}, + "host_pool" => %w{oid host_name state im_mad vm_mad tm_mad last_mon_time managed}, "host_attributes" => %w{id name type value}, - "hostshares" => %w{hsid endpoint disk_usage mem_usage + "host_shares" => %w{hid endpoint disk_usage mem_usage cpu_usage max_disk max_mem max_cpu running_vms} + "network_pool" => %w{oid uid name type bridge}, + "vn_template" => %w{id name type value} } @@ -100,8 +101,6 @@ module ONE @db.busy_handler do |data, retries| if retries < 3 - puts "Timeout connecting to the database, retrying. "+ - "Tries left #{2-retries}" sleep 1 1 else @@ -125,6 +124,7 @@ module ONE res=result.collect {|row| r=Hash.new + TABLES[table].each_with_index {|value, index| r[value]=row[index] } @@ -289,15 +289,25 @@ module ONE def delete(*args) self.action("finalize", args[0]) end + + def get_db + if !@db + @db=Database.new + end + @db + end + + def close_db + if @db + @db.close + @db=nil + end + end def get(options=nil) begin - @db=Database.new + res=get_db.select_table_with_names("vm_pool", options) - res=@db.select_table_with_names("vmpool", options) - - @db.close - result=res rescue result=[false, "Error accessing database"] @@ -311,7 +321,7 @@ module ONE if res[0] res[1].each {|row| hostname=self.get_history_host(row["oid"]) - row["hostname"]=hostname + row["host_name"]=hostname } end res @@ -323,47 +333,29 @@ module ONE ########### def get_history_host(id, db=nil) - if db - my_db=db - else - my_db=Database.new - end + my_db=get_db - res=my_db.select_table_with_names("history", :where => "oid=#{id}") - - my_db.close if !db + res=my_db.select_table_with_names("history", :where => "vid=#{id}") if res and res[0] and res[1] and res[1][-1] - return hostname=res[1][-1]["hostname"] + return hostname=res[1][-1]["host_name"] else return nil end end def get_history(id, db=nil) - if db - my_db=db - else - my_db=Database.new - end + my_db=get_db - res=my_db.select_table_with_names("history", :where => "oid=#{id}") + res=my_db.select_table_with_names("history", :where => "vid=#{id}") - my_db.close if !db - return res end def get_template(id, db=nil) - if db - my_db=db - else - my_db=Database.new - end + my_db=get_db - res=my_db.select_table_with_names("vm_template", :where => "id=#{id}") - - my_db.close if !db + res=my_db.select_table_with_names("vm_attributes", :where => "id=#{id}") if res && res[0] template=Hash.new @@ -431,16 +423,16 @@ module ONE # id if there is only one vm with that name # array of ids if there is more than one vm def get_vm_from_name(name) - db=Database.new + db=get_db res_template=db.select_table_with_names( - "vm_template", + "vm_attributes", :where => "name=\"NAME\" AND value=\"#{name}\"") return nil if !res_template[0] or res_template[1].length<1 selected_vms=res_template[1].collect {|sel_template| template_id=sel_template["id"] - res_vm=get(:where => "template=#{template_id} AND state<>6") + res_vm=get(:where => "template_id=#{template_id} AND state<>6") if !res_vm[0] or res_vm[1].length<1 nil else @@ -483,7 +475,7 @@ module ONE "enable_" => [:to_i, nil] } end - + def allocate(*args) case args[4] when /^true$/i, 1 @@ -507,11 +499,7 @@ module ONE def get_generic(table, options=nil) begin - @db=Database.new - - res=@db.select_table_with_names(table, options) - - @db.close + res=get_db.select_table_with_names(table, options) result=res rescue @@ -522,7 +510,7 @@ module ONE end def get(options=nil) - get_generic("hostpool", options) + get_generic("host_pool", options) end def get_host_attributes(hid) @@ -530,13 +518,27 @@ module ONE end def get_host_share(hid) - get_generic("hostshares", :where => "hsid=#{hid}") + get_generic("host_shares", :where => "hid=#{hid}") end def prefix "host" end + def get_db + if !@db + @db=Database.new + end + @db + end + + def close_db + if @db + @db.close + @db=nil + end + end + ########### # HELPERS # @@ -562,9 +564,90 @@ module ONE return nil if !res[0] or res[1].length<1 if res[1].length==1 - return res[1][0]["hid"] + return res[1][0]["oid"] else - return res[1].collect {|host| host["hid"] } + return res[1].collect {|host| host["oid"] } + end + end + end + + + class VN < CommandContainer + + + def commands + { + "allocate_" => [:to_s], + "info" => [:to_i], + "delete" => [:to_i], + } + end + + def allocate(*args) + begin + f=open(args[0], "r") + template=f.read + f.close + rescue + return [false, "Can not read template"] + end + + self.allocate_(template) + end + + def get_generic(table, options=nil) + begin + @db=Database.new + + res=@db.select_table_with_names(table, options) + + @db.close + + result=res + rescue + result=[false, "Error accessing database"] + end + + result + end + + def get(options=nil) + get_generic("network_pool", options) + end + + def get_vn_attributes(nid) + get_generic("vn_template", :where => "oid=#{nid}") + end + + def get_vn_leases(nid) + get_generic("leases", :where => "oid=#{nid}") + end + + def prefix + "vn" + end + + + ########### + # HELPERS # + ########### + + def get_vn_id(name) + vn_id=name.strip + # Check if the name is not a number (is not an ID) + vn_id=get_vn_from_name(vn_id) if !vn_id.match(/^[0123456789]+$/) + return vn_id + end + + def get_vn_from_name(name) + res=get(:where => "name=\"#{name}\"") + + return nil if !res[0] or res[1].length<1 + + if res[1].length==1 + return res[1][0]["oid"] + else + return res[1].collect {|vn| vn["oid"] } end end end diff --git a/src/client/ruby/onehost b/src/client/ruby/onehost index 042e4d833f..2bafaa9cb1 100755 --- a/src/client/ruby/onehost +++ b/src/client/ruby/onehost @@ -37,7 +37,7 @@ ShowTableHost={ :name => "HID", :desc => "ONE identifier for host", :size => 4, - :proc => lambda {|d,e| d["hid"] } + :proc => lambda {|d,e| d["oid"] } }, :name => { :name => "NAME", @@ -123,7 +123,7 @@ class HostShow result=res header_host_small res[1].each {|row| - res2=@host.get_host_attributes(row["hid"]) + res2=@host.get_host_attributes(row["oid"]) if res2[0] attributes=res2[1] attributes.each {|a| @@ -133,7 +133,7 @@ class HostShow } end - res2=@host.get_host_share(row["hid"]) + res2=@host.get_host_share(row["oid"]) if res2[0] attributes=res2[1] attributes.each {|a| @@ -142,7 +142,6 @@ class HostShow row["hs_max_cpu"]=a["max_cpu"] row["hs_mem_usage"]=a["mem_usage"] row["hs_cpu_usage"]=a["cpu_usage"] - row["hs_running_vms"]=a["running_vms"] } end } @@ -178,7 +177,7 @@ class OnehostParse < CommandParse Commands: * add (Adds a new machine to the pool) - onehost add + onehost add * show (Gets info from a host) onehost show @@ -216,7 +215,13 @@ EOT end server=ONE::Server.new -host=ONE::Host.new(server) +$host=host=ONE::Host.new(server) + +def command_exit(code) + $host.close_db + exit(code) +end + onehost_opts=OnehostParse.new onehost_opts.parse(ARGV) @@ -227,8 +232,8 @@ command=ARGV.shift case command when "add" - check_parameters("add", 3) - result=host.allocate(*[ARGV[0], ARGV[1], ARGV[2], "tm_mad", "true"]) + check_parameters("add", 4) + result=host.allocate(*[ARGV[0], ARGV[1], ARGV[2], ARGV[3], "true"]) when "show" check_parameters("show", 1) @@ -238,7 +243,7 @@ when "show" puts result[1] else puts "Error: "+result[1] - exit -1 + command_exit -1 end when "delete" @@ -247,7 +252,7 @@ when "delete" result=host.delete(host_id) if result[0] puts "Host deleted" - exit 0 + command_exit 0 end when "list" @@ -270,7 +275,7 @@ when "enable" result=host.enable(host_id) if result[0] puts "Host enabled" - exit 0 + command_exit 0 end when "disable" @@ -279,15 +284,18 @@ when "disable" result=host.disable(host_id) if result[0] puts "Host disabled" - exit 0 + command_exit 0 end else onehost_opts.print_help - exit -1 + command_exit -1 end if !result[0] puts "Error: " + result[1].to_s - exit -1 + command_exit -1 end + +command_exit 0 + diff --git a/src/client/ruby/onenetwork b/src/client/ruby/onenetwork new file mode 100755 index 0000000000..b5e15de415 --- /dev/null +++ b/src/client/ruby/onenetwork @@ -0,0 +1,225 @@ +#!/usr/bin/env ruby + +# -------------------------------------------------------------------------- # +# Copyright 2002-2008, Distributed Systems Architecture Group, Universidad # +# Complutense de Madrid (dsa-research.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. # +#--------------------------------------------------------------------------- # + + + +ONE_LOCATION=ENV["ONE_LOCATION"] + +if !ONE_LOCATION + puts "ONE_LOCATION not set" + exit -1 +end + +$: << ONE_LOCATION+"/lib/ruby" + +require 'one' +require 'client_utilities' +require 'command_parse' + +ShowTableVN={ + :nid => { + :name => "NID", + :desc => "ONE identifier for virtual network", + :size => 4, + :proc => lambda {|d,e| d["oid"] } + }, + :name => { + :name => "NAME", + :desc => "name of the virtual network", + :size => 15, + :left => true, + :proc => lambda {|d,e| d["name"] } + }, + :type => { + :name => "TYPE", + :desc => "NType of virtual network", + :size => 4, + :proc => lambda {|d,e| d["type"] } + }, + :size => { + :name => "SIZE", + :desc => "Number of hosts (free + used) in the virtual network", + :size => 6, + :proc => lambda {|d,e| d["SIZE"] } + }, + :bridge => { + :name => "BRIDGE", + :desc => "Bridge associated to the virtual network", + :size => 6, + :left => true, + :proc => lambda {|d,e| d["bridge"] } + }, + + + :default => [:nid, :name, :type, :size, :bridge] +} + +class VNShow + def initialize(vn) + @vn=vn + @table=ShowTable.new(ShowTableVN, :vn => @vn) + end + + def close + end + + def header_vn_small + scr_bold + scr_underline + puts @table.header_str + scr_restore + end + + def list_short(options=nil) + res=@vn.get + if options + @table.columns=options[:columns] if options[:columns] + end + + if res[0] + result=res + header_vn_small + res[1].each {|row| + res2=@vn.get_vn_attributes(row["oid"]) + if res2[0] + attributes=res2[1] + attributes.each {|a| + if %w{SIZE}.include? a["name"] + row[a["name"]]=a["value"] + end + } + end + } + puts @table.data_str(result[1], options) + result + else + result=res + end + end + + def top(options=nil) + delay=1 + delay=options[:delay] if options && options[:delay] + + result=nil + + begin + while true + scr_cls + scr_move(0,0) + result=list_short(options) + sleep delay + end + rescue Exception + end + result + end +end + +class OneVNParse < CommandParse + + COMMANDS_HELP=<<-EOT +Commands: + +* create (Creates a new virtual network) + onenetwork create