-
Notifications
You must be signed in to change notification settings - Fork 27
Slicehost
lux edited this page Sep 13, 2010
·
1 revision
Initially I created this library to make it easier for me to work with the Slicehost API, which is implemented via ActiveResource. Here’s how I setup my code to work with it.
Here is the basic setup code for creating all of the Slicehost API classes locally. Make sure to change APIKEY to your actual API key.
<?php require_once ('ActiveResource.php'); define ('SLICEURL', 'https://[email protected]/'); class Slice extends ActiveResource { var $site = SLICEURL; } class Zone extends ActiveResource { var $site = SLICEURL; } class Record extends ActiveResource { var $site = SLICEURL; } class Flavor extends ActiveResource { var $site = SLICEURL; } class Image extends ActiveResource { var $site = SLICEURL; } class Backup extends ActiveResource { var $site = SLICEURL; } ?>
Now you can include the above script and start using the Slicehost API, for example:
<?php require_once ('Slicehost.php'); // create a new slice $slice = new Slice (array ( 'image_id' => 1, 'flavor_id' => 1, 'name' => 'example.com', )); $s = $slice->save (); // get some info about the slice $ip_address = (string) $s->addresses->address; $root_password = $s->root_password; $slice_id = $s->id; // create a new dns zone for the slice $zone = new Zone (array ('origin' => 'example.com', 'ttl' => 86400)); $z = $zone->save (); // add some records to the new zone $record = new Record (array ( 'record_type' => ''A', 'zone_id' => $z->id, 'name' => 'example.com', 'data' => $ip_address, 'ttl' => '86400, )); $record->save (); $record = new Record (array ( 'record_type' => ''A', 'zone_id' => $z->id, 'name' => 'www', 'data' => $ip_address, 'ttl' => '86400, )); $record->save (); // rebooting a slice $slice = new Slice; $slice->find ($slice_id); $slice->put ('reboot'); ?>