Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

...

The .NET SDK for CloudStack provides a client side library to allow Microsoft .NET programs to access the CloudStack REST APIs.

Background

Wiki MarkupThe CloudStack API is loosely based on the REST architecture \ [2\]. Whilst providing a good deal of flexibility for a developer, it also has the potential to impose a heavy cost in that the developer is responsible for marshalling all the request arguments into the required format; correctly signing the request; dealing with asynchronous methods; handling fault conditions and parsing the response fields.

The .NET SDK for CloudStack addresses these issues for developers in the Microsoft .NET environment by concealing all of these implementation details underneath a high level request/response API that is directly accessible from all .NET supported languages.

...

Code Block
titleClient.cs
borderStylesolid
public class Client : IDisposable

{

  public Client (Uri serverUri, string apiKey, SecureString secretKey) { … }
   …

}

The server Uri, apiKey and secretKey are securely cached within the client session object and used to sign each request that is sent to the CloudStack server.  The session class will securely delete the secret key during object disposal.

...

Code Block
titleICloudStackSDK.cs
borderStylesolid
interface ICloudStackSDK

{

    …
    AttachVolumeResponse attachVolume (AttachVolumeRequest request);

    …
};

The Request and Response classes have the expected properties, for example:

Code Block
titleAttachVolumeRequest.cs
borderStylesolid
public class AttachVolumeRequest : APIRequest

{

    public string Id { … }

    public string VirtualMachineId { … }

    public string DeviceId { … }

}

So a typical usage of the strongly typed API of the .NET SDK for CloudStack might look like:

Code Block
titleUsageExample.cs
borderStylesolid
Client client = new Client(serverUri, myApiKey, mySecretKey);

AttachVolumeRequest request = new AttachVolumeRequest ()
{
    Id = myVolumeId,
    VirtualMachineId = myVmId,
    DeviceId = “/dev/xvdc”
};
AttachVolumeResponse response = client.attachVolume(request);

…

...

Code Block
titleUsageExample.cs
borderStylesolid
Client client = new Client(serverUri, myApiKey, mySecretKey);

APIRequest request = new APIRequest (“listaccounts”);

request.Parameters\[“accounttype”\] = “admin”;

APIResponse response = client.SendRequest(request);

Console.Writeline (“Raw XML response: {0}”, response.XmlResponse);

...