Skip to content

Instantly share code, notes, and snippets.

@kaz29

kaz29/avail-zones-soap.php Secret

Created Feb 9, 2011
Embed
What would you like to do?
ニフティクラウドAPI利用サンプル AWSのチュートリアル<http://aws.amazon.com/articles/2433> を元にニフティクラウドAPI用に修正、追加したサンプルです。
<?php
// use the AWS-aware extension of PHP 5's SoapClient
require_once 'AWSforPHP/AWSSoapClient.php';
// use the Nifty Cloud WSDL
$wsdl = 'http://cloud.nifty.com/api/wsdl/NiftyCloud.wsdl';
$ec2 = new AWSSoapClient($wsdl);
// call a method
$result = $ec2->DescribeAvailabilityZones();
if ( !is_array($result->availabilityZoneInfo->item) ) {
echo "{$result->availabilityZoneInfo->item->zoneName}:";
echo "{$result->availabilityZoneInfo->item->zoneState}\n";
} else {
foreach ($result->availabilityZoneInfo->item as $z) {
echo "{$z->zoneName}: {$z->zoneState}\n";
}
}
<?php
require_once 'AWSforPHP/AWSSoapClient.php';
// use the Nifty Cloud WSDL
$wsdl = 'http://cloud.nifty.com/api/wsdl/NiftyCloud.wsdl';
$ec2 = new AWSSoapClient($wsdl);
// you should really check for SoapFaults here
$result = $ec2->DescribeInstances();
$items = $result->reservationSet->item;
// find our image id
$ami = 'CentOS 5.3 64bit Plain';
// this loop would be the same for a Tarzan response body
foreach ($items as $item) {
if (property_exists($item->instancesSet, 'item')) {
$instance = $item->instancesSet->item;
if (is_array($instance)) {
// multiple instances launched in this case
foreach ($instance as $i) {
if (property_exists($i, 'imageId') &&
$i->imageId == $ami) {
echo $i->dnsName."\n";
}
}
} elseif (is_object($instance)) {
if (property_exists($instance, 'imageId') &&
$instance->imageId == $ami) {
echo $instance->dnsName."\n";
}
}
}
}
<?php
// use the AWS-aware extension of PHP 5's SoapClient
require_once 'AWSforPHP/AWSSoapClient.php';
// use the Nifty Cloud WSDL
$wsdl = 'http://cloud.nifty.com/api/wsdl/NiftyCloud.wsdl';
$ec2 = new AWSSoapClient($wsdl);
// call a method
$param = array(
'instanceId' => 'apitest',
'disableApiTermination' => array(
'value' => false,
),
);
$result = $ec2->ModifyInstanceAttribute($param);
echo "return code = {$result->return}\n";
<?php
// use the AWS-aware extension of PHP 5's SoapClient
require_once 'AWSforPHP/AWSSoapClient.php';
// use the Nifty Cloud WSDL
$wsdl = 'http://cloud.nifty.com/api/wsdl/NiftyCloud.wsdl';
$ec2 = new AWSSoapClient($wsdl);
// call a method
$param = array(
'imageId' => 1,
'keyName' => 'default',
'instanceType' => 'mini',
'instanceId' => 'apitest',
'password' => null, // 使用する場合は、パスワードを設定してください
'minCount' => 1,
'maxCount' => 1,
'groupSet' => null,
);
$result = $ec2->RunInstances($param);
echo "RunInstances instanceId={$result->instancesSet->item->instanceId}\n";
echo "imageId:{$result->instancesSet->item->imageId}\n";
echo "instanceType:{$result->instancesSet->item->instanceType}\n";
<?php
// use the AWS-aware extension of PHP 5's SoapClient
require_once 'AWSforPHP/AWSSoapClient.php';
// use the Nifty Cloud WSDL
$wsdl = 'http://cloud.nifty.com/api/wsdl/NiftyCloud.wsdl';
$ec2 = new AWSSoapClient($wsdl);
// call a method
$param = array(
'instancesSet' => array(
'item' => array(
'instanceId' => 'apitest',
),
),
);
$result = $ec2->StartInstances($param);
echo "StartInstances instanceId={$result->instancesSet->item->instanceId}\n";
echo "currentState:{$result->instancesSet->item->currentState->name}\n";
echo "previousState:{$result->instancesSet->item->previousState->name}\n";
<?php
// use the AWS-aware extension of PHP 5's SoapClient
require_once 'AWSforPHP/AWSSoapClient.php';
// use the Nifty Cloud WSDL
$wsdl = 'http://cloud.nifty.com/api/wsdl/NiftyCloud.wsdl';
$ec2 = new AWSSoapClient($wsdl);
// call a method
$param = array(
'instancesSet' => array(
'item' => array(
'instanceId' => 'apitest',
'force' => false,
),
),
);
$result = $ec2->StopInstances($param);
echo "StopInstances instanceId={$result->instancesSet->item->instanceId}\n";
echo "currentState:{$result->instancesSet->item->currentState->name}\n";
echo "previousState:{$result->instancesSet->item->previousState->name}\n";
<?php
// use the AWS-aware extension of PHP 5's SoapClient
require_once 'AWSforPHP/AWSSoapClient.php';
// use the Nifty Cloud WSDL
$wsdl = 'http://cloud.nifty.com/api/wsdl/NiftyCloud.wsdl';
$ec2 = new AWSSoapClient($wsdl);
// call a method
$param = array(
'instancesSet' => array(
'item' => array(
'instanceId' => 'apitest',
),
),
);
$result = $ec2->TerminateInstances($param);
echo "TerminateInstances instanceId={$result->instancesSet->item->instanceId}\n";
echo "currentState:{$result->instancesSet->item->currentState->name}\n";
echo "previousState:{$result->instancesSet->item->previousState->name}\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.