function BasicRESTCall($verb, $host, $port, $path, $extra_headers = array(), $params = array()) { include 'config.php'; $auth = get_auth_data(); $headers = array("Authorization:" . $auth); $headers = array_merge($headers, $extra_headers); if ($im_use_rest_ssl) { $protocol = 'https'; } else { $protocol = 'http'; } try { $res = Http::connect($host, $port, $protocol)->setHeaders($headers)->exec($verb, $path, $params); $status = $res->getStatus(); $output = $res->getOutput(); } catch (Exception $e) { $status = 600; $output = "Exception: " . $e->getMessage(); } $res = $output; if ($status != 200) { $res = 'Error: Code: ' . strval($status) . '. ' . GetErrorMessage($output); } return new Http_response($status, $res); }
function GetInfrastructureState($host, $port, $id) { $auth = get_auth_data(); $xmlrpc_client = new xmlrpc_client('/', $host, $port); $xmlrpc_msg = new xmlrpcmsg('GetInfrastructureState', array(new xmlrpcval($id, "string"), $auth)); $xmlrpc_resp = $xmlrpc_client->send($xmlrpc_msg); if ($xmlrpc_resp->faultCode()) { return 'Error: ' . $xmlrpc_resp->faultString(); } else { $res = php_xmlrpc_decode($xmlrpc_resp->value()); } $success = $res[0]; $state = $res[1]['state']; if ($success) { return $state; } else { return 'Error'; } }