本文整理汇总了C#中CloudServersProvider类的典型用法代码示例。如果您正苦于以下问题:C# CloudServersProvider类的具体用法?C# CloudServersProvider怎么用?C# CloudServersProvider使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CloudServersProvider类属于命名空间,在下文中一共展示了CloudServersProvider类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateServerNodeAsync
private async Task<CloudServersServerNode> CreateServerNodeAsync(CloudServersProvider provider, Server server, FlavorDetails[] flavors, ServerImage[] images)
{
FlavorDetails flavor = flavors.FirstOrDefault(i => server.Flavor != null && string.Equals(server.Flavor.Id, i.Id, StringComparison.OrdinalIgnoreCase));
try
{
if (flavor == null && server.Flavor != null)
flavor = await Task.Run(() => provider.GetFlavor(server.Flavor.Id));
}
catch (ResponseException)
{
// ignore
flavor = null;
}
ServerImage image = images.FirstOrDefault(i => server.Image != null && string.Equals(server.Image.Id, i.Id, StringComparison.OrdinalIgnoreCase));
try
{
if (image == null && server.Image != null)
image = await Task.Run(() => provider.GetImage(server.Image.Id));
}
catch (ResponseException)
{
// ignore
image = null;
}
return new CloudServersServerNode(provider, server, flavor, image);
}
示例2: TestInitialize
public void TestInitialize()
{
IComputeProvider provider = new CloudServersProvider(Bootstrapper.Settings.TestIdentity);
Server server = provider.GetDetails(_server.Id);
if (server.Status != ServerState.Active)
Assert.Inconclusive("Could not run test because the server is in the '{0}' state (expected '{1}').", server.Status, ServerState.Active);
}
示例3: ClassInitialize
public static void ClassInitialize(TestContext testContext)
{
IComputeProvider provider = new CloudServersProvider(Bootstrapper.Settings.TestIdentity);
string serverName = UserComputeTests.UnitTestServerPrefix + Path.GetRandomFileName();
Flavor flavor = UserComputeTests.ListAllFlavorsWithDetails(provider).OrderBy(i => i.RAMInMB).ThenBy(i => i.DiskSizeInGB).FirstOrDefault();
if (flavor == null)
Assert.Inconclusive("Couldn't find a flavor to use for the test server.");
SimpleServerImage[] images = UserComputeTests.ListAllImages(provider).ToArray();
SimpleServerImage image = images.FirstOrDefault(i => i.Name.IndexOf("CentOS 6.0", StringComparison.OrdinalIgnoreCase) >= 0);
if (image == null)
Assert.Inconclusive("Couldn't find the CentOS 6.0 image to use for the test server.");
Stopwatch timer = Stopwatch.StartNew();
Console.Write("Creating server for image {0}...", image.Name);
NewServer server = provider.CreateServer(serverName, image.Id, flavor.Id);
Assert.IsNotNull(server);
Assert.IsFalse(string.IsNullOrEmpty(server.Id));
_password = server.AdminPassword;
_server = provider.WaitForServerActive(server.Id);
Assert.IsNotNull(_server);
Assert.AreEqual(server.Id, _server.Id);
Assert.AreEqual(ServerState.Active, _server.Status);
Console.WriteLine("done. {0} seconds", timer.Elapsed.TotalSeconds);
}
示例4: Should_Create_A_New_Complex_Server_In_DFW
public void Should_Create_A_New_Complex_Server_In_DFW()
{
var provider = new CloudServersProvider(_testIdentity);
_testServer2 = provider.CreateServer("net-sdk-test-server2", "d531a2dd-7ae9-4407-bb5a-e5ea03303d98", "2", metadata: new Metadata{{"Key1", "Value1"}, {"Key2", "Value2"}}, attachToPublicNetwork: true, attachToServiceNetwork: true);
Assert.IsNotNull(_testServer2);
Assert.IsNotNull(_testServer2.Id);
}
示例5: Should_Create_A_New_Server_In_DFW
public void Should_Create_A_New_Server_In_DFW()
{
var provider = new CloudServersProvider(_testIdentity);
_testServer = provider.CreateServer("net-sdk-test-server", "d531a2dd-7ae9-4407-bb5a-e5ea03303d98", "2");
Assert.IsNotNull(_testServer);
Assert.IsNotNull(_testServer.Id);
}
示例6: Should_Create_A_New_Complex_Server_In_DFW
public void Should_Create_A_New_Complex_Server_In_DFW()
{
var provider = new CloudServersProvider(_testIdentity);
_newTestServer2 = provider.CreateServer("net-sdk-test-server2", _initImage.Id, _initFlavor.Id, metadata: new Metadata { { "Key1", "Value1" }, { "Key2", "Value2" } }, attachToPublicNetwork: true, attachToServiceNetwork: true);
Assert.IsNotNull(_newTestServer2);
Assert.IsNotNull(_newTestServer2.Id);
}
示例7: Should_Create_A_New_Server_In_DFW
public void Should_Create_A_New_Server_In_DFW()
{
var provider = new CloudServersProvider(_testIdentity);
_newTestServer = provider.CreateServer("net-sdk-test-server", _initImage.Id, _initFlavor.Id);
Assert.IsNotNull(_newTestServer);
Assert.IsNotNull(_newTestServer.Id);
}
示例8: Should_Wait_Until_Server_Becomes_Active_Or_A_Maximum_Of_10_Minutes
public void Should_Wait_Until_Server_Becomes_Active_Or_A_Maximum_Of_10_Minutes()
{
var provider = new CloudServersProvider(_testIdentity);
var serverDetails = provider.WaitForServerActive(_testServer.Id);
Assert.IsNotNull(serverDetails);
Assert.AreEqual("ACTIVE", serverDetails.Status);
}
示例9: Init
public static void Init(TestContext context)
{
_testIdentity = new RackspaceCloudIdentity(Bootstrapper.Settings.TestIdentity);
var provider = new CloudServersProvider(_testIdentity);
_initImage = provider.ListImages(imageName: "CentOS 6.3").First();
_initFlavor = provider.ListFlavors().OrderBy(f => f.Id).First();
}
示例10: Main
public static void Main(string[] args)
{
if (args.Length < 2 || args.Length > 3)
{
Console.WriteLine("Usage: {0} username api_key [region (US|UK)]", Environment.CommandLine);
Environment.Exit(1);
}
RackspaceImpersonationIdentity auth = new RackspaceImpersonationIdentity();
auth.Username = args[0];
auth.APIKey = args[1];
if (args.Length == 3)
{
if (args[2] != "UK" && args[2] != "US")
{
Console.WriteLine("region must be either US or UK", Environment.CommandLine);
Environment.Exit(1);
}
switch (args[2])
{
case "UK": { auth.CloudInstance = CloudInstance.UK; }; break;
case "US": { auth.CloudInstance = CloudInstance.Default; }; break;
}
}
else
{
auth.CloudInstance = CloudInstance.Default;
}
try
{
IIdentityProvider identityProvider = new CloudIdentityProvider();
var userAccess = identityProvider.Authenticate(auth);
}
catch (ResponseException ex2)
{
Console.WriteLine("Authentication failed with the following message: {0}", ex2.Message);
Environment.Exit(1);
}
var cloudServers = new CloudServersProvider(auth);
var servers = cloudServers.ListServers();
foreach (Server serv in servers)
{
var date = System.DateTime.Now;
var success = serv.CreateSnapshot(serv.Name + "_" + date.Year + "-" + date.Month + "-" + date.Day);
if (success)
{
Console.WriteLine("Image for server {0} has been created successfully.", serv.Name);
}
else
{
Console.WriteLine("Image for server {0} could not be created.", serv.Name);
}
}
}
示例11: ClassCleanup
public static void ClassCleanup()
{
IComputeProvider provider = new CloudServersProvider(Bootstrapper.Settings.TestIdentity);
Stopwatch timer = Stopwatch.StartNew();
Console.Write(" Deleting...");
bool deleted = provider.DeleteServer(_server.Id);
Assert.IsTrue(deleted);
provider.WaitForServerDeleted(_server.Id);
Console.Write("done. {0} seconds", timer.Elapsed.TotalSeconds);
}
示例12: CloudServersServerNode
public CloudServersServerNode(CloudServersProvider provider, Server server, FlavorDetails flavor, ServerImage image)
{
if (provider == null)
throw new ArgumentNullException("provider");
if (server == null)
throw new ArgumentNullException("server");
this._provider = provider;
this._server = server;
this._flavor = flavor;
this._image = image;
}
示例13: Init
public static void Init(TestContext context)
{
_testIdentity = new RackspaceCloudIdentity(Bootstrapper.Settings.TestIdentity);
var provider = new CloudServersProvider(_testIdentity);
_initImage = provider.ListImages(imageName: "CentOS 6.3").First();
_initFlavor = provider.ListFlavors().OrderBy(f => f.Id).First();
var netProvider = new CloudNetworksProvider(_testIdentity);
var networks = netProvider.ListNetworks();
_testNetwork = networks.FirstOrDefault(n => !n.Label.Equals("public") && !n.Label.Equals("private"));
}
示例14: Run
public async Task Run(string username, string apiKey, string region)
{
// Configure authentication
var identity = new CloudIdentity
{
Username = username,
APIKey = apiKey
};
var identityService = new CloudIdentityProvider(identity);
var result = identityService.Authenticate();
var serverService = new CloudServersProvider(identity, region, null, null);
var rackConnectService = new RackConnectService(identityService, region);
// Create a cloud server on your hybrid network
Console.WriteLine($"Looking up your RackConnect network in {region}...");
var networks = await rackConnectService.ListNetworksAsync();
var network = networks.FirstOrDefault();
if (network == null)
throw new Exception($"You do not have a Hybrid Cloud / RackConnect network configured in the {region} which is required to run this sample.");
Console.WriteLine("Creating sample cloud server... ");
// Ubuntu 14.04 LTS (Trusty Tahr) (PVHVM)
const string ubuntuImageId = "09de0a66-3156-48b4-90a5-1cf25a905207";
// 512MB Standard Instance
const string standardFlavorId = "2";
var requestedServer = serverService.CreateServer("sample", ubuntuImageId, standardFlavorId,
networks: new string[] {network.Id});
serverService.WaitForServerActive(requestedServer.Id);
Console.WriteLine("Allocating a public IP address...");
var ip = await rackConnectService.CreatePublicIPAsync(
new PublicIPCreateDefinition {ShouldRetain = true});
await ip.WaitUntilActiveAsync();
Console.WriteLine($"Acquired {ip.PublicIPv4Address}!");
Console.WriteLine("Assigning the public IP to the sample cloud server...");
await ip.AssignAsync(requestedServer.Id);
await ip.WaitUntilActiveAsync();
Console.WriteLine("Deleting sample cloud server...");
serverService.DeleteServer(requestedServer.Id);
Console.WriteLine("Deallocating the public IP address...");
await ip.DeleteAsync();
}
示例15: Main
static void Main(string[] args)
{
var identity = new CloudIdentity
{
Username = Environment.GetEnvironmentVariable("OPENSTACKNET_USER"),
APIKey = Environment.GetEnvironmentVariable("OPENSTACKNET_APIKEY")
};
var authProvider = new CloudIdentityProvider(identity);
Console.WriteLine("--- Servers ---");
var serversProvider = new CloudServersProvider(identity);
var servers = serversProvider.ListServers();
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("Id\t\t\t\t\tName");
Console.ResetColor();
Console.WriteLine();
foreach (var server in servers)
{
Console.WriteLine("{0}\t{1}", server.Id, server.Name);
}
Console.WriteLine();
Console.WriteLine("--- CDN Services ---");
var cdnService = new ContentDeliveryNetworkService(authProvider, "DFW");
var cdns = cdnService.ListServices();
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("Id\t\t\t\t\tName");
Console.ResetColor();
Console.WriteLine();
foreach (var cdn in cdns)
{
Console.WriteLine("{0}\t{1}", cdn.Id, cdn.Name);
}
Console.WriteLine();
Console.WriteLine("Press any key to exit...");
Console.ReadLine();
}