/* -------------------------------------------------------------------------- */ /* Copyright 2002-2009, 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. */ /* -------------------------------------------------------------------------- */ #include "Nebula.h" #include "VirtualMachinePool.h" #include int VirtualMachinePool::allocate ( int uid, const string& stemplate, int * oid, bool on_hold) { VirtualMachine * vm; char * error_msg; int rc; // Build a new Virtual Machine object vm = new VirtualMachine; if (on_hold == true) { vm->state = VirtualMachine::HOLD; } else { vm->state = VirtualMachine::PENDING; } vm->uid = uid; rc = vm->vm_template.parse(stemplate,&error_msg); if ( rc != 0 ) { ostringstream oss; oss << error_msg; Nebula::log("ONE", Log::ERROR, oss); free(error_msg); return -2; } // Insert the Object in the pool *oid = PoolSQL::allocate(vm); if ( *oid == -1 ) { return -1; } return 0; } /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ int VirtualMachinePool::get_running( vector& oids) { ostringstream os; string where; os << "state == " << VirtualMachine::ACTIVE << " and lcm_state == " << VirtualMachine::RUNNING; where = os.str(); return PoolSQL::search(oids,VirtualMachine::table,where); }; /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ int VirtualMachinePool::get_pending( vector& oids) { ostringstream os; string where; os << "state == " << VirtualMachine::PENDING; where = os.str(); return PoolSQL::search(oids,VirtualMachine::table,where); };