function onapp_CreateAccount($params) { global $_LANG; if (wrapper_check()) { return wrapper_check(); } $status = serviceStatus($params['serviceid']); serviceStatus($params['serviceid'], 'Active'); $service = get_service($params['serviceid']); $getvm = get_vm($params['serviceid']); serviceStatus($params['serviceid'], $status); if (isset($getvm->_id)) { return $_LANG["onappvmexist"]; } elseif ($params['domain'] == "") { return $_LANG["onapphostnamenotfound"]; } elseif (($params['configoption2'] == "" || count(explode(',', $params['configoption2'])) != 1) && !isset($service['os'])) { return $_LANG["onapptemplatenotone"]; } serviceStatus($params['serviceid'], 'Active'); $vm = create_vm($params['accountid'], $params['domain'], isset($service['os']) ? $service['os'] : $params['configoption2']); _ips_resolve_all($params['accountid']); serviceStatus($params['serviceid'], $status); if (!is_null($vm->error)) { return is_array($vm->error) ? $_LANG["onappcantcreatevm"] . "<br/>\n " . implode(', ', $vm->error) : $_LANG["onappcantcreatevm"] . $vm->error; } elseif (!is_null($vm->_obj->error)) { return is_array($vm->_obj->error) ? $_LANG["onappcantcreatevm"] . "<br/>\n " . implode(', ', $vm->_obj->error) : $_LANG["onappcantcreatevm"] . $vm->_obj->error; } return 'success'; }
/** * Action create virtual machine */ function _action_vm_create() { global $_ONAPPVARS, $_LANG; foreach (array('templateid', 'hostname') as $val) { $_ONAPPVARS[$val] = get_value($val); } /* TODO check template $templates = get_templates($_ONAPPVARS['service']['serverid'], $_ONAPPVARS['service']["configoption2"]); $os = $_ONAPPVARS['service']['os']; if (! is_null($os) && isset($templates[$os]) ) { $templates = array( $os => $templates[$os] ); }; */ if (isset($_ONAPPVARS['vm']->_id)) { $_ONAPPVARS['error'] = $_LANG["onappvmexist"]; } elseif (!isset($_ONAPPVARS['hostname']) || $_ONAPPVARS['hostname'] == "") { $_ONAPPVARS['error'] = $_LANG["onapphostnamenotfound"]; } elseif (!isset($_ONAPPVARS['templateid'])) { $_ONAPPVARS['error'] = $_LANG["onapptemplatenotset"]; } if (isset($_ONAPPVARS['error'])) { return false; } $_ONAPPVARS['vm'] = create_vm($_ONAPPVARS['id'], $_ONAPPVARS['hostname'], $_ONAPPVARS['templateid']); _ips_resolve_all($_ONAPPVARS['id']); return true; }