Skip to content

Rackspace Cloud Servers Code Samples

Alan Quillin edited this page Apr 25, 2014 · 5 revisions

Rackspace Cloud Servers Code Samples

Here we will provide samples for basic operations on CloudServersProvider.

ScreenShot

CloudServersProvider requries we pass in CloudIdentity. We can create CloudIdentity by passing any 2 combination Username/Password or Username/APIKey.

var cloudIdentity = new CloudIdentity() { Username = "username", Password = "password" };

or

var cloudIdentity = new CloudIdentity() { APIKey = "apikey", Username = "username" };

For more information on IdentityProvider

There are 2 ways to pass in the identity credentials to CloudBlockStorageProvider:

  1. In the constructor.
  2. Into each method individually.

Our samples below will assume the identity has been passed into the constructor.

Listing available server images

var cloudServers = new CloudServersProvider(cloudIdentity);
var images = cloudServers.ListImages();

This returns IEnumerable<SimpleServerImage> with each SimpleServerImage containing values for the image name and ID. The ID is later used when creating a server.

Listing available server flavors

var cloudServers = new CloudServersProvider(cloudIdentity);
var flavors = cloudServers.ListFlavors();

This returns IEnumerable<Flavor> with each Flavor containing the values for the flavor name and ID. The ID is later used when creating a server.

Listing available server flavors - with details

var cloudServers = new CloudServersProvider(cloudIdentity);
var flavors = cloudServers.ListFlavorsWithDetails();

This returns IEnumerable<FlavorDetails> with each FlavorDetails containing the values for the flavor name and ID. The ID is later used when creating a server. It also contains RAM, disk and vCPU values.

Creating a server in the account's default region

var cloudServers = new CloudServersProvider(cloudIdentity);
var server = cloudServers.CreateServer("server-name", "image-id", "flavor-id");

This will return a NewServer object which will contain the default admin password. This is the only time the password can be retrieved from the server without resetting it

Retrieve server details

var cloudServers = new CloudServersProvider(cloudIdentity);
var server = cloudServers.GetDetails("server-id");

This will return a Server object containing all details of the cloud server.

Deleting a server

var cloudServers = new CloudServersProvider(cloudIdentity);
var server = cloudServers.DeleteServer("server-id");

Returns a bool indicating if the action was successful