{"id":144,"date":"2015-10-06T12:13:59","date_gmt":"2015-10-06T11:13:59","guid":{"rendered":"http:\/\/www.haxed.me.uk\/?p=144"},"modified":"2015-10-06T13:03:49","modified_gmt":"2015-10-06T12:03:49","slug":"creating-cloud-servers-using-python-pyrax","status":"publish","type":"post","link":"https:\/\/haxed.me.uk\/index.php\/2015\/10\/06\/creating-cloud-servers-using-python-pyrax\/","title":{"rendered":"Creating Cloud Servers using Python &#038; Pyrax"},"content":{"rendered":"<p>Today I have been playing around with some Python. This time using Pyrax and the Rackspace API. Here is how I did it. In my case I was using a CentOS 7 image.<\/p>\n<p>Step 1. Install pip and pyrax<\/p>\n<pre>\r\nyum install python-pip gcc make\r\npip install --upgrade pip\r\npip install pyrax\r\n<\/pre>\n<p>Step 2. Consult the docs! <\/p>\n<pre> https:\/\/developer.rackspace.com\/docs\/cloud-servers\/getting-started\/<\/pre>\n<p>Which has support for JAVA, PHP, Python, GO, RUBY, .NET and more.<\/p>\n<p>Step 3. Create your import directives<\/p>\n<pre>\r\nimport os\r\nimport pyrax\r\n<\/pre>\n<p>Step 3. Create your Authorisation <\/p>\n<pre>\r\n# Authentication Section\r\n# myusername is the mycloud username for the Rackspace User in portal\r\n# 99ghghghghgh12345a289872342 is the APIKEY, you need to replace these with the values you use for your account\r\npyrax.set_setting(\"identity_type\", \"rackspace\")\r\npyrax.set_default_region('LON')\r\npyrax.set_credentials('myusername', '99ghghghghgh12345a289872342')\r\n\r\ncs = pyrax.cloudservers\r\n\r\n<\/pre>\n<p>Step 4. Listing some flavours: It&#8217;s possible to list the different virtual machine flavors (HARDWARE TYPE)<\/p>\n<pre>\r\nflavor_list = cs.list_flavors()\r\nprint flavor_list\r\n<\/pre>\n<p>Step 5. Set the flavor we want to use to create a server. In this case we are spinning up a performance 1 server with 1GB RAM.<\/p>\n<pre>\r\nflavor = cs.flavors.get('performance1-1')\r\n<\/pre>\n<p>Step 6. Set the image we want to use to create the server. I have a custom image from a previous server I made I want to use.<\/p>\n<pre>\r\nimage = pyrax.images.get('d9aa9583-6468-4963-85b7-b6d1025cd0c7')\r\n<\/pre>\n<p>Step 7. Create the server with the parameters: name, image and flavor.<\/p>\n<pre>\r\nserver = cs.servers.create('testing1', image.id, flavor.id)\r\n<\/pre>\n<p>The complete file should look like:<\/p>\n<pre>\r\nimport os\r\nimport pyrax\r\n\r\n# Authentication Section\r\n\r\npyrax.set_setting(\"identity_type\", \"rackspace\")\r\npyrax.set_default_region('LON')\r\npyrax.set_credentials('adambull', '99ghghghghgh12345a289872342')\r\n\r\ncs = pyrax.cloudservers\r\n\r\nflavor_list = cs.list_flavors()\r\n\r\nflavor = cs.flavors.get('performance1-1')\r\n\r\nimage = pyrax.images.get('d9aa9583-6468-4963-85b7-b6d1025cd0c7')\r\nserver = cs.servers.create('testing1', image.id, flavor.id)\r\n\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Today I have been playing around with some Python. This time using Pyrax and the Rackspace API. Here is how I did it. In my case I was using a CentOS 7 image. Step 1. Install pip and pyrax yum &hellip; <a href=\"https:\/\/haxed.me.uk\/index.php\/2015\/10\/06\/creating-cloud-servers-using-python-pyrax\/\">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":[15,9,17],"tags":[],"class_list":["post-144","post","type-post","status-publish","format-standard","hentry","category-cloud","category-linux","category-python"],"_links":{"self":[{"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/posts\/144","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=144"}],"version-history":[{"count":1,"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/posts\/144\/revisions"}],"predecessor-version":[{"id":157,"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/posts\/144\/revisions\/157"}],"wp:attachment":[{"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/media?parent=144"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/categories?post=144"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/tags?post=144"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}