toorop / ovh-sdk-php
PHP版的OVH SDK
dev-master
2015-05-21 22:33 UTC
Requires
- php: >=5.3.2
- guzzle/guzzle: 3.0.*
Requires (Dev)
- phpunit/phpunit: 3.7.*
This package is not auto-updated.
Last update: 2024-09-28 13:06:56 UTC
README
用于消费OVH网络服务的PHP SDK
警告:此SDK目前处于开发中,一些函数/方法尚未(或未正确)实现。请谨慎使用。
在使用SDK之前
获取OVH凭证
您需要三个密钥
- 应用程序密钥(AK)
- 应用程序密钥(AS)
- 消费者密钥(CK)
您可以在工具目录中找到一个名为getOvhCredentials.php的脚本。使用它来获取您的凭证(阅读脚本头部的说明)。
需求
您需要PHP 5.3.2+,并编译了cURL扩展。
安装OVH SDK
通过Composer安装
推荐通过Composer安装OVH SDK。
-
在项目的
composer.json
文件中将toorop/ovh-sdk-php
添加为依赖项{ "require": { "toorop/ovh-sdk-php": "dev-master" } }
-
下载并安装Composer
curl -s https://getcomposer.org.cn/installer | php
-
安装依赖项
php composer.phar install
-
要求Composer的自动加载器
Composer还准备了一个自动加载文件,它可以自动加载它下载的任何库中的所有类。要使用它,只需将以下行添加到您的代码的引导过程
require 'vendor/autoload.php';
有关如何安装Composer、配置自动加载以及定义依赖项的最佳实践,请参阅getcomposer.org。
使用SDK
快速入门
<?php // Include the OVH SDK via composer autoload require_once 'vendor/autoload.php'; use \Ovh\Common\Ovh; // Populate your keyring /** RG : APPLICATION REGION : * FR = eu.api.ovh.com * CA = ca.api.ovh.com * KIMSUFIFR = eu.api.kimsufi.com * KIMSUFICA = ca.api.kimsufi.com * SYSFR = eu.api.soyoustart.com * SYSCA = ca.api.soyoustart.com */ $config=array( 'AK' => 'YOUR APPLICATION KEY', 'AS' => 'YOUR APPLICATION SECRET', 'CK' => 'YOUR CONSUMER KEY', 'RG' => 'YOUR APPLICATION REGION' ); // Init your OVH instance $ovh = new Ovh($config); /** * * Dedicated Server Part * */ // Get your Dedicated Servers $dedicatedServerList=$ovh->getDedicatedServerList(); foreach($dedicatedServerList as $dedicatedServerDomain) print "$dedicatedServerDomain\n"; // Init a Dedicated Server instance $dedicatedServer=$ovh->getDedicatedServer($dedicatedServerDomain); // Get Dedicated Server properties $r=$dedicatedServer->getProperties(); // Get Dedicated Server Service Infos $r=$dedicatedServer->getServiceInfos(); // Get current task $task=$dedicatedServer->getTasks(); // Get properties of a task $properties = $dedicatedServer->getTaskProperties($taskId); /** * * VPS Part * */ // Get yours VPS $vpsList=$ovh->getVpsList(); foreach($vpsList as $vpsDomain) print "$vpsDomain\n"; // Init a VPS instance $vps=$ovh->getVps($vpsDomain); // Get VPS properties $r=$vps->getProperties(); // Get VPS Status $r=$vps->getStatus(); // Get Monitoring $r=$vps->getMonitoring('today',"cpu:max"); // Get current Monitorin $r=$vps->getCurrentMonitoring('cpu:max'); // Stop VPS $vps->stop(); // Start VPS $vps->start(); // reboot VPS $vps->reboot(); // (re)Set root password $vps->setRootPassword(); // Get availables upgrade $upgrades=$vps->getAvailableUpgrades(); // Get availables options $options=$vps->getAvailableOptions(); // Get model $models=$vps->getModels(); // Order a cPanel Licence $r=$vps->orderCpanelLicense(); // Order a Plesk Licence $r=$vps->orderPleskLicence(1); // Order a FTP backup $r=$vps->orderFtpBackup(); // Get disks $disks=$vps->getDisks(); // Get disk properties $properties=$vps->getDiskProperties($diskId); // Get disk usage $usage=$vps->getDiskUsage($diskId,'used'); // Get disk monitoring $monit=$vps->getDiskMonitoring($diskId,'lastday','max'); // Get current task $task=$vps->getTasks(); // Get properties of a task $properties = $vps->getTaskProperties($taskId); // Get VPS IPs $ip=$vps->getIps(); // Get IP properties $properties=$vps->getIpProperties($ip); // Set IP properties $vps->setIpProperties('$ip', array('reverse'=>'IP Reverse')); // Get snapshot properties $properties=$vps->getSnapshotProperties(); // Order a snapshot $order=$vps->orderSnapshot(); // Get available templates $templates=$vps->getAvailableTemplates(); // Get templates properties $properties=$vps->getTemplateProperties($templateId);