Created
December 23, 2015 09:37
-
-
Save hironobu-s/eb9413ff01739acf4264 to your computer and use it in GitHub Desktop.
php-opencloud example for ConoHa to create VM
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use OpenCloud\OpenStack; | |
use OpenCloud\Networking\Resource\NetworkInterface;; | |
use Guzzle\Http\Exception\ClientErrorResponseException; | |
use Guzzle\Http\Exception\BadResponseException; | |
use OpenCloud\Compute\Resource\Server; | |
require_once __DIR__ . '/vendor/autoload.php'; | |
class ConoHa extends Server { | |
protected $security_groups = []; | |
protected function createJson() { | |
$server = parent::createJson(); | |
// // adminPass | |
if($this->getProperty('adminPass') != null) { | |
$server->server->adminPass = $this->getProperty('adminPass'); | |
} | |
// security_groups | |
$security_groups = $this->getProperty('security_groups'); | |
if (count($security_groups) > 0) { | |
$server->server->security_groups = $security_groups; | |
} | |
return $server; | |
} | |
} | |
// private | |
$opts = [ | |
'username' => 'gncu********', | |
'password' => 'password', | |
'tenantName' => 'gnct*******', | |
]; | |
$client = new OpenStack('https://identity.tyo1.conoha.io/v2.0', $opts); | |
$compute = $client->computeService('Compute Service', 'tyo1'); | |
$create_opts = [ | |
'name' => 'test', | |
'imageId' => 'edc9457e-e4a8-4974-8217-c254d215b460', | |
'flavorId' => '7eea7469-0d85-4f82-8050-6ae742394681', | |
'adminPass' => '***********', | |
"security_groups" => [ | |
[ | |
"name" => "default", | |
], | |
[ | |
"name" => "gncs-ipv4-all", | |
], | |
[ | |
"name" => "gncs-ipv6-all", | |
] | |
], | |
]; | |
try { | |
$server = new ConoHa($compute); | |
$resp = $server->create($create_opts); | |
} catch(BadResponseException $ex) { | |
echo $ex->getResponse(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment