-
Notifications
You must be signed in to change notification settings - Fork 101
Code Samples
This page is designed to help developers quickly get started using the openstack.net SDK. We will try and organize it so that each provider type is group together, however there may be some over lap. Also, we may forget something, or not have thought of a use case, so if you have any questions or suggestion, please reach out to us and we will try and get the examples included.
Since all service endpoints use the identity service for authentication and authorization, we will start here.
try
{
IIdentityProvider identityProvider = new Providers.Rackspace.IdentityProvider();
var userAccess = identityProvider.Authenticate(new RackspaceCloudIdentity
{
Username = "MyUserName",
Password = "MyPassword"
});
}
catch(ResponseException ex2)
{
// do something
}
try
{
IIdentityProvider identityProvider = new Providers.Rackspace.IdentityProvider();
var userAccess = identityProvider.Authenticate(new RackspaceCloudIdentity
{
Username = "MyUserName",
APIKey = "MyAPIKey"
});
}
catch(ResponseException ex2)
{
// do something
}
By default, the US (default) cloud instance is used (This is the instance for all Cloud Regions EXCEPT LON. All future cloud instances will be in US (default) the cloud region). If you need to target the LON cloud instance, you only need to pass in the CloudInstance.UK
try
{
IIdentityProvider identityProvider = new Providers.Rackspace.IdentityProvider();
var userAccess = identityProvider.Authenticate(new RackspaceCloudIdentity{
Username = "MyUserName",
Password = "MyPassword", CloudInstance =CloudInstance.UK});
}
catch(ResponseException ex2)
{
// do something
}
retrieving details about a user is reserved for either admins, or the requesting user retrieving their own information. The examples below show a user retrieving their own if, but we will have an examples of what administrative accounts can do.
try
{
IIdentityProvider identityProvider = new Providers.Rackspace.IdentityProvider();
var identity = new RackspaceCloudIdentity{ Username = "MyUserName", APIKey = "MyPassword" };
var userDetails = identityProvider.GetUserByName(identity, "MyUserName");
}
catch(ResponseException ex2)
{
// do something
}
try
{
IIdentityProvider identityProvider = new Providers.Rackspace.IdentityProvider();
var identity = new RackspaceCloudIdentity{ Username = "MyUserName", APIKey = "MyPassword" };
var userDetails = identityProvider.GetUser(identity, "UserId");
}
catch(ResponseException ex2)
{
// do something
}
These methods are only available to user that exist in the identity:user-admin role. If the requesting user does not exist in this role, a exception will be thrown.
try
{
IIdentityProvider identityProvider = new Providers.Rackspace.IdentityProvider();
var identity = new RackspaceCloudIdentity{ Username = "MyAdminUserName", APIKey = "MyAdminPassword" };
var userDetails = identityProvider.ListRoles(identity)
}
catch(ResponseException ex2)
{
// do something
}