-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathopenvz-panel-api.php
44 lines (39 loc) · 1.37 KB
/
openvz-panel-api.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
class OpenVZPanelAPI
{
private static $_host = 'localhost';
private static $_context = null;
public static function init($user, $password, $host = 'localhost', $port = 3000)
{
self::$_host = $host.':'.$port;
self::$_context = stream_context_create(array(
'http' => array(
'header' => 'Authorization: Basic ' . base64_encode($user.':'.$password)
)
));
}
public static function getVirtualServers($sId)
{
$url = sprintf('http://%s/api/hardware_servers/virtual_servers?id=%s', self::$_host, $sId);
$result = file_get_contents($url, false, self::$_context);
//echo $result;
$doc = simplexml_load_string($result);
$res = array();
foreach ($doc->xpath('//virtual_server') as $node) {
$res []= array(
'identity' => (string)$node->identity,
'ip_address' => (string)$node->ip_address,
'host_name' => (string)$node->host_name,
'description' => (string)$node->description,
'ip_address' => (string)$node->ip_address,
);
// echo $node->ip_address."\n";
// echo $node->identity."\n";
// echo $node->host_name."\n";
// echo $node->description."\n";
// echo "=================\n";
//echo "server: $node\n";
}
return $res;
}
}