/** * Method to check if a network is a cloud * * @return bool True if network is a cloud */ public function isCloud() { if (in_array($this->type, listClouds())) { return True; } else { return False; } }
/** * Function to stop a node. * * @param Array $p Parameters * @return int 0 means ok */ function addNetwork($p) { if (!isset($p['name']) || !isset($p['type'])) { // Missing mandatory parameters error_log('ERROR: ' . $GLOBALS['messages'][80021]); return 80021; } switch ($p['type']) { default: if (in_array($p['type'], listClouds())) { // Cloud already exists } else { if (preg_match('/^pnet[0-9]+$/', $p['type'])) { // Cloud does not exist error_log('ERROR: ' . $GLOBALS['messages'][80056]); return 80056; } else { // Should not be here error_log('ERROR: ' . $GLOBALS['messages'][80020]); return 80020; } } break; case 'bridge': if (!isInterface($p['name'])) { // Interface does not exist -> create bridge return addBridge($p['name']); } else { if (isBridge($p['name'])) { // Bridge already present return 0; } else { if (isOvs($p['name'])) { // OVS exists -> delete it and add bridge $rc = delOvs($p['name']); if ($rc == 0) { // OVS deleted, create the bridge return addBridge($p['name']); } else { // Failed to delete OVS return $rc; } } else { // Non bridge/OVS interface exist -> cannot create error_log('ERROR: ' . $GLOBALS['messages'][80022]); return 80022; } } } break; case 'ovs': if (!isInterface($p['name'])) { // Interface does not exist -> create OVS return addOvs($p['name']); } else { if (isOvs($p['name'])) { // OVS already present return 0; } else { if (isBridge($p['name'])) { // Bridge exists -> delete it and add OVS $rc = delBridge($p['name']); if ($rc == 0) { // Bridge deleted, create the OVS return addOvs($p['name']); } else { // Failed to delete Bridge return $rc; } } else { // Non bridge/OVS interface exist -> cannot create error_log('ERROR: ' . $GLOBALS['messages'][80022]); return 80022; } } } break; } return 0; }