feldsam-inc/one-php

OpenNebula XML-RPC API 绑定

1.4.2 2023-02-21 17:39 UTC

This package is auto-updated.

Last update: 2024-09-21 21:21:58 UTC


README

Latest Stable Version Total Downloads License

此库为您提供了 XML-RPC 客户端,它将 XML 响应解析为数组。
您可以使用点符号遍历它。
我们从 api.rst 文件中生成了所有公共方法。

检查带有文档块的示例方法。更多信息,请查看 src/One.php

/**
 * Retrieves information for all or part of the VMs in the pool.
 *
 * @param int $a Filter flag  -4: Resources belonging to the user's primary group  -3: Resources belonging to the user  -2: All resources  -1: Resources belonging to the user and any of his groups * >= 0: UID User's Resources
 * @param int $b When the next parameter is >= -1 this is the Range start ID. Can be -1. For smaller values this is the offset used for pagination.
 * @param int $c For values >= -1 this is the Range end ID. Can be -1 to get until the last ID. For values < -1 this is the page size used for pagination.
 * @param int $d VM state to filter by.
 * @param string $e Filter in KEY=VALUE format.
 * @return \One\Resource
 */
public function vmpoolInfoextended(int $a, int $b, int $c, int $d, string $e) {
    return $this->makeCall('one.vmpool.infoextended', $a, $b, $c, $d, $e);
}

您的 IDE 将使用这些文档块,您可以在代码中方便地查看文档。无需查看官方文档页面。

示例

连接到 API,创建客户端实例

$client = new \One\One('http://{IP}:2633/RPC2', 'username:password');

调用一些方法并获取响应 - \One\Resource 类实例

try {
    $response = $client->vmpoolInfoextended(-1, -1, -1, -1, '');
} catch (Exception $e) {
    echo $e->getMessage(), "\n";
    exit(1);
}

处理响应
\One\Resource 类实例是对 adbario/php-dot-notation 的包装

$vms = $response->get('VM');

echo "Total number of VMs is " , $vms->count() , "\n";

foreach($vms->all() as $vm) {
    if (!$vm->isEmpty('USER_TEMPLATE.LABELS')) {
        echo "VM ID ", $vm->get('ID'), " has label(s): ", $vm->get('USER_TEMPLATE.LABELS'), "\n";
    } else {
        echo "VM ID ", $vm->get('ID'), " doesn't have any labels.\n";
    }
}

按特定子键索引结果数组

$vms = $response->getIndexedBy('ID', 'VM');
// get VM with ID 2403
$vm = $vms->get(2403);

处理 ACL 规则

理解 ACL 规则

// user readable acl rule
$aclRule = '@131 DATASTORE/%100 USE #0';

// parse rule to hex numbers
list($user, $resource, $rights, $zone) = \One\Acl::parseRule($aclRule);

// use hex in api call
$client->aclAddrule($user, $resource, $rights, $zone);

开发

要贡献错误补丁或新功能,您可以使用 GitHub Pull Request 模型。假设代码和文档是在 Apache License 2.0 许可下贡献的。

更多信息

作者

支持

FeldHost™ 作为 OpenNebula 贡献者 提供 OpenNebula 云解决方案的设计、实施、运营和管理。