{"id":147,"date":"2015-10-06T12:31:58","date_gmt":"2015-10-06T11:31:58","guid":{"rendered":"http:\/\/www.haxed.me.uk\/?p=147"},"modified":"2015-10-06T13:03:10","modified_gmt":"2015-10-06T12:03:10","slug":"creating-cloud-servers-using-php-opencloud-php","status":"publish","type":"post","link":"https:\/\/haxed.me.uk\/index.php\/2015\/10\/06\/creating-cloud-servers-using-php-opencloud-php\/","title":{"rendered":"Creating Cloud Servers using php-OpenCloud &#038; PHP"},"content":{"rendered":"<p>So, I thought after doing such a good job with Python that I would take my trouble to PHP. In this case I was running PHP at the commandline, but there is no reason you can&#8217;t use these in your web application. That&#8217;s one good thing about PHP, right there. It may be the only thing, but, it&#8217;s there!<\/p>\n<p>Step 1. Setup php-opencloud and php and composer<\/p>\n<pre>\r\nyum install php-opencloud php composer\r\n<\/pre>\n<p>Step 2. Setup composer requirement for php-opencloud (this is what is required for the vendor\/autoloader.php file)<\/p>\n<pre>\r\ncomposer require rackspace\/php-opencloud\r\n<\/pre>\n<p>Step 3. Configure opencloud<\/p>\n<pre>\r\n\r\nrequire 'vendor\/autoload.php';\r\n\r\nuse OpenCloud\\Rackspace;\r\n\r\n<\/pre>\n<p>Step 4. Configure Authorisation Section, including my username, apikey and REGION &#8216;LON&#8217;. For Dallas Forth Worth this would be DFW, etc.<\/p>\n<pre>\r\n# Authentication\r\n\r\n$client = new Rackspace(Rackspace::US_IDENTITY_ENDPOINT, array(\r\n    'username' => 'myusername',\r\n    'apiKey'   => '90ghaj4532asdsFgsdrghdi9832'\r\n));\r\n\r\n$service = $client->computeService(null, 'LON');\r\n\r\n<\/pre>\n<p>Step 5. Set Image to use to create server<\/p>\n<pre>\r\n$image = $service->image('d5bb9732-6468-4963-85b7-b6d1025cd0c7');\r\n<\/pre>\n<p>Step 6. Set Flavor to use to create server<\/p>\n<pre>\r\n$flavor = $service->flavor('general1-1');\r\n<\/pre>\n<p>Step 7. Proceed with server build<\/p>\n<pre>\r\n$server = $service->server();\r\n\r\n$response = $server->create(array(\r\n        'name'          =>      'Mein New Test Serven',\r\n        'imageId'       =>      $image->getId(),\r\n        'flavorId'      =>      $flavor->getId()\r\n));\r\n?>\r\n<\/pre>\n<p>Step 8. The completed php file will look something like :<\/p>\n<pre>\n?php<br \/>\nrequire 'vendor\/autoload.php';<\/p>\n<p>use OpenCloud\\Rackspace;<\/p>\n<p># Authentication<\/p>\n<p>$client = new Rackspace(Rackspace::US_IDENTITY_ENDPOINT, array(<br \/>\n    'username' => 'myusername',<br \/>\n    'apiKey'   => '90ghaj4532asdsFgsdrghdi9832'<br \/>\n));<\/p>\n<p>$service = $client->computeService(null, 'LON');<br \/>\n#<br \/>\n# Cloud Image<br \/>\n$image = $service->image('d5bb9732-6468-4963-85b7-b6d1025cd0c7');<br \/>\n#<br \/>\n# Cloud Server Flavor<br \/>\n$flavor = $service->flavor('general1-1');<\/p>\n<p># Proceed with Server Build<\/p>\n<p>$server = $service->server();<\/p>\n<p>$response = $server->create(array(<br \/>\n        'name'          =>      'Mein New Test Serven',<br \/>\n        'imageId'       =>      $image->getId(),<br \/>\n        'flavorId'      =>      $flavor->getId()<br \/>\n));<\/p>\n<p>?><\/p>\n","protected":false},"excerpt":{"rendered":"<p>So, I thought after doing such a good job with Python that I would take my trouble to PHP. In this case I was running PHP at the commandline, but there is no reason you can&#8217;t use these in your &hellip; <a href=\"https:\/\/haxed.me.uk\/index.php\/2015\/10\/06\/creating-cloud-servers-using-php-opencloud-php\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13,15,9,18],"tags":[],"class_list":["post-147","post","type-post","status-publish","format-standard","hentry","category-api","category-cloud","category-linux","category-php"],"_links":{"self":[{"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/posts\/147","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/comments?post=147"}],"version-history":[{"count":1,"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/posts\/147\/revisions"}],"predecessor-version":[{"id":156,"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/posts\/147\/revisions\/156"}],"wp:attachment":[{"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/media?parent=147"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/categories?post=147"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/tags?post=147"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}